Пример #1
0
def chianti_kev_cont_common_load(_extra=None):
    """
    Read X-ray continuum emission info needed for the chianti_kev functions.

    Returns
    -------
    zindex: `numpy.ndarray`
        Indicies of elements as they appear in periodic table.
    continuum_properties: `dict`
        Properties of continuum emission.
    """
    contfile = manager.get("chianti_cont_1_250")
    # Read file
    contents = scipy.io.readsav(contfile)
    zindex = contents["zindex"]
    edge_str = {
        "CONVERSION": _clean_array_dims(contents["edge_str"]["CONVERSION"]),
        "WVL": _clean_array_dims(contents["edge_str"]["WVL"]),
        "WVLEDGE": _clean_array_dims(contents["edge_str"]["WVLEDGE"])
    }
    continuum_properties = {
        "totcont": contents["totcont"],
        "totcont_lo": contents["totcont_lo"],
        "edge_str": edge_str,
        "ctemp": contents["ctemp"],
        "chianti_doc": _clean_chianti_doc(contents["chianti_doc"])
    }

    return zindex, continuum_properties
Пример #2
0
def load_chianti_continuum():
    """
    Read X-ray continuum emission info from an IDL sav file produced by CHIANTI

    Returns
    -------
    continuum_intensities: `xarray.DataArray`
        Continuum intensity as a function of element, temperature and energy/wavelength
        and associated metadata and coordinates.

    Notes
    -----
    By default, this function uses the file located at
    https://hesperia.gsfc.nasa.gov/ssw/packages/xray/dbase/chianti/chianti_cont_1_250_v71.sav
    To use a different file call this function in the following way:
    >>> from sunpy.data import manager # doctest: +SKIP
    >>> with manager.override_file("chianti_continuum", uri=filename): # doctest: +SKIP
    ...    line_info = load_chianti_lines_light() # doctest: +SKIP

    where filename is the location of the file to be read.
    """
    # Define units
    intensity_unit = u.ph * u.cm**3 / (u.s * u.keV * u.sr)
    temperature_unit = u.K
    wave_unit = u.AA
    # Read file
    contfile = manager.get("chianti_continuum")
    contents = scipy.io.readsav(contfile)
    # Concatenate low and high wavelength intensity arrays.
    intensities = np.concatenate((contents["totcont_lo"], contents["totcont"]),
                                 axis=-1)
    # Integrate over sphere surface of radius equal to observer distance
    # to get intensity at source. This means that physical intensities can
    # be calculated by dividing by 4 * pi * R**2 where R is the observer distance.
    intensities *= 4 * np.pi
    intensity_unit *= u.sr
    # Put file data into intuitive structure and return data.
    continuum_intensities = xarray.DataArray(
        intensities,
        dims=["element_index", "temperature", "wavelength"],
        coords={
            "element_index": contents["zindex"],
            "temperature": contents["ctemp"],
            "wavelength": _clean_array_dims(contents["edge_str"]["WVL"])
        },
        attrs={
            "units": {
                "data": intensity_unit,
                "temperature": temperature_unit,
                "wavelength": wave_unit
            },
            "file":
            contfile,
            "wavelength_edges":
            _clean_array_dims(contents["edge_str"]["WVLEDGE"]) * wave_unit,
            "chianti_doc":
            _clean_chianti_doc(contents["chianti_doc"])
        })
    return continuum_intensities
Пример #3
0
def _read_linefile():
    linefile = manager.get('chianti_lines_1_10')
    # Read file
    contents = scipy.io.readsav(linefile)
    zindex = contents["zindex"]
    out = contents["out"]

    return contents
