LSST Applications g04e9c324dd+8c5ae1fdc5,g123d84c11c+8c5ae1fdc5,g1fd858c14a+f0198063e6,g262e1987ae+c6225025ea,g29a0cc5914+89c23462b9,g29ae962dfc+995a808b2f,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g386d1ae640+e9e157c1c7,g3fd5ace14f+a961a9460f,g47891489e3+f62ff855a3,g4d44eb3520+56a94b3db7,g53246c7159+8c5ae1fdc5,g67b6fd64d1+f62ff855a3,g67fd3c3899+0d5d1c50aa,g71d780ea3c+cf951d6fc1,g7375c97bd6+b0659b51fd,g74acd417e5+29806445f4,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+f62ff855a3,g8d7436a09f+fe340099f4,g8ea07a8fe4+72e50bfcbe,g90f42f885a+232124b352,g97be763408+3c512867c4,ga1e959baac+5fbc491aed,ga2a72113ab+fe106acc69,gabf8522325+f227d7ba3a,gac2eed3f23+f62ff855a3,gae5946ca99+0d5d1c50aa,gb89ab40317+f62ff855a3,gd14cc1c8cb+796e414499,gd8ff7fe66e+0d5d1c50aa,gdab6d2f7ff+29806445f4,gdc713202bf+0d5d1c50aa,ge410e46f29+f62ff855a3,geaed405ab2+2322f1d6ea,gffca2db377+8c5ae1fdc5,w.2025.32
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.pipe.tasks.functors.MomentsIvvSky Class Reference
Inheritance diagram for lsst.pipe.tasks.functors.MomentsIvvSky:
lsst.pipe.tasks.functors.MomentsBase lsst.pipe.tasks.functors.Functor

Public Member Functions

 columns (self)
 
 sky_uu (self, df)
 
 sky_vv (self, df)
 
 sky_uv (self, df)
 
 name (self)
 
 noDup (self)
 
 multilevelColumns (self, data, columnIndex=None, returnTuple=False)
 
 __call__ (self, data, dropna=False)
 
 difference (self, data1, data2, **kwargs)
 
 fail (self, df)
 
 shortname (self)
 

Public Attributes

 shape_xx = shape_xx
 
 shape_yy = shape_yy
 
 shape_xy = shape_xy
 
 colCD_1_1 = colCD_1_1
 
 colCD_1_2 = colCD_1_2
 
 colCD_2_1 = colCD_2_1
 
 colCD_2_2 = colCD_2_2
 
 filt = filt
 
str dataset = dataset if dataset is not None else self._defaultDataset
 
 log = logging.getLogger(type(self).__name__)
 
 name
 

Protected Member Functions

 _func (self, df)
 
 _get_data_columnLevels (self, data, columnIndex=None)
 
 _get_data_columnLevelNames (self, data, columnIndex=None)
 
 _colsFromDict (self, colDict, columnIndex=None)
 
 _get_columnIndex (self, data)
 
 _get_data (self, data)
 
 _setLevels (self, df)
 
 _dropna (self, vals)
 

Protected Attributes

 _noDup = noDup
 

Static Protected Attributes

str _defaultDataset = 'ref'
 
tuple _dfLevels = ('column',)
 
bool _defaultNoDup = False
 

Detailed Description

Rotate pixel moments Ixx,Iyy,Iyy into ra,dec frame and arcseconds

Definition at line 2070 of file functors.py.

Member Function Documentation

◆ __call__()

lsst.pipe.tasks.functors.Functor.__call__ ( self,
data,
dropna = False )
inherited

Definition at line 348 of file functors.py.

348 def __call__(self, data, dropna=False):
349 df = self._get_data(data)
350 try:
351 vals = self._func(df)
352 except Exception as e:
353 self.log.error("Exception in %s call: %s: %s", self.name, type(e).__name__, e)
354 vals = self.fail(df)
355 if dropna:
356 vals = self._dropna(vals)
357
358 return vals
359

◆ _colsFromDict()

lsst.pipe.tasks.functors.Functor._colsFromDict ( self,
colDict,
columnIndex = None )
protectedinherited
Converts dictionary column specficiation to a list of columns.

Definition at line 218 of file functors.py.

