How to Specify Skymap at NCSA RSP?

I’m trying to run Louise Edward’s tutorial, delegate-contributions-dp01/Structure/StructureAroundCluster/StructureAroundCluster_090521.ipynb, at NCSA and encountering skymap issues. It wants me to specify which skymap in this routine, and I’m not sure how to do that:
def cutout_coadd(butler, ra, dec, band=‘r’, datasetType=‘deepCoadd’,
cutoutSideLength=51, **kwargs):
“”"
Produce a cutout from a coadd at the given ra, dec position.

Adapted from DC2 tutorial notebook by Michael Wood-Vasey.

Parameters
----------
butler: lsst.daf.persistence.Butler
    Servant providing access to a data repository
ra: float
    Right ascension of the center of the cutout, in degrees
dec: float
    Declination of the center of the cutout, in degrees
band: string
    Filter of the image to load
datasetType: string ['deepCoadd']
    Which type of coadd to load.  Doesn't support 'calexp'
skymap: lsst.afw.skyMap.SkyMap [optional]
    Pass in to avoid the Butler read.  Useful if you have lots of them.
cutoutSideLength: float [optional]
    Size of the cutout region in pixels.

Returns
-------
MaskedImage
"""
radec = geom.SpherePoint(ra, dec, geom.degrees)
cutoutSize = geom.ExtentI(cutoutSideLength, cutoutSideLength)

if skymap is None:
    skymap = butler.get("skyMap")

# Look up the tract, patch for the RA, Dec
tractInfo = skymap.findTract(radec)
patchInfo = tractInfo.findPatch(radec)
xy = geom.PointI(tractInfo.getWcs().skyToPixel(radec))
bbox = geom.BoxI(xy - cutoutSize // 2, cutoutSize)
patch = tractInfo.getSequentialPatchIndex(patchInfo)

coaddId = {'tract': tractInfo.getId(), 'patch': patch, 'band': band}
parameters = {'bbox': bbox}

cutout_image = butler.get(datasetType, parameters=parameters,
                           dataId=coaddId)

return cutout_image

Select a position at roughly the center of the galaxy cluster:

cutout_image = cutout_coadd(butler, ra, dec, datasetType=‘deepCoadd’,
cutoutSideLength=501)
print("The size of the cutout in pixels is: ", cutout_image.image.array.shape)

This returns

UnboundLocalError Traceback (most recent call last)
/tmp/ipykernel_3588/2834475231.py in
1 # Select a position at roughly the center of the galaxy cluster:
----> 2 cutout_image = cutout_coadd(butler, ra, dec, datasetType=‘deepCoadd’,
3 cutoutSideLength=501)
4 print("The size of the cutout in pixels is: ", cutout_image.image.array.shape)

/tmp/ipykernel_3588/3823562161.py in cutout_coadd(butler, ra, dec, band, datasetType, cutoutSideLength, **kwargs)
31 cutoutSize = geom.ExtentI(cutoutSideLength, cutoutSideLength)
32
—> 33 if skymap is None:
34 skymap = butler.get(“skyMap”)
35

UnboundLocalError: local variable ‘skymap’ referenced before assignment

I got it! I had to assign DC2 to skymap in dataID below, and I had to add it to the coaddId
radec = geom.SpherePoint(ra, dec, geom.degrees)
cutoutSize = geom.ExtentI(cutoutSideLength, cutoutSideLength)
if skymap is None:
dataID = {“skymap”: “DC2”}
skymap = butler.get(“skyMap”, dataID)
# Look up the tract, patch for the RA, Dec
tractInfo = skymap.findTract(radec)
patchInfo = tractInfo.findPatch(radec)
xy = geom.PointI(tractInfo.getWcs().skyToPixel(radec))
bbox = geom.BoxI(xy - cutoutSize // 2, cutoutSize)
patch = tractInfo.getSequentialPatchIndex(patchInfo)

coaddId = {'tract': tractInfo.getId(), 'patch': patch, 'band': band, "skymap": 'DC2'}
parameters = {'bbox': bbox}
1 Like

I ran the notebook and could run it as-it-is without any issue. Your suggested solution seems to be making changes after the point from where the error was thrown. Can you check if the function signature was copied correctly?

Thanks for helping out and attempting to recreate the issue @arunkannawadi !

This error and its solution only apply when running the notebook on the version of the Rubin Science Platform (RSP) deployed at NCSA, not at the Interim Data Facility (IDF; the Google Cloud, data.lsst.cloud) – the IDF is where all DP0 Delegates have their RSP accounts. So that is why you did not encounter the issue. Sorry for the confusion!

1 Like