From befdc81957371036b0ce2a726680db4a8d682442 Mon Sep 17 00:00:00 2001 From: Abelardo Moralejo Date: Tue, 8 Oct 2024 10:16:09 +0200 Subject: [PATCH 01/10] Computing the run pointing in sky coordinates So far the first event's pointing was used. This is problematic for runs in which the pointing is unstable at the beginning. --- lstchain/high_level/hdu_table.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/lstchain/high_level/hdu_table.py b/lstchain/high_level/hdu_table.py index b2793e87ed..06917a82c9 100644 --- a/lstchain/high_level/hdu_table.py +++ b/lstchain/high_level/hdu_table.py @@ -14,6 +14,7 @@ from astropy.coordinates import AltAz, SkyCoord from astropy.coordinates.erfa_astrom import ErfaAstromInterpolator, erfa_astrom from astropy.io import fits +from astropy.stats import circmean from astropy.table import QTable, Table from astropy.time import Time @@ -257,21 +258,35 @@ def get_timing_params(data, epoch=LST_EPOCH): return time_pars, time_utc -def get_pointing_params(data, source_pos, time_utc): +def get_pointing_params(data, source_pos, time_utc, exclude_fraction=0.2): """ - Convert the telescope pointing position for the first event from AltAz - into ICRS frame of reference. + Convert the telescope pointing directions into ICRS frame of reference, + and average them for the run (excluding the first events, for which there + may be some mispointing due to not-yet-stable tracking). + + exclude_fraction: fraction of the run that will me excluded from the + averaging (the excluded events are the ones at the beginning of the run) Note: The angular difference from the source is just used for logging here. + + Returns the average pointing in ICRS frame """ + pointing_alt = data["pointing_alt"] pointing_az = data["pointing_az"] - pnt_icrs = SkyCoord( - alt=pointing_alt[0], - az=pointing_az[0], - frame=AltAz(obstime=time_utc[0], location=LST1_LOCATION), - ).transform_to(frame="icrs") + first_event = int(exclude_fraction * len(data)) + with erfa_astrom.set(ErfaAstromInterpolator(300 * u.s)): + evtwise_pnt_icrs = SkyCoord( + alt=pointing_alt[first_event:], + az=pointing_az[first_event:], + frame=AltAz(obstime=time_utc[first_event:], location=LST1_LOCATION), + ).transform_to(frame="icrs") + + mean_ra = circmean(evtwise_pnt_icrs.ra) + mean_dec = np.mean(evtwise_pnt_icrs.dec) + + pnt_icrs = SkyCoord(ra=mean_ra, dec=mean_dec, frame="icrs") source_pointing_diff = source_pos.separation(pnt_icrs) From fa440afab6649395e1f6e42b90a8af4fff26e269 Mon Sep 17 00:00:00 2001 From: Abelardo Moralejo Date: Tue, 8 Oct 2024 11:49:12 +0200 Subject: [PATCH 02/10] Update conf.py (remove source of docs error?) --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index d245f1ca92..27e7601bd4 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -143,7 +143,7 @@ # import sphinx_rtd_theme html_theme = 'sphinx_rtd_theme' -html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] +# html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the From 65f6e9477ebc9449a4fea88086890479a984dda0 Mon Sep 17 00:00:00 2001 From: Abelardo Moralejo Date: Tue, 8 Oct 2024 14:48:00 +0200 Subject: [PATCH 03/10] Check pointing stability and display warning if not good --- lstchain/high_level/hdu_table.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lstchain/high_level/hdu_table.py b/lstchain/high_level/hdu_table.py index 06917a82c9..84ea95c935 100644 --- a/lstchain/high_level/hdu_table.py +++ b/lstchain/high_level/hdu_table.py @@ -275,23 +275,35 @@ def get_pointing_params(data, source_pos, time_utc, exclude_fraction=0.2): pointing_alt = data["pointing_alt"] pointing_az = data["pointing_az"] + max_median_angle = 0.05 * u.deg # Is this a reasonable limit? + # If median of the angle between the pointing directions and their mean in the run + # is larger than max_median_angle a warning will be displayed about unstable pointing. + first_event = int(exclude_fraction * len(data)) with erfa_astrom.set(ErfaAstromInterpolator(300 * u.s)): evtwise_pnt_icrs = SkyCoord( - alt=pointing_alt[first_event:], - az=pointing_az[first_event:], - frame=AltAz(obstime=time_utc[first_event:], location=LST1_LOCATION), + alt=pointing_alt, + az=pointing_az, + frame=AltAz(obstime=time_utc, location=LST1_LOCATION), ).transform_to(frame="icrs") - - mean_ra = circmean(evtwise_pnt_icrs.ra) - mean_dec = np.mean(evtwise_pnt_icrs.dec) - + + mean_ra = circmean(evtwise_pnt_icrs[first_event:].ra) + mean_dec = np.mean(evtwise_pnt_icrs[first_event:].dec) pnt_icrs = SkyCoord(ra=mean_ra, dec=mean_dec, frame="icrs") + median_angle_wrt_mean_pointing = np.median(pnt_icrs.separation(evtwise_pnt_icrs)) + median_angle_wrt_mean_pointing_2 = np.median(pnt_icrs.separation(evtwise_pnt_icrs[first_event:])) + + log.info("Median of angle between pointing direction and mean pointing:") + log.info(f" All events: {median_angle_wrt_mean_pointing:.3f}") + if median_angle_wrt_mean_pointing > max_median_angle: + log.warn(f" ==> The telescope pointing seems to be unstable during the Run!") + log.info(f" Excluding the first {100*exclude_fraction:.1f}% of events: {median_angle_wrt_mean_pointing_2:.3f}") + source_pointing_diff = source_pos.separation(pnt_icrs) log.info( - f"Source pointing difference with camera pointing is {source_pointing_diff:.3f}" + f"Angle between source direction and mean telescope pointing is {source_pointing_diff:.3f}" ) return pnt_icrs From 82ffcbcd1be593dfddefec3fa7b126994df327aa Mon Sep 17 00:00:00 2001 From: Abelardo Moralejo Date: Tue, 8 Oct 2024 14:51:12 +0200 Subject: [PATCH 04/10] remove f in string with no vars --- lstchain/high_level/hdu_table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lstchain/high_level/hdu_table.py b/lstchain/high_level/hdu_table.py index 84ea95c935..7139f6fc55 100644 --- a/lstchain/high_level/hdu_table.py +++ b/lstchain/high_level/hdu_table.py @@ -297,7 +297,7 @@ def get_pointing_params(data, source_pos, time_utc, exclude_fraction=0.2): log.info("Median of angle between pointing direction and mean pointing:") log.info(f" All events: {median_angle_wrt_mean_pointing:.3f}") if median_angle_wrt_mean_pointing > max_median_angle: - log.warn(f" ==> The telescope pointing seems to be unstable during the Run!") + log.warn(" ==> The telescope pointing seems to be unstable during the Run!") log.info(f" Excluding the first {100*exclude_fraction:.1f}% of events: {median_angle_wrt_mean_pointing_2:.3f}") source_pointing_diff = source_pos.separation(pnt_icrs) From 4609a588b8b52af99f5e9cd07a787a30ddbf2ea5 Mon Sep 17 00:00:00 2001 From: Abelardo Moralejo Date: Thu, 10 Oct 2024 17:22:07 +0200 Subject: [PATCH 05/10] Fix comment Co-authored-by: Daniel Morcuende --- lstchain/high_level/hdu_table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lstchain/high_level/hdu_table.py b/lstchain/high_level/hdu_table.py index 7139f6fc55..102ba54e0b 100644 --- a/lstchain/high_level/hdu_table.py +++ b/lstchain/high_level/hdu_table.py @@ -264,7 +264,7 @@ def get_pointing_params(data, source_pos, time_utc, exclude_fraction=0.2): and average them for the run (excluding the first events, for which there may be some mispointing due to not-yet-stable tracking). - exclude_fraction: fraction of the run that will me excluded from the + exclude_fraction: fraction of the events that will be excluded from the averaging (the excluded events are the ones at the beginning of the run) Note: The angular difference from the source is just used for logging here. From 8406eaf7e6b99bbfcab421b3925180db199e4937 Mon Sep 17 00:00:00 2001 From: Abelardo Moralejo Date: Thu, 10 Oct 2024 17:22:28 +0200 Subject: [PATCH 06/10] warn => warning Co-authored-by: Daniel Morcuende --- lstchain/high_level/hdu_table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lstchain/high_level/hdu_table.py b/lstchain/high_level/hdu_table.py index 102ba54e0b..92fedd20ec 100644 --- a/lstchain/high_level/hdu_table.py +++ b/lstchain/high_level/hdu_table.py @@ -297,7 +297,7 @@ def get_pointing_params(data, source_pos, time_utc, exclude_fraction=0.2): log.info("Median of angle between pointing direction and mean pointing:") log.info(f" All events: {median_angle_wrt_mean_pointing:.3f}") if median_angle_wrt_mean_pointing > max_median_angle: - log.warn(" ==> The telescope pointing seems to be unstable during the Run!") + log.warning(" ==> The telescope pointing seems to be unstable during the Run!") log.info(f" Excluding the first {100*exclude_fraction:.1f}% of events: {median_angle_wrt_mean_pointing_2:.3f}") source_pointing_diff = source_pos.separation(pnt_icrs) From 6fc28d32a4b105344207f981c030ced9710399fd Mon Sep 17 00:00:00 2001 From: Abelardo Moralejo Date: Thu, 10 Oct 2024 17:23:45 +0200 Subject: [PATCH 07/10] Update lstchain/high_level/hdu_table.py Co-authored-by: Daniel Morcuende --- lstchain/high_level/hdu_table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lstchain/high_level/hdu_table.py b/lstchain/high_level/hdu_table.py index 92fedd20ec..3554e65a33 100644 --- a/lstchain/high_level/hdu_table.py +++ b/lstchain/high_level/hdu_table.py @@ -298,7 +298,7 @@ def get_pointing_params(data, source_pos, time_utc, exclude_fraction=0.2): log.info(f" All events: {median_angle_wrt_mean_pointing:.3f}") if median_angle_wrt_mean_pointing > max_median_angle: log.warning(" ==> The telescope pointing seems to be unstable during the Run!") - log.info(f" Excluding the first {100*exclude_fraction:.1f}% of events: {median_angle_wrt_mean_pointing_2:.3f}") + log.info(f" Excluding the first {exclude_fraction:.1%} of events: {median_angle_wrt_mean_pointing_2:.3f}") source_pointing_diff = source_pos.separation(pnt_icrs) From b81354fbdfbda4adb4e16233ee67eb24f986d0be Mon Sep 17 00:00:00 2001 From: Abelardo Moralejo Date: Mon, 14 Oct 2024 11:37:02 +0200 Subject: [PATCH 08/10] Changed log message related to unstable pointing --- lstchain/high_level/hdu_table.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lstchain/high_level/hdu_table.py b/lstchain/high_level/hdu_table.py index 3554e65a33..727cd1ad23 100644 --- a/lstchain/high_level/hdu_table.py +++ b/lstchain/high_level/hdu_table.py @@ -275,7 +275,10 @@ def get_pointing_params(data, source_pos, time_utc, exclude_fraction=0.2): pointing_alt = data["pointing_alt"] pointing_az = data["pointing_az"] - max_median_angle = 0.05 * u.deg # Is this a reasonable limit? + max_off_angle = 0.05 * u.deg + # Keep track of how often pointing is beyond max_off_angle w.r.t. the median + # run pointing + # If median of the angle between the pointing directions and their mean in the run # is larger than max_median_angle a warning will be displayed about unstable pointing. @@ -291,14 +294,11 @@ def get_pointing_params(data, source_pos, time_utc, exclude_fraction=0.2): mean_dec = np.mean(evtwise_pnt_icrs[first_event:].dec) pnt_icrs = SkyCoord(ra=mean_ra, dec=mean_dec, frame="icrs") - median_angle_wrt_mean_pointing = np.median(pnt_icrs.separation(evtwise_pnt_icrs)) - median_angle_wrt_mean_pointing_2 = np.median(pnt_icrs.separation(evtwise_pnt_icrs[first_event:])) + off_fraction = ((pnt_icrs.separation(evtwise_pnt_icrs) > max_off_angle).sum() / + len(evtwise_pnt_icrs)) - log.info("Median of angle between pointing direction and mean pointing:") - log.info(f" All events: {median_angle_wrt_mean_pointing:.3f}") - if median_angle_wrt_mean_pointing > max_median_angle: - log.warning(" ==> The telescope pointing seems to be unstable during the Run!") - log.info(f" Excluding the first {exclude_fraction:.1%} of events: {median_angle_wrt_mean_pointing_2:.3f}") + log.info(f"Mean pointing RA: {mean_ra.to(u.deg):.3f}, Dec: {mean_dec.to(u.deg):.3f}") + log.info(f"Fraction of events with pointing beyond {max_off_angle:.3f} of mean pointing: {off_fraction:.6f}") source_pointing_diff = source_pos.separation(pnt_icrs) From 14399c204a3f5d73f62588b14f9c28ad009e4c20 Mon Sep 17 00:00:00 2001 From: Abelardo Moralejo Date: Fri, 18 Oct 2024 14:03:31 +0200 Subject: [PATCH 09/10] Corrected comment --- lstchain/high_level/hdu_table.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lstchain/high_level/hdu_table.py b/lstchain/high_level/hdu_table.py index 727cd1ad23..f5fcdcc94c 100644 --- a/lstchain/high_level/hdu_table.py +++ b/lstchain/high_level/hdu_table.py @@ -276,8 +276,8 @@ def get_pointing_params(data, source_pos, time_utc, exclude_fraction=0.2): pointing_az = data["pointing_az"] max_off_angle = 0.05 * u.deg - # Keep track of how often pointing is beyond max_off_angle w.r.t. the median - # run pointing + # Keep track of how often pointing is beyond max_off_angle w.r.t. the mean + # run pointing (computed excluding the beginning of run - see exclude_fraction) # If median of the angle between the pointing directions and their mean in the run # is larger than max_median_angle a warning will be displayed about unstable pointing. From 9df60c6ee3e19027f09681b66a513bee44a07ac4 Mon Sep 17 00:00:00 2001 From: Abelardo Moralejo Date: Fri, 18 Oct 2024 14:04:27 +0200 Subject: [PATCH 10/10] Fixed comment --- lstchain/high_level/hdu_table.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lstchain/high_level/hdu_table.py b/lstchain/high_level/hdu_table.py index f5fcdcc94c..da601a1ca5 100644 --- a/lstchain/high_level/hdu_table.py +++ b/lstchain/high_level/hdu_table.py @@ -279,9 +279,6 @@ def get_pointing_params(data, source_pos, time_utc, exclude_fraction=0.2): # Keep track of how often pointing is beyond max_off_angle w.r.t. the mean # run pointing (computed excluding the beginning of run - see exclude_fraction) - # If median of the angle between the pointing directions and their mean in the run - # is larger than max_median_angle a warning will be displayed about unstable pointing. - first_event = int(exclude_fraction * len(data)) with erfa_astrom.set(ErfaAstromInterpolator(300 * u.s)): evtwise_pnt_icrs = SkyCoord(