Skip to content

Commit

Permalink
Merge pull request #272 from bhilbert4/spacephot-asn-filenames
Browse files Browse the repository at this point in the history
Determine asn names programmatically
  • Loading branch information
camipacifici authored Feb 4, 2025
2 parents d283310 + 000ff62 commit 836a7a6
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 28 deletions.
125 changes: 97 additions & 28 deletions notebooks/NIRCam/psf_photometry_with_space_phot/nircam_spacephot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"\n",
"**Author**: Ori Fox\n",
"<br>\n",
"**Last Updated**: August, 2023"
"**Last Updated**: January, 2025"
]
},
{
Expand Down Expand Up @@ -136,45 +136,114 @@
{
"cell_type": "code",
"execution_count": null,
"id": "545860a5-cca4-4185-82fb-e4d962690be8",
"id": "2fdd7e2a-a1ac-4abc-b40d-6d209642cb75",
"metadata": {},
"outputs": [],
"source": [
"# Download NIRCam Data PID 1537 (Calibration Program) and NIRCam Data PID 1476 (LMC)\n",
"files_to_download = [\n",
" 'jw01537-o024_t001_nircam_clear-f444w-sub160_i2d.fits',\n",
" 'jw01537-o024_20241003t130922_image3_00001_asn.json',\n",
" 'jw01537024001_0310a_00001_nrcblong_cal.fits',\n",
" 'jw01537024001_0310a_00002_nrcblong_cal.fits',\n",
" 'jw01537024001_0310a_00003_nrcblong_cal.fits',\n",
" 'jw01537024001_0310a_00004_nrcblong_cal.fits',\n",
" 'jw01537024001_0310k_00001_nrcblong_cal.fits',\n",
" 'jw01537024001_0310k_00002_nrcblong_cal.fits',\n",
" 'jw01537024001_0310k_00003_nrcblong_cal.fits',\n",
" 'jw01537024001_0310k_00004_nrcblong_cal.fits',\n",
" 'jw01476-o001_t001_nircam_clear-f150w_i2d.fits',\n",
" 'jw01476-o001_20240910t004333_image3_00023_asn.json',\n",
" 'jw01476001007_02101_00001_nrca1_cal.fits',\n",
" 'jw01476001007_02101_00002_nrca1_cal.fits',\n",
" 'jw01476001007_02101_00003_nrca1_cal.fits',\n",
" 'jw01476001008_02101_00001_nrca1_cal.fits',\n",
" 'jw01476001008_02101_00002_nrca1_cal.fits',\n",
" 'jw01476001008_02101_00003_nrca1_cal.fits',\n",
" 'jw01476001008_02101_00004_nrca1_cal.fits',\n",
" 'jw01476001008_02101_00005_nrca1_cal.fits',\n",
" 'jw01476001008_02101_00006_nrca1_cal.fits'\n",
"]\n",
"def get_asn_filenames(program, observation, objnum, filtername):\n",
" \"\"\"Query MAST to determine the name of the association file for the given\n",
" program, observation, and object number. This function is more convenient\n",
" than hardcoding a filename because the filenames include datestamps of when\n",
" they were produced. So each time the files are reprocessed in MAST, the\n",
" filenames change.\n",
"\n",
" Parameters\n",
" ----------\n",
" program : int\n",
" Program ID number. e.g. 1067\n",
"\n",
" observation : int\n",
" Observation number. e.g. 24\n",
"\n",
" objnum : int\n",
" Object number. \n",
"\n",
" filtername : str\n",
" Name of the filter used in the observation. e.g. \"F444W\"\n",
"\n",
" Returns\n",
" -------\n",
" files_to_download : list\n",
" List of filenames matching the input parameters\n",
" \"\"\"\n",
" prog_str = str(program).zfill(5)\n",
" obs_str = str(observation).zfill(3)\n",
" obj_str = str(objnum).zfill(5)\n",
" \n",
" obs_id_table = Observations.query_criteria(instrument_name=[\"NIRCAM/IMAGE\"],\n",
" provenance_name=[\"CALJWST\"], # Executed observations\n",
" obs_id=['jw' + prog_str + '-o' + obs_str + '*'],\n",
" filters=[filtername.upper()]\n",
" )\n",
" matching_files = []\n",
" for exposure in (obs_id_table):\n",
" products = Observations.get_product_list(exposure)\n",
" filtered_products = Observations.filter_products(products, productSubGroupDescription='ASN')\n",
" matching_files.extend(filtered_products['dataURI'])\n",
"\n",
" matching_files = [os.path.basename(e) for e in matching_files if f'_image3_{obj_str}_asn' in e]\n",
" return matching_files"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5f01a02b-aca9-4642-a378-91d4296f4bd8",
"metadata": {},
"outputs": [],
"source": [
"def download_files(files_to_download):\n",
" \"\"\"Download a list of files from MAST.\n",
"\n",
" Parameters\n",
" ----------\n",
" files_to_download : list\n",
" List of filenames\n",
" \"\"\"\n",
" for file in files_to_download:\n",
" # Check if the file already exists in the current working directory\n",
" if os.path.exists(file):\n",
" print(f\"File {file} already exists. Skipping download.\")\n",
" continue\n",
" cal_uri = f'mast:JWST/product/{file}'\n",
" Observations.download_file(cal_uri)\n",
" Observations.download_file(cal_uri)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "545860a5-cca4-4185-82fb-e4d962690be8",
"metadata": {},
"outputs": [],
"source": [
"# Download NIRCam Data PID 1537 (Calibration Program) and NIRCam Data PID 1476 (LMC)\n",
"files_to_download = ['jw01537-o024_t001_nircam_clear-f444w-sub160_i2d.fits',\n",
" 'jw01537024001_0310a_00001_nrcblong_cal.fits',\n",
" 'jw01537024001_0310a_00002_nrcblong_cal.fits',\n",
" 'jw01537024001_0310a_00003_nrcblong_cal.fits',\n",
" 'jw01537024001_0310a_00004_nrcblong_cal.fits',\n",
" 'jw01537024001_0310k_00001_nrcblong_cal.fits',\n",
" 'jw01537024001_0310k_00002_nrcblong_cal.fits',\n",
" 'jw01537024001_0310k_00003_nrcblong_cal.fits',\n",
" 'jw01537024001_0310k_00004_nrcblong_cal.fits',\n",
" 'jw01476-o001_t001_nircam_clear-f150w_i2d.fits',\n",
" 'jw01476001007_02101_00001_nrca1_cal.fits',\n",
" 'jw01476001007_02101_00002_nrca1_cal.fits',\n",
" 'jw01476001007_02101_00003_nrca1_cal.fits',\n",
" 'jw01476001008_02101_00001_nrca1_cal.fits',\n",
" 'jw01476001008_02101_00002_nrca1_cal.fits',\n",
" 'jw01476001008_02101_00003_nrca1_cal.fits',\n",
" 'jw01476001008_02101_00004_nrca1_cal.fits',\n",
" 'jw01476001008_02101_00005_nrca1_cal.fits',\n",
" 'jw01476001008_02101_00006_nrca1_cal.fits'\n",
" ]\n",
"\n",
"# Get the names of the related association files and add those\n",
"# to the list of files to download\n",
"asn_files_to_download = [get_asn_filenames(1537, 24, 1, 'F444W')[0],\n",
" get_asn_filenames(1476, 1, 23, 'F150W')[0]\n",
" ]\n",
"files_to_download += asn_files_to_download\n",
"\n",
"# Call the function to download files\n",
"download_files(files_to_download)"
Expand Down Expand Up @@ -1072,7 +1141,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.10"
"version": "3.11.11"
},
"toc-showcode": false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ numpy>=1.25.2
pandas>=2.1.0
jwst>=1.11.4
astropy>=5.3.3
astroquery>=0.4.9
photutils>=1.11.0
ipywidgets>=8.1.1
matplotlib>=3.7.2
Expand Down

0 comments on commit 836a7a6

Please sign in to comment.