本文整理汇总了Python中asdf.AsdfFile.tree['model']方法的典型用法代码示例。如果您正苦于以下问题:Python AsdfFile.tree['model']方法的具体用法?Python AsdfFile.tree['model']怎么用?Python AsdfFile.tree['model']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asdf.AsdfFile
的用法示例。
在下文中一共展示了AsdfFile.tree['model']方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ote2asdf
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree['model'] [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
示例2: ref_dist_coeff
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree['model'] [as 别名]
#.........这里部分代码省略.........
print('Coefficient for x1_1: ', x1_1i)
x0_2i = coeffxi[5]
print('Coefficient for x0_2: ', x0_2i)
x3_0i = coeffxi[6]
print('Coefficient for x3_0: ', x3_0i)
x2_1i = coeffxi[7]
print('Coefficient for x2_1: ', x2_1i)
x1_2i = coeffxi[8]
print('Coefficient for x1_2: ', x1_2i)
x0_3i = coeffxi[9]
print('Coefficient for x0_3: ', x0_3i)
x4_0i = coeffxi[10]
print('Coefficient for x4_0: ', x4_0i)
x3_1i = coeffxi[11]
print('Coefficient for x3_1: ', x3_1i)
x2_2i = coeffxi[12]
print('Coefficient for x2_2: ', x2_2i)
x1_3i = coeffxi[13]
print('Coefficient for x1_3: ', x1_3i)
x0_4i = coeffxi[14]
print('Coefficient for x0_4: ', x0_4i)
"Transform coefficients to get distorted, ideal, detector y."
y0_0i = coeffyi[0]
print('Coefficient for y0_0: ', y0_0i)
y1_0i = coeffyi[1]
print('Coefficient for y1_0: ', y1_0i)
y0_1i = coeffyi[2]
print('Coefficient for y0_1: ', y0_1i)
y2_0i = coeffyi[3]
print('Coefficient for y2_0: ', y2_0i)
y1_1i = coeffyi[4]
print('Coefficient for y1_1: ', y1_1i)
y0_2i = coeffyi[5]
print('Coefficient for y0_2: ', y0_2i)
y3_0i = coeffyi[6]
print('Coefficient for y3_0: ', y3_0i)
y2_1i = coeffyi[7]
print('Coefficient for y2_1: ', y2_1i)
y1_2i = coeffyi[8]
print('Coefficient for y1_2: ', y1_2i)
y0_3i = coeffyi[9]
print('Coefficient for y0_3: ', y0_3i)
y4_0i = coeffyi[10]
print('Coefficient for y4_0: ', y4_0i)
y3_1i = coeffyi[11]
print('Coefficient for y3_1: ', y3_1i)
y2_2i = coeffyi[12]
print('Coefficient for y2_2: ', y2_2i)
y1_3i = coeffyi[13]
print('Coefficient for y1_3: ', y1_3i)
y0_4i = coeffyi[14]
print('Coefficient for y0_4: ', y0_4i)
"Create reference file using asdf formats."
polyxr = models.Polynomial2D(4, c0_0=x0_0r, c1_0=x1_0r, c0_1=x0_1r, c2_0=x2_0r, c1_1=x1_1r, c0_2=x0_2r, c3_0=x3_0r, c2_1=x2_1r, c1_2=x1_2r, c0_3=x0_3r, c4_0=x4_0r, c3_1=x3_1r, c2_2=x2_2r, c1_3=x1_3r, c0_4=x0_4r)
polyyr = models.Polynomial2D(4, c0_0=y0_0r, c1_0=y1_0r, c0_1=y0_1r, c2_0=y2_0r, c1_1=y1_1r, c0_2=y0_2r, c3_0=y3_0r, c2_1=y2_1r, c1_2=y1_2r, c0_3=y0_3r, c4_0=y4_0r, c3_1=y3_1r, c2_2=y2_2r, c1_3=y1_3r, c0_4=y0_4r)
mapping = models.Mapping([0, 1, 0, 1])
det2sky = mapping | polyxr & polyyr
polyxi = models.Polynomial2D(4, c0_0=x0_0i, c1_0=x1_0i, c0_1=x0_1i, c2_0=x2_0i, c1_1=x1_1i, c0_2=x0_2i, c3_0=x3_0i, c2_1=x2_1i, c1_2=x1_2i, c0_3=x0_3i, c4_0=x4_0i, c3_1=x3_1i, c2_2=x2_2i, c1_3=x1_3i, c0_4=x0_4i)
polyyi = models.Polynomial2D(4, c0_0=y0_0i, c1_0=y1_0i, c0_1=y0_1i, c2_0=y2_0i, c1_1=y1_1i, c0_2=y0_2i, c3_0=y3_0i, c2_1=y2_1i, c1_2=y1_2i, c0_3=y0_3i, c4_0=y4_0i, c3_1=y3_1i, c2_2=y2_2i, c1_3=y1_3i, c0_4=y0_4i)
mapping = models.Mapping([0, 1, 0, 1])
sky2det = mapping | polyxi & polyyi
det2sky.inverse = sky2det
f = AsdfFile()
f.tree['model'] = det2sky
f.tree['TITLE'] = "NIRISS CDP5 distortion reference data."
f.tree['FILENAME'] = "niriss_ref_dist_coeff_image.asdf"
f.tree['EXP_TYPE'] = "NIS_IMAGE"
f.tree['REFTYPE'] = "DISTORTION"
f.tree['AUTHOR'] = "Michael A. Wolfe, Alex Fullerton"
f.tree['PEDIGREE'] = "GROUND"
f.tree['INSTRUMENT'] = "NIRISS"
f.tree['DETECTOR'] = "NIS"
f.tree['USEAFTER'] = "Jan 01 2015 00:00:00.00"
f.tree['DESCRIP'] = "This is a distortion correction reference file."
f.tree['HISTORY'] = "This file is being delivered because it is the distortion correction file. This file was created from the python script niriss_ref_dist_coeff.py and data provied by Alex Fullerton. There is no documentation yet and the python script is titled: niriss_ref_dist_coeff.py. The data used to create the file can be found in the text files: NIS_Ideal2Real.txt & NIS_Real2Ideal.txt."
f.write_to('niriss_ref_distortion_image.asdf')
f = AsdfFile()
f.tree['model'] = det2sky
f.tree['TITLE'] = "NIRISS CDP5 distortion reference data."
f.tree['FILENAME'] = "jwst_niriss_distortion_0001.asdf"
f.tree['EXP_TYPE'] = "NIS_IMAGE"
f.tree['REFTYPE'] = "DISTORTION"
f.tree['AUTHOR'] = "Michael A. Wolfe, Alex Fullerton"
f.tree['PEDIGREE'] = "GROUND"
f.tree['INSTRUMENT'] = "NIRISS"
f.tree['DETECTOR'] = "NIS"
f.tree['USEAFTER'] = "Jan 01 2015 00:00:00.00"
f.tree['DESCRIP'] = "This is a distortion correction reference file."
f.tree['HISTORY'] = "This file is being delivered because it is the distortion correction file. This file was created from the python script niriss_ref_dist_coeff.py and data provied by Alex Fullerton. There is no documentation yet and the python script is titled: niriss_ref_dist_coeff.py. The data used to create the file can be found in the text files: NIS_Ideal2Real.txt & NIS_Real2Ideal.txt."
f.write_to('jwst_niriss_distortion_0001.asdf')
print('Done, done, and done with creating the disrtortion correction reference file. Git the bleep along little doggies!!!!!')
dist_coeff()
示例3: fore2asdf
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree['model'] [as 别名]
def fore2asdf(pcffore, outname, ref_kw):
"""
forward direction : msa 2 ote
backward_direction: msa 2 fpa
"""
with open(pcffore) as f:
lines = [l.strip() for l in f.readlines()]
fore_det2sky = linear_from_pcf_det2sky(pcffore)
fore_linear = fore_det2sky
fore_linear.inverse = fore_det2sky.inverse & Identity(1)
# compute the polynomial
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)
# Polynomial Correction in x
x_poly_backward = models.Polynomial2D(degree, name="x_poly_backward", **xcoeff_forward)
xlines_distortion = lines[xcoeff_index + 22: xcoeff_index + 43]
xcoeff_forward_distortion = coeffs_from_pcf(degree, xlines_distortion)
x_poly_backward_distortion = models.Polynomial2D(degree, name="x_backward_distortion",
**xcoeff_forward_distortion)
# do chromatic correction
# the input is Xote, Yote, lam
model_x_backward = (Mapping((0, 1), n_inputs=3) | x_poly_backward) + \
((Mapping((0,1), n_inputs=3) | x_poly_backward_distortion) * \
(Mapping((2,)) | Identity(1)))
ycoeff_index = lines.index('*yForwardCoefficients 21 2')
ycoeff_forward = coeffs_from_pcf(degree, lines[ycoeff_index + 1: ycoeff_index + 22])
y_poly_backward = models.Polynomial2D(degree, name="y_poly_backward", **ycoeff_forward)
ylines_distortion = lines[ycoeff_index + 22: ycoeff_index + 43]
ycoeff_forward_distortion = coeffs_from_pcf(degree, ylines_distortion)
y_poly_backward_distortion = models.Polynomial2D(degree, name="y_backward_distortion",
**ycoeff_forward_distortion)
# do chromatic correction
# the input is Xote, Yote, lam
model_y_backward = (Mapping((0,1), n_inputs=3) | y_poly_backward) + \
((Mapping((0, 1), n_inputs=3) | y_poly_backward_distortion) * \
(Mapping((2,)) | Identity(1) ))
xcoeff_index = lines.index('*xBackwardCoefficients 21 2')
xcoeff_backward = coeffs_from_pcf(degree, lines[xcoeff_index + 1: xcoeff_index + 22])
x_poly_forward = models.Polynomial2D(degree,name="x_poly_forward", **xcoeff_backward)
xcoeff_backward_distortion = coeffs_from_pcf(degree, lines[xcoeff_index + 22: xcoeff_index + 43])
x_poly_forward_distortion = models.Polynomial2D(degree, name="x_forward_distortion", **xcoeff_backward_distortion)
# the chromatic correction is done here
# the input is Xmsa, Ymsa, lam
model_x_forward = (Mapping((0,1), n_inputs=3) | x_poly_forward) + \
((Mapping((0,1), n_inputs=3) | x_poly_forward_distortion) * \
(Mapping((2,)) | Identity(1)))
ycoeff_index = lines.index('*yBackwardCoefficients 21 2')
ycoeff_backward = coeffs_from_pcf(degree, lines[ycoeff_index + 1: ycoeff_index + 22])
y_poly_forward = models.Polynomial2D(degree, name="y_poly_forward",**ycoeff_backward)
ycoeff_backward_distortion = coeffs_from_pcf(degree, lines[ycoeff_index + 22: ycoeff_index + 43])
y_poly_forward_distortion = models.Polynomial2D(degree, name="y_forward_distortion",
**ycoeff_backward_distortion)
# do chromatic correction
# the input is Xmsa, Ymsa, lam
model_y_forward = (Mapping((0,1), n_inputs=3) | y_poly_forward) + \
((Mapping((0,1), n_inputs=3) | y_poly_forward_distortion) * \
(Mapping((2,)) | Identity(1)))
#assign inverse transforms
model_x = model_x_forward.copy()
model_y = model_y_forward.copy()
model_x.inverse = model_x_backward
model_y.inverse = model_y_backward
output2poly_mapping = Identity(2, name="output_mapping")
output2poly_mapping.inverse = Mapping([0, 1, 2, 0, 1, 2])
input2poly_mapping = Mapping([0, 1, 2, 0, 1, 2], name="input_mapping")
input2poly_mapping.inverse = Identity(2)
model_poly = input2poly_mapping | (model_x & model_y) | output2poly_mapping
model = model_poly | fore_linear
f = AsdfFile()
f.tree = ref_kw.copy()
f.tree['model'] = model
asdffile = f.write_to(outname)
return asdffile
示例4: pcf2asdf
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree['model'] [as 别名]
def pcf2asdf(pcffile, outname, ref_file_kw):
"""
Create an asdf reference file with the transformation coded in a NIRSPEC
Camera.pcf or Collimator*.pcf file.
- forward (team): sky to detector
- Shift inputs to input_rotation_center
- Rotate inputs
- Scale inputs
- Shift inputs to output_rot_center
- Apply polynomial distortion
- backward_team (team definition) detector to sky
- Apply polynomial distortion
- Shift inputs to output_rot_center
- Scale inputs
- Rotate inputs
- Shift inputs to input_rotation_center
WCS implementation
- forward: detector to sky
- equivalent to backward_team
- backward: sky to detector
- equivalent to forward_team
Parameters
----------
pcffile : str
one of the NIRSPEC ".pcf" reference files provided by the IDT team.
"pcf" stands for "polynomial coefficients fit"
outname : str
Name of reference file to be wriiten to disk.
Returns
-------
fasdf : AsdfFile
AsdfFile object
Examples
--------
>>> pcf2asdf("Camera.pcf", "camera.asdf")
"""
linear_det2sky = linear_from_pcf_det2sky(pcffile)
with open(pcffile) as f:
lines = [l.strip() for l in f.readlines()]
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_backward = models.Polynomial2D(degree, name='x_poly_backward', **xcoeff_forward)
ycoeff_index = lines.index('*yForwardCoefficients 21 2')
ycoeff_forward = coeffs_from_pcf(degree, lines[ycoeff_index + 1: ycoeff_index + 22])
y_poly_backward = models.Polynomial2D(degree, name='y_poly_backward', **ycoeff_forward)
xcoeff_index = lines.index('*xBackwardCoefficients 21 2')
xcoeff_backward = coeffs_from_pcf(degree, lines[xcoeff_index + 1: xcoeff_index + 22])
x_poly_forward = models.Polynomial2D(degree, name='x_poly_forward', **xcoeff_backward)
ycoeff_index = lines.index('*yBackwardCoefficients 21 2')
ycoeff_backward = coeffs_from_pcf(degree, lines[ycoeff_index + 1: ycoeff_index + 22])
y_poly_forward = models.Polynomial2D(degree, name='y_poly_forward', **ycoeff_backward)
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 | linear_det2sky
f = AsdfFile()
f.tree = ref_file_kw.copy()
f.tree['model'] = model
f.write_to(outname)
示例5: ote2asdf
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree['model'] [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()
scale = models.Scale(1 / float(factors[0]), name="x_scale") & \
models.Scale(1 / float(factors[1]), name="y_scale")
# this corresponds to modeling Rotation direction as is
rotation_angle = lines[lines.index('*Rotation') + 1]
rotation = models.Rotation2D(float(rotation_angle), name='rotation')
input_rot_center = lines[lines.index('*InputRotationCentre 2 1') + 1].split()
output_offset = models.Shift(float(input_rot_center[0]), name='output_x_shift') & \
models.Shift(float(input_rot_center[1]), name='output_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') + 1].split()
input_offset = models.Shift(-float(output_rot_center[0]), name='input_x_shift') & \
models.Shift(-float(output_rot_center[1]), name='input_y_shift')
degree = int(lines[lines.index('*FitOrder') + 1])
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('*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)
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)
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)
x_poly_forward.inverse = x_poly_backward
y_poly_forward.inverse = y_poly_backward
mlinear = input_offset | rotation | scale | output_offset
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.write_to(outname)
示例6: fore2asdf
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree['model'] [as 别名]
def fore2asdf(pcffore, outname, ref_kw):
"""
forward direction : msa 2 ote
backward_direction: msa 2 fpa
"""
with open(pcffore) 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 in ote2msa direction
scale = models.Scale(1. / float(factors[0]), name='scale_x') & \
models.Scale(1 / float(factors[1]), name='scale_y')
rotation_angle = lines[lines.index('*Rotation') + 1]
rotation = models.Rotation2D(float(rotation_angle), name='rotation')
input_rot_center = lines[lines.index('*InputRotationCentre 2') + 1].split()
output_offset = models.Shift(float(input_rot_center[0]), name="output_x_shift") & \
models.Shift(float(input_rot_center[1]), name="output_y_shift")
output_rot_center = lines[lines.index('*OutputRotationCentre 2') + 1].split()
input_offset = models.Shift(-float(output_rot_center[0]), name="input_x_shift") & \
models.Shift(-float(output_rot_center[1]), name="input_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)
# Polynomial Correction in x
x_poly_backward = models.Polynomial2D(degree, name="x_poly_backward", **xcoeff_forward)
xlines_distortion = lines[xcoeff_index + 22: xcoeff_index + 43]
xcoeff_forward_distortion = coeffs_from_pcf(degree, xlines_distortion)
x_poly_backward_distortion = models.Polynomial2D(degree, name="x_backward_distortion",
**xcoeff_forward_distortion)
# do chromatic correction
# the input is Xote, Yote, lam
model_x_backward = (Mapping((0, 1), n_inputs=3) | x_poly_backward) + \
((Mapping((0,1), n_inputs=3) | x_poly_backward_distortion) * Mapping((2,)))
ycoeff_index = lines.index('*yForwardCoefficients 21 2')
ycoeff_forward = coeffs_from_pcf(degree, lines[ycoeff_index + 1: ycoeff_index + 22])
y_poly_backward = models.Polynomial2D(degree, name="y_poly_backward", **ycoeff_forward)
ylines_distortion = lines[ycoeff_index + 22: ycoeff_index + 43]
ycoeff_forward_distortion = coeffs_from_pcf(degree, ylines_distortion)
y_poly_backward_distortion = models.Polynomial2D(degree, name="y_backward_distortion",
**ycoeff_forward_distortion)
# do chromatic correction
# the input is Xote, Yote, lam
model_y_backward = (Mapping((0,1), n_inputs=3) | y_poly_backward) + \
((Mapping((0, 1), n_inputs=3) | y_poly_backward_distortion) * Mapping((2,)))
xcoeff_index = lines.index('*xBackwardCoefficients 21 2')
xcoeff_backward = coeffs_from_pcf(degree, lines[xcoeff_index + 1: xcoeff_index + 22])
x_poly_forward = models.Polynomial2D(degree,name="x_poly_forward", **xcoeff_backward)
xcoeff_backward_distortion = coeffs_from_pcf(degree, lines[xcoeff_index + 22: xcoeff_index + 43])
x_poly_forward_distortion = models.Polynomial2D(degree, name="x_forward_distortion", **xcoeff_backward_distortion)
# the chromatic correction is done here
# the input is Xmsa, Ymsa, lam
model_x_forward = (Mapping((0,1), n_inputs=3) | x_poly_forward) + \
((Mapping((0,1), n_inputs=3) | x_poly_forward_distortion) * Mapping((2,)))
ycoeff_index = lines.index('*yBackwardCoefficients 21 2')
ycoeff_backward = coeffs_from_pcf(degree, lines[ycoeff_index + 1: ycoeff_index + 22])
y_poly_forward = models.Polynomial2D(degree, name="y_poly_forward",**ycoeff_backward)
ycoeff_backward_distortion = coeffs_from_pcf(degree, lines[ycoeff_index + 22: ycoeff_index + 43])
y_poly_forward_distortion = models.Polynomial2D(degree, name="y_forward_distortion",
**ycoeff_backward_distortion)
# do chromatic correction
# the input is Xmsa, Ymsa, lam
model_y_forward = (Mapping((0,1), n_inputs=3) | y_poly_forward) + \
((Mapping((0,1), n_inputs=3) | y_poly_forward_distortion) * Mapping((2,)))
#assign inverse transforms
model_x = model_x_forward.copy()
model_y = model_y_forward.copy()
model_x.inverse = model_x_backward
model_y.inverse = model_y_backward
output2poly_mapping = Identity(2, name="output_mapping")
output2poly_mapping.inverse = Mapping([0, 1, 2, 0, 1, 2])
input2poly_mapping = Mapping([0, 1, 2, 0, 1, 2], name="input_mapping")
input2poly_mapping.inverse = Identity(2)
model_poly = input2poly_mapping | (model_x & model_y) | output2poly_mapping
fore_linear = (input_offset | rotation | scale | output_offset)
fore_linear_inverse = fore_linear.inverse
fore_linear.inverse = fore_linear_inverse & Identity(1)
model = model_poly | fore_linear
f = AsdfFile()
f.tree = ref_kw.copy()
f.tree['model'] = model
#.........这里部分代码省略.........
示例7: pcf2asdf
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import tree['model'] [as 别名]
def pcf2asdf(pcffile, outname, ref_file_kw):
"""
Create an asdf reference file with the transformation coded in a NIRSPEC
Camera.pcf or Collimator*.pcf file.
- forward (team): sky to detector
- Shift inputs to input_rotation_center
- Rotate inputs
- Scale inputs
- Shift inputs to output_rot_center
- Apply polynomial distortion
- backward_team (team definition) detector to sky
- Apply polynomial distortion
- Shift inputs to output_rot_center
- Scale inputs
- Rotate inputs
- Shift inputs to input_rotation_center
WCS implementation
- forward: detector to sky
- equivalent to backward_team
- backward: sky to detector
- equivalent to forward_team
Parameters
----------
pcffile : str
one of the NIRSPEC ".pcf" reference files provided by the IDT team.
"pcf" stands for "polynomial coefficients fit"
outname : str
Name of reference file to be wriiten to disk.
Returns
-------
fasdf : AsdfFile
AsdfFile object
Examples
--------
>>> pcf2asdf("Camera.pcf", "camera.asdf")
"""
with open(pcffile) as f:
lines = [l.strip() for l in f.readlines()]
factors = lines[lines.index('*Factor 2') + 1].split()
scale = models.Scale(1 / float(factors[0]), name="x_scale") & \
models.Scale(1 / float(factors[1]), name="y_scale")
rotation_angle = lines[lines.index('*Rotation') + 1]
# Backward rotation is in the counter-clockwise direction as in modeling
# Forward is clockwise
backward_rotation = models.Rotation2D(float(rotation_angle), name='rotation')
rotation = backward_rotation.copy()
# 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()
output_offset = models.Shift(float(input_rot_center[0]), name='output_x_shift') & \
models.Shift(float(input_rot_center[1]), name='output_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()
input_offset = models.Shift(-float(output_rot_center[0]), name='input_x_shift') & \
models.Shift(-float(output_rot_center[1]), name='input_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_backward = models.Polynomial2D(degree, name='x_poly_backward', **xcoeff_forward)
ycoeff_index = lines.index('*yForwardCoefficients 21 2')
ycoeff_forward = coeffs_from_pcf(degree, lines[ycoeff_index + 1: ycoeff_index + 22])
y_poly_backward = models.Polynomial2D(degree, name='y_poly_backward', **ycoeff_forward)
xcoeff_index = lines.index('*xBackwardCoefficients 21 2')
xcoeff_backward = coeffs_from_pcf(degree, lines[xcoeff_index + 1: xcoeff_index + 22])
x_poly_forward = models.Polynomial2D(degree, name='x_poly_forward', **xcoeff_backward)
ycoeff_index = lines.index('*yBackwardCoefficients 21 2')
ycoeff_backward = coeffs_from_pcf(degree, lines[ycoeff_index + 1: ycoeff_index + 22])
y_poly_forward = models.Polynomial2D(degree, name='y_poly_forward', **ycoeff_backward)
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 | input_offset |scale |rotation |output_offset
f = AsdfFile()
f.tree = ref_file_kw.copy()
f.tree['model'] = model
f.write_to(outname)