本文整理汇总了Python中asdf.AsdfFile.open方法的典型用法代码示例。如果您正苦于以下问题:Python AsdfFile.open方法的具体用法?Python AsdfFile.open怎么用?Python AsdfFile.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类asdf.AsdfFile
的用法示例。
在下文中一共展示了AsdfFile.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calc_cube
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import open [as 别名]
def calc_cube(numb, fried_parameter = 4, time_between = 0.7):
filepath = os.getcwd().split("vApp_reduction",1)[0]+"vApp_reduction/data/psf_cube_cache/"
filepath += "psf_cube_"+str(float(fried_parameter))+"_"+str(float(time_between))+"_"+str(int(numb))+".asdf"
#expand to only demand numb =< numb on disk
if os.path.exists(filepath):
tree = AsdfFile.open(filepath, copy_arrays=True).tree
tree_keys = tree.keys()
psf_params = sorted(list(filter(lambda key: isinstance(key, float), tree_keys)))
psf_cube = list(map(lambda param: np.copy(tree[param]), psf_params))
return psf_cube, psf_params
else:
path = os.getcwd()+"/code/psf/generate_vAPP_cube.py"
params = [str(fried_parameter), str(time_between), str(numb)]
cmd = [sys.executable, path, *params]
print("please run: ")
print(' '.join(cmd))
input("Press Enter to continue...")
tree = AsdfFile.open(filepath).tree
tree_keys = tree.keys()
psf_params = sorted(list(filter(lambda key: isinstance(key, float), tree_keys)))
psf_cube = list(map(lambda param: tree[param], psf_params))
return psf_cube, psf_params
示例2: alpha_beta2XanYan
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import open [as 别名]
def alpha_beta2XanYan(input_model, reference_files):
"""
Create the transform from detector to Xan, Yan frame.
forward transform:
RegionsSelector
label_mapper is LabelMapperDict()
{channel_wave_range (): channel_number}
selector is {channel_number: ab2Xan & ab2Yan}
bacward_transform
RegionsSelector
label_mapper is LabelMapperDict()
{channel_wave_range (): channel_number}
selector is {channel_number: Xan2ab & Yan2ab}
"""
band = input_model.meta.instrument.band
channel = input_model.meta.instrument.channel
# used to read the wavelength range
channels = [c + band for c in channel]
f = AsdfFile.open(reference_files['v2v3'])
v23 = f.tree['model']
f.close()
f = AsdfFile.open(reference_files['wavelengthrange'])
# the following should go in the asdf reader
wave_range = f.tree['wavelengthrange'].copy()
wave_channels = f.tree['channels']
wr = {}
for ch, r in zip(wave_channels, wave_range):
wr[ch] = r
f.close()
dict_mapper = {}
sel = {}
for c in channels:
ch = int(c[0])
dict_mapper[tuple(wr[c])] = models.Mapping((2,), name="mapping_lam") | \
models.Const1D(ch, name="channel #")
map1 = models.Mapping((1, 0, 1, 0), name='map2poly')
map1._outputs = ('alpha', 'beta', 'alpha', 'beta')
map1._inputs = ('alpha', 'beta')
map1.inverse = models.Mapping((0, 1))
ident1 = models.Identity(1, name='identity_lam')
ident1._inputs = ('lam',)
chan_v23 = v23[c]
v23chan_backward = chan_v23.inverse
del chan_v23.inverse
v23_spatial = map1 | chan_v23
v23_spatial.inverse = map1 | v23chan_backward
v23c = v23_spatial & ident1
sel[ch] = v23c
wave_range_mapper = selector.LabelMapperRange(('alpha', 'beta', 'lam'), dict_mapper,
inputs_mapping=models.Mapping([2,]))
wave_range_mapper.inverse = wave_range_mapper.copy()
ab2xyan = selector.RegionsSelector(('alpha', 'beta', 'lam'), ('v2', 'v3', 'lam'),
label_mapper=wave_range_mapper,
selector=sel)
return ab2xyan
示例3: test_backwards_compat_gcrs
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import open [as 别名]
def test_backwards_compat_gcrs():
obsgeoloc = (
3.0856775814671916e+16,
9.257032744401574e+16,
6.1713551629343834e+19
)
obsgeovel = (2.0, 1.0, 8.0)
old_frame_yaml = """
frames:
- !wcs/celestial_frame-1.0.0
axes_names: [lon, lat]
name: CelestialFrame
reference_frame:
type: GCRS
obsgeoloc:
- [%f, %f, %f]
- !unit/unit-1.0.0 m
obsgeovel:
- [%f, %f, %f]
- !unit/unit-1.0.0 m s-1
obstime: !time/time-1.0.0 2010-01-01 00:00:00.000
unit: [!unit/unit-1.0.0 deg, !unit/unit-1.0.0 deg]
""" % (obsgeovel + obsgeoloc)
new_frame_yaml = """
frames:
- !wcs/celestial_frame-1.1.0
axes_names: [lon, lat]
name: CelestialFrame
reference_frame:
type: GCRS
obsgeoloc:
- !unit/quantity-1.1.0 {unit: !unit/unit-1.0.0 m, value: %f}
- !unit/quantity-1.1.0 {unit: !unit/unit-1.0.0 m, value: %f}
- !unit/quantity-1.1.0 {unit: !unit/unit-1.0.0 m, value: %f}
obsgeovel:
- !unit/quantity-1.1.0 {unit: !unit/unit-1.0.0 m s-1, value: %f}
- !unit/quantity-1.1.0 {unit: !unit/unit-1.0.0 m s-1, value: %f}
- !unit/quantity-1.1.0 {unit: !unit/unit-1.0.0 m s-1, value: %f}
obstime: !time/time-1.1.0 2010-01-01 00:00:00.000
unit: [!unit/unit-1.0.0 deg, !unit/unit-1.0.0 deg]
""" % (obsgeovel + obsgeoloc)
old_buff = helpers.yaml_to_asdf(old_frame_yaml)
old_asdf = AsdfFile.open(old_buff)
old_frame = old_asdf.tree['frames'][0]
old_loc = old_frame.reference_frame.obsgeoloc
old_vel = old_frame.reference_frame.obsgeovel
new_buff = helpers.yaml_to_asdf(new_frame_yaml)
new_asdf = AsdfFile.open(new_buff)
new_frame = new_asdf.tree['frames'][0]
new_loc = new_frame.reference_frame.obsgeoloc
new_vel = new_frame.reference_frame.obsgeovel
assert (old_loc.x == new_loc.x and old_loc.y == new_loc.y and
old_loc.z == new_loc.z)
assert (old_vel.x == new_vel.x and old_vel.y == new_vel.y and
old_vel.z == new_vel.z)
示例4: ifuslit_to_msa
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import open [as 别名]
def ifuslit_to_msa(slits, reference_files):
"""
The transform from slit_frame to msa_frame.
Parameters
----------
slits_id : list
A list of slit IDs for all open shutters/slitlets.
msafile : str
The name of the msa reference file.
Returns
-------
model : `~jwst_lib.pipeline_models.Slit2Msa` model.
Transform from slit_frame to msa_frame.
"""
with AsdfFile.open(reference_files['ifufore']) as f:
ifufore = f.tree['model']
ifuslicer = AsdfFile.open(reference_files['ifuslicer'])
models = {}
ifuslicer_model = (ifuslicer.tree['model']).rename('ifuslicer_model')
for slit in slits:
slitdata = ifuslicer.tree['data'][slit]
slitdata_model = (get_slit_location_model(slitdata)).rename('slitdata_model')
msa_transform = slitdata_model | ifuslicer_model
models[slit] = msa_transform
ifuslicer.close()
return Slit2Msa(models)
示例5: imaging_distortion
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import open [as 别名]
def imaging_distortion(input_model, reference_files):
"""
Create pixe2sky and sky2pixel transformation for the MIRI imager.
Parameters
----------
model : jwst_lib.models.ImagingModel
input model
reference_files : dict
reference files from CRDS
using CDP 3 Reference distortion file
MIRI_FM_MIRIMAGE_F1000W_PSF_03.01.00.fits
reference files/corrections needed (pixel to sky):
1. Filter dependent shift in (x,y) (!with an oposite sign to that delievred by the IT)
2. Apply MI
3. Apply Ai and BI matrices
4. Apply the TI matrix (this gives V2/V3 coordinates)
5. Apply V2/V3 to sky transformation
ref_file: filter_offset.asdf - (1)
ref_file: distortion.asdf -(2,3,4)
"""
distortion = AsdfFile.open(reference_files['distortion']).tree['model']
filter_offset = AsdfFile.open(reference_files['filteroffset']).tree[input_model.meta.instrument.filter]
full_distortion = models.Shift(filter_offset['row_offset']) & models.Shift(
filter_offset['column_offset']) | distortion
full_distortion = full_distortion.rename('distortion')
return full_distortion
示例6: detector_to_gwa
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import open [as 别名]
def detector_to_gwa(reference_files, detector, disperser):
"""
Transform from DETECTOR frame to GWA frame.
Parameters
----------
reference_files: dict
Dictionary with reference files returned by CRDS.
detector : str
The detector keyword.
disperser : dict
A corrected disperser ASDF object.
Returns
-------
model : `~astropy.modeling.core.Model` model.
Transform from DETECTOR frame to GWA frame.
"""
with AsdfFile.open(reference_files['fpa']) as f:
fpa = f.tree[detector].copy()
with AsdfFile.open(reference_files['camera']) as f:
camera = f.tree['model'].copy()
angles = [disperser['theta_x'], disperser['theta_y'],
disperser['theta_z'], disperser['tilt_y']]
rotation = Rotation3DToGWA(angles, axes_order="xyzy", name='rotaton')
u2dircos = Unitless2DirCos(name='unitless2directional_cosines')
model = (models.Shift(-1) & models.Shift(-1) | fpa | camera | u2dircos | rotation)
return model
示例7: ifu_msa_to_oteip
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import open [as 别名]
def ifu_msa_to_oteip(reference_files):
"""
Transform from the MSA frame to the OTEIP frame.
Parameters
----------
reference_files: dict
Dictionary with reference files returned by CRDS.
Returns
-------
model : `~astropy.modeling.core.Model` model.
Transform from MSA to OTEIP.
"""
with AsdfFile.open(reference_files['fore']) as f:
fore = f.tree['model'].copy()
with AsdfFile.open(reference_files['ifufore']) as f:
ifufore = f.tree['model'].copy()
msa2fore_mapping = Mapping((0, 1, 2, 2))
msa2fore_mapping.inverse = Identity(3)
ifu_fore_transform = ifufore & Identity(1)
ifu_fore_transform.inverse = Mapping((0, 1, 2, 2)) | ifufore.inverse & Identity(1)
fore_transform = msa2fore_mapping | fore & Identity(1)
return msa2fore_mapping | ifu_fore_transform | fore_transform
示例8: gwa_to_ifuslit
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import open [as 别名]
def gwa_to_ifuslit(slits, disperser, wrange, order, reference_files):
"""
GWA to SLIT transform.
Parameters
----------
slits : list
A list of slit IDs for all IFU slits 0-29.
disperser : dict
A corrected disperser ASDF object.
filter : str
The filter used.
grating : str
The grating used in the observation.
reference_files: dict
Dictionary with reference files returned by CRDS.
Returns
-------
model : `~jwst.transforms.Gwa2Slit` model.
Transform from GWA frame to SLIT frame.
"""
ymin = -.55
ymax = .55
agreq = AngleFromGratingEquation(disperser['groove_density'], order, name='alpha_from_greq')
lgreq = WavelengthFromGratingEquation(disperser['groove_density'], order, name='lambda_from_greq')
collimator2gwa = collimator_to_gwa(reference_files, disperser)
mask = mask_slit(ymin, ymax)
ifuslicer = AsdfFile.open(reference_files['ifuslicer'])
ifupost = AsdfFile.open(reference_files['ifupost'])
slit_models = {}
ifuslicer_model = ifuslicer.tree['model']
for slit in slits:
slitdata = ifuslicer.tree['data'][slit]
slitdata_model = get_slit_location_model(slitdata)
ifuslicer_transform = (slitdata_model | ifuslicer_model)
ifupost_transform = ifupost.tree[slit]['model']
msa2gwa = ifuslicer_transform | ifupost_transform | collimator2gwa
gwa2msa = gwa_to_ymsa(msa2gwa)# TODO: Use model sets here
bgwa2msa = Mapping((0, 1, 0, 1), n_inputs=3) | \
Const1D(0) * Identity(1) & Const1D(-1) * Identity(1) & Identity(2) | \
Identity(1) & gwa2msa & Identity(2) | \
Mapping((0, 1, 0, 1, 2, 3)) | Identity(2) & msa2gwa & Identity(2) | \
Mapping((0, 1, 2, 5), n_inputs=7) | Identity(2) & lgreq | mask
# msa to before_gwa
#msa2bgwa = Mapping((0, 1, 2, 2)) | msa2gwa & Identity(1) | Mapping((3, 0, 1, 2)) | agreq
msa2bgwa = msa2gwa & Identity(1) | Mapping((3, 0, 1, 2)) | agreq
bgwa2msa.inverse = msa2bgwa
slit_models[slit] = bgwa2msa
ifuslicer.close()
ifupost.close()
return Gwa2Slit(slit_models)
示例9: imaging
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import open [as 别名]
def imaging(input_model, reference_files):
"""
Imaging pipeline
frames : detector, gwa, msa, sky
"""
# Get the corrected disperser model
disperser = get_disperser(input_model, reference_files['disperser'])
# DETECTOR to GWA transform
det2gwa = detector_to_gwa(reference_files, input_model.meta.instrument.detector, disperser)
gwa_through = Const1D(-1) * Identity(1) & Const1D(-1) * Identity(1) & Identity(1)
angles = [ disperser['theta_x'], disperser['theta_y'],
disperser['theta_z'], disperser['tilt_y']]
rotation = Rotation3DToGWA(angles, axes_order="xyzy", name='rotaton').inverse
dircos2unitless = DirCos2Unitless(name='directional_cosines2unitless')
col = AsdfFile.open(reference_files['collimator']).tree['model']
# Get the default spectral order and wavelength range and record them in the model.
sporder, wrange = get_spectral_order_wrange(input_model, reference_files['wavelengthrange'])
input_model.meta.wcsinfo.waverange_start = wrange[0]
input_model.meta.wcsinfo.waverange_end = wrange[1]
input_model.meta.wcsinfo.spectral_order = sporder
lam = wrange[0] + (wrange[1] - wrange[0]) * .5
lam_model = Mapping((0, 1, 1)) | Identity(2) & Const1D(lam)
gwa2msa = gwa_through | rotation | dircos2unitless | col | lam_model
gwa2msa.inverse = col.inverse | dircos2unitless.inverse | rotation.inverse | gwa_through
# MSA to OTEIP transform
msa2ote = msa_to_oteip(reference_files)
msa2oteip = msa2ote | Mapping((0, 1), n_inputs=3)
msa2oteip.inverse = Mapping((0, 1, 0, 1)) | msa2ote.inverse | Mapping((0, 1), n_inputs=3)
# OTEIP to V2,V3 transform
with AsdfFile.open(reference_files['ote']) as f:
oteip2v23 = f.tree['model'].copy()
# Create coordinate frames in the NIRSPEC WCS pipeline
# "detector", "gwa", "msa", "oteip", "v2v3", "world"
det, gwa, msa_frame, oteip, v2v3 = create_imaging_frames()
imaging_pipeline = [(det, det2gwa),
(gwa, gwa2msa),
(msa_frame, msa2oteip),
(oteip, oteip2v23),
(v2v3, None)]
return imaging_pipeline
示例10: imaging_distortion
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import open [as 别名]
def imaging_distortion(input_model, reference_files):
"""
Create pixe2sky and sky2pixel transformation for the MIRI imager.
Parameters
----------
model : jwst.datamodels.ImagingModel
input model
reference_files : dict
reference files from CRDS
using CDP 3 Reference distortion file
Old one: ~~MIRI_FM_MIRIMAGE_F1000W_PSF_03.01.00.fits~~
Current one: MIRI_FM_MIRIMAGE_DISTORTION_06.03.00.fits
reference files/corrections needed (pixel to sky):
1. Filter dependent shift in (x,y) (!with an oposite sign to that delievred by the IT)
2. Apply MI
3. Apply Ai and BI matrices
4. Apply the TI matrix (this gives V2/V3 coordinates)
5. Apply V2/V3 to sky transformation
ref_file: filter_offset.asdf - (1)
ref_file: distortion.asdf -(2,3,4)
"""
# Load the distortion and filter from the reference files.
# Load in the distortion file.
distortion = AsdfFile.open(reference_files['distortion']).tree['model']
filter_offset = AsdfFile.open(reference_files['filteroffset']).tree[input_model.meta.instrument.filter]
# Now apply each of the models. The Scale(60) converts from arc-minutes to deg.
full_distortion = models.Shift(filter_offset['column_offset']) & models.Shift(
filter_offset['row_offset']) | distortion | models.Scale(1/60) & models.Scale(1/60)
# ToDo: This will likely have to change in the future, but the "filteroffset" file we have
# ToDo: currently does not contain that key.
filter_offset = None
if input_model.meta.instrument.filter in AsdfFile.open(reference_files['filteroffset']).tree:
filter_offset = AsdfFile.open(reference_files['filteroffset']).tree[input_model.meta.instrument.filter]
full_distortion = models.Shift(filter_offset['row_offset']) & models.Shift(
filter_offset['column_offset']) | distortion
else:
full_distortion = distortion
full_distortion = full_distortion.rename('distortion')
return full_distortion
示例11: oteip_to_v23
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import open [as 别名]
def oteip_to_v23(reference_files):
"""
Transform from the OTEIP frame to the V2V3 frame.
Parameters
----------
reference_files: dict
Dictionary with reference files returned by CRDS.
Returns
-------
model : `~astropy.modeling.core.Model` model.
Transform from OTEIP to V2V3.
"""
with AsdfFile.open(reference_files['ote']) as f:
ote = f.tree['model'].copy()
fore2ote_mapping = Identity(3, name='fore2ote_mapping')
fore2ote_mapping.inverse = Mapping((0, 1, 2, 2))
# Create the transform to v2/v3/lambda. The wavelength units up to this point are
# meters as required by the pipeline but the desired output wavelength units is microns.
# So we are going to Scale the spectral units by 1e6 (meters -> microns)
# The spatial units are currently in deg. Convertin to arcsec.
oteip_to_xyan = fore2ote_mapping | (ote & Scale(1e6))
# Add a shift for the aperture.
oteip2v23 = oteip_to_xyan | Identity(1) & (Shift(468 / 3600) | Scale(-1)) & Identity(1)
return oteip2v23
示例12: slit_to_msa
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import open [as 别名]
def slit_to_msa(open_slits, msafile):
"""
The transform from slit_frame to msa_frame.
Parameters
----------
open_slits : list
A list of slit IDs for all open shutters/slitlets.
msafile : str
The name of the msa reference file.
Returns
-------
model : `~jwst.transforms.Slit2Msa` model.
Transform from slit_frame to msa_frame.
"""
msa = AsdfFile.open(msafile)
models = []
for quadrant in range(1, 6):
slits_in_quadrant = [s for s in open_slits if s.quadrant==quadrant]
if any(slits_in_quadrant):
msa_data = msa.tree[quadrant]['data']
msa_model = msa.tree[quadrant]['model']
for slit in slits_in_quadrant:
slit_id = slit.shutter_id
slitdata = msa_data[slit_id]
slitdata_model = get_slit_location_model(slitdata)
msa_transform = slitdata_model | msa_model
models.append(msa_transform)
msa.close()
return Slit2Msa(open_slits, models)
示例13: get_wavelength_range
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import open [as 别名]
def get_wavelength_range(input_model, path=None):
"""
Return the wavelength range used for computing the WCS.
Needs access to the reference file used to construct the WCS object.
Parameters
----------
input_model : `jwst.datamodels.ImagingModel`
Data model after assign_wcs has been run.
path : str
Directory where the reference file is. (optional)
"""
fname = input_model.meta.ref_file.wavelengthrange.name.split('/')[-1]
if path is None and not os.path.exists(fname):
raise IOError("Reference file {0} not found. Please specify a path.".format(fname))
else:
fname = os.path.join(path, fname)
f = AsdfFile.open(fname)
wave_range = f.tree['wavelengthrange'].copy()
wave_channels = f.tree['channels']
f.close()
wr = dict(zip(wave_channels, wave_range))
channel = input_model.meta.instrument.channel
band = input_model.meta.instrument.band
return dict([(ch+band, wr[ch+band]) for ch in channel ])
示例14: get_spectral_order_wrange
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import open [as 别名]
def get_spectral_order_wrange(input_model, wavelengthrange_file):
"""
Read the spectral order and wavelength range from the reference file.
Parameters
----------
filter : str
The filter used.
grating : str
The grating used in the observation.
wavelength_range_file : str
Reference file of type "wavelengthrange".
"""
full_range = [.6e-6, 5.3e-6]
filter = input_model.meta.instrument.filter
lamp = input_model.meta.instrument.lamp_state
grating = input_model.meta.instrument.grating
wave_range = AsdfFile.open(wavelengthrange_file)
if filter == "OPAQUE":
keyword = lamp + '_' + grating
else:
keyword = filter + '_' + grating
try:
order = wave_range.tree['filter_grating'][keyword]['order']
wrange = wave_range.tree['filter_grating'][keyword]['range']
except KeyError:
order = -1
wrange = full_range
log.warning("Combination {0} missing in wavelengthrange file, setting order to -1 and range to {1}.".format(keyword, full_range))
wave_range.close()
return order, wrange
示例15: collimator_to_gwa
# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import open [as 别名]
def collimator_to_gwa(reference_files, disperser):
"""
Transform from COLLIMATOR to GWA frame.
Parameters
----------
reference_files: dict
Dictionary with reference files returned by CRDS.
disperser : dict
A corrected disperser ASDF object.
Returns
-------
model : `~astropy.modeling.core.Model` model.
Transform from COLLIMATOR to GWA frame.
"""
with AsdfFile.open(reference_files['collimator']) as f:
collimator = f.tree['model'].copy()
angles = [disperser['theta_x'], disperser['theta_y'],
disperser['theta_z'], disperser['tilt_y']]
rotation = Rotation3DToGWA(angles, axes_order="xyzy", name='rotaton')
u2dircos = Unitless2DirCos(name='unitless2directional_cosines')
return collimator.inverse | u2dircos | rotation