<s> from __future__ import print_function , division <EOL> import warnings <EOL> import numpy as np <EOL> from astropy import log as logger <EOL> from . . util . functions import FreezableClass , bool2str , str2bool , is_numpy_array <EOL> from . . filter import Filter <EOL> class OutputConf ( FreezableClass ) : <EOL> def __init__ ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . output_density = '<STR_LIT:none>' <EOL> self . output_density_diff = '<STR_LIT:none>' <EOL> self . output_specific_energy = '<STR_LIT>' <EOL> self . output_n_photons = '<STR_LIT:none>' <EOL> self . _freeze ( ) <EOL> @ classmethod <EOL> def read ( cls , group ) : <EOL> self = cls ( ) <EOL> self . output_density = group . attrs [ '<STR_LIT>' ] . decode ( '<STR_LIT:utf-8>' ) <EOL> self . output_density_diff = group . attrs [ '<STR_LIT>' ] . decode ( '<STR_LIT:utf-8>' ) <EOL> self . output_specific_energy = group . attrs [ '<STR_LIT>' ] . decode ( '<STR_LIT:utf-8>' ) <EOL> self . output_n_photons = group . attrs [ '<STR_LIT>' ] . decode ( '<STR_LIT:utf-8>' ) <EOL> return self <EOL> def write ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = np . string_ ( self . output_density . encode ( '<STR_LIT:utf-8>' ) ) <EOL> group . attrs [ '<STR_LIT>' ] = np . string_ ( self . output_density_diff . encode ( '<STR_LIT:utf-8>' ) ) <EOL> group . attrs [ '<STR_LIT>' ] = np . string_ ( self . output_specific_energy . encode ( '<STR_LIT:utf-8>' ) ) <EOL> group . attrs [ '<STR_LIT>' ] = np . string_ ( self . output_n_photons . encode ( '<STR_LIT:utf-8>' ) ) <EOL> class RunConf ( object ) : <EOL> def __init__ ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . set_n_initial_iterations ( <NUM_LIT:5> ) <EOL> self . n_photons = { } <EOL> self . set_propagation_check_frequency ( <NUM_LIT> ) <EOL> self . set_seed ( - <NUM_LIT> ) <EOL> self . set_raytracing ( False ) <EOL> self . set_max_interactions ( <NUM_LIT> ) <EOL> self . set_max_reabsorptions ( <NUM_LIT> ) <EOL> self . set_pda ( False ) <EOL> self . set_mrw ( False ) <EOL> self . set_convergence ( False ) <EOL> self . set_kill_on_absorb ( False ) <EOL> self . set_kill_on_scatter ( False ) <EOL> self . set_forced_first_scattering ( True ) <EOL> self . set_output_bytes ( <NUM_LIT:8> ) <EOL> self . set_sample_sources_evenly ( False ) <EOL> self . set_enforce_energy_range ( True ) <EOL> self . set_copy_input ( True ) <EOL> self . _monochromatic = False <EOL> self . set_specific_energy_type ( '<STR_LIT>' ) <EOL> super ( RunConf , self ) . __init__ ( ) <EOL> def set_propagation_check_frequency ( self , frequency ) : <EOL> '''<STR_LIT>''' <EOL> if not np . isscalar ( frequency ) or isinstance ( frequency , basestring ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if frequency < <NUM_LIT:0.> or frequency > <NUM_LIT:1.> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . _frequency = frequency <EOL> def _read_propagation_check_frequency ( self , group ) : <EOL> self . _frequency = group . attrs [ '<STR_LIT>' ] <EOL> def _write_propagation_check_frequency ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = self . _frequency <EOL> def set_seed ( self , seed ) : <EOL> '''<STR_LIT>''' <EOL> if type ( seed ) != int or seed >= <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . _seed = seed <EOL> def _read_seed ( self , group ) : <EOL> self . _seed = group . attrs [ '<STR_LIT>' ] <EOL> def _write_seed ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = self . _seed <EOL> def set_n_initial_iterations ( self , n_iter ) : <EOL> '''<STR_LIT>''' <EOL> self . n_iter = n_iter <EOL> def _read_n_initial_iterations ( self , group ) : <EOL> self . n_iter = group . attrs [ '<STR_LIT>' ] <EOL> def _write_n_initial_iterations ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = self . n_iter <EOL> def set_n_photons ( self , initial = None , imaging = None , <EOL> imaging_sources = None , imaging_dust = None , <EOL> raytracing_sources = None , raytracing_dust = None , <EOL> stats = <NUM_LIT:0> ) : <EOL> '''<STR_LIT>''' <EOL> self . n_photons . clear ( ) <EOL> if self . n_iter == <NUM_LIT:0> : <EOL> if initial is not None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> if '<STR_LIT>' in self . n_photons : <EOL> del self . n_photons [ '<STR_LIT>' ] <EOL> else : <EOL> if initial is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> self . n_photons [ '<STR_LIT>' ] = initial <EOL> if self . raytracing : <EOL> if raytracing_sources is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> self . n_photons [ '<STR_LIT>' ] = raytracing_sources <EOL> if raytracing_dust is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> self . n_photons [ '<STR_LIT>' ] = raytracing_dust <EOL> else : <EOL> if raytracing_sources is not None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if raytracing_dust is not None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if self . _monochromatic : <EOL> if imaging_sources is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> self . n_photons [ '<STR_LIT>' ] = imaging_sources <EOL> if imaging_dust is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> self . n_photons [ '<STR_LIT>' ] = imaging_dust <EOL> if imaging is not None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> if imaging_sources is not None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if imaging_dust is not None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if imaging is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> self . n_photons [ '<STR_LIT>' ] = imaging <EOL> self . n_photons [ '<STR_LIT>' ] = stats <EOL> def _read_n_photons ( self , group ) : <EOL> if self . n_iter != <NUM_LIT:0> : <EOL> self . n_photons [ '<STR_LIT>' ] = group . attrs [ '<STR_LIT>' ] <EOL> if self . _monochromatic : <EOL> self . n_photons [ '<STR_LIT>' ] = group . attrs [ '<STR_LIT>' ] <EOL> self . n_photons [ '<STR_LIT>' ] = group . attrs [ '<STR_LIT>' ] <EOL> else : <EOL> self . n_photons [ '<STR_LIT>' ] = group . attrs [ '<STR_LIT>' ] <EOL> if self . raytracing : <EOL> self . n_photons [ '<STR_LIT>' ] = group . attrs [ '<STR_LIT>' ] <EOL> self . n_photons [ '<STR_LIT>' ] = group . attrs [ '<STR_LIT>' ] <EOL> self . n_photons [ '<STR_LIT>' ] = group . attrs [ '<STR_LIT>' ] <EOL> def _write_n_photons ( self , group ) : <EOL> if self . n_photons == { } : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if self . n_iter == <NUM_LIT:0> : <EOL> if '<STR_LIT>' in self . n_photons and self . n_photons [ '<STR_LIT>' ] is not None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> if '<STR_LIT>' in self . n_photons and self . n_photons [ '<STR_LIT>' ] is not None : <EOL> group . attrs [ '<STR_LIT>' ] = self . n_photons [ '<STR_LIT>' ] <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if self . _monochromatic : <EOL> if '<STR_LIT>' in self . n_photons : <EOL> group . attrs [ '<STR_LIT>' ] = self . n_photons [ '<STR_LIT>' ] <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if '<STR_LIT>' in self . n_photons : <EOL> group . attrs [ '<STR_LIT>' ] = self . n_photons [ '<STR_LIT>' ] <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if '<STR_LIT>' in self . n_photons : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> if '<STR_LIT>' in self . n_photons : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if '<STR_LIT>' in self . n_photons : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if '<STR_LIT>' in self . n_photons : <EOL> group . attrs [ '<STR_LIT>' ] = self . n_photons [ '<STR_LIT>' ] <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if self . raytracing : <EOL> if '<STR_LIT>' in self . n_photons : <EOL> group . attrs [ '<STR_LIT>' ] = self . n_photons [ '<STR_LIT>' ] <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if '<STR_LIT>' in self . n_photons : <EOL> group . attrs [ '<STR_LIT>' ] = self . n_photons [ '<STR_LIT>' ] <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> if '<STR_LIT>' in self . n_photons : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if '<STR_LIT>' in self . n_photons : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> group . attrs [ '<STR_LIT>' ] = self . n_photons [ '<STR_LIT>' ] <EOL> def set_raytracing ( self , raytracing ) : <EOL> '''<STR_LIT>''' <EOL> self . raytracing = raytracing <EOL> def _read_raytracing ( self , group ) : <EOL> self . raytracing = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> def _write_raytracing ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . raytracing ) <EOL> def set_max_interactions ( self , inter_max , warn = True ) : <EOL> '''<STR_LIT>''' <EOL> self . n_inter_max = inter_max <EOL> self . n_inter_max_warn = warn <EOL> def _read_max_interactions ( self , group ) : <EOL> self . n_inter_max = group . attrs [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in group . attrs : <EOL> self . n_inter_max_warn = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . n_inter_max_warn = True <EOL> def _write_max_interactions ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = self . n_inter_max <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . n_inter_max_warn ) <EOL> def set_max_reabsorptions ( self , reabs_max , warn = True ) : <EOL> '''<STR_LIT>''' <EOL> self . n_reabs_max = reabs_max <EOL> self . n_reabs_max_warn = warn <EOL> def _read_max_reabsorptions ( self , group ) : <EOL> self . n_reabs_max = group . attrs [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in group . attrs : <EOL> self . n_reabs_max_warn = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . n_reabs_max_warn = True <EOL> def _write_max_reabsorptions ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = self . n_reabs_max <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . n_reabs_max_warn ) <EOL> def set_pda ( self , pda ) : <EOL> '''<STR_LIT>''' <EOL> self . pda = pda <EOL> def _read_pda ( self , group ) : <EOL> self . pda = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> def _write_pda ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . pda ) <EOL> def set_mrw ( self , mrw , gamma = <NUM_LIT:1.0> , inter_max = <NUM_LIT:1000> , warn = True ) : <EOL> '''<STR_LIT>''' <EOL> self . mrw = mrw <EOL> self . mrw_gamma = gamma <EOL> self . n_inter_mrw_max = inter_max <EOL> self . n_inter_mrw_max_warn = warn <EOL> def _read_mrw ( self , group ) : <EOL> self . mrw = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> if self . mrw : <EOL> self . mrw_gamma = group . attrs [ '<STR_LIT>' ] <EOL> self . n_inter_mrw_max = group . attrs [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in group . attrs : <EOL> self . n_inter_mrw_max_warn = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . n_inter_mrw_max_warn = True <EOL> def _write_mrw ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . mrw ) <EOL> if self . mrw : <EOL> group . attrs [ '<STR_LIT>' ] = self . mrw_gamma <EOL> group . attrs [ '<STR_LIT>' ] = self . n_inter_mrw_max <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . n_inter_mrw_max_warn ) <EOL> def set_convergence ( self , convergence , percentile = <NUM_LIT> , absolute = <NUM_LIT:0.> , relative = <NUM_LIT:0.> ) : <EOL> '''<STR_LIT>''' <EOL> self . check_convergence = True <EOL> self . convergence_percentile = percentile <EOL> self . convergence_absolute = absolute <EOL> self . convergence_relative = relative <EOL> def _read_convergence ( self , group ) : <EOL> self . check_convergence = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> if self . check_convergence : <EOL> self . convergence_percentile = group . attrs [ '<STR_LIT>' ] <EOL> self . convergence_absolute = group . attrs [ '<STR_LIT>' ] <EOL> self . convergence_relative = group . attrs [ '<STR_LIT>' ] <EOL> def _write_convergence ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . check_convergence ) <EOL> if self . check_convergence : <EOL> group . attrs [ '<STR_LIT>' ] = self . convergence_percentile <EOL> group . attrs [ '<STR_LIT>' ] = self . convergence_absolute <EOL> group . attrs [ '<STR_LIT>' ] = self . convergence_relative <EOL> def set_kill_on_absorb ( self , kill_on_absorb ) : <EOL> '''<STR_LIT>''' <EOL> self . kill_on_absorb = kill_on_absorb <EOL> def _read_kill_on_absorb ( self , group ) : <EOL> self . kill_on_absorb = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> def _write_kill_on_absorb ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . kill_on_absorb ) <EOL> def set_kill_on_scatter ( self , kill_on_scatter ) : <EOL> '''<STR_LIT>''' <EOL> self . kill_on_scatter = kill_on_scatter <EOL> def _read_kill_on_scatter ( self , group ) : <EOL> if '<STR_LIT>' in group . attrs : <EOL> self . kill_on_scatter = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . kill_on_scatter = False <EOL> def _write_kill_on_scatter ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . kill_on_scatter ) <EOL> def set_forced_first_scattering ( self , forced_first_scattering ) : <EOL> '''<STR_LIT>''' <EOL> self . forced_first_scattering = forced_first_scattering <EOL> def _read_forced_first_scattering ( self , group ) : <EOL> self . forced_first_scattering = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> def _write_forced_first_scattering ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . forced_first_scattering ) <EOL> def set_enforce_energy_range ( self , enforce ) : <EOL> '''<STR_LIT>''' <EOL> self . enforce_energy_range = enforce <EOL> def _read_enforce_energy_range ( self , group ) : <EOL> self . enforce_energy_range = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> def _write_enforce_energy_range ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . enforce_energy_range ) <EOL> def set_copy_input ( self , copy ) : <EOL> '''<STR_LIT>''' <EOL> self . copy_input = copy <EOL> def _read_copy_input ( self , group ) : <EOL> self . copy_input = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> def _write_copy_input ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . copy_input ) <EOL> def set_output_bytes ( self , io_bytes ) : <EOL> '''<STR_LIT>''' <EOL> self . physics_io_bytes = io_bytes <EOL> def _read_output_bytes ( self , group ) : <EOL> self . physics_io_bytes = group . attrs [ '<STR_LIT>' ] <EOL> def _write_output_bytes ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = self . physics_io_bytes <EOL> def set_sample_sources_evenly ( self , sample_sources_evenly ) : <EOL> '''<STR_LIT>''' <EOL> self . sample_sources_evenly = sample_sources_evenly <EOL> def _read_sample_sources_evenly ( self , group ) : <EOL> self . sample_sources_evenly = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> def _write_sample_sources_evenly ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . sample_sources_evenly ) <EOL> def set_specific_energy_type ( self , specific_energy_type ) : <EOL> '''<STR_LIT>''' <EOL> if specific_energy_type in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> self . specific_energy_type = specific_energy_type <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def _read_specific_energy_type ( self , group ) : <EOL> if '<STR_LIT>' in group . attrs : <EOL> self . specific_energy_type = group . attrs [ '<STR_LIT>' ] . decode ( '<STR_LIT:ascii>' ) <EOL> else : <EOL> self . specific_energy_type = '<STR_LIT>' <EOL> def _write_specific_energy_type ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = np . string_ ( self . specific_energy_type . encode ( '<STR_LIT:utf-8>' ) ) <EOL> def read_run_conf ( self , group ) : <EOL> '''<STR_LIT>''' <EOL> self . _read_propagation_check_frequency ( group ) <EOL> self . _read_seed ( group ) <EOL> self . _read_n_initial_iterations ( group ) <EOL> self . _read_raytracing ( group ) <EOL> self . _read_n_photons ( group ) <EOL> self . _read_max_interactions ( group ) <EOL> self . _read_max_reabsorptions ( group ) <EOL> self . _read_pda ( group ) <EOL> self . _read_mrw ( group ) <EOL> self . _read_convergence ( group ) <EOL> self . _read_kill_on_absorb ( group ) <EOL> self . _read_kill_on_scatter ( group ) <EOL> self . _read_forced_first_scattering ( group ) <EOL> self . _read_output_bytes ( group ) <EOL> self . _read_sample_sources_evenly ( group ) <EOL> self . _read_enforce_energy_range ( group ) <EOL> self . _read_copy_input ( group ) <EOL> self . _read_specific_energy_type ( group ) <EOL> def write_run_conf ( self , group ) : <EOL> '''<STR_LIT>''' <EOL> self . _write_propagation_check_frequency ( group ) <EOL> self . _write_seed ( group ) <EOL> self . _write_n_initial_iterations ( group ) <EOL> self . _write_n_photons ( group ) <EOL> self . _write_raytracing ( group ) <EOL> self . _write_max_interactions ( group ) <EOL> self . _write_max_reabsorptions ( group ) <EOL> self . _write_pda ( group ) <EOL> self . _write_mrw ( group ) <EOL> self . _write_convergence ( group ) <EOL> self . _write_kill_on_absorb ( group ) <EOL> self . _write_kill_on_scatter ( group ) <EOL> self . _write_forced_first_scattering ( group ) <EOL> self . _write_output_bytes ( group ) <EOL> self . _write_sample_sources_evenly ( group ) <EOL> self . _write_enforce_energy_range ( group ) <EOL> self . _write_copy_input ( group ) <EOL> self . _write_specific_energy_type ( group ) <EOL> class ImageConf ( FreezableClass ) : <EOL> def __init__ ( self , sed = True , image = True ) : <EOL> '''<STR_LIT>''' <EOL> self . sed = sed <EOL> self . image = image <EOL> if self . sed : <EOL> self . set_aperture_radii ( <NUM_LIT:1> , np . inf , np . inf ) <EOL> if self . image : <EOL> self . n_x = self . n_y = None <EOL> self . xmin = self . xmax = self . ymin = self . ymax = None <EOL> self . n_wav = None <EOL> self . wav_min = None <EOL> self . wav_max = None <EOL> self . iwav_min = None <EOL> self . iwav_max = None <EOL> self . set_output_bytes ( <NUM_LIT:8> ) <EOL> self . set_track_origin ( '<STR_LIT>' ) <EOL> self . set_uncertainties ( False ) <EOL> self . set_stokes ( False ) <EOL> self . _set_monochromatic ( False ) <EOL> self . _filters = [ ] <EOL> self . _freeze ( ) <EOL> def add_filter ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> filt = Filter ( ** kwargs ) <EOL> self . _filters . append ( filt ) <EOL> return filt <EOL> def _read_filters ( self , group ) : <EOL> if '<STR_LIT>' in group . attrs and str2bool ( group . attrs [ '<STR_LIT>' ] ) : <EOL> self . _filters = [ ] <EOL> n_filt = group . attrs [ '<STR_LIT>' ] <EOL> for ifilter in range ( n_filt ) : <EOL> self . _filters . append ( Filter . from_hdf5_group ( group , '<STR_LIT>' . format ( ifilter + <NUM_LIT:1> ) ) ) <EOL> else : <EOL> self . _filters = None <EOL> def _write_filters ( self , group ) : <EOL> if self . n_wav is not None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( len ( self . _filters ) > <NUM_LIT:0> ) <EOL> if self . _filters is not None : <EOL> group . attrs [ '<STR_LIT>' ] = len ( self . _filters ) <EOL> for ifilter , filt in enumerate ( self . _filters ) : <EOL> filt . to_hdf5_group ( group , '<STR_LIT>' . format ( ifilter + <NUM_LIT:1> ) ) <EOL> def set_output_bytes ( self , io_bytes ) : <EOL> '''<STR_LIT>''' <EOL> self . io_bytes = io_bytes <EOL> def _read_output_bytes ( self , group ) : <EOL> self . io_bytes = group . attrs [ '<STR_LIT>' ] <EOL> def _write_output_bytes ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = self . io_bytes <EOL> def set_image_size ( self , n_x , n_y ) : <EOL> '''<STR_LIT>''' <EOL> if type ( n_x ) != int : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if type ( n_y ) != int : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . n_x = n_x <EOL> self . n_y = n_y <EOL> def _read_image_size ( self , group ) : <EOL> self . n_x = group . attrs [ '<STR_LIT>' ] <EOL> self . n_y = group . attrs [ '<STR_LIT>' ] <EOL> def _write_image_size ( self , group ) : <EOL> if self . n_x is None or self . n_y is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> group . attrs [ '<STR_LIT>' ] = self . n_x <EOL> group . attrs [ '<STR_LIT>' ] = self . n_y <EOL> def set_image_limits ( self , xmin , xmax , ymin , ymax ) : <EOL> '''<STR_LIT>''' <EOL> self . xmin = xmin <EOL> self . xmax = xmax <EOL> self . ymin = ymin <EOL> self . ymax = ymax <EOL> def _read_image_limits ( self , group ) : <EOL> self . xmin = group . attrs [ '<STR_LIT>' ] <EOL> self . xmax = group . attrs [ '<STR_LIT>' ] <EOL> self . ymin = group . attrs [ '<STR_LIT>' ] <EOL> self . ymax = group . attrs [ '<STR_LIT>' ] <EOL> def _write_image_limits ( self , group ) : <EOL> if self . xmin is None or self . xmax is None or self . ymin is None or self . ymax is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> group . attrs [ '<STR_LIT>' ] = self . xmin <EOL> group . attrs [ '<STR_LIT>' ] = self . xmax <EOL> group . attrs [ '<STR_LIT>' ] = self . ymin <EOL> group . attrs [ '<STR_LIT>' ] = self . ymax <EOL> def set_aperture_range ( self , n_ap , ap_min , ap_max ) : <EOL> warnings . warn ( "<STR_LIT>" , DeprecationWarning ) <EOL> return self . set_aperture_radii ( n_ap , ap_min , ap_max ) <EOL> def set_aperture_radii ( self , n_ap , ap_min , ap_max ) : <EOL> '''<STR_LIT>''' <EOL> if type ( n_ap ) is not int : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . n_ap = n_ap <EOL> self . ap_min = ap_min <EOL> self . ap_max = ap_max <EOL> def _read_aperture_range ( self , group ) : <EOL> self . n_ap = group . attrs [ '<STR_LIT>' ] <EOL> self . ap_min = group . attrs [ '<STR_LIT>' ] <EOL> self . ap_max = group . attrs [ '<STR_LIT>' ] <EOL> def _write_aperture_range ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = self . n_ap <EOL> group . attrs [ '<STR_LIT>' ] = self . ap_min <EOL> group . attrs [ '<STR_LIT>' ] = self . ap_max <EOL> def _set_monochromatic ( self , monochromatic , frequencies = None ) : <EOL> """<STR_LIT>""" <EOL> self . _monochromatic = monochromatic <EOL> if monochromatic : <EOL> if self . n_wav is not None or self . wav_min is not None or self . wav_max is not None : <EOL> logger . warn ( "<STR_LIT>" ) <EOL> self . n_wav = None <EOL> self . wav_min = None <EOL> self . wav_max = None <EOL> self . set_wavelength_index_range ( <NUM_LIT:1> , len ( frequencies ) ) <EOL> else : <EOL> if self . iwav_min is not None or self . iwav_max is not None : <EOL> log . warn ( "<STR_LIT>" ) <EOL> self . iwav_min = None <EOL> self . iwav_max = None <EOL> def _read_monochromatic ( self , group ) : <EOL> self . _monochromatic = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> def _write_monochromatic ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . _monochromatic ) <EOL> def set_wavelength_range ( self , n_wav , wav_min , wav_max ) : <EOL> '''<STR_LIT>''' <EOL> if type ( n_wav ) is not int : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if self . _monochromatic : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . n_wav = n_wav <EOL> self . wav_min = wav_min <EOL> self . wav_max = wav_max <EOL> def _read_wavelength_range ( self , group ) : <EOL> self . n_wav = group . attrs [ '<STR_LIT>' ] <EOL> self . wav_min = group . attrs [ '<STR_LIT>' ] <EOL> self . wav_max = group . attrs [ '<STR_LIT>' ] <EOL> def _write_wavelength_range ( self , group ) : <EOL> if self . n_wav is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> group . attrs [ '<STR_LIT>' ] = self . n_wav <EOL> if self . wav_min is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> group . attrs [ '<STR_LIT>' ] = self . wav_min <EOL> if self . wav_max is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> group . attrs [ '<STR_LIT>' ] = self . wav_max <EOL> def set_wavelength_index_range ( self , iwav_min , iwav_max ) : <EOL> '''<STR_LIT>''' <EOL> if not self . _monochromatic : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . iwav_min = iwav_min <EOL> self . iwav_max = iwav_max <EOL> def _read_wavelength_index_range ( self , group ) : <EOL> self . iwav_min = group . attrs [ '<STR_LIT>' ] <EOL> self . iwav_max = group . attrs [ '<STR_LIT>' ] <EOL> def _write_wavelength_index_range ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = self . iwav_max - self . iwav_min + <NUM_LIT:1> <EOL> group . attrs [ '<STR_LIT>' ] = self . iwav_min <EOL> group . attrs [ '<STR_LIT>' ] = self . iwav_max <EOL> def set_track_origin ( self , track_origin , n_scat = None ) : <EOL> '''<STR_LIT>''' <EOL> if track_origin is True : <EOL> track_origin = '<STR_LIT>' <EOL> elif track_origin is False : <EOL> track_origin = '<STR_LIT>' <EOL> elif track_origin not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . track_origin = track_origin <EOL> self . track_n_scat = n_scat or <NUM_LIT:0> <EOL> def _read_track_origin ( self , group ) : <EOL> self . track_origin = group . attrs [ '<STR_LIT>' ] . decode ( '<STR_LIT:ascii>' ) <EOL> if '<STR_LIT>' in group . attrs : <EOL> self . track_n_scat = group . attrs [ '<STR_LIT>' ] <EOL> else : <EOL> self . track_n_scat = <NUM_LIT:0> <EOL> def _write_track_origin ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = np . string_ ( self . track_origin . encode ( '<STR_LIT:utf-8>' ) ) <EOL> group . attrs [ '<STR_LIT>' ] = self . track_n_scat <EOL> def set_uncertainties ( self , uncertainties ) : <EOL> '''<STR_LIT>''' <EOL> self . uncertainties = uncertainties <EOL> def _read_uncertainties ( self , group ) : <EOL> self . uncertainties = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> def _write_uncertainties ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . uncertainties ) <EOL> def set_stokes ( self , stokes ) : <EOL> '''<STR_LIT>''' <EOL> self . stokes = stokes <EOL> def _read_stokes ( self , group ) : <EOL> if '<STR_LIT>' in group . attrs : <EOL> self . stokes = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . stokes = True <EOL> def _write_stokes ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . stokes ) <EOL> @ classmethod <EOL> def read ( cls , group ) : <EOL> self = cls ( ) <EOL> self . _read_viewing_info ( group ) <EOL> self . _read_main_info ( group ) <EOL> return self <EOL> def write ( self , group ) : <EOL> self . _write_viewing_info ( group ) <EOL> self . _write_main_info ( group ) <EOL> def _read_viewing_info ( self , group ) : <EOL> pass <EOL> def _validate_viewing_info ( self ) : <EOL> pass <EOL> def _write_viewing_info ( self , group ) : <EOL> pass <EOL> def _read_main_info ( self , group ) : <EOL> self . sed = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> self . image = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> if self . sed : <EOL> self . _read_aperture_range ( group ) <EOL> if self . image : <EOL> self . _read_image_size ( group ) <EOL> self . _read_image_limits ( group ) <EOL> self . _read_monochromatic ( group ) <EOL> if self . _monochromatic : <EOL> self . _read_wavelength_index_range ( group ) <EOL> else : <EOL> if '<STR_LIT>' in group . attrs and group . attrs [ '<STR_LIT>' ] : <EOL> self . _read_filters ( group ) <EOL> else : <EOL> self . _read_wavelength_range ( group ) <EOL> self . _read_output_bytes ( group ) <EOL> self . _read_track_origin ( group ) <EOL> self . _read_uncertainties ( group ) <EOL> self . _read_stokes ( group ) <EOL> def _write_main_info ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . sed ) <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . image ) <EOL> if self . sed : <EOL> self . _write_aperture_range ( group ) <EOL> if self . image : <EOL> self . _write_image_size ( group ) <EOL> self . _write_image_limits ( group ) <EOL> self . _write_monochromatic ( group ) <EOL> if self . _monochromatic : <EOL> self . _write_wavelength_index_range ( group ) <EOL> else : <EOL> if len ( self . _filters ) > <NUM_LIT:0> : <EOL> self . _write_filters ( group ) <EOL> else : <EOL> self . _write_wavelength_range ( group ) <EOL> self . _write_output_bytes ( group ) <EOL> self . _write_track_origin ( group ) <EOL> self . _write_uncertainties ( group ) <EOL> self . _write_stokes ( group ) <EOL> class BinnedImageConf ( ImageConf ) : <EOL> def __init__ ( self , n_theta = None , n_phi = None , ** kwargs ) : <EOL> self . n_theta = n_theta <EOL> self . n_phi = n_phi <EOL> ImageConf . __init__ ( self , ** kwargs ) <EOL> def set_viewing_bins ( self , n_theta , n_phi ) : <EOL> '''<STR_LIT>''' <EOL> self . n_theta = n_theta <EOL> self . n_phi = n_phi <EOL> def _read_viewing_bins ( self , group ) : <EOL> self . n_theta = group . attrs [ '<STR_LIT>' ] <EOL> self . n_phi = group . attrs [ '<STR_LIT>' ] <EOL> def _write_viewing_bins ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = self . n_theta <EOL> group . attrs [ '<STR_LIT>' ] = self . n_phi <EOL> def _read_viewing_info ( self , group ) : <EOL> self . _read_viewing_bins ( group ) <EOL> def _write_viewing_info ( self , group ) : <EOL> self . _write_viewing_bins ( group ) <EOL> class PeeledImageConf ( ImageConf ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . set_viewing_angles ( [ ] , [ ] ) <EOL> self . set_inside_observer ( None ) <EOL> self . set_ignore_optical_depth ( False ) <EOL> self . set_peeloff_origin ( None ) <EOL> self . set_depth ( - np . inf , np . inf ) <EOL> ImageConf . __init__ ( self , ** kwargs ) <EOL> def set_viewing_angles ( self , theta , phi ) : <EOL> '''<STR_LIT>''' <EOL> if isinstance ( theta , ( list , tuple ) ) : <EOL> theta = np . array ( theta ) <EOL> if isinstance ( phi , ( list , tuple ) ) : <EOL> phi = np . array ( phi ) <EOL> if not is_numpy_array ( theta ) or theta . ndim != <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if not is_numpy_array ( phi ) or phi . ndim != <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if len ( theta ) != len ( phi ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . viewing_angles = list ( zip ( theta , phi ) ) <EOL> self . n_view = len ( self . viewing_angles ) <EOL> def _read_viewing_angles ( self , group ) : <EOL> angles = group [ '<STR_LIT>' ] <EOL> self . viewing_angles = list ( zip ( angles [ '<STR_LIT>' ] , angles [ '<STR_LIT>' ] ) ) <EOL> def _write_viewing_angles ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = len ( self . viewing_angles ) <EOL> group . create_dataset ( '<STR_LIT>' , data = np . array ( self . viewing_angles , dtype = [ ( '<STR_LIT>' , float ) , ( '<STR_LIT>' , float ) ] ) ) <EOL> def set_inside_observer ( self , position ) : <EOL> '''<STR_LIT>''' <EOL> if isinstance ( position , ( list , tuple ) ) : <EOL> position = np . array ( position ) <EOL> if position is not None : <EOL> if not is_numpy_array ( position ) or position . ndim != <NUM_LIT:1> or len ( position ) != <NUM_LIT:3> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . inside_observer = position <EOL> def _read_inside_observer ( self , group ) : <EOL> self . inside_observer = ( group . attrs [ '<STR_LIT>' ] , <EOL> group . attrs [ '<STR_LIT>' ] , <EOL> group . attrs [ '<STR_LIT>' ] ) <EOL> def _write_inside_observer ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = self . inside_observer [ <NUM_LIT:0> ] <EOL> group . attrs [ '<STR_LIT>' ] = self . inside_observer [ <NUM_LIT:1> ] <EOL> group . attrs [ '<STR_LIT>' ] = self . inside_observer [ <NUM_LIT:2> ] <EOL> def set_ignore_optical_depth ( self , ignore_optical_depth ) : <EOL> '''<STR_LIT>''' <EOL> self . ignore_optical_depth = ignore_optical_depth <EOL> def _read_ignore_optical_depth ( self , group ) : <EOL> self . ignore_optical_depth = str2bool ( group . attrs [ '<STR_LIT>' ] ) <EOL> def _write_ignore_optical_depth ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( self . ignore_optical_depth ) <EOL> def set_peeloff_origin ( self , position ) : <EOL> '''<STR_LIT>''' <EOL> if isinstance ( position , ( list , tuple ) ) : <EOL> position = np . array ( position ) <EOL> if position is not None : <EOL> if not is_numpy_array ( position ) or position . ndim != <NUM_LIT:1> or len ( position ) != <NUM_LIT:3> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . peeloff_origin = position <EOL> def _read_peeloff_origin ( self , group ) : <EOL> self . peeloff_origin = ( group . attrs [ '<STR_LIT>' ] , <EOL> group . attrs [ '<STR_LIT>' ] , <EOL> group . attrs [ '<STR_LIT>' ] ) <EOL> def _write_peeloff_origin ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = self . peeloff_origin [ <NUM_LIT:0> ] <EOL> group . attrs [ '<STR_LIT>' ] = self . peeloff_origin [ <NUM_LIT:1> ] <EOL> group . attrs [ '<STR_LIT>' ] = self . peeloff_origin [ <NUM_LIT:2> ] <EOL> def set_depth ( self , d_min , d_max ) : <EOL> '''<STR_LIT>''' <EOL> self . d_min = d_min <EOL> self . d_max = d_max <EOL> def _read_depth ( self , group ) : <EOL> self . d_min = group . attrs [ '<STR_LIT>' ] <EOL> self . d_max = group . attrs [ '<STR_LIT>' ] <EOL> def _write_depth ( self , group ) : <EOL> group . attrs [ '<STR_LIT>' ] = self . d_min <EOL> group . attrs [ '<STR_LIT>' ] = self . d_max <EOL> def _read_viewing_info ( self , group ) : <EOL> if str2bool ( group . attrs [ '<STR_LIT>' ] ) : <EOL> self . _read_inside_observer ( group ) <EOL> else : <EOL> self . _read_peeloff_origin ( group ) <EOL> self . _read_ignore_optical_depth ( group ) <EOL> self . _read_viewing_angles ( group ) <EOL> self . _read_depth ( group ) <EOL> def _write_viewing_info ( self , group ) : <EOL> if self . peeloff_origin is not None and self . inside_observer is not None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if self . inside_observer is not None : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( True ) <EOL> self . _write_inside_observer ( group ) <EOL> if self . viewing_angles == [ ] : <EOL> self . set_viewing_angles ( [ <NUM_LIT> ] , [ <NUM_LIT:0.> ] ) <EOL> if self . image and self . xmin < self . xmax : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . d_min < <NUM_LIT:0.> : <EOL> if self . d_min != - np . inf : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . d_min = <NUM_LIT:0.> <EOL> if self . d_max < <NUM_LIT:0.> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> elif len ( self . viewing_angles ) > <NUM_LIT:0> : <EOL> group . attrs [ '<STR_LIT>' ] = bool2str ( False ) <EOL> if self . peeloff_origin is None : <EOL> self . set_peeloff_origin ( ( <NUM_LIT:0.> , <NUM_LIT:0.> , <NUM_LIT:0.> ) ) <EOL> self . _write_peeloff_origin ( group ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . _write_ignore_optical_depth ( group ) <EOL> self . _write_viewing_angles ( group ) <EOL> self . _write_depth ( group ) </s>
