Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-38753: Use InMemoryDatasetHandle for mock ref cat handle #316

Merged
merged 2 commits into from
Apr 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 9 additions & 50 deletions python/lsst/meas/algorithms/testUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
#

__all__ = ["plantSources", "makeRandomTransmissionCurve", "makeDefectList",
"MockReferenceObjectLoaderFromFiles"]
"MockReferenceObjectLoaderFromFiles", "MockRefcatDataId"]

import numpy as np
import esutil

import lsst.geom
import lsst.afw.image as afwImage
from lsst.pipe.base import InMemoryDatasetHandle
from lsst import sphgeom
from . import SingleGaussianPsf
from . import Defect
Expand Down Expand Up @@ -193,59 +194,17 @@ class MockRefcatDataId:

Parameters
----------
pixelization : `lsst.sphgeom.Pixelization`
Pixelization object.
index : `int`
Pixel index number.
region : `lsst.sphgeom.Region`
The region associated with this mock dataId.
"""
def __init__(self, pixelization, index):
self._region = pixelization.pixel(index)
def __init__(self, region):
self._region = region

@property
def region(self):
return self._region


class MockRefcatDeferredDatasetHandle:
"""Mock reference catalog dataset handle.

The mock handle needs a get() and a name for logging.

Parameters
----------
catalog : `lsst.afw.table.SourceCatalog`
Reference catalog.
name : `str`
Name of reference catalog.
"""
def __init__(self, catalog, name):
self._catalog = catalog
self._name = name

def get(self):
return self._catalog

class MockRef:
def __init__(self, name):
self._name = name

class MockDatasetType:
def __init__(self, name):
self._name = name

@property
def name(self):
return self._name

@property
def datasetType(self):
return self.MockDatasetType(self._name)

@property
def ref(self):
return self.MockRef(self._name)


class MockReferenceObjectLoaderFromFiles(ReferenceObjectLoader):
"""A simple mock of ReferenceObjectLoader.

Expand Down Expand Up @@ -284,7 +243,7 @@ def _createDataIdsAndRefcats(self, filenames, htmLevel, name):
-------
dataIds : `list` [`MockRefcatDataId`]
List of mock dataIds.
refCats : `list` [`MockRefcatDeferredDatasetHandle`]
refCats : `list` [`lsst.pipe.base.InMemoryDatasetHandle`]
List of mock deferred dataset handles.

Raises
Expand All @@ -306,7 +265,7 @@ def _createDataIdsAndRefcats(self, filenames, htmLevel, name):
if len(np.unique(ids)) != 1:
raise RuntimeError(f"File {filename} contains more than one pixel at level {htmLevel}")

dataIds.append(MockRefcatDataId(pixelization, ids[0]))
refCats.append(MockRefcatDeferredDatasetHandle(cat, name))
dataIds.append(MockRefcatDataId(pixelization.pixel(ids[0])))
refCats.append(InMemoryDatasetHandle(cat, name=name))

return dataIds, refCats