Skip to content

Commit

Permalink
Merge pull request #28 from lsst/tickets/DM-34689
Browse files Browse the repository at this point in the history
DM-34689: Add run of GenerateHipsTask.
  • Loading branch information
erykoff authored Aug 17, 2022
2 parents 9afefbc + 1df4182 commit 8d44a37
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bin.src/ci_imsim_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@ def run(self, currentState: BuildState):
subprocess.run(pipetask, check=True)


@ciRunner.register("hips_generate", index_command := index_command + 1)
class HipsGenerateCommand(BaseCommand):
def run(self, currentState: BuildState):
hipsDir = os.path.join(self.runner.RunDir, "hips")
args = (
"--long-log",
"run",
"-j", str(self.arguments.num_cores),
"-b", self.runner.RunDir,
"-i", HIPS_COLLECTION,
"--output", HIPS_COLLECTION,
"-p", "$CI_IMSIM_DIR/resources/gen_hips.yaml",
"-c", "generateHips:hips_base_uri="+hipsDir,
"-c", "generateColorHips:hips_base_uri="+hipsDir,
"--register-dataset-types"
)
pipetask = self.runner.getExecutableCmd("CTRL_MPEXEC_DIR", "pipetask", args)
subprocess.run(pipetask, check=True)


ciRunner.register("test", index_command := index_command + 1)(TestRunner)

ciRunner.run()
29 changes: 29 additions & 0 deletions resources/gen_hips.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
description: Run GenerateHipsTask
instrument: lsst.obs.lsst.LsstCamImSim
tasks:
generateHips:
class: lsst.pipe.tasks.hips.GenerateHipsTask
config:
python: |
config.properties.creator_did_template = "temp://lsst/ci_imsim/hips/images/band_{band}"
config.properties.obs_title_template = "CI imSim for band {band}"
config.properties.obs_description_template = "Coadded data from ci_imsim, band {band}."
config.properties.prov_progenitor = ["Coadded data from the ci_imsim test dataset.",
"HiPS generation: internal pre-release code (https://pipelines.lsst.io/v/w_2022_22/index.html)"]
config.properties.t_min = 59582.04
config.properties.t_max = 61406.04
config.properties.obs_ack = "We gratefully acknowledge permission to use the DC2 simulated dataset from the LSST Dark Energy Science Collaboration and thank the collaboration for all the work and insight it represents."
generateColorHips:
class: lsst.pipe.tasks.hips.GenerateColorHipsTask
config:
python: |
config.properties.creator_did_template = "temp://lsst/ci_imsim/hips/images/color_gri"
config.properties.obs_title_template = "CI imSim: gri color visualization"
config.properties.obs_description_template = "Color visualization of coadded data from ci_imsim (red: band i, green: band r, blue: band g) with a hue-preserving stretch."
config.properties.prov_progenitor = ["Coadded data from the ci_imsim test dataset.",
"HiPS generation: internal pre-release code (https://pipelines.lsst.io/v/w_2022_22/index.html)"]
config.properties.t_min = 59582.04
config.properties.t_max = 61406.04
config.properties.obs_ack = "We gratefully acknowledge permission to use the DC2 simulated dataset from the LSST Dark Energy Science Collaboration and thank the collaboration for all the work and insight it represents."
43 changes: 43 additions & 0 deletions tests/test_hips_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@

import unittest
import os
import re

from lsst.daf.butler import Butler
from lsst.utils import getPackageDir
from lsst.resources import ResourcePath


class TestHipsOutputs(unittest.TestCase):
Expand All @@ -33,6 +35,7 @@ def setUp(self):
instrument="LSSTCam-imSim", skymap="discrete/ci_imsim/4k",
writeable=False, collections=["LSSTCam-imSim/runs/ci_imsim_hips"])
self._bands = ['u', 'g', 'r', 'i', 'z', 'y']
self.hips_uri_base = ResourcePath(os.path.join(getPackageDir("ci_imsim"), "DATA", "hips"))

def test_hips_exist(self):
"""Test that the HIPS images exist and are readable."""
Expand All @@ -50,6 +53,46 @@ def test_hips_exist(self):
self.assertEqual(exp.wcs.getFitsMetadata()["CTYPE1"], "RA---HPX")
self.assertEqual(exp.wcs.getFitsMetadata()["CTYPE2"], "DEC--HPX")

def test_hips_trees_exist(self):
"""Test that the HiPS tree exists and has correct files."""
for band in self._bands:
self._check_hips_tree(self.hips_uri_base.join(f"band_{band}", forceDirectory=True))
self._check_hips_tree(self.hips_uri_base.join("color_gri", forceDirectory=True), check_fits=False)

def _check_hips_tree(self, hips_uri, check_fits=True):
"""Check a HiPS tree for files.
Parameters
----------
hips_uri : `lsst.resources.ResourcePath`
URI of base of HiPS tree.
check_fits : `bool`, optional
Check if FITS images exist.
"""
self.assertTrue(hips_uri.join("properties").exists(), msg="properties file not found.")
self.assertTrue(hips_uri.join("Moc.fits").exists(), msg="Moc.fits file not found.")
allsky = hips_uri.join("Norder3", forceDirectory=True).join("Allsky.png")
self.assertTrue(allsky.exists(), msg="Allsky.png file not found.")

for order in range(3, 12):
order_uri = hips_uri.join(f"Norder{order}", forceDirectory=True)
png_uris = list(
ResourcePath.findFileResources(
candidates=[order_uri],
file_filter=re.compile(r'Npix.*\.png'),
)
)
self.assertGreater(len(png_uris), 0, msg="No PNGs found.")

if check_fits:
fits_uris = list(
ResourcePath.findFileResources(
candidates=[order_uri],
file_filter=re.compile(r'Npix.*\.fits'),
)
)
self.assertEqual(len(fits_uris), len(png_uris), msg="Number of FITS != number of PNGs.")


if __name__ == "__main__":
unittest.main()

0 comments on commit 8d44a37

Please sign in to comment.