218 def _colsFromDict(self, colDict, columnIndex=None):
219 """Converts dictionary column specficiation to a list of columns."""
220 new_colDict = {}
221 columnLevels = self._get_data_columnLevels(None, columnIndex=columnIndex)
222
223 for i, lev in enumerate(columnLevels):
224 if lev in colDict:
225 if isinstance(colDict[lev], str):
226 new_colDict[lev] = [colDict[lev]]
227 else:
228 new_colDict[lev] = colDict[lev]
229 else:
230 new_colDict[lev] = columnIndex.levels[i]
231
232 levelCols = [new_colDict[lev] for lev in columnLevels]
233 cols = list(product(*levelCols))
234 colsAvailable = [col for col in cols if col in columnIndex]
235 return colsAvailable
236

◆ _dropna()

lsst.pipe.tasks.functors.Functor._dropna ( self,
vals )
protectedinherited

Definition at line 345 of file functors.py.

345 def _dropna(self, vals):
346 return vals.dropna()
347

◆ _func()

lsst.pipe.tasks.functors.MomentsIvvSky._func ( self,
df )
protected

Reimplemented from lsst.pipe.tasks.functors.Functor.

Definition at line 2076 of file functors.py.

2076 def _func(self, df):
2077 sky_vv_radians = self.sky_vv(df)
2078
2079 return pd.Series(sky_vv_radians*((180/np.pi)*3600)**2, index=df.index).astype('float32')
2080
2081

◆ _get_columnIndex()

lsst.pipe.tasks.functors.Functor._get_columnIndex ( self,
data )
protectedinherited
Return columnIndex.

Definition at line 294 of file functors.py.

294 def _get_columnIndex(self, data):
295 """Return columnIndex."""
296
297 if isinstance(data, (DeferredDatasetHandle, InMemoryDatasetHandle)):
298 return data.get(component="columns")
299 else:
300 return None
301

◆ _get_data()

lsst.pipe.tasks.functors.Functor._get_data ( self,
data )
protectedinherited
Retrieve DataFrame necessary for calculation.

The data argument can be a `~pandas.DataFrame`, a
`~lsst.daf.butler.DeferredDatasetHandle`, or
an `~lsst.pipe.base.InMemoryDatasetHandle`.

Returns a DataFrame upon which `self._func` can act.

Definition at line 302 of file functors.py.

302 def _get_data(self, data):
303 """Retrieve DataFrame necessary for calculation.
304
305 The data argument can be a `~pandas.DataFrame`, a
306 `~lsst.daf.butler.DeferredDatasetHandle`, or
307 an `~lsst.pipe.base.InMemoryDatasetHandle`.
308
309 Returns a DataFrame upon which `self._func` can act.
310 """
311 # We wrap a DataFrame in a handle here to take advantage of the
312 # DataFrame delegate DataFrame column wrangling abilities.
313 if isinstance(data, pd.DataFrame):
314 _data = InMemoryDatasetHandle(data, storageClass="DataFrame")
315 elif isinstance(data, (DeferredDatasetHandle, InMemoryDatasetHandle)):
316 _data = data
317 else:
318 raise RuntimeError(f"Unexpected type provided for data. Got {get_full_type_name(data)}.")
319
320 # First thing to do: check to see if the data source has a multilevel
321 # column index or not.
322 columnIndex = self._get_columnIndex(_data)
323 is_multiLevel = isinstance(columnIndex, pd.MultiIndex)
324
325 # Get proper columns specification for this functor.
326 if is_multiLevel:
327 columns = self.multilevelColumns(_data, columnIndex=columnIndex)
328 else:
329 columns = self.columns
330
331 # Load in-memory DataFrame with appropriate columns the gen3 way.
332 df = _data.get(parameters={"columns": columns})
333
334 # Drop unnecessary column levels.
335 if is_multiLevel:
336 df = self._setLevels(df)
337
338 return df
339

◆ _get_data_columnLevelNames()

lsst.pipe.tasks.functors.Functor._get_data_columnLevelNames ( self,
data,
columnIndex = None )
protectedinherited
Gets the content of each of the column levels for a multilevel
table.

Definition at line 204 of file functors.py.

