Coverage for python/lsst/sims/featureScheduler/features/features.py : 19%

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
'Last_observation', 'LastSequence_observation', 'LastFilterChange', 'N_observations', 'Coadded_depth', 'Last_observed', 'N_obs_night', 'Pair_in_night', 'Rotator_angle', 'N_observations_season', 'N_obs_count_season']
""" Base class for features. """ # self.feature should be a float, bool, or healpix size numpy array, or numpy masked array self.feature = None
return self.feature
""" Feature that tracks progreess of the survey. Takes observations and updates self.feature """ """ Parameters ---------- obsevation : dict-like Object that contains the information about the observation (ra, dec, filter, mjd, etc) indx : ints (None) The healpixel indices that the observation overlaps. """ raise NotImplementedError
"""Count the number of observations. Total number, not tracked over sky
Parameters ---------- filtername : str (None) The filter to count (if None, all filters counted) """ self.feature = 0 self.filtername = filtername self.tag = tag
if (self.filtername is None) and (self.tag is None): # Track all observations self.feature += 1 elif (self.filtername is not None) and (self.tag is None) and (observation['filter'][0] in self.filtername): # Track all observations on a specified filter self.feature += 1 elif (self.filtername is None) and (self.tag is not None) and (observation['tag'][0] in self.tag): # Track all observations on a specified tag self.feature += 1 elif ((self.filtername is None) and (self.tag is not None) and # Track all observations on a specified filter on a specified tag (observation['filter'][0] in self.filtername) and (observation['tag'][0] in self.tag)): self.feature += 1
"""Count the number of observations.
Parameters ---------- filtername : str (None) The filter to count (if None, all filters counted) """ season_modulo=2, offset=None, max_season=None, season_length=365.25): self.feature = 0 self.filtername = filtername self.tag = tag self.season = season self.season_modulo = season_modulo if offset is None: self.offset = np.zeros(hp.nside2npix(nside), dtype=int) else: self.offset = offset self.max_season = max_season self.season_length = season_length
season = utils.season_calc(observation['night'], modulo=self.season_modulo, offset=self.offset[indx], max_season=self.max_season, season_length=self.season_length) if self.season in season: if (self.filtername is None) and (self.tag is None): # Track all observations self.feature += 1 elif (self.filtername is not None) and (self.tag is None) and (observation['filter'][0] in self.filtername): # Track all observations on a specified filter self.feature += 1 elif (self.filtername is None) and (self.tag is not None) and (observation['tag'][0] in self.tag): # Track all observations on a specified tag self.feature += 1 elif ((self.filtername is None) and (self.tag is not None) and # Track all observations on a specified filter on a specified tag (observation['filter'][0] in self.filtername) and (observation['tag'][0] in self.tag)): self.feature += 1
"""Count the number of observations.
Parameters ---------- note : str (None) Only count observations that have str in their note field """ self.feature = 0 self.note = note
# Track all observations if self.note is None: self.feature += 1 else: if self.note == observation['note']: self.feature += 1
"""Track the last observation. Useful if you want to see when the last time a survey took an observation.
Parameters ---------- survey_name : str (None) Only records if the survey name matches (or survey_name set to None) """ self.survey_name = survey_name # Start out with an empty observation self.feature = utils.empty_observation()
if self.survey_name is not None: if self.survey_name in observation['note']: self.feature = observation else: self.feature = observation
"""When was the last observation """ self.sequence_ids = sequence_ids # The ids of all sequence observations... # Start out with an empty observation self.feature = utils.empty_observation()
if observation['survey_id'] in self.sequence_ids: self.feature = observation
"""Record when the filter last changed. """ self.feature = {'mjd': 0., 'previous_filter': None, 'current_filter': None}
if self.feature['current_filter'] is None: self.feature['mjd'] = observation['mjd'][0] self.feature['previous_filter'] = None self.feature['current_filter'] = observation['filter'][0] elif observation['filter'][0] != self.feature['current_filter']: self.feature['mjd'] = observation['mjd'][0] self.feature['previous_filter'] = self.feature['current_filter'] self.feature['current_filter'] = observation['filter'][0]
""" Track the number of observations that have been made across the sky.
Parameters ---------- filtername : str ('r') String or list that has all the filters that can count. nside : int (32) The nside of the healpixel map to use mask_indx : list of ints (None) List of healpixel indices to mask and interpolate over
""" if nside is None: nside = utils.set_default_nside()
self.feature = np.zeros(hp.nside2npix(nside), dtype=float) self.filtername = filtername self.mask_indx = mask_indx
""" Parameters ---------- indx : ints The indices of the healpixel map that have been observed by observation """
if self.filtername is None or observation['filter'][0] in self.filtername: self.feature[indx] += 1
if self.mask_indx is not None: overlap = np.intersect1d(indx, self.mask_indx) if overlap.size > 0: # interpolate over those pixels that are DD fields. # XXX. Do I need to kdtree this? Maybe make a dict on init # to lookup the N closest non-masked pixels, then do weighted average. pass
""" Track the number of observations that have been made across sky
Parameters ---------- season : int Only count observations in this season (year). filtername : str ('r') String or list that has all the filters that can count. nside : int (32) The nside of the healpixel map to use offset : int (0) The offset to use when computing the season (days) modulo : int (None) How to mod the years when computing season
""" max_season=None, season_length=365.25): if offset is None: offset = np.zeros(hp.nside2npix(nside), dtype=int) if nside is None: nside = utils.set_default_nside()
self.feature = np.zeros(hp.nside2npix(nside), dtype=float) self.filtername = filtername self.offset = offset self.modulo = modulo self.season = season self.max_season = max_season self.season_length = season_length
""" Parameters ---------- indx : ints The indices of the healpixel map that have been observed by observation """
observation_season = utils.season_calc(observation['night'], offset=self.offset[indx], modulo=self.modulo, max_season=self.max_season, season_length=self.season_length) if self.season in observation_season: if self.filtername is None or observation['filter'][0] in self.filtername: self.feature[indx] += 1
""" Track the co-added depth that has been reached accross the sky """ if nside is None: nside = utils.set_default_nside() self.filtername = filtername # Starting at limiting mag of zero should be fine. self.feature = np.zeros(hp.nside2npix(nside), dtype=float)
if observation['filter'][0] == self.filtername: m5 = m5_flat_sed(observation['filter'][0], observation['skybrightness'][0], observation['FWHMeff'][0], observation['exptime'][0], observation['airmass'][0]) self.feature[indx] = 1.25 * np.log10(10.**(0.8*self.feature[indx]) + 10.**(0.8*m5))
""" Track when a pixel was last observed. Assumes observations are added in chronological order. """ if nside is None: nside = utils.set_default_nside()
self.filtername = filtername self.feature = np.zeros(hp.nside2npix(nside), dtype=float)
if self.filtername is None: self.feature[indx] = observation['mjd'] elif observation['filter'][0] in self.filtername: self.feature[indx] = observation['mjd']
""" Track how many times something has been observed in a night (Note, even if there are two, it might not be a good pair.)
Parameters ---------- filtername : string ('r') Filter to track. nside : int (32) Scale of the healpix map
""" if nside is None: nside = utils.set_default_nside()
self.filtername = filtername self.feature = np.zeros(hp.nside2npix(nside), dtype=int) self.night = None
if observation['night'][0] != self.night: self.feature *= 0 self.night = observation['night'][0] if observation['filter'][0] in self.filtername: self.feature[indx] += 1
""" Track how many pairs have been observed within a night
Parameters ---------- gap_min : float (25.) The minimum time gap to consider a successful pair in minutes gap_max : float (45.) The maximum time gap to consider a successful pair (minutes) """ if nside is None: nside = utils.set_default_nside()
self.filtername = filtername self.feature = np.zeros(hp.nside2npix(nside), dtype=float) self.indx = np.arange(self.feature.size) self.last_observed = Last_observed(filtername=filtername) self.gap_min = gap_min / (24.*60) # Days self.gap_max = gap_max / (24.*60) # Days self.night = 0 # Need to keep a full record of times and healpixels observed in a night. self.mjd_log = [] self.hpid_log = []
if observation['filter'][0] in self.filtername: if indx is None: indx = self.indx # Clear values if on a new night if self.night != observation['night']: self.feature *= 0. self.night = observation['night'] self.mjd_log = [] self.hpid_log = []
# record the mjds and healpixels that were observed self.mjd_log.extend([np.max(observation['mjd'])]*np.size(indx)) self.hpid_log.extend(list(indx))
# Look for the mjds that could possibly pair with observation tmin = observation['mjd'] - self.gap_max tmax = observation['mjd'] - self.gap_min mjd_log = np.array(self.mjd_log) left = np.searchsorted(mjd_log, tmin) right = np.searchsorted(mjd_log, tmax, side='right') # Now check if any of the healpixels taken in the time gap # match the healpixels of the observation. matches = np.in1d(indx, self.hpid_log[int(left):int(right)]) # XXX--should think if this is the correct (fastest) order to check things in. self.feature[indx[matches]] += 1
""" Track what rotation angles things are observed with. XXX-under construction """ """
""" if nside is None: nside = utils.set_default_nside()
self.filtername = filtername # Actually keep a histogram at each healpixel self.feature = np.zeros((hp.nside2npix(nside), 360./binsize), dtype=float) self.bins = np.arange(0, 360+binsize, binsize)
if observation['filter'][0] == self.filtername: # I think this is how to broadcast things properly. self.feature[indx, :] += np.histogram(observation.rotSkyPos, bins=self.bins)[0] |