From 5fcfee74ae89746fdb79200765bdda1753e04e32 Mon Sep 17 00:00:00 2001 From: rcooke Date: Wed, 22 Nov 2023 21:37:57 +0000 Subject: [PATCH 1/3] add scattlight --- pypeit_files/keck_esi_ech_1x1.pypeit | 10 +++--- pypeit_files/keck_esi_ech_2x1.pypeit | 6 ++-- pypeit_files/keck_kcwi_medium_bl.pypeit | 20 ++++++------ pypeit_files/keck_kcwi_small_bh2_4200.pypeit | 32 ++++++++++---------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/pypeit_files/keck_esi_ech_1x1.pypeit b/pypeit_files/keck_esi_ech_1x1.pypeit index 5fadd3c1..7933d153 100644 --- a/pypeit_files/keck_esi_ech_1x1.pypeit +++ b/pypeit_files/keck_esi_ech_1x1.pypeit @@ -19,11 +19,11 @@ data read e221024_0030.fits.gz | arc,tilt | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,1 | 59876.13062376 | 13.37481353 | 900.0 e221024_0031.fits.gz | arc,tilt | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,1 | 59876.14176821 | 13.37481353 | 900.0 e221024_0032.fits.gz | arc,tilt | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,1 | 59876.15287133 | 13.37481353 | 900.0 -e221024_0033.fits.gz | pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,1 | 59876.164063 | 13.37481353 | 300.0 -e221024_0034.fits.gz | pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,1 | 59876.16811821 | 13.37481353 | 300.0 -e221024_0035.fits.gz | pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,1 | 59876.17222064 | 13.37481353 | 300.0 -e221024_0036.fits.gz | pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,1 | 59876.17629946 | 13.37481353 | 300.0 -e221024_0037.fits.gz | pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,1 | 59876.18039598 | 13.37481353 | 300.0 +e221024_0033.fits.gz | scattlight,pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,1 | 59876.164063 | 13.37481353 | 300.0 +e221024_0034.fits.gz | scattlight,pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,1 | 59876.16811821 | 13.37481353 | 300.0 +e221024_0035.fits.gz | scattlight,pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,1 | 59876.17222064 | 13.37481353 | 300.0 +e221024_0036.fits.gz | scattlight,pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,1 | 59876.17629946 | 13.37481353 | 300.0 +e221024_0037.fits.gz | scattlight,pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,1 | 59876.18039598 | 13.37481353 | 300.0 e221024_0040.fits.gz | science | 327.7962083333333 | 28.864194444444447 | BD+28d4211 | Echellette | 0.50_arcsec | 1,1 | 59876.19697098 | 1.06673153 | 200.0 e221024_0084.fits.gz | science | 159.90299999999996 | 43.102833333333336 | Feige34 | Echellette | 0.50_arcsec | 1,1 | 59876.63783175 | 1.5492896 | 400.0 e221024_0086.fits.gz | science | 76.37783333333331 | 52.831833333333336 | G191-B2B | Echellette | 0.50_arcsec | 1,1 | 59876.6468748 | 1.34392841 | 400.0 diff --git a/pypeit_files/keck_esi_ech_2x1.pypeit b/pypeit_files/keck_esi_ech_2x1.pypeit index f30f942b..0fafd016 100644 --- a/pypeit_files/keck_esi_ech_2x1.pypeit +++ b/pypeit_files/keck_esi_ech_2x1.pypeit @@ -22,9 +22,9 @@ e221025_0008.fits.gz | bias | 63.99999999999999 | e221025_0009.fits.gz | bias | 63.99999999999999 | 0.081 | unknown | Echellette | 0.30_arcsec | 1,2 | 59877.12013462 | 13.37481353 | 0.0 | 0 e221025_0010.fits.gz | bias | 63.99999999999999 | 0.081 | unknown | Echellette | 0.30_arcsec | 1,2 | 59877.12074261 | 13.37481353 | 0.0 | 0 e221025_0011.fits.gz | bias | 63.99999999999999 | 0.081 | unknown | Echellette | 0.30_arcsec | 1,2 | 59877.1213683 | 13.37481353 | 0.0 | 0 -e221025_0015.fits.gz | pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,2 | 59877.14545754 | 13.37481353 | 150.0 | 0 -e221025_0016.fits.gz | pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,2 | 59877.14780094 | 13.37481353 | 150.0 | 0 -e221025_0017.fits.gz | pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,2 | 59877.15016796 | 13.37481353 | 150.0 | 0 +e221025_0015.fits.gz | scattlight,pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,2 | 59877.14545754 | 13.37481353 | 150.0 | 0 +e221025_0016.fits.gz | scattlight,pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,2 | 59877.14780094 | 13.37481353 | 150.0 | 0 +e221025_0017.fits.gz | scattlight,pixelflat,illumflat,trace | 63.99999999999999 | 0.081 | unknown | Echellette | 0.50_arcsec | 1,2 | 59877.15016796 | 13.37481353 | 150.0 | 0 #e221025_0020.fits.gz | standard | 329.4120833333333 | 43.21761111111111 | HIP_108400 | Echellette | 0.50_arcsec | 1,2 | 59877.19462768 | 1.1481189 | 5.0 | 0 e221025_0079.fits.gz | science | 126.82599999999996 | 35.81644444444444 | HIP_41454 | Echellette | 0.50_arcsec | 1,2 | 59877.65401136 | 1.0611031 | 10.0 | 0 #e221025_0081.fits.gz | standard | 127.03662499999997 | 47.30138888888889 | HIP_41526 | Echellette | 0.50_arcsec | 1,2 | 59877.65644921 | 1.14408958 | 5.0 | 0 diff --git a/pypeit_files/keck_kcwi_medium_bl.pypeit b/pypeit_files/keck_kcwi_medium_bl.pypeit index 77bccd9e..f444f03a 100644 --- a/pypeit_files/keck_kcwi_medium_bl.pypeit +++ b/pypeit_files/keck_kcwi_medium_bl.pypeit @@ -28,15 +28,15 @@ setup end # Read in the data data read path /Users/rcooke/Software/PypeIt-development-suite/RAW_DATA/keck_kcwi/bl/ -| filename | frametype | ra | dec | target | dispname | decker | binning | mjd | airmass | exptime | dispangle | -| kb210705_00018.fits | align | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.085659 | 1.41 | 0.7 | 27.7546692 | -| kb210705_00019.fits | arc,tilt | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.086344 | 1.41 | 10.0 | 27.7546692 | -| kb210705_00027.fits | illumflat,trace | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.092483 | 1.41 | 14.0 | 27.7546692 | -| kb210705_00028.fits | illumflat,trace | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.093333 | 1.41 | 14.0 | 27.7546692 | -| kb210705_00029.fits | illumflat,trace | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.094183 | 1.41 | 14.0 | 27.7546692 | -| kb210705_00021.fits | pixelflat | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.087288 | 1.41 | 0.7 | 27.7546692 | -| kb210705_00022.fits | pixelflat | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.087985 | 1.41 | 0.7 | 27.7546692 | -| kb210705_00023.fits | pixelflat | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.088681 | 1.41 | 0.7 | 27.7546692 | -| kb210705_00051.fits | science | 349.99274999999994 | -5.166055555555556 | feige110 | BL | Medium | 2,2 | 59400.618459 | 1.1 | 5.0 | 27.7546692 | +| filename | frametype | ra | dec | target | dispname | decker | binning | mjd | airmass | exptime | dispangle | +| kb210705_00018.fits | align | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.085659 | 1.41 | 0.7 | 27.7546692 | +| kb210705_00019.fits | arc,tilt | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.086344 | 1.41 | 10.0 | 27.7546692 | +| kb210705_00027.fits | illumflat,trace | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.092483 | 1.41 | 14.0 | 27.7546692 | +| kb210705_00028.fits | illumflat,trace | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.093333 | 1.41 | 14.0 | 27.7546692 | +| kb210705_00029.fits | illumflat,trace | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.094183 | 1.41 | 14.0 | 27.7546692 | +| kb210705_00021.fits | scattlight,pixelflat | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.087288 | 1.41 | 0.7 | 27.7546692 | +| kb210705_00022.fits | scattlight,pixelflat | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.087985 | 1.41 | 0.7 | 27.7546692 | +| kb210705_00023.fits | scattlight,pixelflat | 57.99999999999999 | 45.0 | unknown | BL | Medium | 2,2 | 59400.088681 | 1.41 | 0.7 | 27.7546692 | +| kb210705_00051.fits | science | 349.99274999999994 | -5.166055555555556 | feige110 | BL | Medium | 2,2 | 59400.618459 | 1.1 | 5.0 | 27.7546692 | data end diff --git a/pypeit_files/keck_kcwi_small_bh2_4200.pypeit b/pypeit_files/keck_kcwi_small_bh2_4200.pypeit index 0cc1f1d2..0150f063 100644 --- a/pypeit_files/keck_kcwi_small_bh2_4200.pypeit +++ b/pypeit_files/keck_kcwi_small_bh2_4200.pypeit @@ -25,21 +25,21 @@ setup end # Read in the data data read path /Users/rcooke/Software/PypeIt-development-suite/RAW_DATA/keck_kcwi/bh2_4200/ -| filename | frametype | ra | dec | target | dispname | decker | binning | mjd | airmass | exptime | dispangle | -| KB.20191219.12282.fits.gz | align | 57.99999999999999 | 45.0 | unknown | BH2 | Small | 1,1 | 58836.142164 | 1.41 | 48.0 | 240.9942169 | -| KB.20200310.09562.fits.gz | arc,tilt | 57.99999999999999 | 45.0 | unknown | BH2 | Small | 1,1 | 58918.110674 | 1.41 | 112.2 | 240.9942169 | -| KB.20191220.61384.fits.gz | bias | 58.02958333333333 | 44.997194444444446 | DOME PHLAT | BH2 | Small | 1,1 | 58837.71047 | 1.41 | 0.0 | 240.6334229 | -| KB.20191220.61577.fits.gz | bias | 58.02958333333333 | 44.997194444444446 | DOME PHLAT | BH2 | Small | 1,1 | 58837.712701 | 1.41 | 0.0 | 240.6334229 | -| KB.20191220.61753.fits.gz | bias | 58.02958333333333 | 44.997194444444446 | DOME PHLAT | BH2 | Small | 1,1 | 58837.714744 | 1.41 | 0.0 | 240.6334229 | -| KB.20191221.11862.fits.gz | dark | 57.99999999999999 | 45.0 | unknown | BH2 | Small | 1,1 | 58838.137295 | 1.41 | 3600.0 | 240.6334229 | -| KB.20191221.15638.fits.gz | dark | 24.927999999999997 | 34.8915 | eng042 | BH2 | Small | 1,1 | 58838.180999 | 1.13 | 3600.0 | 240.6334229 | -| KB.20191219.59875.fits.gz | pixelflat | 67.35 | 0.059000000000000004 | HORIZON STOW | BH2 | Small | 1,1 | 58836.692999 | 13.37 | 48.0 | 240.9942169 | -| KB.20191219.60099.fits.gz | pixelflat | 67.35 | 0.059000000000000004 | HORIZON STOW | BH2 | Small | 1,1 | 58836.695597 | 13.37 | 48.0 | 240.9942169 | -| KB.20191219.60323.fits.gz | pixelflat | 67.35 | 0.059000000000000004 | HORIZON STOW | BH2 | Small | 1,1 | 58836.698194 | 13.37 | 48.0 | 240.9942169 | -| KB.20191219.56886.fits.gz | science | 191.3984583333333 | 42.640166666666666 | BB1245p4238 | BH2 | Small | 1,1 | 58836.658409 | 1.15 | 1200.0 | 240.9942169 | -| KB.20191219.57662.fits.gz | science | 191.3984583333333 | 42.640166666666666 | BB1245p4238 | BH2 | Small | 1,1 | 58836.667393 | 1.13 | 600.0 | 240.9942169 | -| KB.20191220.62342.fits.gz | illumflat,trace | 58.02958333333333 | 44.997194444444446 | DOME PHLAT | BH2 | Small | 1,1 | 58837.721556 | 1.41 | 300.0 | 240.9942169 | -| KB.20191220.62818.fits.gz | illumflat,trace | 58.02958333333333 | 44.997194444444446 | DOME PHLAT | BH2 | Small | 1,1 | 58837.727069 | 1.41 | 300.0 | 240.9942169 | -| KB.20191220.63295.fits.gz | illumflat,trace | 58.02958333333333 | 44.997194444444446 | DOME PHLAT | BH2 | Small | 1,1 | 58837.732582 | 1.41 | 300.0 | 240.9942169 | +| filename | frametype | ra | dec | target | dispname | decker | binning | mjd | airmass | exptime | dispangle | +| KB.20191219.12282.fits.gz | align | 57.99999999999999 | 45.0 | unknown | BH2 | Small | 1,1 | 58836.142164 | 1.41 | 48.0 | 240.9942169 | +| KB.20200310.09562.fits.gz | arc,tilt | 57.99999999999999 | 45.0 | unknown | BH2 | Small | 1,1 | 58918.110674 | 1.41 | 112.2 | 240.9942169 | +| KB.20191220.61384.fits.gz | bias | 58.02958333333333 | 44.997194444444446 | DOME PHLAT | BH2 | Small | 1,1 | 58837.71047 | 1.41 | 0.0 | 240.6334229 | +| KB.20191220.61577.fits.gz | bias | 58.02958333333333 | 44.997194444444446 | DOME PHLAT | BH2 | Small | 1,1 | 58837.712701 | 1.41 | 0.0 | 240.6334229 | +| KB.20191220.61753.fits.gz | bias | 58.02958333333333 | 44.997194444444446 | DOME PHLAT | BH2 | Small | 1,1 | 58837.714744 | 1.41 | 0.0 | 240.6334229 | +| KB.20191221.11862.fits.gz | dark | 57.99999999999999 | 45.0 | unknown | BH2 | Small | 1,1 | 58838.137295 | 1.41 | 3600.0 | 240.6334229 | +| KB.20191221.15638.fits.gz | dark | 24.927999999999997 | 34.8915 | eng042 | BH2 | Small | 1,1 | 58838.180999 | 1.13 | 3600.0 | 240.6334229 | +| KB.20191219.59875.fits.gz | scattlight,pixelflat | 67.35 | 0.059000000000000004 | HORIZON STOW | BH2 | Small | 1,1 | 58836.692999 | 13.37 | 48.0 | 240.9942169 | +| KB.20191219.60099.fits.gz | scattlight,pixelflat | 67.35 | 0.059000000000000004 | HORIZON STOW | BH2 | Small | 1,1 | 58836.695597 | 13.37 | 48.0 | 240.9942169 | +| KB.20191219.60323.fits.gz | scattlight,pixelflat | 67.35 | 0.059000000000000004 | HORIZON STOW | BH2 | Small | 1,1 | 58836.698194 | 13.37 | 48.0 | 240.9942169 | +| KB.20191219.56886.fits.gz | science | 191.3984583333333 | 42.640166666666666 | BB1245p4238 | BH2 | Small | 1,1 | 58836.658409 | 1.15 | 1200.0 | 240.9942169 | +| KB.20191219.57662.fits.gz | science | 191.3984583333333 | 42.640166666666666 | BB1245p4238 | BH2 | Small | 1,1 | 58836.667393 | 1.13 | 600.0 | 240.9942169 | +| KB.20191220.62342.fits.gz | illumflat,trace | 58.02958333333333 | 44.997194444444446 | DOME PHLAT | BH2 | Small | 1,1 | 58837.721556 | 1.41 | 300.0 | 240.9942169 | +| KB.20191220.62818.fits.gz | illumflat,trace | 58.02958333333333 | 44.997194444444446 | DOME PHLAT | BH2 | Small | 1,1 | 58837.727069 | 1.41 | 300.0 | 240.9942169 | +| KB.20191220.63295.fits.gz | illumflat,trace | 58.02958333333333 | 44.997194444444446 | DOME PHLAT | BH2 | Small | 1,1 | 58837.732582 | 1.41 | 300.0 | 240.9942169 | data end From dd8b26108cfd7d90b5cf2dd317f775cc89c09cac Mon Sep 17 00:00:00 2001 From: rcooke Date: Fri, 24 Nov 2023 18:16:44 +0000 Subject: [PATCH 2/3] add scattered light test --- vet_tests/test_scattlight.py | 97 ++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 vet_tests/test_scattlight.py diff --git a/vet_tests/test_scattlight.py b/vet_tests/test_scattlight.py new file mode 100644 index 00000000..41cc0c9d --- /dev/null +++ b/vet_tests/test_scattlight.py @@ -0,0 +1,97 @@ +""" +Module to run tests on arcoadd +""" +import os + +import pytest +import numpy as np + +from pypeit import scattlight +from pypeit.core import scattlight as core_scattlight +from pypeit import edgetrace +from pypeit.spectrographs.util import load_spectrograph + +from IPython import embed + +import warnings +warnings.simplefilter("ignore", UserWarning) + + +def test_scattlight_keckesi(redux_out): + """ Calculate the residuals of the scattered light subtraction for Keck ESI""" + droot = os.path.join(redux_out, + 'keck_esi', + 'ech_1x1', + 'Calibrations') + + # Load the calibration frames + scattlightframe = scattlight.ScatteredLight.from_file(os.path.join(droot, 'ScatteredLight_A_0_DET01.fits.gz')) + slits = edgetrace.EdgeTraceSet.from_file(os.path.join(droot, 'Edges_A_0_DET01.fits.gz')).get_slits() + + # Grab the spectrograph and parset + spec = load_spectrograph("keck_esi") + par = spec.default_pypeit_par() + + # Get the central trace of each slit + left, right, _ = slits.select_edges(initial=True, flexure=None) + centrace = 0.5 * (left + right) + + # Find all pixels off the slit + spatbin = slits.binspat + pad = par['scienceframe']['process']['scattlight']['finecorr_pad'] // spatbin + mask_regions = par['scienceframe']['process']['scattlight']['finecorr_mask'] + offslitmask = slits.slit_img(pad=pad, initial=True, flexure=None) == -1 + # Mask the user-specified inter-slit regions + offslitmask = core_scattlight.mask_slit_regions(offslitmask, centrace, mask_regions=mask_regions) + + # Calculate the residual correction + ww = np.where(offslitmask) + resid = (scattlightframe.scattlight_raw - scattlightframe.scattlight_model)/scattlightframe.scattlight_model + + # Calculate some statistics + medval = np.median(resid[ww]) + stdval = 1.4826 * np.median(np.abs(resid[ww]-medval)) + + # Check the scattered light tolerance + assert(np.abs(medval) < stdval) # Check that the median value is within 1 standard deviation of 0 + assert(stdval < 0.1) # Check that the correction is better than 10% + + +def test_scattlight_keckkcwi(redux_out): + """ Calculate the residuals of the scattered light subtraction for Keck/KCWI """ + droot = os.path.join(redux_out, + 'keck_kcwi', + 'small_bh2_4200', + 'Calibrations') + + # Load the calibration frames + scattlightframe = scattlight.ScatteredLight.from_file(os.path.join(droot, 'ScatteredLight_A_0_DET01.fits.gz')) + slits = edgetrace.EdgeTraceSet.from_file(os.path.join(droot, 'Edges_A_0_DET01.fits.gz')).get_slits() + + # Grab the spectrograph and parset + spec = load_spectrograph("keck_kcwi") + par = spec.default_pypeit_par() + + # Get the central trace of each slit + left, right, _ = slits.select_edges(initial=True, flexure=None) + centrace = 0.5 * (left + right) + + # Find all pixels off the slit + spatbin = slits.binspat + pad = par['scienceframe']['process']['scattlight']['finecorr_pad'] // spatbin + mask_regions = par['scienceframe']['process']['scattlight']['finecorr_mask'] + offslitmask = slits.slit_img(pad=pad, initial=True, flexure=None) == -1 + # Mask the user-specified inter-slit regions + offslitmask = core_scattlight.mask_slit_regions(offslitmask, centrace, mask_regions=mask_regions) + + # Calculate the residual correction + ww = np.where(offslitmask) + resid = (scattlightframe.scattlight_raw - scattlightframe.scattlight_model)/scattlightframe.scattlight_model + + # Calculate some statistics + medval = np.median(resid[ww]) + stdval = 1.4826 * np.median(np.abs(resid[ww]-medval)) + + # Check the scattered light tolerance + assert(np.abs(medval) < stdval) # Check that the median value is within 1 standard deviation of 0 + assert(stdval < 0.1) # Check that the correction is better than 10% From 7ad2a3c7d210fedc1002fa601360d5596fa94af7 Mon Sep 17 00:00:00 2001 From: rcooke Date: Sat, 25 Nov 2023 19:29:46 +0000 Subject: [PATCH 3/3] fix scattered light test --- vet_tests/test_scattlight.py | 68 +++++++++++++++--------------------- 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/vet_tests/test_scattlight.py b/vet_tests/test_scattlight.py index 41cc0c9d..b1458757 100644 --- a/vet_tests/test_scattlight.py +++ b/vet_tests/test_scattlight.py @@ -17,21 +17,21 @@ warnings.simplefilter("ignore", UserWarning) -def test_scattlight_keckesi(redux_out): - """ Calculate the residuals of the scattered light subtraction for Keck ESI""" - droot = os.path.join(redux_out, - 'keck_esi', - 'ech_1x1', - 'Calibrations') - +def scattlight_resid(droot, par, tol=0.1): + """ Calculate the residual, and check that it is within the allowed tolerance. + + Args: + droot (:obj:`str`): + The root directory that points to the calibrations folder + par (:class:`~pypeit.par.pypeitpar.PypeItPar`): + Parameters required by all of PypeIt methods + tol (:obj:`float`, optional): + Allowed tolerance (default = 0.1 = 10% tolerance) + """ # Load the calibration frames scattlightframe = scattlight.ScatteredLight.from_file(os.path.join(droot, 'ScatteredLight_A_0_DET01.fits.gz')) slits = edgetrace.EdgeTraceSet.from_file(os.path.join(droot, 'Edges_A_0_DET01.fits.gz')).get_slits() - # Grab the spectrograph and parset - spec = load_spectrograph("keck_esi") - par = spec.default_pypeit_par() - # Get the central trace of each slit left, right, _ = slits.select_edges(initial=True, flexure=None) centrace = 0.5 * (left + right) @@ -54,7 +54,22 @@ def test_scattlight_keckesi(redux_out): # Check the scattered light tolerance assert(np.abs(medval) < stdval) # Check that the median value is within 1 standard deviation of 0 - assert(stdval < 0.1) # Check that the correction is better than 10% + assert(stdval < tol) # Check that the correction is better than 10% + + +def test_scattlight_keckesi(redux_out): + """ Calculate the residuals of the scattered light subtraction for Keck ESI""" + droot = os.path.join(redux_out, + 'keck_esi', + 'Ech_1x1', + 'Calibrations') + + # Grab the spectrograph and parset + spec = load_spectrograph("keck_esi") + par = spec.default_pypeit_par() + + # Check the residuals + scattlight_resid(droot, par, tol=0.1) def test_scattlight_keckkcwi(redux_out): @@ -64,34 +79,9 @@ def test_scattlight_keckkcwi(redux_out): 'small_bh2_4200', 'Calibrations') - # Load the calibration frames - scattlightframe = scattlight.ScatteredLight.from_file(os.path.join(droot, 'ScatteredLight_A_0_DET01.fits.gz')) - slits = edgetrace.EdgeTraceSet.from_file(os.path.join(droot, 'Edges_A_0_DET01.fits.gz')).get_slits() - # Grab the spectrograph and parset spec = load_spectrograph("keck_kcwi") par = spec.default_pypeit_par() - # Get the central trace of each slit - left, right, _ = slits.select_edges(initial=True, flexure=None) - centrace = 0.5 * (left + right) - - # Find all pixels off the slit - spatbin = slits.binspat - pad = par['scienceframe']['process']['scattlight']['finecorr_pad'] // spatbin - mask_regions = par['scienceframe']['process']['scattlight']['finecorr_mask'] - offslitmask = slits.slit_img(pad=pad, initial=True, flexure=None) == -1 - # Mask the user-specified inter-slit regions - offslitmask = core_scattlight.mask_slit_regions(offslitmask, centrace, mask_regions=mask_regions) - - # Calculate the residual correction - ww = np.where(offslitmask) - resid = (scattlightframe.scattlight_raw - scattlightframe.scattlight_model)/scattlightframe.scattlight_model - - # Calculate some statistics - medval = np.median(resid[ww]) - stdval = 1.4826 * np.median(np.abs(resid[ww]-medval)) - - # Check the scattered light tolerance - assert(np.abs(medval) < stdval) # Check that the median value is within 1 standard deviation of 0 - assert(stdval < 0.1) # Check that the correction is better than 10% + # Check the residuals + scattlight_resid(droot, par, tol=0.1)