Skip to content

Commit

Permalink
Merge pull request #36 from lsst/tickets/DM-39609
Browse files Browse the repository at this point in the history
DM-39609: Use more modern Butler APIs
  • Loading branch information
timj authored Jun 12, 2023
2 parents d0bb060 + 09ebbdd commit 4f127d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
19 changes: 10 additions & 9 deletions bin.src/ci_imsim_export_external_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import argparse
import logging

import lsst.log
from lsst.daf.butler import Butler, FileDataset

if __name__ == "__main__":
Expand All @@ -23,18 +22,20 @@
help="Collections to search for; default ellipsis (...)"
)
parser.add_argument("-v", "--verbose", action="store_const", dest="logLevel",
default=lsst.log.Log.INFO, const=lsst.log.Log.DEBUG,
default=logging.INFO, const=logging.DEBUG,
help="Set the log level to DEBUG.")

args = parser.parse_args()
log = lsst.log.Log.getLogger("lsst.daf.butler")
log.setLevel(args.logLevel)
collections = args.collections.split(',')

# Forward python logging to lsst logger
collections = args.collections
if collections == "...":
collections = ...
else:
collections = collections.split(',')

logging.basicConfig(level=logging.INFO)
lgr = logging.getLogger("lsst.daf.butler")
lgr.setLevel(logging.INFO if args.logLevel == lsst.log.Log.INFO else logging.DEBUG)
lgr.addHandler(lsst.log.LogHandler())
lgr.setLevel(args.logLevel)

butler = Butler(
args.root,
Expand Down Expand Up @@ -72,5 +73,5 @@ def rewrite(dataset: FileDataset) -> FileDataset:
export.saveDatasets(butler.registry.queryDatasets(datasetTypeName, collections=collections),
elements=(), rewrite=rewrite)
for flattenChains in (True, False):
for collection in butler.registry.queryCollections(args.collections, flattenChains=flattenChains):
for collection in butler.registry.queryCollections(collections, flattenChains=flattenChains):
export.saveCollection(collection)
5 changes: 3 additions & 2 deletions tests/test_hips_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ def test_hips_exist(self):
# There are 90 HiPS images for each band.
self.assertEqual(len(datasets), 90)

stored = self.butler.stored_many(datasets)
for dataset in datasets:
self.assertTrue(self.butler.datastore.exists(dataset), msg="File exists for deepCoadd_hpx")
self.assertTrue(stored[dataset], msg="File exists for deepCoadd_hpx")

exp = self.butler.getDirect(list(datasets)[0])
exp = self.butler.get(list(datasets)[0])

self.assertEqual(exp.wcs.getFitsMetadata()["CTYPE1"], "RA---HPX")
self.assertEqual(exp.wcs.getFitsMetadata()["CTYPE2"], "DEC--HPX")
Expand Down

0 comments on commit 4f127d9

Please sign in to comment.