Coverage for python/lsst/sims/maf/metrics/cadenceMetrics.py : 65%

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
'RapidRevisitMetric', 'NRevisitsMetric', 'IntraNightGapsMetric', 'InterNightGapsMetric', 'AveGapMetric']
"""Calculate the fraction of images with a previous template image of desired quality. """ metricName='TemplateExistsMetric', **kwargs): units='fraction', **kwargs)
""""Calculate the fraction of images with a previous template image of desired quality.
Parameters ---------- dataSlice : numpy.array Numpy structured array containing the data related to the visits provided by the slicer. slicePoint : dict, optional Dictionary containing information about the slicepoint currently active in the slicer.
Returns ------- float The fraction of images with a 'good' previous template image. """ # Check that data is sorted in observationStartMJD order # Find the minimum seeing up to a given time # Find the difference between the seeing and the minimum seeing at the previous visit # First image never has a template; check how many others do
"""Calculate how uniformly the observations are spaced in time. Returns a value between -1 and 1. A value of zero means the observations are perfectly uniform.
Parameters ---------- surveyLength : float, optional The overall duration of the survey. Default 10. """ surveyLength=10., **kwargs): """surveyLength = time span of survey (years) """
""""Calculate the survey uniformity.
This is based on how a KS-test works: look at the cumulative distribution of observation dates, and compare to a perfectly uniform cumulative distribution. Perfectly uniform observations = 0, perfectly non-uniform = 1.
Parameters ---------- dataSlice : numpy.array Numpy structured array containing the data related to the visits provided by the slicer. slicePoint : dict, optional Dictionary containing information about the slicepoint currently active in the slicer.
Returns ------- float Uniformity of 'observationStartMJDCol'. """ # If only one observation, there is no uniformity # Scale dates to lie between 0 and 1, where 0 is the first observation date and 1 is surveyLength (self.surveyLength * 365.25)
"""Calculate uniformity of time between consecutive visits on short timescales (for RAV1).
Parameters ---------- mjdCol : str, optional The column containing the 'time' value. Default observationStartMJD. minNvisits : int, optional The minimum number of visits required within the time interval (dTmin to dTmax). Default 100. dTmin : float, optional The minimum dTime to consider (in days). Default 40 seconds. dTmax : float, optional The maximum dTime to consider (in days). Default 30 minutes. """ dTmin=40.0 / 60.0 / 60.0 / 24.0, dTmax=30.0 / 60.0 / 24.0, metricName='RapidRevisitUniformity', **kwargs): # Update minNvisits, as 0 visits will crash algorithm and 1 is nonuniform by definition. self.minNvisits = 2
"""Calculate the uniformity of visits within dTmin to dTmax.
Uses a the same 'uniformity' calculation as the UniformityMetric, based on the KS-test. A value of 0 is perfectly uniform; a value of 1 is purely non-uniform.
Parameters ---------- dataSlice : numpy.array Numpy structured array containing the data related to the visits provided by the slicer. slicePoint : dict, optional Dictionary containing information about the slicepoint currently active in the slicer.
Returns ------- float The uniformity measurement of the visits within time interval dTmin to dTmax. """ # Calculate consecutive visit time intervals # Identify dtimes within interval from dTmin/dTmax. # If there are not enough visits in this time range, return bad value. return self.badval # Throw out dtimes outside desired range, and sort, then scale to 0-1. # Set up a uniform distribution between 0-1 (to match dtimes). # Look at the differences between our times and the uniform times.
"""Calculate the number of consecutive visits with time differences less than dT.
Parameters ---------- dT : float, optional The time interval to consider (in minutes). Default 30. normed : bool, optional Flag to indicate whether to return the total number of consecutive visits with time differences less than dT (False), or the fraction of overall visits (True). Note that we would expect (if all visits occur in pairs within dT) this fraction would be 0.5! """ else:
"""Count the number of consecutive visits occuring within time intervals dT.
Parameters ---------- dataSlice : numpy.array Numpy structured array containing the data related to the visits provided by the slicer. slicePoint : dict, optional Dictionary containing information about the slicepoint currently active in the slicer.
Returns ------- float Either the total number of consecutive visits within dT or the fraction compared to overall visits. """
""" Calculate the gap between consecutive observations within a night, in hours.
Parameters ---------- reduceFunc : function, optional Function that can operate on array-like structures. Typically numpy function. Default np.median. """
metricName='Median Intra-Night Gap', **kwargs): units = 'hours' self.mjdCol = mjdCol self.nightCol = nightCol self.reduceFunc = reduceFunc super(IntraNightGapsMetric, self).__init__(col=[self.mjdCol, self.nightCol], units=units, metricName=metricName, **kwargs)
"""Calculate the (reduceFunc) of the gap between consecutive obervations within a night.
Parameters ---------- dataSlice : numpy.array Numpy structured array containing the data related to the visits provided by the slicer. slicePoint : dict, optional Dictionary containing information about the slicepoint currently active in the slicer.
Returns ------- float The (reduceFunc) value of the gap, in hours. """ dataSlice.sort(order=self.mjdCol) dt = np.diff(dataSlice[self.mjdCol]) dn = np.diff(dataSlice[self.nightCol])
good = np.where(dn == 0) if np.size(good[0]) == 0: result = self.badval else: result = self.reduceFunc(dt[good]) * 24 return result
""" Calculate the gap between consecutive observations between nights, in days.
Parameters ---------- reduceFunc : function, optional Function that can operate on array-like structures. Typically numpy function. Default np.median. """ metricName='Median Inter-Night Gap', **kwargs): units = 'days' self.mjdCol = mjdCol self.nightCol = nightCol self.reduceFunc = reduceFunc super(InterNightGapsMetric, self).__init__(col=[self.mjdCol, self.nightCol], units=units, metricName=metricName, **kwargs)
"""Calculate the (reduceFunc) of the gap between consecutive nights of observations. Parameters ---------- dataSlice : numpy.array Numpy structured array containing the data related to the visits provided by the slicer. slicePoint : dict, optional Dictionary containing information about the slicepoint currently active in the slicer.
Returns ------- float The (reduceFunc) of the gap between consecutive nights of observations, in days. """ dataSlice.sort(order=self.mjdCol) unights = np.unique(dataSlice[self.nightCol]) if np.size(unights) < 2: result = self.badval else: # Find the first and last observation of each night firstOfNight = np.searchsorted(dataSlice[self.nightCol], unights) lastOfNight = np.searchsorted(dataSlice[self.nightCol], unights, side='right') - 1 diff = dataSlice[self.mjdCol][firstOfNight[1:]] - dataSlice[self.mjdCol][lastOfNight[:-1]] result = self.reduceFunc(diff) return result
""" Calculate the gap between any consecutive observations, in hours, regardless of night boundaries.
Parameters ---------- reduceFunc : function, optional Function that can operate on array-like structures. Typically numpy function. Default np.median. """ metricName='AveGap', **kwargs): units = 'hours' self.mjdCol = mjdCol self.nightCol = nightCol self.reduceFunc = reduceFunc super(AveGapMetric, self).__init__(col=[self.mjdCol, self.nightCol], units=units, metricName=metricName, **kwargs)
"""Calculate the (reduceFunc) of the gap between consecutive observations.
Different from inter-night and intra-night gaps, between this is really just counting all of the times between consecutive observations (not time between nights or time within a night).
Parameters ---------- dataSlice : numpy.array Numpy structured array containing the data related to the visits provided by the slicer. slicePoint : dict, optional Dictionary containing information about the slicepoint currently active in the slicer.
Returns ------- float The (reduceFunc) of the time between consecutive observations, in hours. """ dataSlice.sort(order=self.mjdCol) diff = np.diff(dataSlice[self.mjdCol]) result = self.reduceFunc(diff) * 24. return result |