From ae95dd63eb6e6b128fe960f2ee04ed5869f5fc3a Mon Sep 17 00:00:00 2001 From: Hatice Karatay Date: Tue, 17 Oct 2023 16:13:37 -0400 Subject: [PATCH] Fix remaining style errors --- .../00_Optimal_extraction.ipynb | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/notebooks/NIRISS_WFSS_postpipeline/00_Optimal_extraction.ipynb b/notebooks/NIRISS_WFSS_postpipeline/00_Optimal_extraction.ipynb index 14e6093e1..6b9f4a245 100755 --- a/notebooks/NIRISS_WFSS_postpipeline/00_Optimal_extraction.ipynb +++ b/notebooks/NIRISS_WFSS_postpipeline/00_Optimal_extraction.ipynb @@ -132,12 +132,11 @@ "\n", "# Image array from direct image. This is for optimal extraction and masking.\n", "# This image should already be sky-subtracted; otherwise, you will encounter a wrong result with optimal extraction.\n", - "# fixed\n", + "\n", "infile = f'{DIR_DATA}l3_nis_{filt_det}_i2d_skysub.fits'\n", "hdu = fits.open(infile)\n", "\n", "# This is just for error array;\n", - "# fixed\n", "infile = f'{DIR_DATA}l3_nis_{filt_det}_i2d.fits'\n", "hdu_err = fits.open(infile)\n", "\n", @@ -251,15 +250,14 @@ "# Which filter, grating, and object?\n", "filt = 'f200w'\n", "\n", - "#grism = 'G150R'\n", + "# grism = 'G150R'\n", "grism = 'G150C'\n", "\n", "id = '00004'\n", "\n", "# Zero-indexed number for dither --- the test data here has two dither positions, so 0 or 1.\n", "ndither = 0\n", - "print(DIR_DATA)\n", - "# fixed\n", + "\n", "file_2d = f'{DIR_DATA}l3_nis_{filt}_{grism}_s{id}_cal.fits'\n", "hdu_2d = fits.open(file_2d)\n", "\n", @@ -372,7 +370,7 @@ "outputs": [], "source": [ "# Sum along x (disperse) direction\n", - "flux_y = np.zeros(len(sci_rot[:,0]), 'float')\n", + "flux_y = np.zeros(len(sci_rot[:, 0]), 'float')\n", "for ii in range(sci_rot.shape[0]):\n", " flux_y[ii] = np.sum(sci_rot[ii, :])\n", "\n", @@ -450,17 +448,17 @@ " # 1. DQ array\n", " # 2. error value\n", " # 3. CR detection\n", - " mask_tmp = (dq_2d[:, ii] == 0) & (err_2d[:, ii]>0) & ( (data_2d[:, ii] - flux_y[:] * flux_disp1[ii])**2 < sig**2 * err_2d[:, ii]**2)\n", + " mask_tmp = (dq_2d[:, ii] == 0) & (err_2d[:, ii] > 0) & ((data_2d[:, ii] - flux_y[:] * flux_disp1[ii])**2 < sig**2 * err_2d[:, ii]**2)\n", " ivar = 1. / err_2d[:, ii]**2\n", "\n", " num = flux_y[:] * data_2d[:, ii] * ivar\n", " den = flux_y[:]**2 * ivar\n", " flux_disp[ii] = num[mask_tmp].sum(axis=0) / den[mask_tmp].sum(axis=0)\n", " err_disp[ii] = np.sqrt(1./den[mask_tmp].sum(axis=0))\n", - " wave_disp[ii] = wave_2d[0,ii]\n", + " wave_disp[ii] = wave_2d[0, ii]\n", " \n", "plt.errorbar(wave_disp, flux_disp, yerr=err_disp)\n", - "plt.xlim(1.7,2.3)" + "plt.xlim(1.7, 2.3)" ] }, { @@ -516,7 +514,7 @@ "for ii in range(sci_rot.shape[0]):\n", " flux_tmp = sci_rot[ii, :]\n", " xx_tmp = np.arange(0, len(sci_rot[ii, :]), 1)\n", - " plt.plot(xx_tmp, flux_tmp, label='y=%d'%(ii))\n", + " plt.plot(xx_tmp, flux_tmp, label=f'y={ii}')\n", " \n", "plt.legend(loc=1, fontsize=8)\n", "plt.xlabel('Wavelength direction')\n", @@ -562,19 +560,21 @@ "outputs": [], "source": [ "# Fitting function with Moffat\n", - "\n", "# Moffat fnc.\n", + "\n", "def moffat(xx, A, x0, gamma, alp):\n", " yy = A * (1. + (xx-x0)**2/gamma**2)**(-alp)\n", " return yy\n", "\n", + "\n", "def fit_mof(xx, lsf):\n", - " #xx = lsf * 0\n", - " #for ii in range(len(lsf)):\n", + " # xx = lsf * 0\n", + " # for ii in range(len(lsf)):\n", " # xx[ii] = ii - len(lsf)/2.\n", " popt, pcov = curve_fit(moffat, xx, lsf)\n", " return popt\n", "\n", + "\n", "def LSF_mof(xsf, lsf, f_plot=True):\n", " '''\n", " Input:\n", @@ -594,13 +594,13 @@ " A, xm, gamma, alpha = -1, -1, -1, -1\n", " pass\n", "\n", - " if A>0:\n", + " if A > 0:\n", " lsf_mod = moffat(xsf, A, 0, gamma, alpha)\n", " \n", " if f_plot:\n", " yy = moffat(xsf, A, xm, gamma, alpha)\n", " plt.plot(xsf, yy, 'r.', ls='-', label='Data')\n", - " plt.plot(xsf, lsf_mod, 'b+', ls='-', label='Model:$gamma=%.2f$\\n$alpha=%.2f$'%(gamma, alpha))\n", + " plt.plot(xsf, lsf_mod, 'b+', ls='-', label=f'Model: gamma={gamma:2f}\\nalpha={alpha:2f}')\n", " plt.legend()\n", " plt.show()\n", " \n", @@ -630,7 +630,7 @@ "fm = open(f'{DIR_OUT}l3_nis_{filt}_{grism}_s{id}_moffat.txt', 'w')\n", "fm.write('# A x0 gamma alp\\n')\n", "fm.write('# Moffat function\\n')\n", - "fm.write('%.3f %.3f %.3f %.3f\\n'%(A, xm, gamma, alpha))\n", + "fm.write(f'{A:.3f} {xm:.3f} {gamma:.3f} {alpha:.3f}\\n')\n", "\n", "fm.close()" ] @@ -726,12 +726,12 @@ " fm = open(f'{DIR_OUT}l3_nis_{filt}_{grism}_s{id}_moffat.txt', 'w')\n", " fm.write('# A x0 gamma alp\\n')\n", " fm.write('# Moffat function\\n')\n", - " fm.write('%.3f %.3f %.3f %.3f\\n'%(A, xm, gamma, alpha))\n", + " fm.write(f'{A:.3f} {xm:.3f} {gamma:.3f} {alpha:.3f}\\n')\n", " fm.close()\n", "\n", " # This is for Optimal extraction;\n", " # Sum along x (disperse) direction\n", - " flux_y = np.zeros(len(sci_rot[:,0]), 'float')\n", + " flux_y = np.zeros(len(sci_rot[:, 0]), 'float')\n", " for ii in range(sci_rot.shape[0]):\n", " flux_y[ii] = np.sum(sci_rot[ii, :])\n", " \n", @@ -755,10 +755,10 @@ " den = flux_y[:]**2 * ivar\n", " flux_disp[ii] = num[mask_tmp].sum(axis=0)/den[mask_tmp].sum(axis=0)\n", " err_disp[ii] = np.sqrt(1./den[mask_tmp].sum(axis=0))\n", - " wave_disp[ii] = wave_2d[0,ii]\n", + " wave_disp[ii] = wave_2d[0, ii]\n", "\n", " plt.close()\n", - " con_plot = (wave_disp>0)\n", + " con_plot = (wave_disp > 0)\n", " plt.errorbar(wave_disp[con_plot], flux_disp[con_plot], yerr=err_disp[con_plot])\n", " plt.ylim(-0, 3000)\n", " plt.show()\n", @@ -796,11 +796,11 @@ "outputs": [], "source": [ "grism = 'G150C'\n", - "id = '00003'\n", + "id = '00003'\n", "DIR_OUT = './output/'\n", "\n", - "filts = ['f115w', 'f150w', 'f200w']\n", - "ndithers = np.arange(0,2,1) # There are four dithers in the data set;\n", + "filts = ['f115w', 'f150w', 'f200w']\n", + "ndithers = np.arange(0, 2, 1) # There are four dithers in the data set;\n", "\n", "sig = 5.0\n", "\n", @@ -866,12 +866,12 @@ " fm = open(f'{DIR_OUT}l3_nis_{filt}_{grism}_s{id}_moffat.txt', 'w')\n", " fm.write('# A x0 gamma alp\\n')\n", " fm.write('# Moffat function\\n')\n", - " fm.write('%.3f %.3f %.3f %.3f\\n'%(A, xm, gamma, alpha))\n", + " fm.write(f'{A:.3f} {xm:.3f} {gamma:.3f} {alpha:.3f}\\n')\n", " fm.close()\n", "\n", " # This is for Optimal extraction;\n", " # Sum along x (disperse) direction\n", - " flux_y = np.zeros(len(sci_rot[:,0]), 'float')\n", + " flux_y = np.zeros(len(sci_rot[:, 0]), 'float')\n", " for ii in range(sci_rot.shape[0]):\n", " flux_y[ii] = np.sum(sci_rot[ii, :])\n", " \n", @@ -895,7 +895,7 @@ " den = flux_y[:]**2 * ivar\n", " flux_disp[ii] = num[mask_tmp].sum(axis=0)/den[mask_tmp].sum(axis=0)\n", " err_disp[ii] = np.sqrt(1./den[mask_tmp].sum(axis=0))\n", - " wave_disp[ii] = wave_2d[0,ii]\n", + " wave_disp[ii] = wave_2d[0, ii]\n", "\n", " plt.close()\n", " con_plot = (wave_disp > 0)\n",