From 28458262abbf58f88cf786010501b5ef72ab6077 Mon Sep 17 00:00:00 2001 From: Tyler Desjardins Date: Sun, 6 Jan 2019 16:20:08 -0800 Subject: [PATCH] Fixed PEP8 errors --- .../optimize_image_sampling.ipynb | 188 +++++++++--------- 1 file changed, 94 insertions(+), 94 deletions(-) diff --git a/notebooks/DrizzlePac/optimize_image_sampling/optimize_image_sampling.ipynb b/notebooks/DrizzlePac/optimize_image_sampling/optimize_image_sampling.ipynb index 643c056c..1bccb114 100644 --- a/notebooks/DrizzlePac/optimize_image_sampling/optimize_image_sampling.ipynb +++ b/notebooks/DrizzlePac/optimize_image_sampling/optimize_image_sampling.ipynb @@ -70,9 +70,9 @@ "source": [ "# Querying MAST and downloading files.\n", "obs_ids = ['ib1f19010']\n", - "obs_table = Observations.query_criteria(obs_id=obs_ids,obstype='all')\n", + "obs_table = Observations.query_criteria(obs_id=obs_ids, obstype='all')\n", "\n", - "download_tab = Observations.download_products(obs_table['obsid'],mrp_only=False,productSubGroupDescription=['FLT'])" + "download_tab = Observations.download_products(obs_table['obsid'], mrp_only=False, productSubGroupDescription=['FLT'])" ] }, { @@ -106,31 +106,31 @@ "source": [ "flt_files = glob.glob('*flt.fits')\n", "\n", - "plate_scale = fits.getval(flt_files[0],'idcscale',ext=1)\n", + "plate_scale = fits.getval(flt_files[0], 'idcscale',ext=1)\n", "print('Plate scale: {:>6.4f}'.format(plate_scale))\n", - "postarg1 = np.empty(len(flt_files),dtype=np.float)\n", - "postarg2 = np.empty(len(flt_files),dtype=np.float)\n", - "x_phase = np.empty(len(flt_files),dtype=np.float)\n", - "y_phase = np.empty(len(flt_files),dtype=np.float)\n", + "postarg1 = np.empty(len(flt_files), dtype=np.float)\n", + "postarg2 = np.empty(len(flt_files), dtype=np.float)\n", + "x_phase = np.empty(len(flt_files), dtype=np.float)\n", + "y_phase = np.empty(len(flt_files), dtype=np.float)\n", "\n", - "for i,im in enumerate(flt_files):\n", + "for i, im in enumerate(flt_files):\n", " with fits.open(im) as hdu:\n", " postarg1[i] = hdu[0].header['postarg1']\n", " postarg2[i] = hdu[0].header['postarg2']\n", - " x_phase[i] = abs(np.modf(postarg1[i]/plate_scale)[0])\n", - " y_phase[i] = abs(np.modf(postarg2[i]/plate_scale)[0])\n", + " x_phase[i] = abs(np.modf(postarg1[i] / plate_scale)[0])\n", + " y_phase[i] = abs(np.modf(postarg2[i] / plate_scale)[0])\n", " \n", - "fig,ax = plt.subplots(1,2,figsize=(12,6))\n", + "fig, ax = plt.subplots(1, 2, figsize=(12, 6))\n", "\n", - "ax[0].plot(postarg1,postarg2,'k+-',ms=15,lw=1)\n", - "ax[0].set_xlabel('arcsec',fontsize='large')\n", - "ax[0].set_ylabel('arcsec',fontsize='large')\n", + "ax[0].plot(postarg1, postarg2, 'k+-', ms=15, lw=1)\n", + "ax[0].set_xlabel('arcsec', fontsize='large')\n", + "ax[0].set_ylabel('arcsec', fontsize='large')\n", "\n", - "ax[1].plot(x_phase,y_phase,'k+-',ms=15,lw=1)\n", - "ax[1].set_xlim(-0.05,1)\n", - "ax[1].set_ylim(-0.05,1)\n", - "ax[1].set_xlabel('X pixel phase',fontsize='large')\n", - "ax[1].set_ylabel('Y pixel phase',fontsize='large')" + "ax[1].plot(x_phase, y_phase, 'k+-', ms=15, lw=1)\n", + "ax[1].set_xlim(-0.05, 1)\n", + "ax[1].set_ylim(-0.05, 1)\n", + "ax[1].set_xlabel('X pixel phase', fontsize='large')\n", + "ax[1].set_ylabel('Y pixel phase', fontsize='large')" ] }, { @@ -151,30 +151,30 @@ "outputs": [], "source": [ "drizzlepac.astrodrizzle.AstroDrizzle('*flt.fits',\n", - " output = 'f160w_noopt',\n", - " runfile = '',\n", - " context = False,\n", - " build = True,\n", - " preserve= False,\n", - " clean = True,\n", - " driz_sep_bits = '64,512',\n", - " final_bits = '64,512',\n", - " final_wcs = True,\n", - " final_rot = 0.)\n", + " output='f160w_noopt',\n", + " runfile='',\n", + " context=False,\n", + " build=True,\n", + " preserve=False,\n", + " clean=True,\n", + " driz_sep_bits='64,512',\n", + " final_bits='64,512',\n", + " final_wcs=True,\n", + " final_rot=0.)\n", "\n", "drizzlepac.astrodrizzle.AstroDrizzle('*flt.fits',\n", - " output = 'f160w_opt',\n", - " runfile = '',\n", - " context = False,\n", - " build = True,\n", - " preserve= False,\n", - " clean = True,\n", - " driz_sep_bits = '64,512',\n", - " final_bits = '64,512',\n", - " final_pixfrac = 0.8,\n", - " final_wcs = True,\n", - " final_rot = 0.,\n", - " final_scale = 0.065)" + " output='f160w_opt',\n", + " runfile='',\n", + " context=False,\n", + " build=True,\n", + " preserve=False,\n", + " clean=True,\n", + " driz_sep_bits='64,512',\n", + " final_bits='64,512',\n", + " final_pixfrac=0.8,\n", + " final_wcs=True,\n", + " final_rot=0.,\n", + " final_scale=0.065)" ] }, { @@ -199,10 +199,10 @@ " sci1 = hdu[1].data\n", " wht1 = hdu[2].data\n", " \n", - "norm1 = ImageNormalize(sci1,vmin=-0.2,vmax=25,stretch=LogStretch())\n", - "fig,ax = plt.subplots(1,2,figsize=(16,8),subplot_kw={'projection':im1wcs})\n", - "ax[0].imshow(sci1,norm=norm1,cmap='gray',origin='lower')\n", - "ax[1].imshow(wht1,cmap='gray',origin='lower')" + "norm1 = ImageNormalize(sci1, vmin=-0.2, vmax=25, stretch=LogStretch())\n", + "fig, ax = plt.subplots(1, 2, figsize=(16, 8), subplot_kw={'projection':im1wcs})\n", + "ax[0].imshow(sci1, norm=norm1, cmap='gray', origin='lower')\n", + "ax[1].imshow(wht1, cmap='gray', origin='lower')" ] }, { @@ -225,24 +225,24 @@ "metadata": {}, "outputs": [], "source": [ - "radeclims = wcs.utils.pixel_to_skycoord([825,875],[930,980],im1wcs)\n", + "radeclims = wcs.utils.pixel_to_skycoord([825, 875], [930, 980], im1wcs)\n", "\n", "with fits.open('f160w_opt_drz.fits') as hdu:\n", " im2wcs = wcs.WCS(hdu[1].header)\n", " sci2 = hdu[1].data\n", " wht2 = hdu[2].data\n", "\n", - "norm2 = ImageNormalize(sci2,vmin=-0.05,vmax=25,stretch=LogStretch())\n", + "norm2 = ImageNormalize(sci2, vmin=-0.05, vmax=25, stretch=LogStretch())\n", " \n", - "fig = plt.figure(figsize=(16,8))\n", + "fig = plt.figure(figsize=(16, 8))\n", "\n", - "ax = fig.add_subplot(1,2,1,projection=im1wcs)\n", - "ax.imshow(sci1,norm=norm2,cmap='gray')\n", + "ax = fig.add_subplot(1, 2, 1, projection=im1wcs)\n", + "ax.imshow(sci1, norm=norm2, cmap='gray')\n", "ax.set_xlim(radeclims.to_pixel(im1wcs)[0])\n", "ax.set_ylim(radeclims.to_pixel(im1wcs)[1])\n", "\n", - "ax = fig.add_subplot(1,2,2,projection=im2wcs)\n", - "ax.imshow(sci2,norm=norm2,cmap='gray')\n", + "ax = fig.add_subplot(1, 2, 2, projection=im2wcs)\n", + "ax.imshow(sci2, norm=norm2, cmap='gray')\n", "ax.set_xlim(radeclims.to_pixel(im2wcs)[0])\n", "ax.set_ylim(radeclims.to_pixel(im2wcs)[1]) " ] @@ -271,23 +271,23 @@ "metadata": {}, "outputs": [], "source": [ - "pixfracs = np.arange(0.1,1.1,0.1)\n", + "pixfracs = np.arange(0.1, 1.1, 0.1)\n", "\n", "for pixfrac in pixfracs:\n", " outname = 'f160w_{:.1f}'.format(pixfrac)\n", " drizzlepac.astrodrizzle.AstroDrizzle('*flt.fits',\n", - " output = outname,\n", - " runfile = '',\n", - " context = False,\n", - " build = True,\n", - " preserve= False,\n", - " clean = True,\n", - " driz_sep_bits = '64,512',\n", - " final_bits = '64,512',\n", - " final_pixfrac = pixfrac,\n", - " final_wcs = True,\n", - " final_rot = 0.,\n", - " final_scale = 0.065)" + " output=outname,\n", + " runfile='',\n", + " context=False,\n", + " build=True,\n", + " preserve=False,\n", + " clean=True,\n", + " driz_sep_bits='64,512',\n", + " final_bits='64,512',\n", + " final_pixfrac=pixfrac,\n", + " final_wcs=True,\n", + " final_rot=0.,\n", + " final_scale=0.065)" ] }, { @@ -317,21 +317,21 @@ " sci3 = hdu3[1].data\n", " wht3 = hdu3[2].data\n", "\n", - "fig,ax = plt.subplots(2,3,figsize=(16,10),sharex=True,sharey=True)\n", - "fig.subplots_adjust(hspace=0,wspace=0)\n", + "fig,ax = plt.subplots(2, 3, figsize=(16, 10), sharex=True, sharey=True)\n", + "fig.subplots_adjust(hspace=0, wspace=0)\n", "\n", - "norm3 = ImageNormalize(wht2,vmin=400,vmax=600,stretch=LinearStretch())\n", - "ax[0,0].imshow(sci1,norm=norm2,cmap='gray')\n", - "ax[0,0].text(1640,1920,'final_pixfrac=0.1',fontsize='20',color='gold')\n", - "ax[0,1].imshow(sci2,norm=norm2,cmap='gray')\n", - "ax[0,1].text(1640,1920,'final_pixfrac=0.8',fontsize='20',color='gold')\n", - "ax[0,2].imshow(sci3,norm=norm2,cmap='gray')\n", - "ax[0,2].text(1640,1920,'final_pixfrac=1.0',fontsize='20',color='gold')\n", - "ax[1,0].imshow(wht1,norm=norm3,cmap='gray')\n", - "ax[1,1].imshow(wht2,norm=norm3,cmap='gray')\n", - "ax[1,2].imshow(wht3,norm=norm3,cmap='gray')\n", - "ax[0,0].set_xlim(radeclims.to_pixel(im2wcs)[0])\n", - "ax[0,0].set_ylim(radeclims.to_pixel(im2wcs)[1])" + "norm3 = ImageNormalize(wht2, vmin=400, vmax=600, stretch=LinearStretch())\n", + "ax[0, 0].imshow(sci1, norm=norm2, cmap='gray')\n", + "ax[0, 0].text(1640, 1920, 'final_pixfrac=0.1', fontsize='20', color='gold')\n", + "ax[0, 1].imshow(sci2, norm=norm2, cmap='gray')\n", + "ax[0, 1].text(1640, 1920, 'final_pixfrac=0.8', fontsize='20', color='gold')\n", + "ax[0, 2].imshow(sci3, norm=norm2, cmap='gray')\n", + "ax[0, 2].text(1640, 1920, 'final_pixfrac=1.0', fontsize='20', color='gold')\n", + "ax[1, 0].imshow(wht1, norm=norm3, cmap='gray')\n", + "ax[1, 1].imshow(wht2, norm=norm3, cmap='gray')\n", + "ax[1, 2].imshow(wht3, norm=norm3, cmap='gray')\n", + "ax[0, 0].set_xlim(radeclims.to_pixel(im2wcs)[0])\n", + "ax[0, 0].set_ylim(radeclims.to_pixel(im2wcs)[1])" ] }, { @@ -358,13 +358,13 @@ "source": [ "whtlist = glob.glob('f160w_0.[0-9]*drz.fits')\n", "\n", - "std_med = np.empty(len(whtlist),dtype=float)\n", - "fraclist = np.empty(len(whtlist),dtype=float)\n", + "std_med = np.empty(len(whtlist), dtype=float)\n", + "fraclist = np.empty(len(whtlist), dtype=float)\n", "xlims = radeclims.to_pixel(im1wcs)[0].astype(int)\n", "ylims = radeclims.to_pixel(im1wcs)[1].astype(int)\n", "\n", "#Loop that measures statistics, also some information gathering\n", - "for i,im in enumerate(whtlist):\n", + "for i, im in enumerate(whtlist):\n", " with fits.open(im) as hdu:\n", " hdr = hdu[0].header\n", " wht = hdu[2].data\n", @@ -372,22 +372,22 @@ " target = hdr['TARGNAME']\n", " scale = str(hdr['D001SCAL'])\n", " nimg = hdr['NDRIZIM']\n", - " wht_std = np.std(wht[ylims[0]:ylims[1],xlims[0]:xlims[1]])\n", - " wht_med = np.median(wht[ylims[0]:ylims[1],xlims[0]:xlims[1]])\n", - " std_med[i] = wht_std/wht_med\n", + " wht_std = np.std(wht[ylims[0] : ylims[1], xlims[0] : xlims[1]])\n", + " wht_med = np.median(wht[ylims[0] : ylims[1], xlims[0] : xlims[1]])\n", + " std_med[i] = wht_std / wht_med\n", " fraclist[i] = hdr['D001PIXF']\n", "\n", "#Plotting commands \n", "plt.clf()\n", - "plt.xlim(1.025,-0.025)\n", - "plt.ylim(0.,0.5)\n", - "plt.scatter(fraclist,std_med,s=50)\n", - "plt.axhline(0.2,ls='--',lw=3,c='r')\n", - "plt.xlabel('pixfrac',fontsize=18)\n", - "plt.ylabel('rms/median',fontsize=18)\n", - "plt.text(0.1,0.45,target,fontsize=16,horizontalalignment='right')\n", - "plt.text(0.1,0.40,'Scale='+str(scale)+'\"',fontsize=16,horizontalalignment='right')\n", - "plt.text(0.1,0.35,str(nimg)+' images',fontsize=16,horizontalalignment='right')" + "plt.xlim(1.025, -0.025)\n", + "plt.ylim(0., 0.5)\n", + "plt.scatter(fraclist, std_med, s=50)\n", + "plt.axhline(0.2, ls='--', lw=3, c='r')\n", + "plt.xlabel('pixfrac', fontsize=18)\n", + "plt.ylabel('rms/median', fontsize=18)\n", + "plt.text(0.1, 0.45, target, fontsize=16, horizontalalignment='right')\n", + "plt.text(0.1, 0.40, 'Scale=' + str(scale) + '\"', fontsize=16, horizontalalignment='right')\n", + "plt.text(0.1, 0.35, str(nimg) + ' images', fontsize=16, horizontalalignment='right')" ] }, {