Пример #4
0
def load_xray_abundances(abundance_type=None):
    """
    Returns the abundances written in the xray_abun_file.genx

    The abundances are taken from CHIANTI and MEWE.  The source filenames are:
    cosmic sun_coronal sun_coronal_ext sun_hybrid sun_hybrid_ext sun_photospheric mewe_cosmic mewe_solar
    The first six come fron Chianti, the last two from Mewe.  They are:
    cosmic sun_coronal sun_coronal_ext sun_hybrid sun_hybrid_ext sun_photospheric mewe_cosmic mewe_solar
    These abundances are used with CHIANTI_KEV.  MEWE_KEV can only use the two mewe sourced
    abundance distributions unless using a heavily modified rel_abun structure for all of the elements.

    Parameters
    ----------
    abundance_type: `str`
        Type of abundance to be read from file.  Option are (From Chianti)
        1. cosmic
        2. sun_coronal - default abundance
        3. sun_coronal_ext
        4. sun_hybrid
        5. sun_hybrid_ext
        6. sun_photospheric
        7. mewe_cosmic
        8. mewe_solar - default for mewe_kev

    Returns
    -------
    out:
        Array of 50 abundance levels for first 50 elements.

    """
    # If kwargs not set, set defaults
    if abundance_type is None:
        abundance_type = "sun_coronal"
    xray_abundance_file = manager.get("xray_abundances")
    # Read file
    contents = read_abundance_genx(xray_abundance_file)
    # Restructure data into an easier form.
    try:
        header = contents.pop("header")
    except KeyError:
        header = None
    n_elements = len(contents[list(contents.keys())[0]])
    columns = [np.arange(1, n_elements+1)] + list(contents.values())
    names = ["atomic number"] + list(contents.keys())
    abundances = Table(columns, names=names)

    return abundances
Пример #5
0
def load_xray_abundances(abundance_type=None):
    """
    Returns the abundances written in the xray_abun_file.genx

    The abundances are taken from CHIANTI and MEWE.  The source filenames are:
    cosmic sun_coronal sun_coronal_ext sun_hybrid sun_hybrid_ext sun_photospheric mewe_cosmic mewe_solar
    The first six come fron Chianti, the last two from Mewe.  They are:
    cosmic sun_coronal sun_coronal_ext sun_hybrid sun_hybrid_ext sun_photospheric mewe_cosmic mewe_solar
    These abundances are used with CHIANTI_KEV.  MEWE_KEV can only use the two mewe sourced
    abundance distributions unless using a heavily modified rel_abun structure for all of the elements.

    Parameters
    ----------
    abundance_type: `str`
        Type of abundance to be read from file.  Option are (From Chianti)
        1. cosmic
        2. sun_coronal - default abundance
        3. sun_coronal_ext
        4. sun_hybrid
        5. sun_hybrid_ext
        6. sun_photospheric
        7. mewe_cosmic
        8. mewe_solar - default for mewe_kev

    Returns
    -------
    out:
        Array of 50 abundance levels for first 50 elements.

    """
    # If kwargs not set, set defaults
    if abundance_type is None:
        abundance_type = "sun_coronal"
    xray_abundance_file = manager.get("xray_abundances")
    # Read file
    contents = read_abundance_genx(xray_abundance_file)
    # Extract relevant abundance type
    abundances = contents[abundance_type]

    return abundances
Пример #6
0
def get_adapt_map():
    return manager.get('adapt_map')
Пример #7
0
def get_gong_map():
    """
    Automatically download and unzip a sample GONG synoptic map.
    """
    return manager.get('gong_map')
Пример #8
0
def test_function():
    return manager.get('test_file')
