-
Notifications
You must be signed in to change notification settings - Fork 0
DM-33937: Setup a butler with real data on google cloud #13
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
Changes from all commits
05972d9
465e788
45794d3
127214d
23afc83
776cf52
a705fa4
5424fb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env python | ||
# This file is part of prompt_prototype. | ||
# | ||
# 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/>. | ||
|
||
|
||
"""Selectively export the contents of an ap_verify dataset. | ||
|
||
This script selects the subset of an ap_verify dataset's preloaded repository that | ||
matches what the central prompt processing repository ought to look like. | ||
""" | ||
|
||
|
||
import argparse | ||
import logging | ||
import os | ||
import re | ||
import sys | ||
import time | ||
|
||
import lsst.daf.butler as daf_butler | ||
|
||
|
||
def _make_parser(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--src-repo", required=True, | ||
help="The location of the repository to be exported.") | ||
return parser | ||
|
||
|
||
def main(): | ||
logging.basicConfig(level=logging.INFO, stream=sys.stdout) | ||
|
||
args = _make_parser().parse_args() | ||
gen3_repo = os.path.abspath(args.src_repo) | ||
|
||
logging.info("Exporting Gen 3 registry to configure new repos...") | ||
start = time.time_ns() | ||
_export_for_copy(gen3_repo) | ||
end = time.time_ns() | ||
logging.info("Export finished in %.3fs.", 1e-9 * (end - start)) | ||
|
||
|
||
def _get_dataset_types(): | ||
"""Identify the dataset types that should be marked for export. | ||
|
||
Returns | ||
------- | ||
types : iterable [`str` or `re.Pattern`] | ||
The dataset types to include | ||
""" | ||
# Everything except raws and SS ephemerides | ||
return [re.compile("^(?!raw|visitSsObjects).*")] | ||
|
||
|
||
def _export_for_copy(repo): | ||
"""Export a Gen 3 repository so that a dataset can make copies later. | ||
|
||
Parameters | ||
---------- | ||
repo : `str` | ||
The location of the Gen 3 repository. | ||
""" | ||
butler = daf_butler.Butler(repo) | ||
with butler.export(format="yaml") as contents: | ||
# Need all detectors, even those without data, for visit definition | ||
contents.saveDataIds(butler.registry.queryDataIds({"detector"}).expanded()) | ||
contents.saveDatasets(butler.registry.queryDatasets( | ||
datasetType=_get_dataset_types(), collections=...)) | ||
# Save calibration collection | ||
for collection in butler.registry.queryCollections( | ||
collectionTypes=daf_butler.CollectionType.CALIBRATION): | ||
contents.saveCollection(collection) | ||
# Do not export chains, as they will need to be reworked to satisfy | ||
# prompt processing's assumptions. | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/usr/bin/env python | ||
# This file is part of prompt_prototype. | ||
# | ||
# 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/>. | ||
|
||
|
||
"""Simple script for creating a repository at a remote URI, given | ||
a source repository and export file. | ||
|
||
For most values of --target-repo and --seed-config, this script is only useful | ||
if run from the prompt-proto project on Google Cloud. | ||
|
||
The user is responsible for clearing any old copies of the repository from | ||
both the target URI and the registry database. | ||
""" | ||
|
||
|
||
import argparse | ||
import logging | ||
import os | ||
import sys | ||
|
||
from lsst.utils import getPackageDir | ||
from lsst.utils.timer import time_this | ||
from lsst.daf.butler import Butler, CollectionType, Config | ||
from lsst.obs.base import Instrument | ||
|
||
|
||
def _make_parser(): | ||
parser = argparse.ArgumentParser() | ||
# Could reasonably be positional arguments, but keep them as keywords to | ||
# prevent users from confusing --src-repo with --target-repo. | ||
parser.add_argument("--src-repo", required=True, | ||
help="The location of the repository whose files are to be copied.") | ||
parser.add_argument("--target-repo", required=True, | ||
help="The URI of the repository to create.") | ||
parser.add_argument("--seed-config", | ||
default=os.path.join(getPackageDir("prompt_prototype"), "etc", "db_butler.yaml"), | ||
help="The config file to use for the new repository. Defaults to etc/db_butler.yaml.") | ||
parser.add_argument("--export-file", default="export.yaml", | ||
help="The export file containing the repository contents. Defaults to ./export.yaml.") | ||
return parser | ||
|
||
|
||
def _add_chains(butler): | ||
"""Create collections to serve as a uniform interface. | ||
|
||
Parameters | ||
---------- | ||
butler : `lsst.daf.butler.Butler` | ||
A Butler pointing to the repository to modify. Assumed to already contain the following collections: | ||
|
||
- standard calibration collection | ||
- standard skymap collection | ||
- templates/* | ||
- refcats/* | ||
""" | ||
butler.registry.registerCollection("templates", type=CollectionType.CHAINED) | ||
butler.registry.setCollectionChain( | ||
"templates", | ||
list(butler.registry.queryCollections("templates/*", collectionTypes=CollectionType.RUN)) | ||
) | ||
|
||
butler.registry.registerCollection("refcats", type=CollectionType.CHAINED) | ||
butler.registry.setCollectionChain( | ||
"refcats", | ||
list(butler.registry.queryCollections("refcats/*", collectionTypes=CollectionType.RUN)) | ||
) | ||
|
||
instrument = Instrument.fromName(list(butler.registry.queryDataIds("instrument"))[0]["instrument"], | ||
butler.registry) | ||
defaults = instrument.makeCollectionName("defaults") | ||
butler.registry.registerCollection(defaults, type=CollectionType.CHAINED) | ||
butler.registry.setCollectionChain( | ||
defaults, | ||
[instrument.makeCalibrationCollectionName(), "templates", "skymaps", "refcats"] | ||
) | ||
|
||
|
||
def main(): | ||
logging.basicConfig(level=logging.INFO, stream=sys.stdout) | ||
|
||
args = _make_parser().parse_args() | ||
seed_config = Config(args.seed_config) | ||
logging.info("Creating repository at %s...", args.target_repo) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does the make_local_butler.py file exist? Isn't that identical to this version if the default value for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not believe that integrating what should be a local, highly specific script into the We are deliberately not using the |
||
with time_this(msg="Repository creation", level=logging.INFO): | ||
config = Butler.makeRepo(args.target_repo, config=seed_config, overwrite=False) | ||
with time_this(msg="Butler creation", level=logging.INFO): | ||
butler = Butler(config, writeable=True) | ||
with time_this(msg="Import", level=logging.INFO): | ||
butler.import_(directory=args.src_repo, filename=args.export_file, transfer="auto") | ||
_add_chains(butler) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
registry: | ||
db: postgresql://postgres@localhost:5432/ | ||
namespace: support_data_template |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand this comment. I'd think we could pretend for the purposes of any given repo that a camera has a subset of its actual detectors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something carried over from
ap_verify
. I don't know if it is still true, but visit definition used to fail if any of the detector IDs in the instrument (camera?) definition were missing from the registry.