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-39605: Use butler.dimensions rather than butler.registry.dimensions #64

Merged
merged 8 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
16 changes: 8 additions & 8 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
This configuration only affects single-package Sphinx documenation builds.
"""

from documenteer.sphinxconfig.stackconf import build_package_configs
import lsst.skymap


_g = globals()
_g.update(build_package_configs(
project_name='skymap',
version=lsst.skymap.version.__version__))
from documenteer.conf.pipelinespkg import * # noqa: F403, import *

project = "skymap"
html_theme_options["logotext"] = project # noqa: F405, unknown name
html_title = project
html_short_title = project
doxylink = {}
exclude_patterns = ["changes/*"]
3 changes: 2 additions & 1 deletion examples/plotDodecaSkyMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
centerPoint = numpy.mean(innerPoints[0:-1], axis=0)
ax.plot([centerPoint[0]], [centerPoint[1]], [centerPoint[2]], ".", color=color)

# display outer edge; scale to be approximately in the same plane as the inner region
# Display outer edge; scale to be approximately in the same plane as the
# inner region.
wcs = tractInfo.getWcs()
bbox = tractInfo.getBBox()
outerPixPos = [
Expand Down
11 changes: 6 additions & 5 deletions examples/plotSkyMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ def plotSkyMap3d(skyMap):
ax = fig.gca(projection="3d")
ax.set_axis_off()

# make sure a complete 1x1x1 cube is shown -- what I really want is to constrain the aspect ratio
# but that is not yet supported for 3D plots
# Make sure a complete 1x1x1 cube is shown -- what I really want is to
# constrain the aspect ratio but that is not yet supported for 3D plots.
for direction in (-1, 1):
for point in numpy.diag(direction * numpy.array([1, 1, 1])):
ax.plot([point[0]], [point[1]], [point[2]], 'w')

for tractInfo in skyMap:
# display outer edge; scale to be approximately in the same plane as the inner region
# Display outer edge; scale to be approximately in the same plane as
# the inner region.
wcs = tractInfo.getWcs()
posBox = geom.Box2D(tractInfo.getBBox())
xRange = posBox.getMinX(), posBox.getMaxX()
Expand Down Expand Up @@ -156,8 +157,8 @@ def recenter(self, x, y):
def makePlotter(Projector=DefaultProjector):
"""Make a function that will plot a SkyMap in 2D

The Projector is used to project the center of each tract and its boundaries
onto the plot.
The Projector is used to project the center of each tract and its
boundaries onto the plot.
"""

def plotSkyMap2d(skyMap):
Expand Down
4 changes: 3 additions & 1 deletion examples/showVisitSkyMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def bboxToRaDec(bbox, wcs):


def percent(values, p=0.5):
"""Return a value a faction of the way between the min and max values in a list."""
"""Return a value a faction of the way between the min and max values in a
list.
"""
m = min(values)
interval = max(values) - m
return m + p*interval
Expand Down
44 changes: 25 additions & 19 deletions python/lsst/skymap/baseSkyMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def getPatchInnerDimensions(self):

This value is only used with the ``legacy`` tract builder,
and is ignored otherwise. In general, the config should be
accessed directly with config.tractBuilder["legacy"].patchInnerDimensions.
accessed directly with
``config.tractBuilder["legacy"].patchInnerDimensions``.

Returns
-------
Expand All @@ -86,7 +87,8 @@ def setPatchInnerDimensions(self, value):

This value is only used with the ``legacy`` tract builder,
and is ignored otherwise. In general, the config should be
accessed directly with config.tractBuilder["legacy"].patchInnerDimensions.
accessed directly with
``config.tractBuilder["legacy"].patchInnerDimensions``.

Parameters
----------
Expand Down Expand Up @@ -117,7 +119,7 @@ def setPatchBorder(self, value):
accessed directly with config.tractBuilder["legacy"].patchBorder.

Parameters
-------
----------
border: `int`
"""
self.tractBuilder["legacy"].patchBorder = value
Expand All @@ -132,7 +134,7 @@ class BaseSkyMap:

Parameters
----------
config : `BaseSkyMapConfig` or None (optional)
config : `BaseSkyMapConfig` or `None` (optional)
The configuration for this SkyMap; if None use the default config.

Notes
Expand Down Expand Up @@ -188,9 +190,10 @@ def findTract(self, coord):
- The default implementation is not very efficient; subclasses may wish
to override.

**Warning:**
If tracts do not cover the whole sky then the returned tract may not
include the coord.
.. warning::

