From 36e096f26523b8e078f317576f742e9475d5d63e Mon Sep 17 00:00:00 2001 From: Michael Dulude Date: Sun, 7 Jan 2024 20:26:22 -0500 Subject: [PATCH] Add WFC3 notebook 'uvis_timedep_phot.ipynb' (#113) * updated _toc.yml and _config.yml files * uvis_timedep_phot.ipynb: cleared notebook outputs. * Refactor file path handling for improved clarity * Fix code style and photutils deprecation * Remove codestyle command --------- Co-authored-by: Hatice Karatay --- _config.yml | 1 - _toc.yml | 2 +- .../uvis_timedep_phot.ipynb | 78 ++++++++++--------- 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/_config.yml b/_config.yml index 7fb0b4692..8e361d9f1 100644 --- a/_config.yml +++ b/_config.yml @@ -59,5 +59,4 @@ exclude_patterns: [notebooks/DrizzlePac/align_mosaics/align_mosaics.ipynb, notebooks/WFC3/ir_scattered_light_manual_corrections/Correcting_for_Scattered_Light_in_IR_Exposures_by_Manually_Subtracting_Bad_Reads.ipynb, notebooks/WFC3/photometry_examples/phot_examples.ipynb, notebooks/WFC3/tvb_flattenramp/TVB_flattenramp_notebook.ipynb, - notebooks/WFC3/uvis_time_dependent_photometry/uvis_timedep_phot.ipynb, notebooks/WFC3/zeropoints/zeropoints.ipynb] diff --git a/_toc.yml b/_toc.yml index cc28e3375..3503588df 100644 --- a/_toc.yml +++ b/_toc.yml @@ -75,5 +75,5 @@ parts: - file: notebooks/WFC3/tvb_flattenramp/TVB_flattenramp_notebook.ipynb - file: notebooks/WFC3/photometry_examples/phot_examples.ipynb - file: notebooks/WFC3/uvis_pam_corrections/WFC3_UVIS_Pixel_Area_Map_Corrections_for_Subarrays.ipynb -# - file: notebooks/WFC3/uvis_time_dependent_photometry/uvis_timedep_phot.ipynb + - file: notebooks/WFC3/uvis_time_dependent_photometry/uvis_timedep_phot.ipynb # - file: notebooks/WFC3/zeropoints/zeropoints.ipynb diff --git a/notebooks/WFC3/uvis_time_dependent_photometry/uvis_timedep_phot.ipynb b/notebooks/WFC3/uvis_time_dependent_photometry/uvis_timedep_phot.ipynb index 694ef54cb..fa36d7449 100644 --- a/notebooks/WFC3/uvis_time_dependent_photometry/uvis_timedep_phot.ipynb +++ b/notebooks/WFC3/uvis_time_dependent_photometry/uvis_timedep_phot.ipynb @@ -84,8 +84,6 @@ "metadata": {}, "outputs": [], "source": [ - "%matplotlib inline\n", - "\n", "import os\n", "import glob\n", "import shutil\n", @@ -96,16 +94,13 @@ "\n", "from astropy.io import fits\n", "from astropy.stats import sigma_clipped_stats\n", - "from astropy.coordinates import SkyCoord\n", - "from astropy import wcs\n", "from astroquery.mast import Observations\n", "\n", "from drizzlepac import photeq\n", "from drizzlepac import astrodrizzle\n", "\n", - "from photutils import aperture_photometry, CircularAperture, CircularAnnulus\n", - "\n", - "from stwcs import updatewcs" + "from photutils.aperture import aperture_photometry, CircularAperture, CircularAnnulus\n", + "%matplotlib inline" ] }, { @@ -124,16 +119,17 @@ "metadata": {}, "outputs": [], "source": [ - "data_list = Observations.query_criteria(obs_id=['IBCDA4010','ICH3040F0','IDBHA6040'])\n", - " \n", + "data_list = Observations.query_criteria(obs_id=['IBCDA4010', 'ICH3040F0', 'IDBHA6040'])\n", + "\n", "Observations.download_products(data_list['obsid'], project='CALWF3',\n", - " mrp_only=False,download_dir='./data',productSubGroupDescription=['FLC','ASN'])\n", + " mrp_only=False, download_dir='./data', productSubGroupDescription=['FLC', 'ASN'])\n", "\n", "science_files = glob.glob('data/mastDownload/HST/*/*fits')\n", "\n", "for im in science_files:\n", - " root = im.split('/')[-1]\n", - " os.rename(im,'./'+root)\n", + " root = os.path.basename(im)\n", + " new_path = os.path.join(\"./\", root)\n", + " os.rename(im, new_path)\n", "shutil.rmtree('data/')" ] }, @@ -151,7 +147,6 @@ "outputs": [], "source": [ "df = pd.read_csv('GD153_F606W_public.csv')\n", - "\n", "df" ] }, @@ -230,14 +225,14 @@ " mask = annulus_masks.data\n", " annulus_data_1d = annulus_data[mask > 0]\n", " mean_sigclip, _, _ = sigma_clipped_stats(annulus_data_1d)\n", - " \n", + "\n", " apers = [aperture, annulus_aperture]\n", - " phot_table = aperture_photometry(data,apers)\n", + " phot_table = aperture_photometry(data, apers)\n", "\n", " background = mean_sigclip * aperture.area\n", " final_sum = phot_table['aperture_sum_0'] - background\n", " phots.append(final_sum[0])\n", - " mjds.append(mjd) \n", + " mjds.append(mjd)\n", " dates.append(date)" ] }, @@ -279,7 +274,12 @@ "outputs": [], "source": [ "EE_r10 = 0.91\n", - "df['STMags'] = -21.1 -2.5*np.log10(df['PHOTFLAM']) -2.5*np.log10(df['Countrate']) - 2.5 * np.log10(1./EE_r10)" + "df[\"STMags\"] = (\n", + " - 21.1\n", + " - 2.5 * np.log10(df[\"PHOTFLAM\"])\n", + " - 2.5 * np.log10(df[\"Countrate\"])\n", + " - 2.5 * np.log10(1.0 / EE_r10)\n", + ")" ] }, { @@ -406,9 +406,9 @@ " annulus_data_1d = annulus_data[mask > 0]\n", " mean_sigclip, _, _ = sigma_clipped_stats(annulus_data_1d)\n", " background = mean_sigclip * aperture.area\n", - " \n", + "\n", " apers = [aperture, annulus_aperture]\n", - " phot_table = aperture_photometry(data,apers)\n", + " phot_table = aperture_photometry(data, apers)\n", "\n", " final_sum = phot_table['aperture_sum_0'] - background\n", " phots.append(final_sum[0])\n", @@ -490,20 +490,22 @@ }, "outputs": [], "source": [ - "for asn in glob.glob('*asn.fits'):\n", - " astrodrizzle.AstroDrizzle(asn,\n", - " skymethod= 'match',\n", - " skystat='mean',\n", - " driz_sep_bits='80',\n", - " combine_type='median',\n", - " combine_nhigh=1,\n", - " driz_cr_snr= '3.5 3.0', \n", - " driz_cr_scale= '2.0 1.5',\n", - " final_bits= '80', \n", - " build=True,\n", - " clean=True,\n", - " preserve=False,\n", - " num_cores=1)" + "for asn in glob.glob(\"*asn.fits\"):\n", + " astrodrizzle.AstroDrizzle(\n", + " asn,\n", + " skymethod=\"match\",\n", + " skystat=\"mean\",\n", + " driz_sep_bits=\"80\",\n", + " combine_type=\"median\",\n", + " combine_nhigh=1,\n", + " driz_cr_snr=\"3.5 3.0\",\n", + " driz_cr_scale=\"2.0 1.5\",\n", + " final_bits=\"80\",\n", + " build=True,\n", + " clean=True,\n", + " preserve=False,\n", + " num_cores=1,\n", + " )" ] }, { @@ -537,7 +539,7 @@ "pfls = []\n", "for i, drc in enumerate(drcs):\n", " data = fits.getdata(drc, ext=1)\n", - " \n", + "\n", " mjds.append(np.mean(df.query('Epoch == {}'.format(i+1))['MJD']))\n", " pfls.append(df.query('Epoch == {}'.format(i+1))['PHOTFLAM'].values[0])\n", "\n", @@ -550,9 +552,9 @@ " annulus_data_1d = annulus_data[mask > 0]\n", " mean_sigclip, _, _ = sigma_clipped_stats(annulus_data_1d)\n", " background = mean_sigclip * aperture.area\n", - " \n", + " \n", " apers = [aperture, annulus_aperture]\n", - " phot_table = aperture_photometry(data,apers)\n", + " phot_table = aperture_photometry(data, apers)\n", "\n", " final_sum = phot_table['aperture_sum_0'] - background\n", " phots.append(final_sum[0])" @@ -675,7 +677,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -689,7 +691,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.5" + "version": "3.11.6" } }, "nbformat": 4,