-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'tickets/DM-26613' into master
- Loading branch information
Showing
9 changed files
with
329 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# This file is part of pipe_tasks. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (https://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
__all__ = ["make_discrete_skymap",] | ||
|
||
|
||
from .commands import make_discrete_skymap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# This file is part of obs_base. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (http://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import click | ||
|
||
from lsst.daf.butler.cli.opt import (repo_argument, config_file_option, options_file_option) | ||
from lsst.daf.butler.cli.utils import (cli_handle_exception, split_commas, typeStrAcceptsMultiple) | ||
from lsst.obs.base.cli.opt import instrument_option | ||
from ... import script | ||
|
||
|
||
@click.command(short_help="Define a discrete skymap from calibrated exposures.") | ||
@repo_argument(required=True) | ||
@config_file_option(help="Path to a pex_config override to be included after the Instrument config overrides" | ||
"are applied.") | ||
@options_file_option() | ||
@click.option("--collections", | ||
help=("The collections to be searched (in order) when reading datasets. " | ||
"This includes the seed skymap if --append is specified."), | ||
multiple=True, | ||
callback=split_commas, | ||
metavar=typeStrAcceptsMultiple, | ||
required=True) | ||
@click.option("--out-collection", | ||
help=("The collection to write the skymap to."), | ||
type=str, default="skymaps", show_default=True) | ||
@click.option("--skymap-id", | ||
help=("The identifier of the skymap to write."), | ||
type=str, default="discrete", show_default=True) | ||
@instrument_option(required=True) | ||
def make_discrete_skymap(*args, **kwargs): | ||
"""Define a discrete skymap from calibrated exposures in the butler registry.""" | ||
cli_handle_exception(script.makeDiscreteSkyMap, *args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cmd: | ||
import: lsst.pipe.tasks.cli.cmd | ||
commands: | ||
- make-discrete-skymap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# This file is part of pipe_tasks. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (https://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
from .makeDiscreteSkyMap import makeDiscreteSkyMap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# This file is part of obs_base. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (http://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from lsst.daf.butler import Butler, DatasetType | ||
from lsst.pipe.tasks.makeDiscreteSkyMap import MakeDiscreteSkyMapTask, MakeDiscreteSkyMapConfig | ||
from lsst.obs.base.utils import getInstrument | ||
|
||
|
||
def makeDiscreteSkyMap(repo, config_file, collections, instrument, | ||
out_collection='skymaps', skymap_id='discrete'): | ||
"""Implements the command line interface `butler make-discrete-skymap` subcommand, | ||
should only be called by command line tools and unit test code that tests | ||
this function. | ||
Constructs a skymap from calibrated exposure in the butler repository | ||
Parameters | ||
---------- | ||
repo : `str` | ||
URI to the location to read the repo. | ||
config_file : `str` or `None` | ||
Path to a config file that contains overrides to the skymap config. | ||
collections : `list` [`str`] | ||
An expression specifying the collections to be searched (in order) when | ||
reading datasets, and optionally dataset type restrictions on them. | ||
At least one collection must be specified. This is the collection | ||
with the calibrated exposures. | ||
instrument : `str` | ||
The name or fully-qualified class name of an instrument. | ||
out_collection : `str`, optional | ||
The name of the collection to save the skymap to. Default is 'skymaps'. | ||
skymap_id : `str`, optional | ||
The identifier of the skymap to save. Default is 'discrete'. | ||
""" | ||
butler = Butler(repo, collections=collections, writeable=True, run=out_collection) | ||
instr = getInstrument(instrument, butler.registry) | ||
config = MakeDiscreteSkyMapConfig() | ||
instr.applyConfigOverrides(MakeDiscreteSkyMapTask._DefaultName, config) | ||
|
||
if config_file is not None: | ||
config.load(config_file) | ||
skymap_name = config.coaddName + "Coadd_skyMap" | ||
oldSkyMap = None | ||
if config.doAppend: | ||
if out_collection in collections: | ||
raise ValueError(f"Cannot overwrite dataset. If appending, specify an output " | ||
f"collection not in the input collections.") | ||
dataId = {'skymap': skymap_id} | ||
try: | ||
oldSkyMap = butler.get(skymap_name, collections=collections, dataId=dataId) | ||
except LookupError as e: | ||
msg = (f"Could not find seed skymap for {skymap_name} with dataId {dataId} " | ||
f"in collections {collections} but doAppend is {config.doAppend}. Aborting...") | ||
raise LookupError(msg, *e.args[1:]) | ||
|
||
datasets = butler.registry.queryDatasets('calexp', collections=collections) | ||
wcs_md_tuple_list = [(butler.getDirect('calexp.metadata', ref), butler.getDirect('calexp.wcs', ref)) | ||
for ref in datasets] | ||
task = MakeDiscreteSkyMapTask(config=config) | ||
result = task.run(wcs_md_tuple_list, oldSkyMap) | ||
skymap_dataset_type = DatasetType(skymap_name, dimensions=["skymap", ], | ||
universe=butler.registry.dimensions, | ||
storageClass="SkyMap") | ||
butler.registry.registerDatasetType(skymap_dataset_type) | ||
if config.doAppend: | ||
# By definition if appending the dataset has already been registered | ||
result.skyMap.register(skymap_id, butler.registry) | ||
butler.put(result.skyMap, skymap_name, dataId={'skymap': skymap_id}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
# -*- python -*- | ||
from lsst.sconsUtils import scripts | ||
import os | ||
|
||
from lsst.sconsUtils import env, scripts | ||
|
||
scripts.BasicSConscript.tests(pySingles=['nopytest_test_coadds.py'], | ||
pyList=[]) | ||
|
||
if "DAF_BUTLER_PLUGINS" in os.environ: | ||
env["ENV"]["DAF_BUTLER_PLUGINS"] = os.environ["DAF_BUTLER_PLUGINS"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# This file is part of pipe_tasks. | ||
# | ||
# Developed for the LSST Data Management System. | ||
# This product includes software developed by the LSST Project | ||
# (http://www.lsst.org). | ||
# See the COPYRIGHT file at the top-level directory of this distribution | ||
# for details of code ownership. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Unit tests for daf_butler CLI make-discrete-skymap command. | ||
""" | ||
|
||
import unittest | ||
|
||
from lsst.daf.butler.tests import CliCmdTestBase | ||
from lsst.pipe.tasks.cli.cmd import make_discrete_skymap | ||
|
||
|
||
class DefineMakeDiscreteSkymap(CliCmdTestBase, unittest.TestCase): | ||
|
||
@staticmethod | ||
def defaultExpected(): | ||
return dict(config_file=None, | ||
collections=()) | ||
|
||
@staticmethod | ||
def command(): | ||
return make_discrete_skymap | ||
|
||
def test_repoBasic(self): | ||
"""Test the most basic required arguments.""" | ||
self.run_test(["make-discrete-skymap", | ||
"--collections", "foo/bar,baz", | ||
"--instrument", "a.b.c", "here"], | ||
self.makeExpected(repo="here", | ||
collections=("foo/bar", "baz"), | ||
out_collection="skymaps", | ||
skymap_id="discrete", | ||
instrument="a.b.c")) | ||
|
||
def test_all(self): | ||
"""Test all the arguments.""" | ||
self.run_test(["make-discrete-skymap", | ||
"--instrument", "a.b.c", | ||
"--collections", "foo/bar,baz", | ||
"--config-file", "/path/to/config", | ||
"--collections", "boz", | ||
"--out-collection", "biz", | ||
"--skymap-id", "wiz", | ||
"here"], | ||
self.makeExpected(repo="here", | ||
instrument="a.b.c", | ||
config_file="/path/to/config", | ||
out_collection="biz", | ||
skymap_id="wiz", | ||
# The list of collections must be in | ||
# exactly the same order as it is | ||
# passed in the list of arguments to | ||
# run_test. | ||
collections=("foo/bar", "baz", "boz"))) | ||
|
||
def test_missing(self): | ||
"""test a missing argument""" | ||
self.run_missing(["make-discrete-skymap", "--collections", "foo/bar,baz", "--instrument", "a.b.c"], | ||
'Missing argument "REPO"') | ||
self.run_missing(["make-discrete-skymap", "--collections", "foo/bar,baz", "here"], | ||
'Missing option "-i" / "--instrument"') | ||
self.run_missing(["make-discrete-skymap", "--instrument", "a.b.c", "here"], | ||
'Error: Missing option "--collections".') | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.