204 def _get_data_columnLevelNames(self, data, columnIndex=None):
205 """Gets the content of each of the column levels for a multilevel
206 table.
207 """
208 if columnIndex is None:
209 columnIndex = data.get(component="columns")
210
211 columnLevels = columnIndex.names
212 columnLevelNames = {
213 level: list(np.unique(np.array([c for c in columnIndex])[:, i]))
214 for i, level in enumerate(columnLevels)
215 }
216 return columnLevelNames
217

◆ _get_data_columnLevels()

lsst.pipe.tasks.functors.Functor._get_data_columnLevels ( self,
data,
columnIndex = None )
protectedinherited
Gets the names of the column index levels.

This should only be called in the context of a multilevel table.

Parameters
----------
data : various
    The data to be read, can be a
    `~lsst.daf.butler.DeferredDatasetHandle` or
    `~lsst.pipe.base.InMemoryDatasetHandle`.
columnIndex (optional): pandas `~pandas.Index` object
    If not passed, then it is read from the
    `~lsst.daf.butler.DeferredDatasetHandle`
    for `~lsst.pipe.base.InMemoryDatasetHandle`.

Definition at line 184 of file functors.py.

184 def _get_data_columnLevels(self, data, columnIndex=None):
185 """Gets the names of the column index levels.
186
187 This should only be called in the context of a multilevel table.
188
189 Parameters
190 ----------
191 data : various
192 The data to be read, can be a
193 `~lsst.daf.butler.DeferredDatasetHandle` or
194 `~lsst.pipe.base.InMemoryDatasetHandle`.
195 columnIndex (optional): pandas `~pandas.Index` object
196 If not passed, then it is read from the
197 `~lsst.daf.butler.DeferredDatasetHandle`
198 for `~lsst.pipe.base.InMemoryDatasetHandle`.
199 """
200 if columnIndex is None:
201 columnIndex = data.get(component="columns")
202 return columnIndex.names
203

◆ _setLevels()

lsst.pipe.tasks.functors.Functor._setLevels ( self,
df )
protectedinherited

Definition at line 340 of file functors.py.

340 def _setLevels(self, df):
341 levelsToDrop = [n for n in df.columns.names if n not in self._dfLevels]
342 df.columns = df.columns.droplevel(levelsToDrop)
343 return df
344

◆ columns()

lsst.pipe.tasks.functors.MomentsBase.columns ( self)
inherited
Columns required to perform calculation.

Reimplemented from lsst.pipe.tasks.functors.Functor.

Definition at line 2011 of file functors.py.

2011 def columns(self):
2012 return [
2013 self.shape_xx,
2014 self.shape_yy,
2015 self.shape_xy,
2016 self.colCD_1_1,
2017 self.colCD_1_2,
2018 self.colCD_2_1,
2019 self.colCD_2_2]
2020

◆ difference()

lsst.pipe.tasks.functors.Functor.difference ( self,
data1,
data2,
** kwargs )
inherited
Computes difference between functor called on two different
DataFrame/Handle objects.

Definition at line 360 of file functors.py.

360 def difference(self, data1, data2, **kwargs):
361 """Computes difference between functor called on two different
362 DataFrame/Handle objects.
363 """
364 return self(data1, **kwargs) - self(data2, **kwargs)
365

◆ fail()

lsst.pipe.tasks.functors.Functor.fail ( self,
df )
inherited

Definition at line 366 of file functors.py.

366 def fail(self, df):
367 return pd.Series(np.full(len(df), np.nan), index=df.index)
368

◆ multilevelColumns()

lsst.pipe.tasks.functors.Functor.multilevelColumns ( self,
data,
columnIndex = None,
returnTuple = False )
inherited
Returns columns needed by functor from multilevel dataset.

To access tables with multilevel column structure, the
`~lsst.daf.butler.DeferredDatasetHandle` or
`~lsst.pipe.base.InMemoryDatasetHandle` needs to be passed
either a list of tuples or a dictionary.

Parameters
----------
data : various
    The data as either `~lsst.daf.butler.DeferredDatasetHandle`, or
    `~lsst.pipe.base.InMemoryDatasetHandle`.
columnIndex (optional): pandas `~pandas.Index` object
    Either passed or read in from
    `~lsst.daf.butler.DeferredDatasetHandle`.
