Skip to content

Commit bc5946f

Browse files
authored
Merge pull request #48 from lsst/tickets/SP-2474
tickets/SP-2474: Fix data storage issue in custom coadds notebook
2 parents 9371c4f + 6a3bb0d commit bc5946f

1 file changed

Lines changed: 100 additions & 5 deletions

File tree

DP1/100_How_to_Use_RSP_Tools/105_Image_reprocessing/105_6_Create_custom_coadd_images.ipynb

Lines changed: 100 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"Data Release: DP1 <br>\n",
2020
"Container Size: large <br>\n",
2121
"LSST Science Pipelines version: r29.1.1 <br>\n",
22-
"Last verified to run: 2025-06-24 <br>\n",
22+
"Last verified to run: 2025-07-29 <br>\n",
2323
"Repository: <a href=\"https://github.com/lsst/tutorial-notebooks\">github.com/lsst/tutorial-notebooks</a> <br>"
2424
]
2525
},
@@ -82,6 +82,7 @@
8282
"outputs": [],
8383
"source": [
8484
"import os\n",
85+
"from pathlib import Path\n",
8586
"from lsst.daf.butler import Butler\n",
8687
"from lsst.ctrl.mpexec import SimplePipelineExecutor\n",
8788
"from lsst.pipe.base import Pipeline\n",
@@ -543,7 +544,7 @@
543544
"id": "85394b0f-7222-4624-89af-4c1f9c70d7d8",
544545
"metadata": {},
545546
"source": [
546-
"Users cannot write to the main DP1 Butler repository. Instead, make a writable local repository within your current directory where custom coadd outputs will be written. The call to `use_local_butler` creates a new directory that will contain the local Butler repository, within your current working directory."
547+
"Users cannot write to the main DP1 Butler repository. Instead, make a writable repository where custom coadd outputs will be written. The call to `use_local_butler` creates a new directory that will contain the local Butler repository, within the `$SCRATCH_DIR` temporary space that gets deleted weekly. Use this temporary space because the custom coadd processing produces of order a gigabyte of intermediate files."
547548
]
548549
},
549550
{
@@ -553,8 +554,8 @@
553554
"metadata": {},
554555
"outputs": [],
555556
"source": [
556-
"local_repo_name = os.path.join(os.getenv(\"HOME\"), \"my_local_repo\")\n",
557-
"out_butler = executor.use_local_butler(local_repo_name)"
557+
"local_repo_path = Path(os.getenv(\"SCRATCH_DIR\"), \"my_local_repo\")\n",
558+
"out_butler = executor.use_local_butler(local_repo_path)"
558559
]
559560
},
560561
{
@@ -634,13 +635,107 @@
634635
"> Figure 2: The custom `deep_coadd` image using only the selected subset of input visit images."
635636
]
636637
},
638+
{
639+
"cell_type": "markdown",
640+
"id": "a95de02e-d676-4ca3-8fb8-d1afe410e1d4",
641+
"metadata": {},
642+
"source": [
643+
"### 3.4. Copy the custom coadd output file"
644+
]
645+
},
646+
{
647+
"cell_type": "markdown",
648+
"id": "aa9eacc5-18b0-4a8a-aa05-4b45c12aeee8",
649+
"metadata": {},
650+
"source": [
651+
"The writable Butler repository used for custom coaddition is located within a temporary storage area. The Butler `retrieveArtifacts` method can be used to retrieve a copy of just the custom coadd output file, without copying intermediate files generated by the processing, and placing the custom coadd output file in a desired location. This can be useful to preserve the custom coadd image file without filling up a significant amount of disk quota in a permanent location. Start by retrieving the dataset reference for the custom coadd image output file."
652+
]
653+
},
637654
{
638655
"cell_type": "code",
639656
"execution_count": null,
640657
"id": "91ee3647-96c9-4aa9-9d61-ced39b8c1990",
641658
"metadata": {},
642659
"outputs": [],
643-
"source": []
660+
"source": [
661+
"refs = out_butler.query_datasets('deep_coadd_predetection',\n",
662+
" collections=executor.quantum_graph.metadata[\"output_run\"])"
663+
]
664+
},
665+
{
666+
"cell_type": "markdown",
667+
"id": "f5dee19c-5bc9-4f5b-af9c-aaabfec6ee77",
668+
"metadata": {},
669+
"source": [
670+
"As an example, choose to put the copy of the custom coadd output file in your scratch space area."
671+
]
672+
},
673+
{
674+
"cell_type": "code",
675+
"execution_count": null,
676+
"id": "9e55d973-a30d-4891-a896-6b62e6b08a9c",
677+
"metadata": {},
678+
"outputs": [],
679+
"source": [
680+
"outdir = os.getenv(\"SCRATCH_DIR\")"
681+
]
682+
},
683+
{
684+
"cell_type": "markdown",
685+
"id": "e639644d-14e2-47ba-92d1-03a952f634c2",
686+
"metadata": {},
687+
"source": [
688+
"*Option*: instead choose to copy the custom coadd output file to your home directory, where it will not be deleted within a week."
689+
]
690+
},
691+
{
692+
"cell_type": "code",
693+
"execution_count": null,
694+
"id": "e0f81548-e8c0-4854-b2f7-767da392f27b",
695+
"metadata": {},
696+
"outputs": [],
697+
"source": [
698+
"# outdir = os.getenv(\"HOME\")"
699+
]
700+
},
701+
{
702+
"cell_type": "markdown",
703+
"id": "1fdd59a0-0454-441d-b60f-4d6aeb10d147",
704+
"metadata": {},
705+
"source": [
706+
"Copy the FITS file containing the custom coadd image to the desired location."
707+
]
708+
},
709+
{
710+
"cell_type": "code",
711+
"execution_count": null,
712+
"id": "a3913c72-355a-4289-8061-b22785ff7df9",
713+
"metadata": {},
714+
"outputs": [],
715+
"source": [
716+
"out_butler.retrieveArtifacts(refs, outdir, preserve_path=False, transfer=\"copy\", overwrite=True)"
717+
]
718+
},
719+
{
720+
"cell_type": "markdown",
721+
"id": "044a5afe-202b-4bbd-9c96-91869f89716d",
722+
"metadata": {},
723+
"source": [
724+
"To free up space, delete the writable Butler repository used for custom coaddition. If you wish to continue exploring the writable Butler repository then the following cell can be skipped, though note that the local Butler repo will still be deleted within a week because it is within temporary scratch space. In general, be very careful about any `rm -r` or similar commands that you run on RSP, as there is potential for inadvertently deleting files you wish to retain.\n",
725+
"\n",
726+
"*Option*: Skip the final cell below if you wish to continue working with variables previously defined in this notebook and/or continue using your writable Butler repo."
727+
]
728+
},
729+
{
730+
"cell_type": "code",
731+
"execution_count": null,
732+
"id": "f9c8a16c-ed9e-46f7-81c2-43ea4206dc0d",
733+
"metadata": {},
734+
"outputs": [],
735+
"source": [
736+
"%reset -f\n",
737+
"! rm -r $SCRATCH_DIR/my_local_repo"
738+
]
644739
}
645740
],
646741
"metadata": {

0 commit comments

Comments
 (0)