Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 70 additions & 4 deletions DP2/200_Data_products/202_Images/202_1_Deep_coadds.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"### 1.1. Import packages\n",

@garrethmartin garrethmartin Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line #1.    # save_file = "{}/deep_coadd_{}_{}_{}_{}.fits".format(

save_file = os.path.join(userdir, ...) is slightly safer


Reply via ReviewNB

@garrethmartin garrethmartin Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line #9.    # print("save file: {}".format(save_file))

i think it would be make sense to print the message after you save (e.g. save file -> saved to) so the user knows the cell has actually run and saved a file.


Reply via ReviewNB

@garrethmartin garrethmartin Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would also maybe remove the comments above so the code actually runs and just delete the file during cleanup.

os.remove(save_file)


Reply via ReviewNB

"\n",
"From the LSST Science Pipelines import the packages for the Butler, 2-dimensional sky geometry, and for image display.\n",
"Also import the `numpy` package, `matplotlib` plotting tools, and `Astropy` coordinate utilities."
"Also import the `numpy` package, `matplotlib` plotting tools, and `Astropy` coordinate utilities. Import `os` and `getpass` for setting up a temporary directory to save files."
]
},
{
Expand All @@ -92,7 +92,9 @@
"import astropy.units as u\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib.collections import PatchCollection\n",
"import numpy as np"
"import numpy as np\n",
"import os\n",
"import getpass"
]
},
{
Expand Down Expand Up @@ -1845,16 +1847,80 @@
"outputs": [],
"source": [
"del ref, dataId, use_tract, use_patch, use_columns, objects, tx\n",
"del dataset_refs, deep_coadd"
"del dataset_refs"
]
},
{
"cell_type": "markdown",
"id": "c06ebdd7-482a-43a6-aed8-4ed053c8d184",
"metadata": {},
"source": [
"## 6. Save `deep_coadd` to file\n",
"`deep_coadd` is a `CellCoadd` object type and has an associated method to write the object to file, as described in the [API](https://images.lsst.io/api/lsst.images.cells.CellCoadd.html#lsst.images.cells.CellCoadd.write). It is recommended for users to save temporary files in the shared scratch directory, `/deleted-sundays/`, in sub-directories named with their RSP username."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6f0887f4-b789-42d7-b1da-931d2e42e45b",
"metadata": {},
"outputs": [],
"source": [
"username = getpass.getuser()\n",
"print('username: ', username)\n",
"\n",
"userdir = '/deleted-sundays/' + username\n",
"if not os.path.exists(userdir):\n",
" os.makedirs(userdir)\n",
" print('Created ', userdir)\n",
"else:\n",
" print('Directory already existed: ', userdir)"
]
},
{
"cell_type": "markdown",
"id": "aa295f27-e9df-42cc-9911-192bb3798458",
"metadata": {},
"source": [
"Uncomment the following cell to save `deep_coadd` as a FITS file in the scratch directory."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "255b693c-4767-4152-addf-1d98a7276783",
"metadata": {},
"outputs": [],
"source": [
"# save_file = \"{}/deep_coadd_{}_{}_{}_{}.fits\".format(\n",
"# userdir,\n",
"# deep_coadd.skymap,\n",
"# deep_coadd.tract,\n",
"# deep_coadd.patch.id,\n",
"# deep_coadd.band\n",
"# )\n",
"\n",
"# print(\"save file: {}\".format(save_file))\n",
"# deep_coadd.image.write(save_file)"
]
},
{
"cell_type": "markdown",
"id": "8270ac15-73ee-4e87-ab72-f0a12b3c455f",
"metadata": {},
"source": [
"Clean up."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7cf73981-189c-401d-bde8-e6e8fc26b31e",
"metadata": {},
"outputs": [],
"source": []
"source": [
"del deep_coadd"
]
}
],
"metadata": {
Expand Down
Loading