Пример #9
0
def load_chianti_lines_lite():
    """
    Read X-ray emission line info from an IDL sav file produced by CHIANTI.

    This function does not read all data in the file, but only that required to calculate the
    observed X-ray spectrum.

    Returns
    -------
    line_intensities_at_source: `xarray.DataArray`
        Intensities of each of each line as a function of temperature and
        associated metadata and coordinates.

    Notes
    -----
    CHIANTI File

    By default, this function uses the file located at
    https://hesperia.gsfc.nasa.gov/ssw/packages/xray/dbase/chianti/chianti_lines_1_10_v71.sav.
    To use a different file (created by CHIANTI and saved as a sav file) call this function in the following way:
    >>> from sunpy.data import manager  # doctest: +SKIP
    >>> with manager.override_file("chianti_lines", uri=filename): # doctest: +SKIP
    ...     line_info = load_chianti_lines_light() # doctest: +SKIP

    where filename is the location of the file to be read.

    Intensity Units

    The line intensities read from the CHIANTI file are in units of ph / cm**2 / s / sr.
    Therefore they are specific intensities, i.e. per steradian, or solid angle.
    Here, let us call these intensities, intensity_per_solid_angle.
    The solid angle is given by flare_area / observer_distance**2.
    Total integrated intensity can be rewritten in terms of volume EM and solid angle:

    intensity = intensity_per_solid_angle_per_volEM * volEM * solid_angle
    intensity = intensity_per_solid_angle / (colEM * flare_area) * (flare_area / observer_dist**2) * volEM
    intensity = intensity_per_solid_angle / colEM / observer_dist**2 * volEM

    i.e. flare area cancels. Therefore:

    intensity = intensity_per_solid_angle / colEM / observer_dist**2 * volEM,

    or, dividing both sides by volEM,

    intensity_per_EM = intensity_per_solid_angle / colEM / observer_dist**2

    In this function, we normalize the intensity by colEM and scale it to the source, i.e.
    intensity_out = intensity_per_solid_angle / colEM * 4 * pi
    Therefore the intensity values output by this function must be multiplied by EM
    and divided by 4 pi observer_dist**2 to get physical values at the observer.
    """
    # Read linefile
    linefile = manager.get('chianti_lines')
    contents = scipy.io.readsav(linefile)
    out = contents["out"]

    # Define units
    wvl_units = _clean_units(out["WVL_UNITS"])
    int_units = _clean_units(out["INT_UNITS"])
    energy_unit = u.keV

    # Extract line info and convert from wavelength to energy.
    line_intensities = []
    line_elements = []
    line_peak_energies = []
    for j, lines in enumerate(out["lines"]):
        # Extract line element index and peak energy.
        line_elements.append(lines["IZ"] + 1)  #TODO: Confirm lines["IZ"] is indeed atomic number - 1
        line_peak_energies.append(u.Quantity(lines["WVL"], unit=wvl_units).to(
            energy_unit, equivalencies=u.spectral()))
        # Sort line info in ascending energy.
        ordd = np.argsort(np.array(line_peak_energies[j]))
        line_elements[j] = line_elements[j][ordd]
        line_peak_energies[j] = line_peak_energies[j][ordd]
        # Extract line intensities.
        line_intensities.append(_extract_line_intensities(lines["INT"][ordd]) * int_units)

    # If there is only one element in the line properties, unpack values.
    if len(out["lines"]) == 1:
        line_elements = line_elements[0]
        line_peak_energies = line_peak_energies[0]
        line_intensities = line_intensities[0]

    # Normalize line intensities by EM and integrate over whole sky to get intensity at source.
    # This means that physical intensities can be calculated by dividing by
    # 4 * pi * R**2 where R is the observer distance.
    line_colEMs = 10.**_clean_array_dims(out["LOGEM_ISOTHERMAL"]) / u.cm**5
    line_intensities /= line_colEMs
    line_intensities *= 4 * np.pi * u.sr

    # Put data into intuitive structure and return it.
    line_intensities_per_EM_at_source = xarray.DataArray(
        line_intensities.value,
        dims=["lines", "temperature"],
        coords={"logT": ("temperature", _clean_array_dims(out["LOGT_ISOTHERMAL"])),
                "peak_energy": ("lines", line_peak_energies),
                "atomic_number": ("lines", line_elements)},
        attrs={"units": {"data": line_intensities.unit,
                         "peak_energy": line_peak_energies.unit},
               "file": linefile,
               "element_index": contents["zindex"],
               "chianti_doc": _clean_chianti_doc(contents["chianti_doc"])})

    return line_intensities_per_EM_at_source