Skip to content

Commit

Permalink
added requirements.txt file, updating notebook styling to adhere to P…
Browse files Browse the repository at this point in the history
…EP8 guidelines
  • Loading branch information
gibsongreen committed Feb 6, 2024
1 parent 35a1980 commit eb3f240
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
53 changes: 23 additions & 30 deletions notebooks/niriss_imaging/niriss-imaging-tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,28 @@
"metadata": {},
"outputs": [],
"source": [
"import os, glob\n",
"import os\n",
"import glob\n",
"import numpy as np\n",
"\n",
"# Configure CRDS\n",
"os.environ[\"CRDS_PATH\"] = 'crds_cache'\n",
"os.environ[\"CRDS_SERVER_URL\"] = \"https://jwst-crds.stsci.edu\"\n",
"import crds\n",
"\n",
"# for JWST calibration pipeline\n",
"import jwst\n",
"from jwst import datamodels\n",
"from jwst.pipeline import Detector1Pipeline, Image2Pipeline, Image3Pipeline\n",
"from jwst.associations import asn_from_list, mkpool\n",
"from jwst.associations import asn_from_list\n",
"from jwst.associations.lib.rules_level3_base import DMS_Level3_Base\n",
"\n",
"# For visualizing images\n",
"from jdaviz import Imviz\n",
"\n",
"# Astropy routines for visualizing detected sources:\n",
"from astropy.table import Table\n",
"from astropy.coordinates import SkyCoord\n",
"\n",
"# Configure CRDS\n",
"os.environ[\"CRDS_PATH\"] = 'crds_cache'\n",
"os.environ[\"CRDS_SERVER_URL\"] = \"https://jwst-crds.stsci.edu\"\n",
"\n",
"# To confirm which version of the pipeline you're running:\n",
"print(f\"jwst pipeline version: {jwst.__version__}\")"
]
Expand Down Expand Up @@ -124,7 +125,7 @@
"metadata": {},
"outputs": [],
"source": [
"uncal_files = sorted(glob.glob(os.path.join(data_dir,'*_uncal.fits')))"
"uncal_files = sorted(glob.glob(os.path.join(data_dir, '*_uncal.fits')))"
]
},
{
Expand Down Expand Up @@ -196,7 +197,7 @@
"uncal_science = examine.data\n",
"\n",
"# Load the dataset into Imviz\n",
"imviz_uncal.load_data(uncal_science[0,0,:,:])\n",
"imviz_uncal.load_data(uncal_science[0, 0, :, :])\n",
"\n",
"# Visualize the dataset:\n",
"imviz_uncal.show()"
Expand Down Expand Up @@ -286,7 +287,7 @@
"metadata": {},
"outputs": [],
"source": [
"rate_files = sorted(glob.glob(os.path.join(det1_dir,'*_rate.fits')))"
"rate_files = sorted(glob.glob(os.path.join(det1_dir, '*_rate.fits')))"
]
},
{
Expand Down Expand Up @@ -428,7 +429,7 @@
"metadata": {},
"outputs": [],
"source": [
"cal_files = sorted(glob.glob(os.path.join(image2_dir,'*_cal.fits')))"
"cal_files = sorted(glob.glob(os.path.join(image2_dir, '*_cal.fits')))"
]
},
{
Expand Down Expand Up @@ -561,7 +562,7 @@
"asn_filename, serialized = associations.dump(format=\"json\")\n",
"\n",
"# Write out association file\n",
"with open(asn_filename,\"w\") as fd:\n",
"with open(asn_filename, \"w\") as fd:\n",
" fd.write(serialized)"
]
},
Expand Down Expand Up @@ -616,7 +617,7 @@
"outputs": [],
"source": [
"# Identify *_i2d file and open as datamodel\n",
"i2d = glob.glob(os.path.join(image3_dir,\"*_i2d.fits\"))[0]\n",
"i2d = glob.glob(os.path.join(image3_dir, \"*_i2d.fits\"))[0]\n",
"i2d_f = datamodels.open(i2d)\n",
"\n",
"i2d_f.meta.cal_step.instance"
Expand Down Expand Up @@ -707,18 +708,18 @@
"metadata": {},
"outputs": [],
"source": [
"catalog_file = glob.glob(os.path.join(image3_dir,\"*_cat.ecsv\"))[0]\n",
"catalog_file = glob.glob(os.path.join(image3_dir, \"*_cat.ecsv\"))[0]\n",
"catalog = Table.read(catalog_file)\n",
"\n",
"# To identify point/extended sources, use the 'is_extended' column in the source catalog\n",
"pt_src, = np.where(catalog['is_extended'] == False)\n",
"ext_src, = np.where(catalog['is_extended'] == True)\n",
"pt_src, = np.where(~catalog['is_extended'])\n",
"ext_src, = np.where(catalog['is_extended'])\n",
"\n",
"# Define coordinates of point and extended sources\n",
"pt_coord = Table({'coord':[SkyCoord(ra=catalog['sky_centroid'][pt_src].ra,\n",
" dec=catalog['sky_centroid'][pt_src].dec)]})\n",
"ext_coord = Table({'coord':[SkyCoord(ra=catalog['sky_centroid'][ext_src].ra,\n",
" dec=catalog['sky_centroid'][ext_src].dec)]})"
"pt_coord = Table({'coord': [SkyCoord(ra=catalog['sky_centroid'][pt_src].ra,\n",
" dec=catalog['sky_centroid'][pt_src].dec)]})\n",
"ext_coord = Table({'coord': [SkyCoord(ra=catalog['sky_centroid'][ext_src].ra,\n",
" dec=catalog['sky_centroid'][ext_src].dec)]})"
]
},
{
Expand Down Expand Up @@ -768,12 +769,12 @@
"outputs": [],
"source": [
"# Add marker for point sources:\n",
"viewer_cat.marker = {'color': 'pink', 'markersize':50, 'fill':False}\n",
"viewer_cat.marker = {'color': 'pink', 'markersize': 50, 'fill': False}\n",
"\n",
"viewer_cat.add_markers(pt_coord, use_skycoord=True, marker_name='point_sources')\n",
"\n",
"# Add marker for extended sources:\n",
"viewer_cat.marker = {'color': 'white', 'markersize':100, 'fill': False}\n",
"viewer_cat.marker = {'color': 'white', 'markersize': 100, 'fill': False}\n",
"\n",
"viewer_cat.add_markers(ext_coord, use_skycoord=True, marker_name='extended_sources')\n"
]
Expand All @@ -785,14 +786,6 @@
"source": [
"From zoooming in on different portions of the image, we can see that some saturated point sources are erroneously labeled as point sources, some extended and saturated objects are not detected, parts of diffraction spikes are sometimes detected as \"extended sources\", and in some cases, the detected source centroid is offset from the center of a source. It is recommended for users to optimize source detection for their science goals using either their own tools or by updating parameters to the `source_catalog` step of the pipeline."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aad427db-1935-4261-b46e-346f1230522f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
5 changes: 5 additions & 0 deletions notebooks/niriss_imaging/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
numpy
crds
jwst>=1.2.3
jdaviz
astropy>=4.3.1

0 comments on commit eb3f240

Please sign in to comment.