def test_write(self): print(self.target.to_dict()) fname = 'test.h5' with HDF5Output(fname, append=True) as out: self.target.write(out) os.remove(fname)
def execute(self): import os from exorad.tasks import LoadOptions from exorad.output.hdf5 import HDF5Output loadOptions = LoadOptions() buildChannels = BuildChannels() loadPayload = LoadPayload() payload_file = self.get_task_param('payload_file') output = self.get_task_param('output') ext = os.path.splitext(payload_file)[1] if ext == '.xml': payload = loadOptions(filename=payload_file) if output is not None: with HDF5Output(output) as out: channels = buildChannels(payload=payload, write=True, output=out) else: channels = buildChannels(payload=payload, write=False, output=None) elif ext == 'h5': payload, channels = loadPayload(input=payload_file) else: self.error('Unsupported payload format') raise IOError('Unsupported payload format') wl_min, wl_max = payload['common']['wl_min']['value'], payload[ 'common']['wl_max']['value'] self.set_output([payload, channels, (wl_min, wl_max)])
def test_write(self): loadTargetList = LoadTargetList() targets = loadTargetList(target_list=self.target_list) fname = 'test.h5' with HDF5Output(fname) as o: for target in targets.target: target.write(o) os.remove(fname)
def standard_pipeline(options, target_list, output=None, plot=False, full_contrib=False, n_thread=1, debug=False, log=False): from exorad.utils.ascii_art import ascii_art logger.info(ascii_art) logger.info('code version {}'.format(version)) gc = GlobalCache() gc['n_thread'] = n_thread gc['debug'] = debug if debug: setLogLevel(logging.DEBUG) if isinstance(log, str): addLogFile(fname=log) elif log: addLogFile() if output is not None: out_dir = pathlib.Path(output).parent.absolute() if not os.path.exists(out_dir): os.makedirs(out_dir) logger.info('output directory created') logger.info('output directory set as {}'.format(out_dir)) try: shutil.copy(options, out_dir) except shutil.SameFileError: pass try: shutil.copy(target_list, out_dir) except shutil.SameFileError: pass else: out_dir = None # step 1 load payload payload, channels, (wl_min, wl_max) = preparePayload(payload_file=options, output=output) if full_contrib: from astropy.table import hstack for ch in channels: channels[ch].table = hstack([channels[ch].table, channels[ch].built_instr['optical_path']['signal_table']]) channels[ch].table.remove_column('instrument_signal') # step 1b plot payload efficiency if plot: efficiency_plot(channels=channels, output_dir=out_dir) # step 2 load targetlist targets = loadTargetList(target_list=target_list) # step 3 observe targetlist targets = observeTargetList(targets=targets.target, payload=payload, channels=channels, wl_range=(wl_min, wl_max), plot=plot, out_dir=out_dir) # step 4 save to output if output is not None: for target in targets: with HDF5Output(output, append=True) as out: targets[target].write(out)
class IOTest(unittest.TestCase): setLogLevel(logging.INFO) buildChannels = BuildChannels() fname = 'test.h5' with HDF5Output(fname) as o: channels_built = buildChannels(payload=options, write=True, output=o) file = h5py.File(fname) loadPayload = LoadPayload() payload_loaded, channels_loaded = loadPayload(input=file) def test_instrument_list(self): self.assertListEqual(list(self.channels_built.keys()), list(self.channels_loaded.keys())) def test_instrument_build_from_file(self): with self.assertRaises(ValueError): self.channels_loaded['Phot'].build() with self.assertRaises(ValueError): self.channels_loaded['Spec'].build() os.remove(self.fname)