示例#1
0
文件: io.py 项目: hayesla/sunxspex
def read_abundance_genx(filename):
    # Read file.
    contents = read_genx(filename)
    # Combine data and keys from each entry in file.
    output = OrderedDict()
    for arr in contents["SAVEGEN0"]:
        output[arr["FILNAM"]] = arr["ABUND"]
    # Add header data
    output["header"] = contents["HEADER"]
    output["header"]["CHIANTI VERSION"] = float(contents["SAVEGEN1"][:3])

    return output
示例#2
0
def _read_stix_srm_file(srm_file):
    """
    Read a STIX SRM spectral fits file and extract useful information from it.

    Parameters
    ----------
    srm_file : `str` or `pathlib.Path`
        STIX SRM fits file

    Returns
    -------
    `dict`
        STIX SRM data (photon bins, count bins, and SRM in units of [counts/keV/photons]).
    """
    contents = read_genx(srm_file)
    return {"photon_energy_bin_edges": contents["DRM"]['E_2D'], "count_energy_bin_edges": contents["DRM"]['EDGES_OUT'],
            "drm": contents['DRM']['SMATRIX']}
示例#3
0
import datetime

import numpy as np
import pytest

from sunpy.data.test import get_test_filepath
from sunpy.io.special import genx

TESTING = genx.read_genx(get_test_filepath('generated_sample.genx'))


def test_skeleton():
    # Top level
    toplevel_dims = {
        'MYTEXT': 63,
        'MYTEXT_ARRAY': 3,
        'MYTEXT_ARRAY_DIMENSION': (2, 3),
        'MYNUMBER': 1,
        'MYNUMBER_ARRAY': 3,
        'MYNUMBER_ARRAY_DIMENSION': (2, 3, 4, 5),
        'MYUINT': 1,
        'MYSTRUCTURE': 14,  # the elements inside the OrderedDict
        'MYSTRUCTURE_ARRAY': 6,
        'HEADER': 5
    }
    assert sorted(list(TESTING.keys())) == sorted(list(toplevel_dims.keys()))
    for key, val in toplevel_dims.items():
        if isinstance(val, tuple):
            assert TESTING[key].shape == tuple(reversed(val))
        else:
            if val > 1:
示例#4
0
import os
import datetime

import numpy as np
import pytest

from sunpy.data.test import rootdir
from sunpy.io.special import genx

TESTING = genx.read_genx(os.path.join(rootdir, 'generated_sample.genx'))


def test_skeleton():
    # Top level
    toplevel_dims = {
        'MYTEXT': 63,
        'MYTEXT_ARRAY': 3,
        'MYTEXT_ARRAY_DIMENSION': (2, 3),
        'MYNUMBER': 1,
        'MYNUMBER_ARRAY': 3,
        'MYNUMBER_ARRAY_DIMENSION': (2, 3, 4, 5),
        'MYUINT': 1,
        'MYSTRUCTURE': 14,  # the elements inside the OrderedDict
        'MYSTRUCTURE_ARRAY': 6,
        'HEADER': 5
    }
    assert sorted(list(TESTING.keys())) == sorted(list(toplevel_dims.keys()))
    for key, val in toplevel_dims.items():
        if isinstance(val, tuple):
            assert TESTING[key].shape == tuple(reversed(val))
        else:
示例#5
0
文件: test_genx.py 项目: Cadair/sunpy
import os
import datetime

import numpy as np
import pytest

from sunpy.data.test import rootdir
from sunpy.io.special import genx

TESTING = genx.read_genx(os.path.join(rootdir, 'generated_sample.genx'))


def test_skeleton():
    # Top level
    toplevel_dims = {'MYTEXT': 63, 'MYTEXT_ARRAY': 3, 'MYTEXT_ARRAY_DIMENSION': (2, 3),
                     'MYNUMBER': 1, 'MYNUMBER_ARRAY': 3, 'MYNUMBER_ARRAY_DIMENSION': (2, 3, 4, 5),
                     'MYUINT': 1, 'MYSTRUCTURE': 14,  # the elements inside the OrderedDict
                     'MYSTRUCTURE_ARRAY': 6, 'HEADER': 5}
    assert sorted(list(TESTING.keys())) == sorted(list(toplevel_dims.keys()))
    for key, val in toplevel_dims.items():
        if isinstance(val, tuple):
            assert TESTING[key].shape == tuple(reversed(val))
        else:
            if val > 1:
                assert len(TESTING[key]) == val
            else:
                assert isinstance(TESTING[key], int)


def test_array_elements_values():
    np.testing.assert_allclose(TESTING['MYSTRUCTURE']['MYFARRAY'], np.arange(3.))