当前位置: 首页>>代码示例>>Python>>正文


Python AsdfFile.write_to方法代码示例

本文整理汇总了Python中asdf.AsdfFile.write_to方法的典型用法代码示例。如果您正苦于以下问题:Python AsdfFile.write_to方法的具体用法?Python AsdfFile.write_to怎么用?Python AsdfFile.write_to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在asdf.AsdfFile的用法示例。


在下文中一共展示了AsdfFile.write_to方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: prism2asdf

# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import write_to [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
开发者ID:sosey,项目名称:jwreftools,代码行数:62,代码来源:nirspec_fs_ref_tools.py

示例2: saveto_asdf

# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import write_to [as 别名]
    def saveto_asdf(self, path, header=None, update_path=True):

        """
        This function ...
        :param path:
        :param header:
        :param update_path:
        :return:
        """

        # If a header is not specified, created it from the WCS
        if header is None: header = self.header

        # Import
        from asdf import AsdfFile

        # Create the tree
        tree = dict()

        tree["data"] = self._data
        tree["header"] = header

        # Create the asdf file
        ff = AsdfFile(tree)

        # Write
        ff.write_to(path)

        # Update the path
        if update_path: self.path = path
开发者ID:SKIRT,项目名称:PTS,代码行数:32,代码来源:mask.py

示例3: ifu_slicer2asdf

# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import write_to [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
开发者ID:spacetelescope,项目名称:jwreftools,代码行数:31,代码来源:nirspec_fs_ref_tools.py

示例4: ifu_slicer2asdf

# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import write_to [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
开发者ID:sosey,项目名称:jwreftools,代码行数:31,代码来源:nirspec_fs_ref_tools.py

示例5: pcf_forward

# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import write_to [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)
开发者ID:sosey,项目名称:jwreftools,代码行数:61,代码来源:nirspec_fs_ref_tools.py

示例6: ote2asdf

# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import write_to [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
开发者ID:spacetelescope,项目名称:jwreftools,代码行数:60,代码来源:nirspec_fs_ref_tools.py

示例7: create_v23

# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import write_to [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)
开发者ID:hbushouse,项目名称:jwst,代码行数:57,代码来源:miri_ifu_ref_tools.py

示例8: create_distortion_file

# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import write_to [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)
开发者ID:hbushouse,项目名称:jwst,代码行数:15,代码来源:miri_ifu_ref_tools.py

示例9: runtest

# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import write_to [as 别名]
    def runtest(self):
        from asdf import AsdfFile, block, util
        from asdf.tests import helpers
        from .extension import TestExtension

        name, version = parse_schema_filename(self.filename)
        if should_skip(name, version):
            return

        standard_version = self._find_standard_version(name, version)

        # Make sure that the examples in the schema files (and thus the
        # ASDF standard document) are valid.
        buff = helpers.yaml_to_asdf(
            'example: ' + self.example.strip(), standard_version=standard_version)
        ff = AsdfFile(
            uri=util.filepath_to_url(os.path.abspath(self.filename)),
            extensions=TestExtension())

        # Fake an external file
        ff2 = AsdfFile({'data': np.empty((1024*1024*8), dtype=np.uint8)})

        ff._external_asdf_by_uri[
            util.filepath_to_url(
                os.path.abspath(
                    os.path.join(
                        os.path.dirname(self.filename), 'external.asdf')))] = ff2

        # Add some dummy blocks so that the ndarray examples work
        for i in range(3):
            b = block.Block(np.zeros((1024*1024*8), dtype=np.uint8))
            b._used = True
            ff.blocks.add(b)
        b._array_storage = "streamed"

        try:
            with pytest.warns(None) as w:
                import warnings
                ff._open_impl(ff, buff, mode='rw')
            # Do not tolerate any warnings that occur during schema validation
            assert len(w) == 0, helpers.display_warnings(w)
        except Exception:
            print("From file:", self.filename)
            raise

        # Just test we can write it out.  A roundtrip test
        # wouldn't always yield the correct result, so those have
        # to be covered by "real" unit tests.
        if b'external.asdf' not in buff.getvalue():
            buff = io.BytesIO()
            ff.write_to(buff)
开发者ID:spacetelescope,项目名称:asdf,代码行数:53,代码来源:plugin.py

示例10: fpa2asdf

# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import write_to [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
开发者ID:hbushouse,项目名称:jwst,代码行数:52,代码来源:nirspec_fs_ref_tools.py

示例11: ifupost2asdf

# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import write_to [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
开发者ID:sosey,项目名称:jwreftools,代码行数:62,代码来源:nirspec_fs_ref_tools.py

示例12: create_wavelengthrange_file

# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import write_to [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)
开发者ID:hbushouse,项目名称:jwst,代码行数:49,代码来源:miri_ifu_ref_tools.py

示例13: wavelength_range

# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import write_to [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
开发者ID:spacetelescope,项目名称:jwreftools,代码行数:49,代码来源:nirspec_fs_ref_tools.py

示例14: create_miri_imager_filter_offset

# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import write_to [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)
开发者ID:nden,项目名称:jwst,代码行数:46,代码来源:miri_imager_ref_tools.py

示例15: saveto

# 需要导入模块: from asdf import AsdfFile [as 别名]
# 或者: from asdf.AsdfFile import write_to [as 别名]
    def saveto(self, path, header=None):

        """
        This function ...
        :param path:
        :param header:
        :return:
        """

        # If a header is not specified, created it from the WCS
        if header is None: header = self.header

        # FITS format
        if path.endswith(".fits"):

            from .fits import write_frame  # Import here because io imports SegmentationMap

            # Write to a FITS file
            write_frame(self._data, header, path)

        # ASDF format
        elif path.endswith(".asdf"):

            # Import
            from asdf import AsdfFile

            # Create the tree
            tree = dict()

            tree["data"] = self._data
            tree["header"] = header

            # Create the asdf file
            ff = AsdfFile(tree)

            # Write
            ff.write_to(path)

        # Invalid
        else: raise ValueError("Only the FITS or ASDF filetypes are supported")

        # Update the path
        self.path = path
开发者ID:SKIRT,项目名称:PTS,代码行数:45,代码来源:segmentationmap.py


注:本文中的asdf.AsdfFile.write_to方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。