From 0823bee054a6505b7464604a6dba6700819c764b Mon Sep 17 00:00:00 2001 From: Gabriel Brammer Date: Sat, 16 Nov 2024 11:22:50 +0100 Subject: [PATCH 1/5] add MAST token --- jwst/lib/set_telescope_pointing.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/jwst/lib/set_telescope_pointing.py b/jwst/lib/set_telescope_pointing.py index 6ae0b897e3..720b054ab0 100644 --- a/jwst/lib/set_telescope_pointing.py +++ b/jwst/lib/set_telescope_pointing.py @@ -366,6 +366,8 @@ class TransformParameters: dry_run: bool = False #: URL of the engineering telemetry database REST interface. engdb_url: str = None + #: MAST_TOKEN + mast_token: str = None #: Exposure type exp_type: str = None #: FGS to use as the guiding FGS. If None, will be set to what telemetry provides. @@ -416,6 +418,7 @@ def update_pointing(self): self.pointing = get_pointing(self.obsstart, self.obsend, mnemonics_to_read=self.method.mnemonics, engdb_url=self.engdb_url, + mast_token=self.mast_token, tolerance=self.tolerance, reduce_func=self.reduce_func) @@ -616,7 +619,7 @@ def update_mt_kwds(model): def update_wcs(model, default_pa_v3=0., default_roll_ref=0., siaf_path=None, prd=None, engdb_url=None, - fgsid=None, tolerance=60, allow_default=False, + mast_token=None, fgsid=None, tolerance=60, allow_default=False, reduce_func=None, **transform_kwargs): """Update WCS pointing information @@ -685,6 +688,7 @@ def update_wcs(model, default_pa_v3=0., default_roll_ref=0., siaf_path=None, prd t_pars = t_pars_from_model( model, default_pa_v3=default_pa_v3, engdb_url=engdb_url, + mast_token=mast_token, tolerance=tolerance, allow_default=allow_default, reduce_func=reduce_func, siaf_db=siaf_db, useafter=useafter, **transform_kwargs @@ -956,6 +960,7 @@ def calc_wcs_over_time(obsstart, obsend, t_pars: TransformParameters): # Calculate WCS try: pointings = get_pointing(obsstart, obsend, engdb_url=t_pars.engdb_url, + mast_token=t_pars.mast_token, tolerance=t_pars.tolerance, reduce_func=t_pars.reduce_func) except ValueError: logger.warning("Cannot get valid engineering mnemonics from engineering database") @@ -1630,7 +1635,7 @@ def calc_position_angle(point, ref): def get_pointing(obsstart, obsend, mnemonics_to_read=TRACK_TR_202111_MNEMONICS, - engdb_url=None, tolerance=60, reduce_func=None): + engdb_url=None, mast_token=None, tolerance=60, reduce_func=None): """ Get telescope pointing engineering data. @@ -1642,6 +1647,9 @@ def get_pointing(obsstart, obsend, mnemonics_to_read=TRACK_TR_202111_MNEMONICS, engdb_url : str or None URL of the engineering telemetry database REST interface. + mast_token : str or None + Optional MAST_TOKEN for initializing the engineering db connection. + mnemonics_to_read: {str: bool[,...]} The mnemonics to read. Key is the mnemonic name. Value is a boolean indicating whether the mnemonic @@ -1683,7 +1691,8 @@ def get_pointing(obsstart, obsend, mnemonics_to_read=TRACK_TR_202111_MNEMONICS, logger.info('Reduction function: %s', reduce_func) mnemonics = get_mnemonics(obsstart, obsend, mnemonics_to_read=mnemonics_to_read, - tolerance=tolerance, engdb_url=engdb_url) + tolerance=tolerance, engdb_url=engdb_url, + mast_token=mast_token) reduced = reduce_func(mnemonics_to_read, mnemonics) logger.log(DEBUG_FULL, 'Mnemonics found:') @@ -1796,7 +1805,7 @@ def _roll_angle_from_matrix(matrix, v2, v3): return new_roll -def get_mnemonics(obsstart, obsend, tolerance, mnemonics_to_read=TRACK_TR_202111_MNEMONICS, engdb_url=None): +def get_mnemonics(obsstart, obsend, tolerance, mnemonics_to_read=TRACK_TR_202111_MNEMONICS, engdb_url=None, mast_token=None): """Retrieve pointing mnemonics from the engineering database Parameters @@ -1828,7 +1837,7 @@ def get_mnemonics(obsstart, obsend, tolerance, mnemonics_to_read=TRACK_TR_202111 """ try: - engdb = ENGDB_Service(base_url=engdb_url) + engdb = ENGDB_Service(base_url=engdb_url, token=mast_token) except Exception as exception: raise ValueError( 'Cannot open engineering DB connection' From 0ea081027e5f8e4d2f12f5aaff4269e9bc4dc45c Mon Sep 17 00:00:00 2001 From: Gabriel Brammer Date: Sat, 16 Nov 2024 11:37:07 +0100 Subject: [PATCH 2/5] wrap process_slit in try except --- jwst/extract_2d/nirspec.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jwst/extract_2d/nirspec.py b/jwst/extract_2d/nirspec.py index a134231df8..79cbaa8c72 100644 --- a/jwst/extract_2d/nirspec.py +++ b/jwst/extract_2d/nirspec.py @@ -82,7 +82,15 @@ def nrs_extract2d(input_model, slit_name=None): # Loop over all slit instances that are present for slit in open_slits: - new_model, xlo, xhi, ylo, yhi = process_slit(input_model, slit, exp_type) + try: + new_model, xlo, xhi, ylo, yhi = process_slit( + input_model, slit, exp_type + ) + except ValueError: + log.warning("process_slit failed for slit/subarray " + "{0}".format(slit.name) + ", probably because the cutout has no valid pixels") + continue slits.append(new_model) orig_s_region = new_model.meta.wcsinfo.s_region.strip() From f43b2f29749b3e3b7cd9bc9f86b8c357cab24133 Mon Sep 17 00:00:00 2001 From: Gabriel Brammer Date: Sat, 16 Nov 2024 11:50:21 +0100 Subject: [PATCH 3/5] fix bug --- jwst/extract_2d/nirspec.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/jwst/extract_2d/nirspec.py b/jwst/extract_2d/nirspec.py index 79cbaa8c72..8610ab8419 100644 --- a/jwst/extract_2d/nirspec.py +++ b/jwst/extract_2d/nirspec.py @@ -87,9 +87,10 @@ def nrs_extract2d(input_model, slit_name=None): input_model, slit, exp_type ) except ValueError: - log.warning("process_slit failed for slit/subarray " - "{0}".format(slit.name) - ", probably because the cutout has no valid pixels") + log.warning( + 'process_slit failed for slit/subarray {0}, '.format(slit.name) + + 'probably because the cutout has no valid pixels' + ) continue slits.append(new_model) From 03a7055bb6b8a962e6808c9514752ab49a540e04 Mon Sep 17 00:00:00 2001 From: Gabriel Brammer Date: Tue, 19 Nov 2024 08:51:15 +0100 Subject: [PATCH 4/5] revert extraneous change --- jwst/lib/set_telescope_pointing.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/jwst/lib/set_telescope_pointing.py b/jwst/lib/set_telescope_pointing.py index 0c5ccd98aa..6ea54cc81b 100644 --- a/jwst/lib/set_telescope_pointing.py +++ b/jwst/lib/set_telescope_pointing.py @@ -431,8 +431,6 @@ class TransformParameters: dry_run: bool = False #: URL of the engineering telemetry database REST interface. engdb_url: str | None = None - #: MAST_TOKEN - mast_token: str = None #: Exposure type exp_type: str | None = None #: FGS to use as the guiding FGS. If None, will be set to what telemetry provides. @@ -483,7 +481,6 @@ def update_pointing(self): self.pointing = get_pointing(self.obsstart, self.obsend, mnemonics_to_read=self.method.mnemonics, engdb_url=self.engdb_url, - mast_token=self.mast_token, tolerance=self.tolerance, reduce_func=self.reduce_func) @@ -684,7 +681,7 @@ def update_mt_kwds(model): def update_wcs(model, default_pa_v3=0., default_roll_ref=0., siaf_path=None, prd=None, engdb_url=None, - mast_token=None, fgsid=None, tolerance=60, allow_default=False, + fgsid=None, tolerance=60, allow_default=False, reduce_func=None, **transform_kwargs): """Update WCS pointing information @@ -753,7 +750,6 @@ def update_wcs(model, default_pa_v3=0., default_roll_ref=0., siaf_path=None, prd t_pars = t_pars_from_model( model, default_pa_v3=default_pa_v3, engdb_url=engdb_url, - mast_token=mast_token, tolerance=tolerance, allow_default=allow_default, reduce_func=reduce_func, siaf_db=siaf_db, useafter=useafter, **transform_kwargs @@ -1017,7 +1013,6 @@ def calc_wcs_over_time(obsstart, obsend, t_pars: TransformParameters): # Calculate WCS try: pointings = get_pointing(obsstart, obsend, engdb_url=t_pars.engdb_url, - mast_token=t_pars.mast_token, tolerance=t_pars.tolerance, reduce_func=t_pars.reduce_func) except ValueError: logger.warning("Cannot get valid engineering mnemonics from engineering database") @@ -1692,7 +1687,7 @@ def calc_position_angle(point, ref): def get_pointing(obsstart, obsend, mnemonics_to_read=TRACK_TR_202111_MNEMONICS, - engdb_url=None, mast_token=None, tolerance=60, reduce_func=None): + engdb_url=None, tolerance=60, reduce_func=None): """ Get telescope pointing engineering data. @@ -1704,9 +1699,6 @@ def get_pointing(obsstart, obsend, mnemonics_to_read=TRACK_TR_202111_MNEMONICS, engdb_url : str or None URL of the engineering telemetry database REST interface. - mast_token : str or None - Optional MAST_TOKEN for initializing the engineering db connection. - mnemonics_to_read: {str: bool[,...]} The mnemonics to read. Key is the mnemonic name. Value is a boolean indicating whether the mnemonic @@ -1748,8 +1740,7 @@ def get_pointing(obsstart, obsend, mnemonics_to_read=TRACK_TR_202111_MNEMONICS, logger.info('Reduction function: %s', reduce_func) mnemonics = get_mnemonics(obsstart, obsend, mnemonics_to_read=mnemonics_to_read, - tolerance=tolerance, engdb_url=engdb_url, - mast_token=mast_token) + tolerance=tolerance, engdb_url=engdb_url) reduced = reduce_func(mnemonics_to_read, mnemonics) logger.log(DEBUG_FULL, 'Mnemonics found:') @@ -1862,7 +1853,7 @@ def _roll_angle_from_matrix(matrix, v2, v3): return new_roll -def get_mnemonics(obsstart, obsend, tolerance, mnemonics_to_read=TRACK_TR_202111_MNEMONICS, engdb_url=None, mast_token=None): +def get_mnemonics(obsstart, obsend, tolerance, mnemonics_to_read=TRACK_TR_202111_MNEMONICS, engdb_url=None): """Retrieve pointing mnemonics from the engineering database Parameters @@ -1894,7 +1885,7 @@ def get_mnemonics(obsstart, obsend, tolerance, mnemonics_to_read=TRACK_TR_202111 """ try: - engdb = ENGDB_Service(base_url=engdb_url, token=mast_token) + engdb = ENGDB_Service(base_url=engdb_url) except Exception as exception: raise ValueError( 'Cannot open engineering DB connection' From e047d492546c5d38ce59f73b27abdb62a8f62157 Mon Sep 17 00:00:00 2001 From: Gabriel Brammer Date: Wed, 20 Nov 2024 08:45:19 +0100 Subject: [PATCH 5/5] add change file --- changes/8964.extract_2d.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/8964.extract_2d.rst diff --git a/changes/8964.extract_2d.rst b/changes/8964.extract_2d.rst new file mode 100644 index 0000000000..7141795138 --- /dev/null +++ b/changes/8964.extract_2d.rst @@ -0,0 +1 @@ +Wrap process_slit in try/except during extract_2d.nirspec.nrs_extract2d. \ No newline at end of file