`returnTuple` : `bool`
    If true, then return a list of tuples rather than the column
    dictionary specification.
    This is set to `True` by `CompositeFunctor` in order to be able to
    combine columns from the various component functors.

Reimplemented in lsst.pipe.tasks.functors.Color, and lsst.pipe.tasks.functors.CompositeFunctor.

Definition at line 237 of file functors.py.

237 def multilevelColumns(self, data, columnIndex=None, returnTuple=False):
238 """Returns columns needed by functor from multilevel dataset.
239
240 To access tables with multilevel column structure, the
241 `~lsst.daf.butler.DeferredDatasetHandle` or
242 `~lsst.pipe.base.InMemoryDatasetHandle` needs to be passed
243 either a list of tuples or a dictionary.
244
245 Parameters
246 ----------
247 data : various
248 The data as either `~lsst.daf.butler.DeferredDatasetHandle`, or
249 `~lsst.pipe.base.InMemoryDatasetHandle`.
250 columnIndex (optional): pandas `~pandas.Index` object
251 Either passed or read in from
252 `~lsst.daf.butler.DeferredDatasetHandle`.
253 `returnTuple` : `bool`
254 If true, then return a list of tuples rather than the column
255 dictionary specification.
256 This is set to `True` by `CompositeFunctor` in order to be able to
257 combine columns from the various component functors.
258
259 """
260 if not isinstance(data, (DeferredDatasetHandle, InMemoryDatasetHandle)):
261 raise RuntimeError(f"Unexpected data type. Got {get_full_type_name(data)}.")
262
263 if columnIndex is None:
264 columnIndex = data.get(component="columns")
265
266 # Confirm that the dataset has the column levels the functor is
267 # expecting it to have.
268 columnLevels = self._get_data_columnLevels(data, columnIndex)
269
270 columnDict = {'column': self.columns,
271 'dataset': self.dataset}
272 if self.filt is None:
273 columnLevelNames = self._get_data_columnLevelNames(data, columnIndex)
274 if "band" in columnLevels:
275 if self.dataset == "ref":
276 columnDict["band"] = columnLevelNames["band"][0]
277 else:
278 raise ValueError(f"'filt' not set for functor {self.name}"
279 f"(dataset {self.dataset}) "
280 "and DataFrame "
281 "contains multiple filters in column index. "
282 "Set 'filt' or set 'dataset' to 'ref'.")
283 else:
284 columnDict['band'] = self.filt
285
286 if returnTuple:
287 return self._colsFromDict(columnDict, columnIndex=columnIndex)
288 else:
289 return columnDict
290

◆ name()

◆ noDup()

lsst.pipe.tasks.functors.Functor.noDup ( self)
inherited
Do not explode by band if used on object table.

Definition at line 170 of file functors.py.

170 def noDup(self):
171 """Do not explode by band if used on object table."""
172 if self._noDup is not None:
173 return self._noDup
174 else:
175 return self._defaultNoDup
176

◆ shortname()

lsst.pipe.tasks.functors.Functor.shortname ( self)
inherited
Short name of functor (suitable for column name/dict key).

Reimplemented in lsst.pipe.tasks.functors.Color, and lsst.pipe.tasks.functors.MagDiff.

Definition at line 375 of file functors.py.

375 def shortname(self):
376 """Short name of functor (suitable for column name/dict key)."""
377 return self.name
378
379

◆ sky_uu()

lsst.pipe.tasks.functors.MomentsBase.sky_uu ( self,
df )
inherited
Return the component of the moments tensor aligned with the RA axis, in radians.

Definition at line 2023 of file functors.py.

2023 def sky_uu(self, df):
2024 """Return the component of the moments tensor aligned with the RA axis, in radians."""
2025 i_xx = df[self.shape_xx]
2026 i_yy = df[self.shape_yy]
2027 i_xy = df[self.shape_xy]
2028 CD_1_1 = df[self.colCD_1_1]
2029 CD_1_2 = df[self.colCD_1_2]
2030 CD_2_1 = df[self.colCD_2_1]
2031 return (CD_1_1*(i_xx*CD_1_1 + i_xy*CD_2_1)
2032 + CD_1_2*(i_xy*CD_1_1 + i_yy*CD_2_1))
2033

