idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
36,100
def run ( self , stream = sys . stdout , dry_run = False , stage_files = True , resubmit_failed = False ) : self . _run_chain ( stream , dry_run , stage_files , resubmit_failed = resubmit_failed )
Runs this Chain .
36,101
def print_status ( self , indent = "" , recurse = False ) : print ( "%s%30s : %15s : %20s" % ( indent , "Linkname" , "Link Status" , "Jobs Status" ) ) for link in self . _links . values ( ) : if hasattr ( link , 'check_status' ) : status_vect = link . check_status ( stream = sys . stdout , no_wait = True , do_print = F...
Print a summary of the job status for each Link in this Chain
36,102
def print_summary ( self , stream = sys . stdout , indent = "" , recurse_level = 2 ) : Link . print_summary ( self , stream , indent , recurse_level ) if recurse_level > 0 : recurse_level -= 1 indent += " " for link in self . _links . values ( ) : stream . write ( "\n" ) link . print_summary ( stream , indent , recurs...
Print a summary of the activity done by this Chain .
36,103
def get_component_info ( self , comp ) : if self . components is None : raise ValueError ( 'Model component %s does not have sub-components' % self . sourcekey ) if self . moving : comp_key = "zmax%i" % ( comp . zmax ) elif self . selection_dependent : comp_key = comp . make_key ( '{ebin_name}_{evtype_name}' ) else : r...
Return the information about sub - component specific to a particular data selection
36,104
def add_component_info ( self , compinfo ) : if self . components is None : self . components = { } self . components [ compinfo . comp_key ] = compinfo
Add sub - component specific information to a particular data selection
36,105
def clone_and_merge_sub ( self , key ) : new_comp = copy . deepcopy ( self ) new_comp . components = None new_comp . comp_key = key return new_comp
Clones self and merges clone with sub - component specific information
36,106
def add_columns ( t0 , t1 ) : for colname in t1 . colnames : col = t1 . columns [ colname ] if colname in t0 . columns : continue new_col = Column ( name = col . name , length = len ( t0 ) , dtype = col . dtype ) t0 . add_column ( new_col )
Add columns of table t1 to table t0 .
36,107
def join_tables ( left , right , key_left , key_right , cols_right = None ) : right = right . copy ( ) if cols_right is None : cols_right = right . colnames else : cols_right = [ c for c in cols_right if c in right . colnames ] if key_left != key_right : right [ key_right ] . name = key_left if key_left not in cols_rig...
Perform a join of two tables .
36,108
def strip_columns ( tab ) : for colname in tab . colnames : if tab [ colname ] . dtype . kind in [ 'S' , 'U' ] : tab [ colname ] = np . core . defchararray . strip ( tab [ colname ] )
Strip whitespace from string columns .
36,109
def row_to_dict ( row ) : o = { } for colname in row . colnames : if isinstance ( row [ colname ] , np . string_ ) and row [ colname ] . dtype . kind in [ 'S' , 'U' ] : o [ colname ] = str ( row [ colname ] ) else : o [ colname ] = row [ colname ] return o
Convert a table row to a dictionary .
36,110
def check_log ( logfile , exited = 'Exited with exit code' , successful = 'Successfully completed' , exists = True ) : if not os . path . exists ( logfile ) : return not exists if exited in open ( logfile ) . read ( ) : return 'Exited' elif successful in open ( logfile ) . read ( ) : return 'Successful' else : return '...
Often logfile doesn t exist because the job hasn t begun to run . It is unclear what you want to do in that case ...
36,111
def dispatch_job ( jobname , exe , args , opts , batch_opts , dry_run = True ) : batch_opts . setdefault ( 'W' , 300 ) batch_opts . setdefault ( 'R' , 'rhel60 && scratch > 10' ) cmd_opts = '' for k , v in opts . items ( ) : if isinstance ( v , list ) : cmd_opts += ' ' . join ( [ '--%s=%s' % ( k , t ) for t in v ] ) eli...
Dispatch an LSF job .
36,112
def create_from_flux ( cls , params , emin , emax , flux , scale = 1.0 ) : params = params . copy ( ) params [ 0 ] = 1.0 params [ 0 ] = flux / cls . eval_flux ( emin , emax , params , scale = scale ) return cls ( params , scale )
Create a spectral function instance given its flux .
36,113
def create_from_eflux ( cls , params , emin , emax , eflux , scale = 1.0 ) : params = params . copy ( ) params [ 0 ] = 1.0 params [ 0 ] = eflux / cls . eval_eflux ( emin , emax , params , scale = scale ) return cls ( params , scale )
Create a spectral function instance given its energy flux .
36,114
def _integrate ( cls , fn , emin , emax , params , scale = 1.0 , extra_params = None , npt = 20 ) : emin = np . expand_dims ( emin , - 1 ) emax = np . expand_dims ( emax , - 1 ) params = copy . deepcopy ( params ) for i , p in enumerate ( params ) : params [ i ] = np . expand_dims ( params [ i ] , - 1 ) xedges = np . l...
Fast numerical integration method using mid - point rule .
36,115
def dnde ( self , x , params = None ) : params = self . params if params is None else params return np . squeeze ( self . eval_dnde ( x , params , self . scale , self . extra_params ) )
Evaluate differential flux .
36,116
def ednde ( self , x , params = None ) : params = self . params if params is None else params return np . squeeze ( self . eval_ednde ( x , params , self . scale , self . extra_params ) )
Evaluate E times differential flux .
36,117
def e2dnde ( self , x , params = None ) : params = self . params if params is None else params return np . squeeze ( self . eval_e2dnde ( x , params , self . scale , self . extra_params ) )
Evaluate E^2 times differential flux .
36,118
def dnde_deriv ( self , x , params = None ) : params = self . params if params is None else params return np . squeeze ( self . eval_dnde_deriv ( x , params , self . scale , self . extra_params ) )
Evaluate derivative of the differential flux with respect to E .
36,119
def ednde_deriv ( self , x , params = None ) : params = self . params if params is None else params return np . squeeze ( self . eval_ednde_deriv ( x , params , self . scale , self . extra_params ) )
Evaluate derivative of E times differential flux with respect to E .
36,120
def e2dnde_deriv ( self , x , params = None ) : params = self . params if params is None else params return np . squeeze ( self . eval_e2dnde_deriv ( x , params , self . scale , self . extra_params ) )
Evaluate derivative of E^2 times differential flux with respect to E .
36,121
def flux ( self , emin , emax , params = None ) : params = self . params if params is None else params return np . squeeze ( self . eval_flux ( emin , emax , params , self . scale , self . extra_params ) )
Evaluate the integral flux .
36,122
def eflux ( self , emin , emax , params = None ) : params = self . params if params is None else params return np . squeeze ( self . eval_eflux ( emin , emax , params , self . scale , self . extra_params ) )
Evaluate the integral energy flux .
36,123
def compare_SED ( castroData1 , castroData2 , ylims , TS_thresh = 4.0 , errSigma = 1.0 , specVals = [ ] ) : import matplotlib . pyplot as plt xmin = min ( castroData1 . refSpec . ebins [ 0 ] , castroData2 . refSpec . ebins [ 0 ] ) xmax = max ( castroData1 . refSpec . ebins [ - 1 ] , castroData2 . refSpec . ebins [ - 1 ...
Compare two SEDs
36,124
def make_ring_dicts ( ** kwargs ) : library_yamlfile = kwargs . get ( 'library' , 'models/library.yaml' ) gmm = kwargs . get ( 'GalpropMapManager' , GalpropMapManager ( ** kwargs ) ) if library_yamlfile is None or library_yamlfile == 'None' : return gmm diffuse_comps = DiffuseModelManager . read_diffuse_component_yaml ...
Build and return the information about the Galprop rings
36,125
def make_diffuse_comp_info_dict ( ** kwargs ) : library_yamlfile = kwargs . pop ( 'library' , 'models/library.yaml' ) components = kwargs . pop ( 'components' , None ) if components is None : comp_yamlfile = kwargs . pop ( 'comp' , 'config/binning.yaml' ) components = Component . build_from_yamlfile ( comp_yamlfile ) g...
Build and return the information about the diffuse components
36,126
def read_galprop_rings_yaml ( self , galkey ) : galprop_rings_yaml = self . _name_factory . galprop_rings_yaml ( galkey = galkey , fullpath = True ) galprop_rings = yaml . safe_load ( open ( galprop_rings_yaml ) ) return galprop_rings
Read the yaml file for a partiuclar galprop key
36,127
def make_ring_filename ( self , source_name , ring , galprop_run ) : format_dict = self . __dict__ . copy ( ) format_dict [ 'sourcekey' ] = self . _name_factory . galprop_ringkey ( source_name = source_name , ringkey = "ring_%i" % ring ) format_dict [ 'galprop_run' ] = galprop_run return self . _name_factory . galprop_...
Make the name of a gasmap file for a single ring
36,128
def make_merged_name ( self , source_name , galkey , fullpath ) : format_dict = self . __dict__ . copy ( ) format_dict [ 'sourcekey' ] = self . _name_factory . galprop_sourcekey ( source_name = source_name , galpropkey = galkey ) format_dict [ 'fullpath' ] = fullpath return self . _name_factory . merged_gasmap ( ** for...
Make the name of a gasmap file for a set of merged rings
36,129
def make_xml_name ( self , source_name , galkey , fullpath ) : format_dict = self . __dict__ . copy ( ) format_dict [ 'sourcekey' ] = self . _name_factory . galprop_sourcekey ( source_name = source_name , galpropkey = galkey ) format_dict [ 'fullpath' ] = fullpath return self . _name_factory . srcmdl_xml ( ** format_di...
Make the name of an xml file for a model definition for a set of merged rings
36,130
def make_ring_filelist ( self , sourcekeys , rings , galprop_run ) : flist = [ ] for sourcekey in sourcekeys : for ring in rings : flist += [ self . make_ring_filename ( sourcekey , ring , galprop_run ) ] return flist
Make a list of all the template files for a merged component
36,131
def make_diffuse_comp_info_dict ( self , galkey ) : galprop_rings = self . read_galprop_rings_yaml ( galkey ) ring_limits = galprop_rings . get ( 'ring_limits' ) comp_dict = galprop_rings . get ( 'diffuse_comp_dict' ) remove_rings = galprop_rings . get ( 'remove_rings' , [ ] ) diffuse_comp_info_dict = { } nring = len (...
Make a dictionary maping from merged component to information about that component
36,132
def make_template_name ( self , model_type , sourcekey ) : format_dict = self . __dict__ . copy ( ) format_dict [ 'sourcekey' ] = sourcekey if model_type == 'IsoSource' : return self . _name_factory . spectral_template ( ** format_dict ) elif model_type in [ 'MapCubeSource' , 'SpatialMap' ] : return self . _name_factor...
Make the name of a template file for particular component
36,133
def make_xml_name ( self , sourcekey ) : format_dict = self . __dict__ . copy ( ) format_dict [ 'sourcekey' ] = sourcekey return self . _name_factory . srcmdl_xml ( ** format_dict )
Make the name of an xml file for a model definition of a single component
36,134
def make_diffuse_comp_info_dict ( self , diffuse_sources , components ) : ret_dict = { } for key , value in diffuse_sources . items ( ) : if value is None : continue model_type = value . get ( 'model_type' , 'MapCubeSource' ) if model_type in [ 'galprop_rings' , 'catalog' ] : continue selection_dependent = value . get ...
Make a dictionary maping from diffuse component to information about that component
36,135
def get_unique_match ( table , colname , value ) : if table [ colname ] . dtype . kind in [ 'S' , 'U' ] : mask = table [ colname ] . astype ( str ) == value else : mask = table [ colname ] == value if mask . sum ( ) != 1 : raise KeyError ( "%i rows in column %s match value %s" % ( mask . sum ( ) , colname , value ) ) r...
Get the row matching value for a particular column . If exactly one row matchs return index of that row Otherwise raise KeyError .
36,136
def main_browse ( ) : import argparse parser = argparse . ArgumentParser ( usage = "file_archive.py [options]" , description = "Browse a job archive" ) parser . add_argument ( '--files' , action = 'store' , dest = 'file_archive_table' , type = str , default = 'file_archive_temp.fits' , help = "File archive file" ) pars...
Entry point for command line use for browsing a FileArchive
36,137
def latch_file_info ( self , args ) : self . file_dict . clear ( ) for key , val in self . file_args . items ( ) : try : file_path = args [ key ] if file_path is None : continue if key [ 0 : 4 ] == 'args' : if isinstance ( file_path , list ) : tokens = file_path elif isinstance ( file_path , str ) : tokens = file_path ...
Extract the file paths from a set of arguments
36,138
def output_files ( self ) : ret_list = [ ] for key , val in self . file_dict . items ( ) : if val & FileFlags . output_mask : ret_list . append ( key ) return ret_list
Return a list of the output files produced by this link .
36,139
def chain_input_files ( self ) : ret_list = [ ] for key , val in self . file_dict . items ( ) : if val & FileFlags . in_ch_mask == FileFlags . input_mask : ret_list . append ( key ) return ret_list
Return a list of the input files needed by this chain .
36,140
def chain_output_files ( self ) : ret_list = [ ] for key , val in self . file_dict . items ( ) : if val & FileFlags . out_ch_mask == FileFlags . output_mask : ret_list . append ( key ) return ret_list
Return a list of the all the output files produced by this link .
36,141
def internal_files ( self ) : ret_list = [ ] for key , val in self . file_dict . items ( ) : if val & FileFlags . internal_mask : ret_list . append ( key ) return ret_list
Return a list of the intermediate files produced by this link .
36,142
def temp_files ( self ) : ret_list = [ ] for key , val in self . file_dict . items ( ) : if val & FileFlags . rm_mask : ret_list . append ( key ) return ret_list
Return a list of the temporary files produced by this link .
36,143
def gzip_files ( self ) : ret_list = [ ] for key , val in self . file_dict . items ( ) : if val & FileFlags . gz_mask : ret_list . append ( key ) return ret_list
Return a list of the files compressed by this link .
36,144
def split_local_path ( self , local_file ) : abspath = os . path . abspath ( local_file ) if abspath . find ( self . workdir ) >= 0 : relpath = abspath . replace ( self . workdir , '' ) [ 1 : ] basename = os . path . basename ( relpath ) dirname = os . path . dirname ( relpath ) else : basename = os . path . basename (...
Split the local path into a directory name and a file name
36,145
def construct_scratch_path ( self , dirname , basename ) : return os . path . join ( self . scratchdir , dirname , basename )
Construct and return a path in the scratch area .
36,146
def get_scratch_path ( self , local_file ) : ( local_dirname , local_basename ) = self . split_local_path ( local_file ) return self . construct_scratch_path ( local_dirname , local_basename )
Construct and return a path in the scratch area from a local file .
36,147
def map_files ( self , local_files ) : ret_dict = { } for local_file in local_files : ret_dict [ local_file ] = self . get_scratch_path ( local_file ) return ret_dict
Build a dictionary mapping local paths to scratch paths .
36,148
def make_scratch_dirs ( file_mapping , dry_run = True ) : scratch_dirs = { } for value in file_mapping . values ( ) : scratch_dirname = os . path . dirname ( value ) scratch_dirs [ scratch_dirname ] = True for scratch_dirname in scratch_dirs : if dry_run : print ( "mkdir -f %s" % ( scratch_dirname ) ) else : try : os ....
Make any directories need in the scratch area
36,149
def copy_to_scratch ( file_mapping , dry_run = True ) : for key , value in file_mapping . items ( ) : if not os . path . exists ( key ) : continue if dry_run : print ( "copy %s %s" % ( key , value ) ) else : print ( "copy %s %s" % ( key , value ) ) copyfile ( key , value ) return file_mapping
Copy input files to scratch area
36,150
def copy_from_scratch ( file_mapping , dry_run = True ) : for key , value in file_mapping . items ( ) : if dry_run : print ( "copy %s %s" % ( value , key ) ) else : try : outdir = os . path . dirname ( key ) os . makedirs ( outdir ) except OSError : pass print ( "copy %s %s" % ( value , key ) ) copyfile ( value , key )...
Copy output files from scratch area
36,151
def make_table ( file_dict ) : col_key = Column ( name = 'key' , dtype = int ) col_path = Column ( name = 'path' , dtype = 'S256' ) col_creator = Column ( name = 'creator' , dtype = int ) col_timestamp = Column ( name = 'timestamp' , dtype = int ) col_status = Column ( name = 'status' , dtype = int ) col_flags = Column...
Build and return an astropy . table . Table to store FileHandle
36,152
def make_dict ( cls , table ) : ret_dict = { } for row in table : file_handle = cls . create_from_row ( row ) ret_dict [ file_handle . key ] = file_handle return ret_dict
Build and return a dict of FileHandle from an astropy . table . Table
36,153
def create_from_row ( cls , table_row ) : kwargs = { } for key in table_row . colnames : kwargs [ key ] = table_row [ key ] try : return cls ( ** kwargs ) except KeyError : print ( kwargs )
Build and return a FileHandle from an astropy . table . row . Row
36,154
def check_status ( self , basepath = None ) : if basepath is None : fullpath = self . path else : fullpath = os . path . join ( basepath , self . path ) exists = os . path . exists ( fullpath ) if not exists : if self . flags & FileFlags . gz_mask != 0 : fullpath += '.gz' exists = os . path . exists ( fullpath ) if exi...
Check on the status of this particular file
36,155
def update_table_row ( self , table , row_idx ) : table [ row_idx ] [ 'path' ] = self . path table [ row_idx ] [ 'key' ] = self . key table [ row_idx ] [ 'creator' ] = self . creator table [ row_idx ] [ 'timestamp' ] = self . timestamp table [ row_idx ] [ 'status' ] = self . status table [ row_idx ] [ 'flags' ] = self ...
Update the values in an astropy . table . Table for this instances
36,156
def _get_fullpath ( self , filepath ) : if filepath [ 0 ] == '/' : return filepath return os . path . join ( self . _base_path , filepath )
Return filepath with the base_path prefixed
36,157
def _read_table_file ( self , table_file ) : self . _table_file = table_file if os . path . exists ( self . _table_file ) : self . _table = Table . read ( self . _table_file ) else : self . _table = FileHandle . make_table ( { } ) self . _fill_cache ( )
Read an astropy . table . Table to set up the archive
36,158
def _make_file_handle ( self , row_idx ) : row = self . _table [ row_idx ] return FileHandle . create_from_row ( row )
Build and return a FileHandle object from an astropy . table . row . Row
36,159
def get_handle ( self , filepath ) : localpath = self . _get_localpath ( filepath ) return self . _cache [ localpath ]
Get the FileHandle object associated to a particular file
36,160
def register_file ( self , filepath , creator , status = FileStatus . no_file , flags = FileFlags . no_flags ) : try : file_handle = self . get_handle ( filepath ) raise KeyError ( "File %s already exists in archive" % filepath ) except KeyError : pass localpath = self . _get_localpath ( filepath ) if status == FileSta...
Register a file in the archive .
36,161
def update_file ( self , filepath , creator , status ) : file_handle = self . get_handle ( filepath ) if status in [ FileStatus . exists , FileStatus . superseded ] : fullpath = file_handle . fullpath if not os . path . exists ( fullpath ) : raise ValueError ( "File %s does not exist" % fullpath ) timestamp = int ( os ...
Update a file in the archive
36,162
def get_file_ids ( self , file_list , creator = None , status = FileStatus . no_file , file_dict = None ) : ret_list = [ ] for fname in file_list : if file_dict is None : flags = FileFlags . no_flags else : flags = file_dict . file_dict [ fname ] try : fhandle = self . get_handle ( fname ) except KeyError : if creator ...
Get or create a list of file ids based on file names
36,163
def get_file_paths ( self , id_list ) : if id_list is None : return [ ] try : path_array = self . _table [ id_list - 1 ] [ 'path' ] except IndexError : print ( "IndexError " , len ( self . _table ) , id_list ) path_array = [ ] return [ path for path in path_array ]
Get a list of file paths based of a set of ids
36,164
def update_file_status ( self ) : nfiles = len ( self . cache . keys ( ) ) status_vect = np . zeros ( ( 6 ) , int ) sys . stdout . write ( "Updating status of %i files: " % nfiles ) sys . stdout . flush ( ) for i , key in enumerate ( self . cache . keys ( ) ) : if i % 200 == 0 : sys . stdout . write ( '.' ) sys . stdou...
Update the status of all the files in the archive
36,165
def norm ( x , mu , sigma = 1.0 ) : return stats . norm ( loc = mu , scale = sigma ) . pdf ( x )
Scipy norm function
36,166
def ln_norm ( x , mu , sigma = 1.0 ) : return np . log ( stats . norm ( loc = mu , scale = sigma ) . pdf ( x ) )
Natural log of scipy norm function truncated at zero
36,167
def lognorm ( x , mu , sigma = 1.0 ) : return stats . lognorm ( sigma , scale = mu ) . pdf ( x )
Log - normal function from scipy
36,168
def lgauss ( x , mu , sigma = 1.0 , logpdf = False ) : x = np . array ( x , ndmin = 1 ) lmu = np . log10 ( mu ) s2 = sigma * sigma lx = np . zeros ( x . shape ) v = np . zeros ( x . shape ) lx [ x > 0 ] = np . log10 ( x [ x > 0 ] ) v = 1. / np . sqrt ( 2 * s2 * np . pi ) * np . exp ( - ( lx - lmu ) ** 2 / ( 2 * s2 ) ) ...
Log10 normal distribution ...
36,169
def create_prior_functor ( d ) : functype = d . get ( 'functype' , 'lgauss_like' ) j_ref = d . get ( 'j_ref' , 1.0 ) if functype == 'norm' : return norm_prior ( d [ 'mu' ] , d [ 'sigma' ] , j_ref ) elif functype == 'lognorm' : return lognorm_prior ( d [ 'mu' ] , d [ 'sigma' ] , j_ref ) elif functype == 'gauss' : return...
Build a prior from a dictionary .
36,170
def marginalization_bins ( self ) : log_mean = np . log10 ( self . mean ( ) ) return np . logspace ( - 1. + log_mean , 1. + log_mean , 1001 ) / self . _j_ref
Binning to use to do the marginalization integrals
36,171
def profile_bins ( self ) : log_mean = np . log10 ( self . mean ( ) ) log_half_width = max ( 5. * self . sigma ( ) , 3. ) return np . logspace ( log_mean - log_half_width , log_mean + log_half_width , 101 ) / self . _j_ref
The binning to use to do the profile fitting
36,172
def normalization ( self ) : norm_r = self . normalization_range ( ) return quad ( self , norm_r [ 0 ] * self . _j_ref , norm_r [ 1 ] * self . _j_ref ) [ 0 ]
The normalization i . e . the intergral of the function over the normalization_range
36,173
def init_return ( self , ret_type ) : if self . _ret_type == ret_type : return if ret_type == "straight" : self . _interp = self . _lnlfn . interp if ret_type == "profile" : self . _profile_loglike_spline ( self . _lnlfn . interp . x ) self . _interp = self . _prof_interp elif ret_type == "marginal" : self . _marginal_...
Specify the return type .
36,174
def clear_cached_values ( self ) : self . _prof_interp = None self . _prof_y = None self . _prof_z = None self . _marg_interp = None self . _marg_z = None self . _post = None self . _post_interp = None self . _interp = None self . _ret_type = None
Removes all of the cached values and interpolators
36,175
def profile_loglike ( self , x ) : if self . _prof_interp is None : return self . _profile_loglike ( x ) [ 1 ] x = np . array ( x , ndmin = 1 ) return self . _prof_interp ( x )
Profile log - likelihood .
36,176
def marginal_loglike ( self , x ) : if self . _marg_interp is None : return self . _marginal_loglike ( x ) x = np . array ( x , ndmin = 1 ) return self . _marg_interp ( x )
Marginal log - likelihood .
36,177
def posterior ( self , x ) : if self . _post is None : return self . _posterior ( x ) x = np . array ( x , ndmin = 1 ) return self . _post_interp ( x )
Posterior function .
36,178
def _marginal_loglike ( self , x ) : yedge = self . _nuis_pdf . marginalization_bins ( ) yw = yedge [ 1 : ] - yedge [ : - 1 ] yc = 0.5 * ( yedge [ 1 : ] + yedge [ : - 1 ] ) s = self . like ( x [ : , np . newaxis ] , yc [ np . newaxis , : ] ) z = 1. * np . sum ( s * yw , axis = 1 ) self . _marg_z = np . zeros ( z . shap...
Internal function to calculate and cache the marginal likelihood
36,179
def _posterior ( self , x ) : yedge = self . _nuis_pdf . marginalization_bins ( ) yc = 0.5 * ( yedge [ 1 : ] + yedge [ : - 1 ] ) yw = yedge [ 1 : ] - yedge [ : - 1 ] like_array = self . like ( x [ : , np . newaxis ] , yc [ np . newaxis , : ] ) * yw like_array /= like_array . sum ( ) self . _post = like_array . sum ( 1 ...
Internal function to calculate and cache the posterior
36,180
def _compute_mle ( self ) : xmax = self . _lnlfn . interp . xmax x0 = max ( self . _lnlfn . mle ( ) , xmax * 1e-5 ) ret = opt . fmin ( lambda x : np . where ( xmax > x > 0 , - self ( x ) , np . inf ) , x0 , disp = False ) mle = float ( ret [ 0 ] ) return mle
Maximum likelihood estimator .
36,181
def build_from_energy_dict ( cls , ebin_name , input_dict ) : psf_types = input_dict . pop ( 'psf_types' ) output_list = [ ] for psf_type , val_dict in sorted ( psf_types . items ( ) ) : fulldict = input_dict . copy ( ) fulldict . update ( val_dict ) fulldict [ 'evtype_name' ] = psf_type fulldict [ 'ebin_name' ] = ebin...
Build a list of components from a dictionary for a single energy range
36,182
def build_from_yamlstr ( cls , yamlstr ) : top_dict = yaml . safe_load ( yamlstr ) coordsys = top_dict . pop ( 'coordsys' ) output_list = [ ] for e_key , e_dict in sorted ( top_dict . items ( ) ) : if e_key == 'coordsys' : continue e_dict = top_dict [ e_key ] e_dict [ 'coordsys' ] = coordsys output_list += cls . build_...
Build a list of components from a yaml string
36,183
def _match_cubes ( ccube_clean , ccube_dirty , bexpcube_clean , bexpcube_dirty , hpx_order ) : if hpx_order == ccube_clean . hpx . order : ccube_clean_at_order = ccube_clean else : ccube_clean_at_order = ccube_clean . ud_grade ( hpx_order , preserve_counts = True ) if hpx_order == ccube_dirty . hpx . order : ccube_dirt...
Match the HEALPIX scheme and order of all the input cubes
36,184
def _compute_intensity ( ccube , bexpcube ) : bexp_data = np . sqrt ( bexpcube . data [ 0 : - 1 , 0 : ] * bexpcube . data [ 1 : , 0 : ] ) intensity_data = ccube . data / bexp_data intensity_map = HpxMap ( intensity_data , ccube . hpx ) return intensity_map
Compute the intensity map
36,185
def _compute_mean ( map1 , map2 ) : data = ( map1 . data + map2 . data ) / 2. return HpxMap ( data , map1 . hpx )
Make a map that is the mean of two maps
36,186
def _compute_ratio ( top , bot ) : data = np . where ( bot . data > 0 , top . data / bot . data , 0. ) return HpxMap ( data , top . hpx )
Make a map that is the ratio of two maps
36,187
def _compute_diff ( map1 , map2 ) : data = map1 . data - map2 . data return HpxMap ( data , map1 . hpx )
Make a map that is the difference of two maps
36,188
def _compute_product ( map1 , map2 ) : data = map1 . data * map2 . data return HpxMap ( data , map1 . hpx )
Make a map that is the product of two maps
36,189
def _compute_counts_from_intensity ( intensity , bexpcube ) : data = intensity . data * np . sqrt ( bexpcube . data [ 1 : ] * bexpcube . data [ 0 : - 1 ] ) return HpxMap ( data , intensity . hpx )
Make the counts map from the intensity
36,190
def _compute_counts_from_model ( model , bexpcube ) : data = model . data * bexpcube . data ebins = model . hpx . ebins ratio = ebins [ 1 : ] / ebins [ 0 : - 1 ] half_log_ratio = np . log ( ratio ) / 2. int_map = ( ( data [ 0 : - 1 ] . T * ebins [ 0 : - 1 ] ) + ( data [ 1 : ] . T * ebins [ 1 : ] ) ) * half_log_ratio re...
Make the counts maps from teh mdoe
36,191
def _make_bright_pixel_mask ( intensity_mean , mask_factor = 5.0 ) : mask = np . zeros ( ( intensity_mean . data . shape ) , bool ) nebins = len ( intensity_mean . data ) sum_intensity = intensity_mean . data . sum ( 0 ) mean_intensity = sum_intensity . mean ( ) for i in range ( nebins ) : mask [ i , 0 : ] = sum_intens...
Make of mask of all the brightest pixels
36,192
def _get_aeff_corrections ( intensity_ratio , mask ) : nebins = len ( intensity_ratio . data ) aeff_corrections = np . zeros ( ( nebins ) ) for i in range ( nebins ) : bright_pixels_intensity = intensity_ratio . data [ i ] [ mask . data [ i ] ] mean_bright_pixel = bright_pixels_intensity . mean ( ) aeff_corrections [ i...
Compute a correction for the effective area from the brighter pixesl
36,193
def _apply_aeff_corrections ( intensity_map , aeff_corrections ) : data = aeff_corrections * intensity_map . data . T return HpxMap ( data . T , intensity_map . hpx )
Multipy a map by the effective area correction
36,194
def _fill_masked_intensity_resid ( intensity_resid , bright_pixel_mask ) : filled_intensity = np . zeros ( ( intensity_resid . data . shape ) ) nebins = len ( intensity_resid . data ) for i in range ( nebins ) : masked = bright_pixel_mask . data [ i ] unmasked = np . invert ( masked ) mean_intensity = intensity_resid ....
Fill the pixels used to compute the effective area correction with the mean intensity
36,195
def _smooth_hpx_map ( hpx_map , sigma ) : if hpx_map . hpx . ordering == "NESTED" : ring_map = hpx_map . swap_scheme ( ) else : ring_map = hpx_map ring_data = ring_map . data . copy ( ) nebins = len ( hpx_map . data ) smoothed_data = np . zeros ( ( hpx_map . data . shape ) ) for i in range ( nebins ) : smoothed_data [ ...
Smooth a healpix map using a Gaussian
36,196
def _intergral_to_differential ( hpx_map , gamma = - 2.0 ) : nebins = len ( hpx_map . data ) diff_map = np . zeros ( ( nebins + 1 , hpx_map . hpx . npix ) ) ebins = hpx_map . hpx . ebins ratio = ebins [ 1 : ] / ebins [ 0 : - 1 ] half_log_ratio = np . log ( ratio ) / 2. ratio_gamma = np . power ( ratio , gamma ) diff_ma...
Convert integral quantity to differential quantity
36,197
def _differential_to_integral ( hpx_map ) : ebins = hpx_map . hpx . ebins ratio = ebins [ 1 : ] / ebins [ 0 : - 1 ] half_log_ratio = np . log ( ratio ) / 2. int_map = ( ( hpx_map . data [ 0 : - 1 ] . T * ebins [ 0 : - 1 ] ) + ( hpx_map . data [ 1 : ] . T * ebins [ 1 : ] ) ) * half_log_ratio return HpxMap ( int_map . T ...
Convert a differential map to an integral map
36,198
def coadd_maps ( geom , maps , preserve_counts = True ) : map_out = gammapy . maps . Map . from_geom ( geom ) for m in maps : m_tmp = m if isinstance ( m , gammapy . maps . HpxNDMap ) : if m . geom . order < map_out . geom . order : factor = map_out . geom . nside // m . geom . nside m_tmp = m . upsample ( factor , pre...
Coadd a sequence of ~gammapy . maps . Map objects .
36,199
def sum_over_energy ( self ) : return Map ( np . sum ( self . counts , axis = 0 ) , self . wcs . dropaxis ( 2 ) )
Reduce a 3D counts cube to a 2D counts map