|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import argparse |
| 4 | +from pathlib import Path |
| 5 | +from shutil import copyfileobj |
| 6 | + |
| 7 | + |
| 8 | +def parse_args(argv=None): |
| 9 | + """Parse command-line arguments.""" |
| 10 | + parser = argparse.ArgumentParser( |
| 11 | + description="Fetch DP2 CCD visit parquet file from the Butler repository. " |
| 12 | + "Requires LSST stack environment." |
| 13 | + ) |
| 14 | + parser.add_argument( |
| 15 | + "--run", |
| 16 | + type=str, |
| 17 | + required=True, |
| 18 | + help="The run identifier for the data (e.g., '20250417_20250921').", |
| 19 | + ) |
| 20 | + parser.add_argument( |
| 21 | + "--version", |
| 22 | + type=str, |
| 23 | + required=True, |
| 24 | + help="The version (e.g., for weekly, 'w_2025_49').", |
| 25 | + ) |
| 26 | + parser.add_argument( |
| 27 | + "--collection", |
| 28 | + type=str, |
| 29 | + required=True, |
| 30 | + help="The collection name (e.g., 'DM-53545').", |
| 31 | + ) |
| 32 | + parser.add_argument( |
| 33 | + "--config", |
| 34 | + type=str, |
| 35 | + default="dp2_prep", |
| 36 | + help="The Butler configuration to use (default: 'dp2_prep').", |
| 37 | + ) |
| 38 | + parser.add_argument( |
| 39 | + "--destination", |
| 40 | + type=Path, |
| 41 | + default=Path(__file__).parent.parent / "data" / "dp2" / "public_parquet" / "ccd_visit.parquet", |
| 42 | + help="The local path to save the parquet file " |
| 43 | + "(default: 'data/dp2/public_parquet/ccd_visit.parquet').", |
| 44 | + ) |
| 45 | + return parser.parse_args(argv) |
| 46 | + |
| 47 | + |
| 48 | +def get_uri(*, run, version, collection, config, **_kwargs): |
| 49 | + """Get LSST URI object for the visit_detector_table parquet file.""" |
| 50 | + from lsst.daf.butler import Butler |
| 51 | + |
| 52 | + collections = f"LSSTCam/runs/DRP/{run}/{version}/{collection}" |
| 53 | + butler = Butler(config, collections=collections) |
| 54 | + uri = butler.getURI("visit_detector_table", dataId={"instrument": "LSSTCam"}) |
| 55 | + return uri |
| 56 | + |
| 57 | + |
| 58 | +def copy_to_local(uri, local_path): |
| 59 | + """Copy file from LSST URI to local path.""" |
| 60 | + with uri.open("rb") as src, local_path.open("wb") as dest: |
| 61 | + copyfileobj(src, dest) |
| 62 | + |
| 63 | + |
| 64 | +def main(argv=None): |
| 65 | + """Fetch DP2 CCD visit parquet file and save it locally.""" |
| 66 | + arg = parse_args(argv) |
| 67 | + uri = get_uri(**vars(arg)) |
| 68 | + copy_to_local(uri, arg.destination) |
| 69 | + |
| 70 | + |
| 71 | +if __name__ == "__main__": |
| 72 | + main() |
0 commit comments