@@ -41,27 +41,25 @@ def help(cls, doc=False):
41
41
class BaseSlicer (object ):
42
42
"""
43
43
Base class for all slicers: sets required methods and implements common functionality.
44
+
45
+ After first construction, the slicer should be ready for setupSlicer to define slicePoints, which will
46
+ let the slicer 'slice' data and generate plots.
47
+ After init after a restore: everything necessary for using slicer for plotting or
48
+ saving/restoring metric data should be present (although slicer does not need to be able to
49
+ slice data again and generally will not be able to).
50
+
51
+ Parameters
52
+ ----------
53
+ verbose: boolean, optional
54
+ True/False flag to send extra output to screen.
55
+ Default True.
56
+ badval: int or float, optional
57
+ The value the Slicer uses to fill masked metric data values
58
+ Default -666.
44
59
"""
45
60
__metaclass__ = SlicerRegistry
46
61
47
62
def __init__ (self , verbose = True , badval = - 666 ):
48
- """Instantiate the base slicer object.
49
-
50
- After first init with a 'blank' slicer: slicer should be ready for setupSlicer to
51
- define slicePoints.
52
- After init after a restore: everything necessary for using slicer for plotting or
53
- saving/restoring metric data should be present (although slicer does not need to be able to
54
- slice data again and generally will not be able to).
55
-
56
- The sliceMetric has a 'memo-ize' functionality that can save previous indexes & return
57
- metric data value calculated for same set of previous indexes, if desired.
58
- CacheSize = 0 effectively turns this off, otherwise cacheSize should be set by the slicer.
59
- (Most useful for healpix slicer, where many healpixels may have same set of LSST visits).
60
-
61
- Minimum set of __init__ kwargs:
62
- verbose: True/False flag to send extra output to screen
63
- badval: the value the Slicer uses to fill masked metric data values
64
- """
65
63
self .verbose = verbose
66
64
self .badval = badval
67
65
# Set cacheSize : each slicer will be able to override if appropriate.
@@ -87,7 +85,6 @@ def __init__(self, verbose=True, badval=-666):
87
85
if self .nslice is not None :
88
86
self .spatialExtent = [0 ,self .nslice - 1 ]
89
87
90
-
91
88
def _runMaps (self , maps ):
92
89
"""Add map metadata to slicePoints.
93
90
"""
@@ -100,6 +97,13 @@ def setupSlicer(self, simData, maps=None):
100
97
101
98
Set up internal parameters necessary for slicer to slice data and generates indexes on simData.
102
99
Also sets _sliceSimData for a particular slicer.
100
+
101
+ Parameters
102
+ -----------
103
+ simData : np.recarray
104
+ The simulated data to be sliced.
105
+ maps : list of lsst.sims.maf.maps objects, optional.
106
+ Maps to apply at each slicePoint, to add to the slicePoint metadata. Default None.
103
107
"""
104
108
# Typically args will be simData, but opsimFieldSlicer also uses fieldData.
105
109
raise NotImplementedError ()
@@ -167,8 +171,12 @@ def writeData(self, outfilename, metricValues, metricName='',
167
171
"""
168
172
Save metric values along with the information required to re-build the slicer.
169
173
170
- outfilename: the output file
171
- metricValues: the metric values to save to disk
174
+ Parameters
175
+ -----------
176
+ outfilename : str
177
+ The output file name.
178
+ metricValues : np.ma.MaskedArray or np.ndarray
179
+ The metric values to save to disk.
172
180
"""
173
181
header = {}
174
182
header ['metricName' ]= metricName
@@ -208,14 +216,29 @@ def outputJSON(self, metricValues, metricName='',
208
216
"""
209
217
Send metric data to JSON streaming API, along with a little bit of metadata.
210
218
211
- Output is
212
- header dictionary with 'metricName/metadata/simDataName/slicerName' and plot labels from plotDict (if provided).
213
- then data for plot:
214
- if oneDSlicer, it's [ [bin_left_edge, value], [bin_left_edge, value]..].
215
- if a spatial slicer, it's [ [lon, lat, value], [lon, lat, value] ..].
216
-
217
- This method will only work for non-complex metrics (i.e. metrics where the metric value is a float or int),
219
+ This method will only work for metrics where the metricDtype is float or int,
218
220
as JSON will not interpret more complex data properly. These values can't be plotted anyway though.
221
+
222
+ Parameters
223
+ -----------
224
+ metricValues : np.ma.MaskedArray or np.ndarray
225
+ The metric values.
226
+ metricName : str, optional
227
+ The name of the metric. Default ''.
228
+ simDataName : str, optional
229
+ The name of the simulated data source. Default ''.
230
+ metadata : str, optional
231
+ The metadata about this metric. Default ''.
232
+ plotDict : dict, optional.
233
+ The plotDict for this metric bundle. Default None.
234
+
235
+ Returns
236
+ --------
237
+ StringIO
238
+ StringIO object containing a header dictionary with metricName/metadata/simDataName/slicerName,
239
+ and plot labels from plotDict, and metric values/data for plot.
240
+ if oneDSlicer, the data is [ [bin_left_edge, value], [bin_left_edge, value]..].
241
+ if a spatial slicer, the data is [ [lon, lat, value], [lon, lat, value] ..].
219
242
"""
220
243
# Bail if this is not a good data type for JSON.
221
244
if not (metricValues .dtype == 'float' ) or (metricValues .dtype == 'int' ):
@@ -307,7 +330,16 @@ def readData(self, infilename):
307
330
"""
308
331
Read metric data from disk, along with the info to rebuild the slicer (minus new slicing capability).
309
332
310
- infilename: the filename containing the metric data.
333
+ Parameters
334
+ -----------
335
+ infilename: str
336
+ The filename containing the metric data.
337
+
338
+ Returns
339
+ -------
340
+ np.ma.MaskedArray, lsst.sims.maf.slicer, dict
341
+ MetricValues stored in data file, the slicer basis for those metric values, and a dictionary
342
+ containing header information (runName, metadata, etc.).
311
343
"""
312
344
import lsst .sims .maf .slicers as slicers
313
345
restored = np .load (infilename )
0 commit comments