opsimsummary.simlib module¶
Module with functionality to represent SNANA simlib data.
-
class
opsimsummary.simlib.
SimlibMixin
[source]¶ Bases:
object
Mixin for SummaryOpsim to provide the following additional functionality geared towards creating simlibs for SNANA. - Calculate additional columns for simlib either on a complete
OpSimOutput.summary dataframe, or for a dataframe for a particular patch of sky (LIBID in the SNANA language).- Calculate variables required for SNANA simlib outside the Opsim data
- The parent class must have the following attributes:
- subset (must be a valid string)
The following attributes cannot be set by the user and are set by simlibVars - user (default can be None) - host (default can be None) - telescope - survey - pixelSize
In order to be able to write out the simlibs to disk, it should also have a method to provide a sequence (may be a generator) of fields, and opsimtables. The fields are instances of a class which has the following information
fieldID ra dec mwebv (which may be set to a default value). The responsibility of selection of such fields and sorting out the correct requirements is of the parent class.
Attributes: simlibVars
Collection of Attributes provided by the static method self.get_simlibVars as an ordered dict with the following keys (user, host, pixelSize, survey, telescope).
Methods
add_simlibCols
(opsimtable[, pixelSize])Parameters: fieldheader
(fieldID, ra, dec, opsimtable[, …])Parameters: get_simlibVars
([user, host, pixelSize, …])Computes quantities only necessary for SNANA Simlib Calculation Parameters ———- user: string, optional, defaults to None user running the program, used in writing out SNANA simlibs only if None, the login name of the user is used. preprocess_lib
(opsimtable)preprocess the dataframe with data for a single SNANA simlib field (ie. simLibheader
([numLibId, saturation_flag, …])return a string that is the header of the simlib file fieldfooter formatSimLibField simLibFooter simlibFieldasString writeSimlib -
static
add_simlibCols
(opsimtable, pixelSize=0.2)[source]¶ Parameters: - opsimtable: `~pandas.DataFrame` object, mandatory
containing an opsim Output of version X. The main requirements here are that the columns ‘finSeeing’, ‘fiveSigmaDepth’, and ‘filtSkyBrightness’ are defined. If the opsim output has differently named variables or transformed variables, these should be changed to meet the criteria.
- pixelSize: float, units of arc sec, defaults to LSST value of 0.2
pixel Size
Returns: - DataFrame with additional columns of ‘simLibPsf’, ‘simLibZPTAVG’, and
- ‘simLibSkySig’
- .. note :: This was written from a piece of f77 code by David
Cinabro sent by email on May 26, 2015.
-
fieldheader
(fieldID, ra, dec, opsimtable, mwebv=0.0, fieldtype=None)[source]¶ Parameters: - fieldID : int
integer for the unique field ID
- ra : float, degrees
ra of the field location
- dec : float, degrees
dec of the field location
- opsimtable : np.array of pd.DataFrame
sequence of OpSim observations in above format to find number of observations.
- mwebv : float, defaults to 0.0
milky way E(B-v) value. This is usually recomputed in SNANA depending on flags, and hence can be left as 0.0
- fieldtype : string, defaults to None
string used to construct Field: fieldtype line, if None this line is left out.
-
static
get_simlibVars
(user=None, host=None, pixelSize=0.2, telescope='LSST', survey='LSST')[source]¶ Computes quantities only necessary for SNANA Simlib Calculation Parameters ———- user: string, optional, defaults to None
user running the program, used in writing out SNANA simlibs only if None, the login name of the user is used.- host: string, optional, defaults to None
- name of host machine, used only in writing out SNANA simlibs default of None assigns the output of hostname to this variable.
- pixelSize: float, optional, defaults to 0.2
- size of the pixel in arcseconds, defaults to 0.2 as appropriate for LSST
- survey: string, optional, defaults to ‘LSST’
- name of survey, required only for writing out SNANA simlibs
- telescope: string, optional, defaults to ‘LSST’
- name of survey, required only for writing out SNANA simlibs
-
pixelSize
= 0.2¶
-
preprocess_lib
(opsimtable)[source]¶ preprocess the dataframe with data for a single SNANA simlib field (ie. data corresponding to a single libid) if necessary.
Parameters: - opsimtable : pd.DataFrame with required data from OpSim corresponding
to a single field.
-
simLibheader
(numLibId=None, saturation_flag=1024, comments='\n')[source]¶ - return a string that is the header of the simlib file
Parameters: - numLibId : int, defaults to None
number of libids in simlib
- saturation_flag : int, defaults to 1024
value desired as saturation flag
comments: string, defaults to `
- `
comments passed on to simlib output
-
simlibVars
¶ Collection of Attributes provided by the static method self.get_simlibVars as an ordered dict with the following keys (user, host, pixelSize, survey, telescope). Calling this. also sets class variables for each of these keys.
-
class
opsimsummary.simlib.
Simlibs
(pointings, opsimversion='lsstv3', raCol='ditheredRA', decCol='ditheredDec', angleUnit='degrees', indexCol='obsHistID', usePointingTree=False, subset='None')[source]¶ Bases:
opsimsummary.summarize_opsim.SynOpSim
,opsimsummary.simlib.SimlibMixin
A class to write out simlibs to disk
Attributes: - host
pointingTree
if self.usePointingTree is False, this is set to None. Otherewise
simlibVars
Collection of Attributes provided by the static method self.get_simlibVars as an ordered dict with the following keys (user, host, pixelSize, survey, telescope).
- user
Methods
add_simlibCols
(opsimtable[, pixelSize])Parameters: df_subset_columns
(df, subset)Return the dataframe df with only a subset of the columns as specified in the list subset fieldheader
(fieldID, ra, dec, opsimtable[, …])Parameters: fromOpSimDB
(dbname[, subset, opsimversion, …])Class Method to instantiate this from an OpSim sqlite database output which largely uses OpSimOutput.fromOpSimDB get_simlibVars
([user, host, pixelSize, …])Computes quantities only necessary for SNANA Simlib Calculation Parameters ———- user: string, optional, defaults to None user running the program, used in writing out SNANA simlibs only if None, the login name of the user is used. get_surveyPix
(surveydf[, numFields, rng])Get a random selection of survey pixels observed that have numbers of visits in between the min and max visits. observedVisitsinRegion
([nside, nest, …])return a pd.DataFrame with the healpixelID=’hid’, ra and dec of the healpixels ‘hpix_ra’, ‘hpix_dec’ in radians, and count the number of visits for all healpixels that have visits satisfying minVisits <= count <= maxVisits . pointingsEnclosing
(ra, dec[, circRadius, …])Helper method returning a generator of pointings overlapping with circles of radius circRadius around a sequence of positions given in terms of `ra and dec. preprocess_lib
(opsimtable)preprocess the dataframe with data for a single SNANA simlib field (ie. sampleRegion
([numFields, minVisits, nest, …])This method samples a number numFields fields provided they have a minimal number of visits minVisits simLibheader
([numLibId, saturation_flag, …])return a string that is the header of the simlib file simlibs_for_fields
(surveyPix[, mwebv])Generator for simlib fields for a sequence of fields defined in a dataFrame called surveyPix. fieldfooter formatSimLibField randomSimlibs simLibFooter simlibFieldasString writeSimlib -
get_surveyPix
(surveydf, numFields=15, rng=<mtrand.RandomState object>)[source]¶ Get a random selection of survey pixels observed that have numbers of visits in between the min and max visits.
Parameters: - surveydf : pd.DataFrame
a pandas dataframe with a collection of selected fields with at least the the following columns a unique index hid for each field, an ra, and a dec
- numFields : integer, defaults to 15
number of samples of fields desired.
- rng : instance of np.random.RandomState, defualts to using 0 as seed
a random state.
Returns: - a dataframe with at least `hid` the original index for each field, `ra`,
- `dec`, and `simlibID` sorted by `simlibId`. This dataframe contains a
- mapping from the new index `simlibId` to the old index `hid`
-
host
= None¶
-
pixelSize
= 0.2¶
-
randomSimlibs
(numFields=50, fname='test.simlib', rng=<mtrand.RandomState object>, outfile=None, mapping_outfile='mapping.csv', mwebv=0.0, fieldtype=None, minVisits=1)[source]¶
-
simlibs_for_fields
(surveyPix, mwebv=0.0)[source]¶ Generator for simlib fields for a sequence of fields defined in a dataFrame called surveyPix. The dataFrame surveyPix must have the following columns simlibId, ra, dec and must be sorted in increasing order of simlibId.
Parameters: - surveyPix : pd.dataFrame
with the following columns simlibId, ra, dec
- mwebv : np.float defaults to 0.
A default value for the MW extinction
Returns: - a generator of fields for the simlib file
-
survey
= 'LSST'¶
-
telescope
= 'LSST'¶
-
user
= None¶