◆ sky_uv()

lsst.pipe.tasks.functors.MomentsBase.sky_uv ( self,
df )
inherited
Return the covariance of the moments tensor in ra, dec coordinates, in radians.

Definition at line 2045 of file functors.py.

2045 def sky_uv(self, df):
2046 """Return the covariance of the moments tensor in ra, dec coordinates, in radians."""
2047 i_xx = df[self.shape_xx]
2048 i_yy = df[self.shape_yy]
2049 i_xy = df[self.shape_xy]
2050 CD_1_1 = df[self.colCD_1_1]
2051 CD_1_2 = df[self.colCD_1_2]
2052 CD_2_1 = df[self.colCD_2_1]
2053 CD_2_2 = df[self.colCD_2_2]
2054 return ((CD_1_1 * i_xx + CD_1_2 * i_xy) * CD_2_1
2055 + (CD_1_1 * i_xy + CD_1_2 * i_yy) * CD_2_2)
2056
2057

◆ sky_vv()

lsst.pipe.tasks.functors.MomentsBase.sky_vv ( self,
df )
inherited
Return the component of the moments tensor aligned with the dec axis, in radians.

Definition at line 2034 of file functors.py.

2034 def sky_vv(self, df):
2035 """Return the component of the moments tensor aligned with the dec axis, in radians."""
2036 i_xx = df[self.shape_xx]
2037 i_yy = df[self.shape_yy]
2038 i_xy = df[self.shape_xy]
2039 CD_1_2 = df[self.colCD_1_2]
2040 CD_2_1 = df[self.colCD_2_1]
2041 CD_2_2 = df[self.colCD_2_2]
2042 return (CD_2_1*(i_xx*CD_1_2 + i_xy*CD_2_2)
2043 + CD_2_2*(i_xy*CD_1_2 + i_yy*CD_2_2))
2044

Member Data Documentation

◆ _defaultDataset

str lsst.pipe.tasks.functors.Functor._defaultDataset = 'ref'
staticprotectedinherited

Definition at line 159 of file functors.py.

◆ _defaultNoDup

bool lsst.pipe.tasks.functors.Functor._defaultNoDup = False
staticprotectedinherited

Definition at line 161 of file functors.py.

◆ _dfLevels

tuple lsst.pipe.tasks.functors.Functor._dfLevels = ('column',)
staticprotectedinherited

Definition at line 160 of file functors.py.

◆ _noDup

lsst.pipe.tasks.functors.Functor._noDup = noDup
protectedinherited

Definition at line 166 of file functors.py.

◆ colCD_1_1

lsst.pipe.tasks.functors.MomentsBase.colCD_1_1 = colCD_1_1
inherited

Definition at line 2004 of file functors.py.

◆ colCD_1_2

lsst.pipe.tasks.functors.MomentsBase.colCD_1_2 = colCD_1_2
inherited

Definition at line 2005 of file functors.py.

◆ colCD_2_1

lsst.pipe.tasks.functors.MomentsBase.colCD_2_1 = colCD_2_1
inherited

Definition at line 2006 of file functors.py.

◆ colCD_2_2

lsst.pipe.tasks.functors.MomentsBase.colCD_2_2 = colCD_2_2
inherited

Definition at line 2007 of file functors.py.

◆ dataset

str lsst.pipe.tasks.functors.Functor.dataset = dataset if dataset is not None else self._defaultDataset
inherited

Definition at line 165 of file functors.py.

◆ filt

lsst.pipe.tasks.functors.Functor.filt = filt
inherited

◆ log

lsst.pipe.tasks.functors.Functor.log = logging.getLogger(type(self).__name__)
inherited

Definition at line 167 of file functors.py.

◆ name

◆ shape_xx

lsst.pipe.tasks.functors.MomentsBase.shape_xx = shape_xx
inherited

Definition at line 2001 of file functors.py.

◆ shape_xy

lsst.pipe.tasks.functors.MomentsBase.shape_xy = shape_xy
inherited

Definition at line 2003 of file functors.py.

◆ shape_yy

lsst.pipe.tasks.functors.MomentsBase.shape_yy = shape_yy
inherited

Definition at line 2002 of file functors.py.


The documentation for this class was generated from the following file: