Beispiel #1
0
def dummy_nirspec_ref(tmpdir_factory):
    """ Generate a dummy apcorr ref file """
    filename = tmpdir_factory.mktemp('dummy_apcorr')
    filename = str(filename.join('dummy_nirspec_apcorr.asdf'))

    refap = {}
    refap['meta'] = {}
    refap['apcorr_table'] = {}
    refap['meta']['telescope'] = 'JWST'
    refap['meta']['reftype'] = 'APCORR'
    refap['meta']['exp_type'] = 'P_EXP_TY'
    refap['meta']['detector'] = 'N/A'
    refap['meta']['datamodel'] = 'NrsIfuApcorrModel'
    refap['meta']['version'] = '1.0'
    refap['meta']['name'] = 'NIRSPEC'
    refap['meta']['origin']= 'STScI'

    dummy_wave = np.zeros(100) + 0.5
    dummy_radius = np.zeros((3,100)) + 0.5
    dummy_apcorr = np.ones((3,100))
    dummy_apcorr_error = np.zeros((3,100))

    refap['apcorr_table'] = {}
    refap['apcorr_table']['wavelength'] =  dummy_wave.copy()
    refap['apcorr_table']['radius'] =  dummy_radius.copy()
    refap['apcorr_table']['apcorr'] =  dummy_apcorr.copy()
    refap['apcorr_table']['apcorr_err'] =  dummy_apcorr_error.copy()
    refap['apcorr_table']['wavelength_units'] =  'microns'
    refap['apcorr_table']['radius_units'] =  'arcseconds'
    refap['apcorr_table']['filter'] =  'ANY'
    refap['apcorr_table']['grating'] =  'ANY'


    ff = AsdfFile(refap)
    ff.set_array_storage(refap['apcorr_table']['wavelength'],'inline')
    ff.set_array_storage(refap['apcorr_table']['radius'],'inline')
    ff.set_array_storage(refap['apcorr_table']['apcorr'],'inline')
    ff.set_array_storage(refap['apcorr_table']['apcorr_err'],'inline')

    ff.write_to(filename)
    return filename
Beispiel #2
0
# http://asdf.readthedocs.io/en/latest/asdf/examples.html

from asdf import AsdfFile
import numpy as np

af = AsdfFile()
af.tree['hello'] = 'world'
af.tree['data'] = np.random.rand(8, 4096)  # 'data': the main content
myarray = np.random.rand(1024)
af.tree['data_ascii'] = myarray
af.set_array_storage(myarray, 'inline')  # specify ascii mode
af.write_to('example.af')

# compression: zlib / bzp2
# af.tree['data'] = np.random.rand(10000, 4096)
# af.write_to('example.af') # 313M, RAW, quick
# af.write_to('example.af', all_array_compression='zlib')
# 295M, SLOW
# af.write_to('example.af', all_array_compression='bzp2')
# 299M, VERY SLOW