Coverage for python/lsst/sims/maf/stackers/baseStacker.py : 77%

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
""" Meta class for Stackers, to build a registry of stacker classes. """
else: if len(modname.split('.')) > 1: modname = '.'.join(modname.split('.')[:-1]) + '.' else: modname = modname + '.' raise Exception('Redefining stacker %s! (there are >1 stackers with the same name)' % (stackername))
return cls.registry[stackername]
for stackername in sorted(cls.registry): if not doc: print(stackername) if doc: print('---- ', stackername, ' ----') print(cls.registry[stackername].__doc__) stacker = cls.registry[stackername]() print(' Columns added to SimData: ', ','.join(stacker.colsAdded)) print(' Default columns required: ', ','.join(stacker.colsReq))
"""Base MAF Stacker: add columns generated at run-time to the simdata array.""" # List of the names of the columns generated by the Stacker.
""" Instantiate the stacker. This method should be overriden by the user. This serves as an example of the variables required by the framework. """ # Add the list of new columns generated by the stacker as class attributes (colsAdded - above). # List of the names of the columns required from the database (to generate the Stacker columns). # Optional: specify the new column types. # Optional: provide a list of units for the columns defined in colsAdded.
return None
""" Evaluate if two stackers are equivalent. """ # If the class names are different, they are not 'the same'. # Otherwise, this is the same stacker class, but may be instantiated differently. # We have to delve a little further, and compare the kwargs & attributes for each stacker. # If the attribute is from numpy, assume it's an array and test it else: return False
""" Evaluate if two stackers are not equal. """ return False else:
""" Add the new Stacker columns to the simData array. If columns already present in simData, just allows 'run' method to overwrite. Returns simData array with these columns added (so 'run' method can set their values). """ # Create description of new recarray. '(depending on stacker).' % (col)) else: # Add references to old data. # Were all columns present and populated with something not None? If so, then consider 'all there'. else:
""" Example: Generate the new stacker columns, given the simdata columns from the database. Returns the new simdata structured array that includes the new stacker columns. """ # Add new columns return simData # If override is set, it means go ahead and recalculate stacker values. # Run the method to calculate/add new data. warnings.warn('Please update the stacker %s so that the _run method matches the current API. ' 'This will give you the option to skip re-running stackers if the columns are ' 'already present.' % (self.__class__.__name__)) return self._run(simData)
# By moving the calculation of these columns to a separate method, we add the possibility of using # stackers with pandas dataframes. The _addStackerCols method won't work with dataframes, but the # _run methods are quite likely to (depending on their details), as they are just populating columns. raise NotImplementedError('Not Implemented: ' 'the child stackers should implement their own _run methods') |