def _test_python(self): """ Test cssens from Python """ # Set-up cssens for differential sensitivity computation with # multiprocessing sens = cscripts.cssens() sens['inobs'] = 'NONE' sens['inmodel'] = self._model sens['srcname'] = 'Crab' sens['caldb'] = self._caldb sens['irf'] = self._irf sens['outfile'] = 'cssens_py1.dat' sens['duration'] = 180.0 sens['rad'] = 3.0 sens['emin'] = 1.0 sens['emax'] = 10.0 sens['bins'] = 2 sens['logfile'] = 'cssens_py1.log' sens['chatter'] = 4 # Run cssens script sens.logFileOpen() # Make sure we get a log file sens.run() sens.save() # Check pull distribution file self._check_result_file('cssens_py1.dat', nrows=3) # Set-up cssens for integral sensitivity computation without # multiprocessing sens = cscripts.cssens() sens['inobs'] = 'NONE' sens['inmodel'] = self._model sens['srcname'] = 'Crab' sens['caldb'] = self._caldb sens['irf'] = self._irf sens['outfile'] = 'cssens_py2.dat' sens['duration'] = 180.0 sens['rad'] = 3.0 sens['emin'] = 1.0 sens['emax'] = 10.0 sens['bins'] = 1 sens['type'] = 'Integral' sens['logfile'] = 'cssens_py2.log' sens['chatter'] = 4 sens['nthreads'] = 1 # Execute cssens script sens.execute() # Check pull distribution file self._check_result_file('cssens_py2.dat') # Return return
def _test_python(self): """ Test cssens from Python """ # Set-up cssens sens = cscripts.cssens() sens['inobs'] = 'NONE' sens['inmodel'] = self._model sens['srcname'] = 'Crab' sens['caldb'] = self._caldb sens['irf'] = self._irf sens['outfile'] = 'cssens_py1.dat' sens['duration'] = 1800.0 sens['rad'] = 3.0 sens['emin'] = 1.0 sens['emax'] = 10.0 sens['bins'] = 1 sens['logfile'] = 'cssens_py1.log' sens['chatter'] = 2 # Run cssens script sens.logFileOpen() # Make sure we get a log file sens.run() sens.save() # Check pull distribution file self._check_result_file('cssens_py1.dat') # Return return
def _test_pickeling(self): """ Test cssens pickeling """ # Perform pickeling tests of empty class self._pickeling(cscripts.cssens()) # Set-up unbinned cssens sens = cscripts.cssens() sens['inobs'] = 'NONE' sens['inmodel'] = self._model sens['srcname'] = 'Crab' sens['caldb'] = self._caldb sens['irf'] = self._irf sens['outfile'] = 'cssens_py1_pickle.dat' sens['duration'] = 180.0 sens['rad'] = 3.0 sens['emin'] = 1.0 sens['emax'] = 10.0 sens['bins'] = 2 sens['logfile'] = 'cssens_py1_pickle.log' sens['chatter'] = 4 # Perform pickeling tests of filled class obj = self._pickeling(sens) # Run csspec script and save light curve obj.logFileOpen() # Make sure we get a log file obj.run() obj.save() # Check result file self._check_result_file('cssens_py1_pickle.dat', nrows=3) # Return return
default=10 ,\ metavar='20' ) source.add_argument( '--emin' ,\ help='Minimum energy for events (TeV)' ,\ type=float ,\ default=0.05 ,\ metavar='0.01' ) source.add_argument( '--emax' ,\ help='Maximum energy for events (TeV)' ,\ type=float ,\ default=10.0 ,\ metavar='100.0' ) args = options.parse_args() sensitivity = cscripts.cssens() sensitivity['inmodel'] = args.inmodel sensitivity['srcname'] = args.srcname sensitivity['caldb'] = args.caldb sensitivity['irf'] = args.irf sensitivity['outfile'] = args.srcname + 'Sens{:.1f}h.txt'.format(args.hours) sensitivity['duration'] = args.hours * 3600. sensitivity['rad'] = args.rad sensitivity['emin'] = args.emin sensitivity['emax'] = args.emax sensitivity['bins'] = args.enumbins sensitivity['enumbins'] = args.enumbins sensitivity['nthreads'] = 2 sensitivity.execute()
def _calculate_sensitivity( self, job_number, duration, cwd=None, parallel_results=None, nthreads=1, load_results=False, verbose=True, ): """Run the `cssens` ctools module based on the given input.""" # set duration to a float duration = float(duration) if verbose: print(f"Running `cssens` job #{job_number} for " f"{self.params['src_name']} for a duration of {duration}s") # create cssens object sen = cscripts.cssens() outfile = (f"{cwd}/cssens_outputs/grbsens-{self.params['sigma']}" f"sigma_obstime-{duration}_irf-{self.params['irf']}.txt") logfile = (f"{cwd}/cssens_logs/grbsens-{self.params['sigma']}" f"sigma_obstime-{duration}_irf-{self.params['irf']}.log") # run cssens if not load_results or not Path(outfile).is_file(): # load input model sen["inmodel"] = self.input_model # set parameters that change each loop sen["duration"] = duration sen["outfile"] = outfile sen["logfile"] = logfile # set global parameters sen["srcname"] = self.params["src_name"] sen["caldb"] = self.params["caldb"] sen["irf"] = self.params["irf"] sen["rad"] = self.params["rad"] sen["emin"] = self.params["emin"] sen["emax"] = self.params["emax"] sen["type"] = self.params["sens_type"] sen["sigma"] = self.params["sigma"] sen["bins"] = self.params["bins"] sen["binsz"] = self.params["binsz"] sen["offset"] = self.params["offset"] sen["npix"] = self.params["npix"] # set number of cores used for energy bins sen["nthreads"] = nthreads # set chatter to max sen["chatter"] = 4 sen.execute() # format results into pandas DataFrame results = self._results_to_df(outfile, duration, job_number, logfile) # add output pandas df to results dictionary self._save_results(results=results, job_number=job_number, parallel_results=parallel_results) if verbose: # print success message print(f"Done with job #{job_number}, duration={duration}s\n")