本文整理汇总了Python中asdf.AsdfFile.tree方法的典型用法代码示例。如果您正苦于以下问题:Python AsdfFile.tree方法的具体用法?Python AsdfFile.tree怎么用?Python AsdfFile.tree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asdf.AsdfFile
的用法示例。
在下文中一共展示了AsdfFile.tree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ifu_slicer2asdf
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree [as 别名]
def ifu_slicer2asdf(ifuslicer, outname):
"""
Create an asdf reference file with the MSA description.
ifu_slicer2asdf("IFU_slicer.sgd", "ifu_slicer.asdf")
Parameters
----------
ifuslicer : str
A fits file with the IFU slicer description
outname : str
Name of output ASDF file.
"""
ref_kw = common_reference_file_keywords("IFUSLICER", "NIRSPEC IFU SLICER description - CDP4")
f = fits.open(ifuslicer)
tree = ref_kw.copy()
data = f[1].data
header = f[1].header
shiftx = models.Shift(header['XREF'], name='ifu_slicer_xref')
shifty = models.Shift(header['YREF'], name='ifu_slicer_yref')
rot = models.Rotation2D(header['ROT'], name='ifu_slicer_rot')
model = rot | shiftx & shifty
tree['model'] = model
tree['data'] = f[1].data
f.close()
fasdf = AsdfFile()
fasdf.tree = tree
fasdf.write_to(outname)
return fasdf
示例2: prism2asdf
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree [as 别名]
def prism2asdf(prifile, tiltyfile, tiltxfile, outname):
"""Create a NIRSPEC prism disperser reference file in ASDF format.
Combine information stored in disperser_G?.dis and disperser_G?_TiltY.gtp
files delievred by the IDT.
Parameters
----------
prifile : list or str
File with primary information for the PRSIM
tiltyfile : str
File with tilt_Y data, e.g. disperser_PRISM_TiltY.gtp.
tiltxfile: str
File with tilt_x data, e.g. disperser_PRISM_TiltX.gtp.
outname : str
Name of output ASDF file.
Returns
-------
fasdf : asdf.AsdfFile
"""
params = common_reference_file_keywords("PRISM", "NIRSPEC PRISM Model")
flist = [prifile, tiltyfile, tiltxfile]
# translate the files
for fname in flist:
try:
refparams = dict_from_file(fname)
except:
print("Disperser file was not converted.")
raise
pdict = {}
coeffs = {}
parts = fname.lower().split(".")[0]
ref = str("_".join(parts.split("_")[1:]))
if "pri" not in fname:
try:
for i, c in enumerate(refparams['CoeffsTemperature00']):
coeffs['c' + str(i)] = c
pdict['tilt_model'] = models.Polynomial1D(len(coeffs)-1, **coeffs)
del refparams['CoeffsTemperature00']
except KeyError:
print("Missing CoeffsTemperature in {0}".format(fname))
raise
# store the rest of the keys
for k, v in refparams.items():
pdict[k] = v
print(pdict)
params[ref] = pdict
fasdf = AsdfFile()
fasdf.tree = params
fasdf.write_to(outname)
return fasdf
示例3: ifu_slicer2asdf
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree [as 别名]
def ifu_slicer2asdf(ifuslicer, outname, ref_kw):
"""
Create an asdf reference file with the MSA description.
ifu_slicer2asdf("IFU_slicer.sgd", "ifu_slicer.asdf")
Parameters
----------
ifuslicer : str
A fits file with the IFU slicer description
outname : str
Name of output ASDF file.
"""
f = fits.open(ifuslicer)
tree = ref_kw.copy()
data = f[1].data
header = f[1].header
shiftx = models.Shift(header['XREF'], name='ifu_slicer_xref')
shifty = models.Shift(header['YREF'], name='ifu_slicer_yref')
rot = models.Rotation2D(header['ROT'], name='ifu_slicer_rot')
model = rot | shiftx & shifty
tree['model'] = model
tree['data'] = f[1].data
f.close()
fasdf = AsdfFile()
fasdf.tree = tree
fasdf.add_history_entry("Build 6")
fasdf.write_to(outname)
return fasdf
示例4: ifupost2asdf
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree [as 别名]
def ifupost2asdf(ifupost_files, outname):
"""
Create a reference file of type ``ifupost`` .
Combines all IDT ``IFU-POST`` reference files in one ASDF file.
forward direction : MSA to Collimator
backward_direction: Collimator to MSA
Parameters
----------
ifupost_files : list
Names of all ``IFU-POST`` IDT reference files
outname : str
Name of output ``ASDF`` file
"""
ref_kw = common_reference_file_keywords("IFUPOST", "NIRSPEC IFU-POST transforms - CDP4")
fa = AsdfFile()
fa.tree = ref_kw
for fifu in ifupost_files:
n = int((fifu.split('IFU-POST_')[1]).split('.pcf')[0])
fa.tree[n] = {}
with open(fifu) as f:
lines = [l.strip() for l in f.readlines()]
factors = lines[lines.index('*Factor 2') + 1].split()
rotation_angle = float(lines[lines.index('*Rotation') + 1])
input_rot_center = lines[lines.index('*InputRotationCentre 2') + 1].split()
output_rot_center = lines[lines.index('*OutputRotationCentre 2') + 1].split()
linear_sky2det = homothetic_sky2det(input_rot_center, rotation_angle, factors, output_rot_center)
degree = int(lines[lines.index('*FitOrder') + 1])
xcoeff_index = lines.index('*xForwardCoefficients 21 2')
xlines = lines[xcoeff_index + 1: xcoeff_index + 22]
xcoeff_forward = coeffs_from_pcf(degree, xlines)
x_poly_forward = models.Polynomial2D(degree, name='x_poly_forward', **xcoeff_forward)
ycoeff_index = lines.index('*yForwardCoefficients 21 2')
ycoeff_forward = coeffs_from_pcf(degree, lines[ycoeff_index + 1: ycoeff_index + 22])
y_poly_forward = models.Polynomial2D(degree, name='y_poly_forward', **ycoeff_forward)
xcoeff_index = lines.index('*xBackwardCoefficients 21 2')
xcoeff_backward = coeffs_from_pcf(degree, lines[xcoeff_index + 1: xcoeff_index + 22])
x_poly_backward = models.Polynomial2D(degree, name='x_poly_backward', **xcoeff_backward)
ycoeff_index = lines.index('*yBackwardCoefficients 21 2')
ycoeff_backward = coeffs_from_pcf(degree, lines[ycoeff_index + 1: ycoeff_index + 22])
y_poly_backward = models.Polynomial2D(degree, name='y_poly_backward', **ycoeff_backward)
output2poly_mapping = Identity(2, name='output_mapping')
output2poly_mapping.inverse = Mapping([0, 1, 0, 1])
input2poly_mapping = Mapping([0, 1, 0, 1], name='input_mapping')
input2poly_mapping.inverse = Identity(2)
model_poly = input2poly_mapping | (x_poly_forward & y_poly_forward) | output2poly_mapping
model = linear_sky2det | model_poly
fa.tree[n]['model'] = model
asdffile = fa.write_to(outname)
return asdffile
示例5: pcf_forward
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree [as 别名]
def pcf_forward(pcffile, outname):
"""
Create the **IDT** forward transform from collimator to gwa.
"""
with open(pcffile) as f:
lines = [l.strip() for l in f.readlines()]
factors = lines[lines.index('*Factor 2') + 1].split()
# factor==1/factor in backward msa2ote direction and factor==factor in sky2detector direction
scale = models.Scale(float(factors[0]), name="x_scale") & \
models.Scale(float(factors[1]), name="y_scale")
rotation_angle = lines[lines.index('*Rotation') + 1]
# The minius sign here is because astropy.modeling has the opposite direction of rotation than the idl implementation
rotation = models.Rotation2D(-float(rotation_angle), name='rotation')
# Here the model is called "output_shift" but in the team version it is the "input_shift".
input_rot_center = lines[lines.index('*InputRotationCentre 2') + 1].split()
input_rot_shift = models.Shift(-float(input_rot_center[0]), name='input_x_shift') & \
models.Shift(-float(input_rot_center[1]), name='input_y_shift')
# Here the model is called "input_shift" but in the team version it is the "output_shift".
output_rot_center = lines[lines.index('*OutputRotationCentre 2') + 1].split()
output_rot_shift = models.Shift(float(output_rot_center[0]), name='output_x_shift') & \
models.Shift(float(output_rot_center[1]), name='output_y_shift')
degree = int(lines[lines.index('*FitOrder') + 1])
xcoeff_index = lines.index('*xForwardCoefficients 21 2')
xlines = lines[xcoeff_index + 1: xcoeff_index + 22]
xcoeff_forward = coeffs_from_pcf(degree, xlines)
x_poly_forward = models.Polynomial2D(degree, name='x_poly_forward', **xcoeff_forward)
ycoeff_index = lines.index('*yForwardCoefficients 21 2')
ycoeff_forward = coeffs_from_pcf(degree, lines[ycoeff_index + 1: ycoeff_index + 22])
y_poly_forward = models.Polynomial2D(degree, name='y_poly_forward', **ycoeff_forward)
xcoeff_index = lines.index('*xBackwardCoefficients 21 2')
xcoeff_backward = coeffs_from_pcf(degree, lines[xcoeff_index + 1: xcoeff_index + 22])
x_poly_backward = models.Polynomial2D(degree, name='x_poly_backward', **xcoeff_backward)
ycoeff_index = lines.index('*yBackwardCoefficients 21 2')
ycoeff_backward = coeffs_from_pcf(degree, lines[ycoeff_index + 1: ycoeff_index + 22])
y_poly_backward = models.Polynomial2D(degree, name='y_poly_backward', **ycoeff_backward)
x_poly_forward.inverse = x_poly_backward
y_poly_forward.inverse = y_poly_backward
poly_mapping1 = Mapping((0, 1, 0, 1))
poly_mapping1.inverse = Identity(2)
poly_mapping2 = Identity(2)
poly_mapping2.inverse = Mapping((0, 1, 0, 1))
model = input_rot_shift | rotation | scale | output_rot_shift | \
poly_mapping1 | x_poly_forward & y_poly_forward | poly_mapping2
f = AsdfFile()
f.tree = {'model': model}
f.write_to(outname)
示例6: ote2asdf
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree [as 别名]
def ote2asdf(otepcf, outname, ref_kw):
"""
ref_kw = common_reference_file_keywords('OTE', 'NIRSPEC OTE transform - CDP4')
ote2asdf('Model/Ref_Files/CoordTransform/OTE.pcf', 'jwst_nirspec_ote_0001.asdf', ref_kw)
"""
with open(otepcf) as f:
lines = [l.strip() for l in f.readlines()]
factors = lines[lines.index('*Factor 2 1') + 1].split()
# this corresponds to modeling Rotation direction as is
rotation_angle = float(lines[lines.index('*Rotation') + 1])
input_rot_center = lines[lines.index('*InputRotationCentre 2 1') + 1].split()
output_rot_center = lines[lines.index('*OutputRotationCentre 2 1') + 1].split()
mlinear = homothetic_det2sky(input_rot_center, rotation_angle, factors, output_rot_center)
degree = int(lines[lines.index('*FitOrder') + 1])
xcoeff_index = lines.index('*xBackwardCoefficients 21 2')
xlines = lines[xcoeff_index + 1].split('\t')
xcoeff_backward = coeffs_from_pcf(degree, xlines)
x_poly_forward = models.Polynomial2D(degree, name='x_poly_forward', **xcoeff_backward)
xcoeff_index = lines.index('*xForwardCoefficients 21 2')
xlines = lines[xcoeff_index + 1].split('\t')
xcoeff_forward = coeffs_from_pcf(degree, xlines)
x_poly_backward = models.Polynomial2D(degree, name='x_poly_backward', **xcoeff_forward)
ycoeff_index = lines.index('*yBackwardCoefficients 21 2')
ylines = lines[ycoeff_index + 1].split('\t')
ycoeff_backward = coeffs_from_pcf(degree, ylines)
y_poly_forward = models.Polynomial2D(degree, name='y_poly_forward', **ycoeff_backward)
ycoeff_index = lines.index('*yForwardCoefficients 21 2')
ylines = lines[ycoeff_index + 1].split('\t')
ycoeff_forward = coeffs_from_pcf(degree, ylines)
y_poly_backward = models.Polynomial2D(degree, name='y_poly_backward', **ycoeff_forward)
x_poly_forward.inverse = x_poly_backward
y_poly_forward.inverse = y_poly_backward
output2poly_mapping = Identity(2, name='output_mapping')
output2poly_mapping.inverse = Mapping([0, 1, 0, 1])
input2poly_mapping = Mapping([0, 1, 0, 1], name='input_mapping')
input2poly_mapping.inverse = Identity(2)
model_poly = input2poly_mapping | (x_poly_forward & y_poly_forward) | output2poly_mapping
model = model_poly | mlinear
f = AsdfFile()
f.tree = ref_kw.copy()
f.tree['model'] = model
f.add_history_entry("Build 6")
f.write_to(outname)
return model_poly, mlinear
示例7: create_v23
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree [as 别名]
def create_v23(reftype, detector, band, channels, data, name):
"""
Create the transform from MIRI Local to telescope V2/V3 system for all channels.
"""
channel = "".join([ch[0] for ch in channels])
tree = {"detector": detector,
"instrument" : "MIRI",
"band": band,
"channel": channel,
"exp_type": "MIR_MRS",
"pedigree": "GROUND",
"title": "MIRI IFU model - based on CDP-4",
"reftype": reftype,
"author": "N. Dencheva"
}
ab_v23 = data[0]
v23_ab = data[1]
m = {}
c0_0, c0_1, c1_0, c1_1 = ab_v23[0][1:]
ch1_v2 = models.Polynomial2D(2, c0_0=c0_0, c1_0=c1_0, c0_1=c0_1, c1_1=c1_1,
name="ab_v23")
c0_0, c0_1, c1_0, c1_1 = v23_ab[0][1:]
ch1_a = models.Polynomial2D(2, c0_0=c0_0, c1_0=c1_0, c0_1=c0_1, c1_1=c1_1,
name="v23_ab")
c0_0, c0_1, c1_0, c1_1 = ab_v23[1][1:]
ch1_v3 = models.Polynomial2D(2, c0_0=c0_0, c1_0=c1_0, c0_1=c0_1, c1_1=c1_1,
name="ab_v23")
c0_0, c0_1, c1_0, c1_1 = v23_ab[1][1:]
ch1_b = models.Polynomial2D(2, c0_0=c0_0, c1_0=c1_0, c0_1=c0_1, c1_1=c1_1,
name="v23_ab")
c0_0, c0_1, c1_0, c1_1 = ab_v23[2][1:]
ch2_v2 = models.Polynomial2D(2, c0_0=c0_0, c1_0=c1_0, c0_1=c0_1, c1_1=c1_1,
name="ab_v23")
c0_0, c0_1, c1_0, c1_1 = v23_ab[2][1:]
ch2_a = models.Polynomial2D(2, c0_0=c0_0, c1_0=c1_0, c0_1=c0_1, c1_1=c1_1,
name="v23_ab")
c0_0, c0_1, c1_0, c1_1 = ab_v23[3][1:]
ch2_v3 = models.Polynomial2D(2, c0_0=c0_0, c1_0=c1_0, c0_1=c0_1, c1_1=c1_1,
name="ab_v23")
c0_0, c0_1, c1_0, c1_1 = v23_ab[3][1:]
ch2_b = models.Polynomial2D(2, c0_0=c0_0, c1_0=c1_0, c0_1=c0_1, c1_1=c1_1,
name="v23_ab")
ch1_for = ch1_v2 & ch1_v3
ch2_for = ch2_v2 & ch2_v3
ch1_for.inverse = ch1_a & ch1_b
ch2_for.inverse = ch2_a & ch2_b
m[channels[0]] = ch1_for
m[channels[1]] = ch2_for
tree['model'] = m
f = AsdfFile()
f.tree = tree
f.write_to(name)
示例8: create_distortion_file
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree [as 别名]
def create_distortion_file(reftype, detector, band, channel, data, name):
tree = create_reffile_header(reftype, detector, band, channel)
adata, bdata, xdata, ydata, sdata1, sdata2 = data
tree['alpha_model'] = adata
tree['beta_model'] = bdata
tree['x_model'] = xdata
tree['y_model'] = ydata
tree['slice_model'] = {str(channel[0])+band: sdata1, str(channel[1])+band: sdata2}
f = AsdfFile()
f.tree = tree
f.write_to(name)
示例9: fpa2asdf
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree [as 别名]
def fpa2asdf(fpafile, outname, ref_kw):
"""
Create an asdf reference file with the FPA description.
The CDP2 delivery includes a fits file - "FPA.fpa" which is the
input to this function. This file is converted to asdf and is a
reference file of type "FPA".
nirspec_fs_ref_tools.fpa2asdf('Ref_Files/CoordTransform/Description/FPA.fpa', 'fpa.asdf')
Parameters
----------
fpafile : str
A fits file with FPA description (FPA.fpa)
outname : str
Name of output ASDF file.
"""
with open(fpafile) as f:
lines = [l.strip() for l in f.readlines()]
# NRS1
ind = lines.index("*SCA491_PitchX")
scalex_nrs1 = models.Scale(1/float(lines[ind+1]), name='fpa_scale_x')
ind = lines.index("*SCA491_PitchY")
scaley_nrs1 = models.Scale(1/float(lines[ind+1]), name='fpa_scale_y')
ind = lines.index("*SCA491_RotAngle")
rot_nrs1 = models.Rotation2D(np.rad2deg(-float(lines[ind+1])), name='fpa_rotation')
ind = lines.index("*SCA491_PosX")
shiftx_nrs1 = models.Shift(-float(lines[ind+1]), name='fpa_shift_x')
ind = lines.index("*SCA491_PosY")
shifty_nrs1 = models.Shift(-float(lines[ind+1]), name='fpa_shift_y')
# NRS2
ind = lines.index("*SCA492_PitchX")
scalex_nrs2 = models.Scale(1/float(lines[ind+1]), name='fpa_scale_x')
ind = lines.index("*SCA492_PitchY")
scaley_nrs2 = models.Scale(1/float(lines[ind+1]), name='fpa_scale_y')
ind = lines.index("*SCA492_RotAngle")
rot_nrs2 = models.Rotation2D(np.rad2deg(float(lines[ind+1])), name='fpa_rotation')
ind = lines.index("*SCA492_PosX")
shiftx_nrs2 = models.Shift(-float(lines[ind+1]), name='fpa_shift_x')
ind = lines.index("*SCA492_PosY")
shifty_nrs2 = models.Shift(-float(lines[ind+1]), name='fpa_shift_y')
tree = ref_kw.copy()
tree['NRS1'] = (shiftx_nrs1 & shifty_nrs1) | rot_nrs1 | (scalex_nrs1 & scaley_nrs1)
tree['NRS2'] = (shiftx_nrs2 & shifty_nrs2) | rot_nrs2 | (scalex_nrs2 & scaley_nrs2)
fasdf = AsdfFile()
fasdf.tree = tree
fasdf.write_to(outname)
return fasdf
示例10: wavelength_range
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree [as 别名]
def wavelength_range(spectral_conf, outname, ref_kw):
"""
Parameters
----------
spectral_conf : str
reference file: spectralconfigurations.txt
outname : str
output file name
"""
with open(spectral_conf) as f:
lines = f.readlines()
lines = [l.strip() for l in lines][13 :]
lines = [l.split() for l in lines]
tree = ref_kw.copy()
filter_grating = {}
for l in lines:
f_g = l[0] + '_' + l[1]
filter_grating[f_g] = {'order': int(l[2]), 'range': [float(l[3]), float(l[4])]}
tree['filter_grating'] = filter_grating
# values in lamp_grating come from private communication with the INS team
#lamp_grating = {}
filter_grating['FLAT1_G140M'] = {'order': -1, 'range': [1e-6, 1.8e-6]}
filter_grating['LINE1_G140M'] = {'order': -1, 'range': [1e-6, 1.8e-6]}
filter_grating['FLAT1_G140H'] = {'order': -1, 'range': [1e-6, 1.8e-6]}
filter_grating['LINE1_G140H'] = {'order': -1, 'range': [1e-6, 1.8e-6]}
filter_grating['FLAT2_G235M'] = {'order': -1, 'range': [1.7e-6, 3.1e-6]}
filter_grating['LINE2_G235M'] = {'order': -1, 'range': [1.7e-6, 3.1e-6]}
filter_grating['FLAT2_G235H'] = {'order': -1, 'range': [1.7e-6, 3.1e-6]}
filter_grating['LINE2_G235H'] = {'order': -1, 'range': [1.7e-6, 3.1e-6]}
filter_grating['FLAT3_G395M'] = {'order': -1, 'range': [2.9e-6, 5.3e-6]}
filter_grating['LINE3_G395M'] = {'order': -1, 'range': [2.9e-6, 5.3e-6]}
filter_grating['FLAT3_G395H'] = {'order': -1, 'range': [2.9e-6, 5.3e-6]}
filter_grating['LINE3_G395H'] = {'order': -1, 'range': [2.9e-6, 5.3e-6]}
filter_grating['REF_G140M'] = {'order': -1, 'range': [1.3e-6, 1.7e-6]}
filter_grating['REF_G140H'] = {'order': -1, 'range': [1.3e-6, 1.7e-6]}
filter_grating['TEST_MIRROR'] = {'order': -1, 'range': [0.6e-6, 5.3e-6]}
#for grating in ["G140H", "G140M", "G235H", "G235M", "G395H", "G395M", "MIRROR"]:
#lamp_grating['FLAT4_{0}'.format(grating)] = {'order': -1, 'range': [0.7e-6, 1.2e-6]}
#for grating in ["G140H", "G140M", "G235H", "G235M", "G395H", "G395M", "MIRROR"]:
#lamp_grating['LINE4_{0}'.format(grating)] = {'order': -1, 'range': [0.6e-6, 5.3e-6]}
#tree['lamp_grating'] = lamp_grating
fasdf = AsdfFile()
fasdf.tree = tree
fasdf.add_history_entry("Build 6")
fasdf.write_to(outname)
return fasdf
示例11: create_wavelengthrange_file
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree [as 别名]
def create_wavelengthrange_file(name):
f = AsdfFile()
#wavelengthrange = {'1SHORT': (4.88, 5.77),
#'1MEDIUM': (5.64, 6.67),
#'1LONG': (6.50, 7.70),
#'2SHORT': (7.47, 8.83),
#'2MEDIUM': (8.63, 10.19),
#'2LONG': (9.96, 11.77),
#'3SHORT': (11.49, 13.55),
#'3MEDIUM': (13.28, 15.66),
#'3LONG': (15.34, 18.09),
#'4SHORT': (17.60, 21.00),
#'4MEDIUM': (20.51, 24.48),
#'4LONG': (23.92, 28.55)
#}
# Relaxing the range to match the distortion. The table above
# comes from the report and is "as designed".
wavelengthrange = {'1SHORT': (4.68, 5.97),
'1MEDIUM': (5.24, 6.87),
'1LONG': (6.2, 7.90),
'2SHORT': (7.27, 9.03),
'2MEDIUM': (8.43, 10.39),
'2LONG': (9.76, 11.97),
'3SHORT': (11.29, 13.75),
'3MEDIUM': (13.08, 15.86),
'3LONG': (15.14, 18.29),
'4SHORT': (17.40, 21.20),
'4MEDIUM': (20.31, 24.68),
'4LONG': (23.72, 28.75)
}
channels = ['1SHORT', '1MEDIUM', '1LONG', '2SHORT', '2MEDIUM', '2LONG',
'3SHORT', '3MEDIUM', '3LONG', '4SHORT', '4MEDIUM', '4LONG']
tree = {
"instrument": "MIRI",
"exp_type": "MIR_MRS",
"pedigree": "GROUND",
"title": "MIRI IFU model - based on CDP-4",
"reftype": "WAVELENGTHRANGE",
"author": "N. Dencheva"
}
tree['channels'] = channels
f.tree = tree
vr = np.empty((12, 2), dtype=np.float)
for i, ch in enumerate(channels):
vr[i] = wavelengthrange[ch]
f.tree['wavelengthrange'] = vr
f.write_to(name)
示例12: create_miri_imager_filter_offset
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree [as 别名]
def create_miri_imager_filter_offset(distfile, outname):
"""
Create an asdf reference file with the filter offsets for the MIRI imager.
Note: The IDT supplied distortion file lists sky to pixel as the
forward transform. Since "forward" in the JWST pipeline is from
pixel to sky, the offsets are taken with the opposite sign.
Parameters
----------
distfile : str
MIRI imager DISTORTION file provided by the IDT team.
outname : str
Name of reference file to be wriiten to disk.
Returns
-------
fasdf : AsdfFile
AsdfFile object
Examples
-------
>>> create_miri_imager_filer_offset('MIRI_FM_MIRIMAGE_DISTORTION_03.02.00.fits',
'jwst_miri_filter_offset_0001.asdf')
"""
with fits.open(distfile) as f:
data = f[9].data
d = dict.fromkeys(data.field('FILTER'))
for i in data:
d[i[0]] = {'column_offset': -i[1], 'row_offset': -i[2]}
tree = {"title": "MIRI imager filter offset - CDP4",
"reftype": "FILTEROFFSET",
"instrument": "MIRI",
"detector": "MIRIMAGE",
"pedigree": "GROUND",
"author": "N. Dencheva",
"exp_type": "MIR_IMAGE"
}
tree.update(d)
f = AsdfFile()
f.tree = tree
f.write_to(outname)
示例13: msa2asdf
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree [as 别名]
def msa2asdf(msafile, outname, ref_kw):
"""
Create an asdf reference file with the MSA description.
mas2asfdf("MSA.msa", "msa.asdf")
Parameters
----------
msafile : str
A fits file with MSA description (MSA.msa)
outname : str
Name of output ASDF file.
"""
f = fits.open(msafile)
tree = ref_kw.copy()
data = f[5].data # SLITS and IFU
header = f[5].header
shiftx = models.Shift(header['SLITXREF'], name='slit_xref')
shifty = models.Shift(header['SLITYREF'], name='slit_yref')
slitrot = models.Rotation2D(header['SLITROT'], name='slit_rot')
tree[5] = {}
tree[5]['model'] = slitrot | shiftx & shifty
tree[5]['data'] = f[5].data
for i in range(1, 5):
header = f[i].header
shiftx = models.Shift(header['QUADXREF'], name='msa_xref')
shifty = models.Shift(header['QUADYREF'], name='msa_yref')
slitrot = models.Rotation2D(header['QUADROT'], name='msa_rot')
tree[i] = {}
tree[i]['model'] = slitrot | shiftx & shifty
tree[i]['data'] = f[i].data
f.close()
fasdf = AsdfFile()
fasdf.tree = tree
fasdf.add_history_entry("Build 6")
fasdf.write_to(outname)
return fasdf
示例14: msa2asdf
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree [as 别名]
def msa2asdf(msafile, outname, ref_kw):
"""
Create an asdf reference file with the MSA description.
The CDP2 delivery includes a fits file - "MSA.msa".
This file is converted to asdf and serves as a reference file of type "REGIONS".
mas2asfdf("MSA.msa", "msa.asdf") --> creates an 85MB file
Parameters
----------
msafile : str
A fits file with MSA description (MSA.msa)
outname : str
Name of output ASDF file.
"""
f = fits.open(msafile)
tree = ref_kw.copy()
data = f[5].data # SLITS and IFU
header = f[5].header
shiftx = models.Shift(header['SLITXREF'], name='slit_xref')
shifty = models.Shift(header['SLITYREF'], name='slit_yref')
slitrot = models.Rotation2D(header['SLITROT'], name='slit_rot')
for j, slit in enumerate(['S200A1', 'S200A2', 'S400A1', 'S1600A1', 'S200B1', 'IFU']):
slitdata = data[j]
t = {}
for i, s in enumerate(['xcenter', 'ycenter', 'xsize', 'ysize']):
t[s] = slitdata[i+1]
model = models.Scale(t['xsize']) & models.Scale(t['ysize']) | \
models.Shift(t['xcenter']) & models.Shift(t['ycenter']) | \
slitrot | shiftx & shifty
t['model'] = model
tree[slit] = t
f.close()
fasdf = AsdfFile()
fasdf.tree = tree
fasdf.write_to(outname)
return fasdf
示例15: wavelength_range
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree [as 别名]
def wavelength_range(spectral_conf, outname, ref_kw):
"""
Parameters
----------
spectral_conf : str
reference file: spectralconfigurations.txt
outname : str
output file name
"""
with open(spectral_conf) as f:
lines = f.readlines()
lines = [l.strip() for l in lines][13 :]
lines = [l.split() for l in lines]
tree = ref_kw.copy()
filter_grating = {}
for l in lines:
f_g = l[0] + '_' + l[1]
filter_grating[f_g] = {'order': int(l[2]), 'range': [float(l[3]), float(l[4])]}
tree['filter_grating'] = filter_grating
fasdf = AsdfFile()
fasdf.tree = tree
fasdf.write_to(outname)
return fasdf