Coverage for python/lsst/sims/maf/stackers/generalStackers.py : 69%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
_buildTree, _xyz_from_ra_dec
'FilterColorStacker', 'ZenithDistStacker', 'ParallacticAngleStacker', 'SeasonStacker', 'DcrStacker', 'FiveSigmaStacker', 'OpSimFieldStacker']
# Original stackers by Peter Yoachim (yoachim@uw.edu) # Filter color stacker by Lynne Jones (lynnej@uw.edu) # Season stacker by Phil Marshall (dr.phil.marshall@gmail.com), # modified by Humna Awan (humna.awan@rutgers.edu)
""" Calculate the 5-sigma limiting depth for a point source in the given conditions.
This is generally not needed, unless the m5 parameters have been updated or m5 was not previously calculated. """
filterCol='filter', exptimeCol='visitExposureTime'):
if cols_present: # Column already present in data; assume it needs updating and recalculate. return simData filts = np.unique(simData[self.filterCol]) for filtername in filts: infilt = np.where(simData[self.filterCol] == filtername) simData['m5_simsUtils'][infilt] = m5_flat_sed(filtername, simData[infilt][self.skybrightnessCol], simData[infilt][self.seeingCol], simData[infilt][self.exptimeCol], simData[infilt][self.airmassCol]) return simData
"""Calculate the normalized airmass for each opsim pointing. """
degrees=True, telescope_lat = -30.2446388):
"""Calculate new column for normalized airmass.""" # Run method is required to calculate column. # Driver runs getColInfo to know what columns are needed from db & which are calculated, # then gets data from db and then calculates additional columns (via run methods here). # Column already present in data; assume it is correct and does not need recalculating. return simData
"""Calculate the zenith distance for each pointing. If 'degrees' is True, then assumes altCol is in degrees and returns degrees. If 'degrees' is False, assumes altCol is in radians and returns radians. """
else: self.unit = ['radians']
"""Calculate new column for zenith distance.""" if cols_present: # Column already present in data; assume it is correct and does not need recalculating. return simData if self.degrees: simData['zenithDistance'] = 90.0 - simData[self.altCol] else: simData['zenithDistance'] = np.pi/2.0 - simData[self.altCol] return simData
"""Calculate the parallax factors for each opsim pointing. Output parallax factor in arcseconds. """
"""Calculate x/y projection of RA1/Dec1 in system with center at RAcen, Deccenp. Input radians. """ # also used in Global Telescope Network website
# Column already present in data; assume it is correct and does not need recalculating. return simData
# Object with a 1 arcsec parallax 0., 0., 1., 0., mtoa_params) # Object with no parallax 0., 0., 0., 0., mtoa_params) ra, dec) # Return ra_pi_amp and dec_pi_amp in arcseconds.
"""Calculate the RA,Dec offset expected for an object due to differential chromatic refraction.
For DCR calculation, we also need zenithDistance, HA, and PA -- but these will be explicitly handled within this stacker so that setup is consistent and they run in order. If those values have already been calculated elsewhere, they will not be overwritten.
Parameters ---------- filterCol : str The name of the column with filter names. Default 'fitler'. altCol : str Name of the column with altitude info. Default 'altitude'. raCol : str Name of the column with RA. Default 'fieldRA'. decCol : str Name of the column with Dec. Default 'fieldDec'. lstCol : str Name of the column with local sidereal time. Default 'observationStartLST'. site : str or lsst.sims.utils.Site Name of the observory or a lsst.sims.utils.Site object. Default 'LSST'. mjdCol : str Name of column with modified julian date. Default 'observationStartMJD' dcr_magnitudes : dict Magitude of the DCR offset for each filter at altitude/zenith distance of 45 degrees. Defaults u=0.07, g=0.07, r=0.50, i=0.045, z=0.042, y=0.04 (all arcseconds).
Returns ------- numpy.array Returns array with additional columns 'ra_dcr_amp' and 'dec_dcr_amp' with the DCR offsets for each observation. Also runs ZenithDistStacker and ParallacticAngleStacker. """
raCol='fieldRA', decCol='fieldDec', lstCol='observationStartLST', site='LSST', mjdCol='observationStartMJD', dcr_magnitudes=None): # DCR amplitudes are in arcseconds. else: self.dcr_magnitudes = dcr_magnitudes # 'zenithDist', 'PA', 'HA' are additional columns required, coming from other stackers which must # also be configured -- so we handle this explicitly here. degrees=self.degrees, lstCol=lstCol, site=site) # Note that RA/Dec could be coming from a dither stacker! # But we will assume that coord stackers will be handled separately.
if cols_present: # Column already present in data; assume it is correct and does not need recalculating. return simData # Need to make sure the Zenith stacker gets run first # Call _run method because already added these columns due to 'colsAdded' line. simData = self.zstacker.run(simData) simData = self.pastacker.run(simData) if self.degrees: zenithTan = np.tan(np.radians(simData[self.zdCol])) parallacticAngle = np.radians(simData[self.paCol]) else: zenithTan = np.tan(simData[self.zdCol]) parallacticAngle = simData[self.paCol] dcr_in_ra = zenithTan * np.sin(parallacticAngle) dcr_in_dec = zenithTan * np.cos(parallacticAngle) for filtername in np.unique(simData[self.filterCol]): fmatch = np.where(simData[self.filterCol] == filtername) dcr_in_ra[fmatch] = self.dcr_magnitudes[filtername] * dcr_in_ra[fmatch] dcr_in_dec[fmatch] = self.dcr_magnitudes[filtername] * dcr_in_dec[fmatch] simData['ra_dcr_amp'] = dcr_in_ra simData['dec_dcr_amp'] = dcr_in_dec return simData
"""Add the Hour Angle for each observation. Always in HOURS. """
"""HA = LST - RA """ # Column already present in data; assume it is correct and does not need recalculating. return simData return simData else: ra = simData[self.raCol] lst = simData[self.lstCol] # Check that LST is reasonable warnings.warn('LST values are not between 0 and 2 pi') # Check that RA is reasonable warnings.warn('RA values are not between 0 and 2 pi') # Wrap the results so HA between -pi and pi # Convert radians to hours
"""Add the parallactic angle to each visit. If 'degrees' is True, this will be in degrees (as are all other angles). If False, then in radians. """
lstCol='observationStartLST', site='LSST'):
# Equation from: # http://www.gb.nrao.edu/~rcreager/GBTMetrology/140ft/l0058/gbtmemo52/memo52.html # or # http://www.gb.nrao.edu/GBT/DA/gbtidl/release2pt9/contrib/contrib/parangle.pro # Column already present in data; assume it is correct and does not need recalculating. return simData # Using the run method (not _run) means that if HA is present, it will not be recalculated. else: dec = simData[self.decCol] np.tan(self.site.latitude_rad) - np.sin(dec) * np.cos(simData['HA']*np.pi/12.)))
"""Translate filters ('u', 'g', 'r' ..) into RGB tuples. """
'g': (0, 1, 1), # cyan 'r': (0, 1, 0), # green 'i': (1, 0.5, 0.3), # orange 'z': (1, 0, 0), # red 'y': (1, 0, 1)} # magenta # self.units used for plot labels # Values required for framework operation: this specifies the data columns required from the database.
# Translate filter names into numbers. # Column already present in data; assume it is correct and does not need recalculating.
"""Add an integer label to show which season a given visit is in.
The season only depends on the RA of the object: we compute the MJD when each object is on the meridian at midnight, and subtract 6 months to get the start date of each season. The season index range is 0-10. Must wrap 0th and 10th to get a total of 10 seasons. """
# Names of columns we need from database. # List of units for our new columns. # And save the column names.
if cols_present: # Column already present in data; assume it is correct and does not need recalculating. return simData # Define year number: (note that opsim defines "years" in flat 365 days). year = np.floor((simData[self.mjdCol] - simData[self.mjdCol][0]) / 365) # Convert RA to Hours if self.degrees: objRA = simData[self.RACol]/15.0 else: objRA = np.degrees(simData[self.RACol])/15.0 # objRA=0 on autumnal equinox. # autumnal equinox 2014 happened on Sept 23 --> Equinox MJD Equinox = 2456923.5 - 2400000.5 # Use 365.25 for the length of a year here, because we're dealing with real seasons. daysSinceEquinox = 0.5*objRA*(365.25/12.0) # 0.5 to go from RA to month; 365.25/12.0 months to days firstSeasonBegan = Equinox + daysSinceEquinox - 0.5*365.25 # in MJD # Now we can compute the number of years since the first season # began, and so assign a global integer season number: globalSeason = np.floor((simData[self.mjdCol] - firstSeasonBegan)/365.25) # Subtract off season number of first observation: season = globalSeason - np.min(globalSeason) simData['year'] = year simData['season'] = season return simData
"""Add the fieldId of the closest OpSim field for each RA/Dec pointing.
Parameters ---------- raCol : str, opt Name of the RA column. Default fieldRA. decCol : str, opt Name of the Dec column. Default fieldDec.
"""
# Returned RA/Dec coordinates in degrees np.radians(dec[asort]))
# Column already present in data; assume it is correct and does not need recalculating. return simData
# use public method (degrees) coord_x, coord_y, coord_z = xyz_from_ra_dec(simData[self.raCol], simData[self.decCol]) field_ids = self.tree.query_ball_point(list(zip(coord_x, coord_y, coord_z)), xyz_angular_radius())
else: # use private method (radians) simData[self.decCol])
|