If tracts do not cover the whole sky then the returned tract may not
include the coord.
"""
distTractInfoList = []
for i, tractInfo in enumerate(self):
Expand All @@ -201,35 +204,37 @@ def findTract(self, coord):
return distTractInfoList[0][2]

def findTractIdArray(self, ra, dec, degrees=False):
"""Find array of tract IDs with vectorized operations (where supported).
"""Find array of tract IDs with vectorized operations (where
supported).

If a given sky map does not support vectorized operations, then a loop
over findTract will be called.

Parameters
----------
ra : `np.ndarray`
ra : `numpy.ndarray`
Array of Right Ascension. Units are radians unless
degrees=True.
dec : `np.ndarray`
dec : `numpy.ndarray`
Array of Declination. Units are radians unless
degrees=True.
degrees : `bool`, optional
Input ra, dec arrays are degrees if True.
Input ra, dec arrays are degrees if `True`.

Returns
-------
tractId : `np.ndarray`
tractId : `numpy.ndarray`
Array of tract IDs

Notes
-----
- If coord is equidistant between multiple sky tract centers then one
is arbitrarily chosen.

**Warning:**
If tracts do not cover the whole sky then the returned tract may not
include the given ra/dec.
.. warning::

If tracts do not cover the whole sky then the returned tract may not
include the given ra/dec.
"""
units = geom.degrees if degrees else geom.radians
coords = [geom.SpherePoint(r*units, d*units) for r, d in zip(np.atleast_1d(ra),
Expand All @@ -255,7 +260,8 @@ def findTractPatchList(self, coordList):

Notes
-----
**warning:**
.. warning::

This uses a naive algorithm that may find some tracts and patches
that do not overlap the region (especially if the region is not a
rectangle aligned along patch x, y).
Expand Down Expand Up @@ -316,8 +322,8 @@ def logSkyMapInfo(self, log):

Parameters
----------
log : `lsst.log.Log`
Log object that information about skymap will be written
log : `logging.Logger`
Log object that information about skymap will be written.
"""
log.info("sky map has %s tracts" % (len(self),))
for tractInfo in self:
Expand Down Expand Up @@ -429,7 +435,7 @@ def register(self, name, butler):
name=self.SKYMAP_DATASET_TYPE_NAME,
dimensions=["skymap"],
storageClass="SkyMap",
universe=butler.registry.dimensions
universe=butler.dimensions
)
butler.registry.registerDatasetType(datasetType)
with butler.transaction():
Expand Down
10 changes: 6 additions & 4 deletions python/lsst/skymap/detail/dodecahedron.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ class Dodecahedron:
def __init__(self, withFacesOnPoles=False):
self._withFacesOnPoles = bool(withFacesOnPoles)

# Basis cartesian vectors describing the faces of a dodecahedron; the full set of vectors is obtained
# by choosing both signs of each nonzero component of each vector.
# Basis cartesian vectors describing the faces of a dodecahedron;
# the full set of vectors is obtained by choosing both signs of each
# nonzero component of each vector.
# The orientation of the resulting dodecahedron, while very convenient
# for specifying face vectors, is not an orientation we want so it must be rotated.
# for specifying face vectors, is not an orientation we want so it
# must be rotated.
g = (1.0 + math.sqrt(5.0)) / 2.0
faceBases = (
(0, 1, g),
Expand Down Expand Up @@ -62,7 +64,7 @@ def getFaceCtr(self, ind):

Returns
-------
results : `np.ndarray`
results : `numpy.ndarray`
Face center as a unit vector.
"""
return self.faceVecList[ind][:]
Expand Down
10 changes: 5 additions & 5 deletions python/lsst/skymap/detail/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


def coordFromVec(vec, defRA=None):
"""Convert an ICRS cartesian vector to an ICRS lsst.geom.SpherePoint
"""Convert an ICRS cartesian vector to an ICRS `lsst.geom.SpherePoint`.

Parameters
----------
Expand All @@ -45,7 +45,7 @@ def coordFromVec(vec, defRA=None):
Raises
------
RuntimeError
If vec too near a pole and defRA is None.
Raised if vec too near a pole and defRA is None.
"""
if abs(vec[0]) < _TinyFloat and abs(vec[1]) < _TinyFloat:
if defRA is None:
Expand All @@ -59,14 +59,14 @@ def coordFromVec(vec, defRA=None):


def makeSkyPolygonFromBBox(bbox, wcs):
"""Make an on-sky polygon from a bbox and a SkyWcs
"""Make an on-sky polygon from a bbox and a SkyWcs.

Parameters
----------
bbox : `lsst.geom.Box2I` or `lsst.geom.Box2D`
Bounding box of region, in pixel coordinates
Bounding box of region, in pixel coordinates.
wcs : `lsst.afw.geom.SkyWcs`
Celestial WCS
Celestial WCS.

Returns
-------
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/skymap/dodecaSkyMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def __init__(self, config=None):
tractRA = tractCoord.getLongitude()
vertexVecList = self._dodecahedron.getVertices(id)

# make initial WCS; don't worry about crPixPos because TractInfo will shift it as required
# Make initial WCS; don't worry about crPixPos because TractInfo
# will shift it as required.
wcs = self._wcsFactory.makeWcs(crPixPos=geom.Point2D(0, 0), crValCoord=tractCoord)

self._tractInfoList.append(
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/skymap/equatSkyMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def __init__(self, config=None):
# CRVal must have Dec=0 for symmetry about the equator
crValCoord = geom.SpherePoint(midRA, geom.Angle(0.0))

# make initial WCS; don't worry about crPixPos because TractInfo will shift it as required
# Make initial WCS; don't worry about crPixPos because TractInfo
# will shift it as required.
wcs = self._wcsFactory.makeWcs(crPixPos=geom.Point2D(0, 0), crValCoord=crValCoord)

self._tractInfoList.append(TractInfo(
Expand Down
14 changes: 8 additions & 6 deletions python/lsst/skymap/patchInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class PatchInfo:
Patch sequential index
tractWcs : `lsst.afw.geom.SkyWcs`
Tract WCS object.
cellInnerDimensions : `Iterable` [`int`, `int`] or `lsst.geom.Extent2I`, optional
cellInnerDimensions : `Iterable` [`int`, `int`] or `lsst.geom.Extent2I`, \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cellInnerDimensions : `Iterable` [`int`, `int`] or `lsst.geom.Extent2I`, \
cellInnerDimensions : `~collections.abc.Iterable` [`int`] or `lsst.geom.Extent2I`, \

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Not sure how I missed that one, and again I think they might be trying to tell us that it's an iterable of list. Tuple[int, int] might be clearer.

optional
Inner dimensions of each cell (x,y pixels).
cellBorder : `int`, optional
Cell border size (pixels).
Expand Down Expand Up @@ -222,7 +223,7 @@ def getCellInfo(self, index):
Raises
------
IndexError
If index is out of range.
Raised if index is out of range.
"""
if self._numCells.x == 0 or self._numCells.y == 0:
raise IndexError("Patch does not contain cells.")
Expand All @@ -239,7 +240,8 @@ def getCellInfo(self, index):
(_index, self._numCells.x - 1, self._numCells.y - 1))
# We offset the index by numCellsInPatchBorder because the cells
# start outside the inner dimensions.
# The cells are defined relative to the patch bounding box (within the tract).
# The cells are defined relative to the patch bounding box (within the
# tract).
patchInnerBBox = self.getInnerBBox()
innerMin = Point2I(*[(_index[i] - self._numCellsInPatchBorder)*self._cellInnerDimensions[i]
+ patchInnerBBox.getBegin()[i]
Expand Down Expand Up @@ -279,7 +281,7 @@ def getSequentialCellIndex(self, cellInfo):
Raises
------
IndexError
If index is out of range.
Raised if index is out of range.
"""
index = cellInfo.getIndex()
return self.getSequentialCellIndexFromPair(index)
Expand All @@ -299,7 +301,7 @@ def getSequentialCellIndexFromPair(self, index):
Raises
------
IndexError
If index is out of range.
Raised if index is out of range.
"""
if isinstance(index, Index2D):
_index = index
Expand All @@ -322,7 +324,7 @@ def getCellIndexPair(self, sequentialIndex):
Raises
------
IndexError
If index is out of range.
Raised if index is out of range.
"""
if self._numCells.x == 0 or self._numCells.y == 0:
raise IndexError("Patch does not contain cells.")
Expand Down
9 changes: 6 additions & 3 deletions python/lsst/skymap/ringsSkyMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class RingsSkyMap(CachingSkyMap):
def __init__(self, config, version=1):
assert version in (0, 1), "Unrecognised version: %s" % (version,)
# We count rings from south to north
# Note: pole caps together count for one additional ring when calculating the ring size
# Note: pole caps together count for one additional ring when
# calculating the ring size.
self._ringSize = math.pi / (config.numRings + 1) # Size of a ring in Declination (radians)
self._ringNums = [] # Number of tracts for each ring
for i in range(config.numRings):
Expand Down Expand Up @@ -175,7 +176,8 @@ def _raToTractNum(self, ra, ringNum):
Returns
-------
tractNum : `int`
Tract number within the ring (starts at 0 for the tract at raStart).
Tract number within the ring (starts at 0 for the tract at
``raStart``).
"""
if ringNum in (-1, self.config.numRings):
return 0
Expand Down Expand Up @@ -226,7 +228,8 @@ def findTractIdArray(self, ra, dec, degrees=False):
indexes[ringNums == -1] = 0
indexes[ringNums == self.config.numRings] = self._numTracts - 1

# We now do the full lookup for all non-polar tracts that have not been set.
# We now do the full lookup for all non-polar tracts that have not
# been set.
inRange, = np.where(indexes < 0)

# Do the ra search
Expand Down