From f620cf5e718ee67e1677f59e7da7e8ea76bf081f Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Wed, 17 Jul 2024 11:30:40 +0200 Subject: [PATCH 01/14] Minor syntax fix --- srttools/imager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srttools/imager.py b/srttools/imager.py index 401ae050..c3f651b5 100644 --- a/srttools/imager.py +++ b/srttools/imager.py @@ -122,7 +122,7 @@ def merge_tables(tables): with warnings.catch_warnings(): warnings.simplefilter("ignore", MergeConflictWarning) scan_table = vstack(tables) - except TableMergeError as e: + except TableMergeError: raise TableMergeError( "ERROR while merging tables. " "Tables:\n" + "\n".join([t.meta["filename"] for t in tables]) @@ -320,7 +320,7 @@ def __init__( super().__init__(data) - if data is not None and not "x" in self.colnames: + if data is not None and "x" not in self.colnames: self.convert_coordinates() self.current = None self._scan_list = None From d489db97ea59e27ee3267150d4f728ef786701e3 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Wed, 17 Jul 2024 11:36:54 +0200 Subject: [PATCH 02/14] Fix lines where summary file is excluded --- srttools/convert.py | 4 ++-- srttools/imager.py | 2 +- srttools/inspect_observations.py | 2 +- srttools/scan.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/srttools/convert.py b/srttools/convert.py index 8d596918..414beae6 100644 --- a/srttools/convert.py +++ b/srttools/convert.py @@ -94,7 +94,7 @@ def launch_convert_coords(name, label, save_locally=False): allfiles += [name] for fname in allfiles: - if "summary.fits" in fname: + if fname.lower().startswith("sum"): continue outroot = fname.replace(".fits", "_" + label) if save_locally: @@ -120,7 +120,7 @@ def launch_mbfits_creator(name, label, test=False, wrap=False, detrend=False, sa mbfits.fill_in_summary(summary) for fname in sorted(glob.glob(os.path.join(name, "*.fits"))): - if "summary.fits" in fname: + if fname.lower().startswith("sum"): continue mbfits.add_subscan(fname, detrend=detrend) diff --git a/srttools/imager.py b/srttools/imager.py index c3f651b5..1c83dd6c 100644 --- a/srttools/imager.py +++ b/srttools/imager.py @@ -441,7 +441,7 @@ def get_opacity(self, datadir=None, dirlist=None): return for s in scans: - if "summary.fits" in s: + if s.lower().startswith("sum"): continue try: results = calculate_opacity(s, plot=False) diff --git a/srttools/inspect_observations.py b/srttools/inspect_observations.py index 1e4ce33d..e0881ae3 100644 --- a/srttools/inspect_observations.py +++ b/srttools/inspect_observations.py @@ -75,7 +75,7 @@ def inspect_directories( for d in directories: fits_files = list_scans(".", [d]) for f in fits_files: - if "summary.fits" in f: + if f.lower().startswith("sum"): continue logging.info("Reading {}".format(f)) try: diff --git a/srttools/scan.py b/srttools/scan.py index fc6ec60b..2a87b557 100644 --- a/srttools/scan.py +++ b/srttools/scan.py @@ -836,7 +836,7 @@ def list_scans(datadir, dirlist): list_of_files += glob.glob(os.path.join(datadir, d, "*.fits[0-9]")) list_of_files += glob.glob(os.path.join(datadir, d, "*.fits[0-9][0-9]")) for f in list_of_files: - if "summary.fits" in f: + if f.lower().startswith("sum"): continue scan_list.append(f) return scan_list From 21321b2d8299e783f2e6d39e154f0b7489c8749a Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Wed, 17 Jul 2024 11:58:20 +0200 Subject: [PATCH 03/14] Try to be better at understanding Summary file names --- srttools/convert.py | 7 ++++--- srttools/converters/classfits.py | 11 ++++++----- srttools/converters/sdfits.py | 9 +++++---- srttools/imager.py | 4 ++-- srttools/inspect_observations.py | 2 +- srttools/monitor/monitor.py | 1 + srttools/scan.py | 20 +++++++++++++++++++- 7 files changed, 38 insertions(+), 16 deletions(-) diff --git a/srttools/convert.py b/srttools/convert.py index 414beae6..dc68a9f3 100644 --- a/srttools/convert.py +++ b/srttools/convert.py @@ -16,6 +16,7 @@ from .converters.mbfits import MBFITS_creator from .converters.classfits import CLASSFITS_creator from .converters.sdfits import SDFITS_creator +from .scan import _is_summary_file, find_summary_file_in_dir def convert_to_complete_fitszilla(fname, outname): @@ -94,7 +95,7 @@ def launch_convert_coords(name, label, save_locally=False): allfiles += [name] for fname in allfiles: - if fname.lower().startswith("sum"): + if _is_summary_file(fname): continue outroot = fname.replace(".fits", "_" + label) if save_locally: @@ -115,12 +116,12 @@ def launch_mbfits_creator(name, label, test=False, wrap=False, detrend=False, sa name = name.rstrip("/") random_name = "tmp_" + str(np.random.random()) mbfits = MBFITS_creator(random_name, test=test) - summary = os.path.join(name, "summary.fits") + summary = find_summary_file_in_dir(name) if os.path.exists(summary): mbfits.fill_in_summary(summary) for fname in sorted(glob.glob(os.path.join(name, "*.fits"))): - if fname.lower().startswith("sum"): + if _is_summary_file(fname): continue mbfits.add_subscan(fname, detrend=detrend) diff --git a/srttools/converters/classfits.py b/srttools/converters/classfits.py index d759e555..736973ce 100644 --- a/srttools/converters/classfits.py +++ b/srttools/converters/classfits.py @@ -11,7 +11,7 @@ The conversion is performed as follows: -1. Load all subscans from a given scan (=a subdirectory with a summary.fits file) +1. Load all subscans from a given scan (=a subdirectory with a summary file) and classify each of them as ON, OFF, CALON, CALOFF. 2. Try to infer patterns in the observation of the kind nON, mOFF, rCAL, and @@ -75,6 +75,7 @@ import glob from ..utils import get_mH2O from ..io import label_from_chan_name +from ..scan import find_summary_file_in_dir from scipy.signal import medfilt import copy import warnings @@ -478,7 +479,7 @@ def __init__(self, dirname, scandir=None, average=True, use_calon=False, test=Fa ---------------- scandir : str Input data directory (to be clear, the directory containing a set - of subscans plus a summary.fits file) + of subscans plus a summary file) average : bool, default True Average all spectra of a given configuration? use_calon : bool, default False @@ -500,7 +501,7 @@ def __init__(self, dirname, scandir=None, average=True, use_calon=False, test=Fa self.write_tables_to_disk() def fill_in_summary(self, summaryfile): - """Fill in the information contained in the summary.fits file.""" + """Fill in the information contained in the summary file.""" with fits.open(summaryfile) as hdul: self.summary.update(hdul[0].header) @@ -515,7 +516,7 @@ def get_scan(self, scandir, average=False): ---------- scandir : str Input data directory (to be clear, the directory containing a set - of subscans plus a summary.fits file) + of subscans plus a summary file) Other Parameters ---------------- @@ -527,7 +528,7 @@ def get_scan(self, scandir, average=False): tables """ scandir = scandir.rstrip("/") - fname = os.path.join(scandir, "summary.fits") + fname = find_summary_file_in_dir(scandir) self.fill_in_summary(fname) for fname in sorted(glob.glob(os.path.join(scandir, "*.fits"))): if "summary" in fname: diff --git a/srttools/converters/sdfits.py b/srttools/converters/sdfits.py index 183a678c..8706b340 100644 --- a/srttools/converters/sdfits.py +++ b/srttools/converters/sdfits.py @@ -12,6 +12,7 @@ classify_chan_columns, interpret_chan_name, ) +from srttools.scan import find_summary_file_in_dir import glob @@ -292,7 +293,7 @@ def __init__(self, dirname, scandir=None, average=True, use_calon=False, test=Fa ---------------- scandir : str Input data directory (to be clear, the directory containing a set - of subscans plus a summary.fits file) + of subscans plus a summary file) average : bool, default True Average all spectra of a given configuration? use_calon : bool, default False @@ -313,7 +314,7 @@ def __init__(self, dirname, scandir=None, average=True, use_calon=False, test=Fa self.write_tables_to_disk() def fill_in_summary(self, summaryfile): - """Fill in the information contained in the summary.fits file.""" + """Fill in the information contained in the summary file.""" with fits.open(summaryfile) as hdul: self.summary.update(hdul[0].header) @@ -328,7 +329,7 @@ def get_scan(self, scandir, average=False): ---------- scandir : str Input data directory (to be clear, the directory containing a set - of subscans plus a summary.fits file) + of subscans plus a summary file) Other Parameters ---------------- @@ -340,7 +341,7 @@ def get_scan(self, scandir, average=False): tables """ scandir = scandir.rstrip("/") - fname = os.path.join(scandir, "summary.fits") + fname = find_summary_file_in_dir(scandir) self.fill_in_summary(fname) for fname in sorted(glob.glob(os.path.join(scandir, "*.fits"))): if "summary" in fname: diff --git a/srttools/imager.py b/srttools/imager.py index 1c83dd6c..af33b675 100644 --- a/srttools/imager.py +++ b/srttools/imager.py @@ -26,7 +26,7 @@ from astropy.table.np_utils import TableMergeError from astropy.time import Time -from .scan import Scan, list_scans +from .scan import Scan, list_scans, _is_summary_file from .read_config import read_config, sample_config_file from .utils import calculate_zernike_moments, calculate_beam_fom, HAS_MAHO from .utils import compare_anything, ds9_like_log_scale, njit @@ -441,7 +441,7 @@ def get_opacity(self, datadir=None, dirlist=None): return for s in scans: - if s.lower().startswith("sum"): + if _is_summary_file(s): continue try: results = calculate_opacity(s, plot=False) diff --git a/srttools/inspect_observations.py b/srttools/inspect_observations.py index e0881ae3..fcd6f80b 100644 --- a/srttools/inspect_observations.py +++ b/srttools/inspect_observations.py @@ -75,7 +75,7 @@ def inspect_directories( for d in directories: fits_files = list_scans(".", [d]) for f in fits_files: - if f.lower().startswith("sum"): + if _is_summary_file(f): continue logging.info("Reading {}".format(f)) try: diff --git a/srttools/monitor/monitor.py b/srttools/monitor/monitor.py index 6e5da706..1c0f0153 100644 --- a/srttools/monitor/monitor.py +++ b/srttools/monitor/monitor.py @@ -48,6 +48,7 @@ class MyEventHandler(PatternMatchingEventHandler): "*/tempfits/*", "*/*.fitstemp", "*/summary.fits", + "*/Sum_*.fits", ] patterns = ["*/*.fits"] + ["*/*.fits{}".format(x) for x in range(MAX_FEEDS)] diff --git a/srttools/scan.py b/srttools/scan.py index 2a87b557..caa8b0b3 100644 --- a/srttools/scan.py +++ b/srttools/scan.py @@ -827,6 +827,24 @@ def frequency_filter(dynamical_spectrum, mask): return lc_corr +def _is_summary_file(fname): + """Check if a file name pattern is compatible with a summary file.""" + return fname[:4].lower() in ["summ", "sum_"] + + +def find_summary_file_in_dir(directory, warn_if_absent=True): + """Find the summary file in an observation directory.""" + summary_files = [] + for pattern in ["summary.fits", "Sum_*.fits"]: + summary_files += glob.glob(os.path.join(directory, pattern)) + + if len(summary_files) > 1: + raise ValueError(f"Multiple summary files found: {summary_files}") + if warn_if_absent and len(summary_files) == 0: + warnings.warn("No summary file in directory") + return summary_files + + def list_scans(datadir, dirlist): """List all scans contained in the directory listed in config.""" scan_list = [] @@ -836,7 +854,7 @@ def list_scans(datadir, dirlist): list_of_files += glob.glob(os.path.join(datadir, d, "*.fits[0-9]")) list_of_files += glob.glob(os.path.join(datadir, d, "*.fits[0-9][0-9]")) for f in list_of_files: - if f.lower().startswith("sum"): + if _is_summary_file(f): continue scan_list.append(f) return scan_list From b411324e568767e20150f1ccf3a3de1c371caf9d Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Wed, 17 Jul 2024 12:09:04 +0200 Subject: [PATCH 04/14] Test properly and fix --- srttools/scan.py | 4 +++- srttools/tests/test_io_and_scan.py | 32 +++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/srttools/scan.py b/srttools/scan.py index caa8b0b3..fcfbf36b 100644 --- a/srttools/scan.py +++ b/srttools/scan.py @@ -840,8 +840,10 @@ def find_summary_file_in_dir(directory, warn_if_absent=True): if len(summary_files) > 1: raise ValueError(f"Multiple summary files found: {summary_files}") - if warn_if_absent and len(summary_files) == 0: + elif warn_if_absent and len(summary_files) == 0: warnings.warn("No summary file in directory") + else: + summary_files = summary_files[0] return summary_files diff --git a/srttools/tests/test_io_and_scan.py b/srttools/tests/test_io_and_scan.py index 46d38691..9e943fd2 100644 --- a/srttools/tests/test_io_and_scan.py +++ b/srttools/tests/test_io_and_scan.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from pathlib import Path from srttools.read_config import read_config from astropy.time import Time from astropy.coordinates import SkyCoord @@ -8,7 +9,12 @@ import astropy.units as u import pytest -from srttools.scan import Scan, HAS_MPL, clean_scan_using_variability +from srttools.scan import ( + Scan, + HAS_MPL, + clean_scan_using_variability, + find_summary_file_in_dir, +) from srttools.io import print_obs_info_fitszilla, bulk_change, main_bulk_change from srttools.io import locations, read_data_fitszilla, mkdir_p from srttools.utils import compare_anything @@ -438,3 +444,27 @@ def teardown_class(klass): for f in glob.glob(os.path.join(klass.datadir, "spectrum", "*.hdf5")): os.unlink(f) shutil.rmtree(os.path.join(klass.datadir, "out_spectrum_test")) + +class TestSummary: + @classmethod + def setup_class(cls): + cls.testdir = "tmp-fake-dir" + os.makedirs(cls.testdir) + + def test_summary_nofiles(self): + with pytest.warns(UserWarning, match="No summary file"): + find_summary_file_in_dir(self.testdir) + + def test_summary_onefile(self): + fname = os.path.join(self.testdir, "summary.fits") + Path.touch(fname) + assert fname == find_summary_file_in_dir(self.testdir) + + def test_summary_multiple(self): + Path.touch(os.path.join(self.testdir, "summary.fits")) + Path.touch(os.path.join(self.testdir, "Sum_asdfhasldfjhal.fits")) + with pytest.raises(ValueError, match="Multiple"): + find_summary_file_in_dir(self.testdir) + + def teardown_class(cls): + shutil.rmtree(cls.testdir) \ No newline at end of file From 76fef896620c4b872c67ffd72cb0aff596959a6a Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Wed, 17 Jul 2024 12:11:14 +0200 Subject: [PATCH 05/14] Add changelog --- docs/changes/242.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/242.bugfix.rst diff --git a/docs/changes/242.bugfix.rst b/docs/changes/242.bugfix.rst new file mode 100644 index 00000000..4a6a502b --- /dev/null +++ b/docs/changes/242.bugfix.rst @@ -0,0 +1 @@ +Support new naming for summary file From bb9c0a899fc5d8591201417c7bde8f2f9120b7e4 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Wed, 17 Jul 2024 12:19:12 +0200 Subject: [PATCH 06/14] Minor syntax fixes --- srttools/global_fit.py | 1 - srttools/interactive_filter.py | 1 - srttools/read_config.py | 1 - srttools/tests/test_io_and_scan.py | 3 ++- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/srttools/global_fit.py b/srttools/global_fit.py index ba3115ad..be66e4d4 100644 --- a/srttools/global_fit.py +++ b/srttools/global_fit.py @@ -1,6 +1,5 @@ """Functions to clean images by fitting linear trends to the initial scans.""" - try: import matplotlib.pyplot as plt from matplotlib.gridspec import GridSpec diff --git a/srttools/interactive_filter.py b/srttools/interactive_filter.py index c69375e9..6d101b29 100644 --- a/srttools/interactive_filter.py +++ b/srttools/interactive_filter.py @@ -1,6 +1,5 @@ """Interactive operations.""" - import copy import warnings import logging diff --git a/srttools/read_config.py b/srttools/read_config.py index 21facd40..ddbceed4 100644 --- a/srttools/read_config.py +++ b/srttools/read_config.py @@ -1,6 +1,5 @@ """Read the configuration file.""" - import os import glob import warnings diff --git a/srttools/tests/test_io_and_scan.py b/srttools/tests/test_io_and_scan.py index 9e943fd2..690369a6 100644 --- a/srttools/tests/test_io_and_scan.py +++ b/srttools/tests/test_io_and_scan.py @@ -445,6 +445,7 @@ def teardown_class(klass): os.unlink(f) shutil.rmtree(os.path.join(klass.datadir, "out_spectrum_test")) + class TestSummary: @classmethod def setup_class(cls): @@ -467,4 +468,4 @@ def test_summary_multiple(self): find_summary_file_in_dir(self.testdir) def teardown_class(cls): - shutil.rmtree(cls.testdir) \ No newline at end of file + shutil.rmtree(cls.testdir) From 85c4d90eddfcc85a12a9e5ea5220f7faa94cdd8a Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Wed, 17 Jul 2024 15:07:10 +0200 Subject: [PATCH 07/14] Fix test name --- srttools/tests/test_imager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srttools/tests/test_imager.py b/srttools/tests/test_imager.py index c6bf4426..8ca4ed48 100644 --- a/srttools/tests/test_imager.py +++ b/srttools/tests/test_imager.py @@ -97,7 +97,7 @@ def setup_class(klass): ) @pytest.mark.skipif("not HAS_SUNPY") - def test_sun_map(self): + def test_sun_map_no_sunpy(self): files = main_inspector([os.path.join(self.simdir, "*"), "-d"]) main_imager(["-c", files[0], "--frame", "sun"]) for f in files: From 80ad0a0288614a9fc97f998c6afe10900035afa0 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Wed, 17 Jul 2024 15:08:10 +0200 Subject: [PATCH 08/14] Fix _is_summary_file and add doctest --- srttools/scan.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/srttools/scan.py b/srttools/scan.py index fcfbf36b..51db5904 100644 --- a/srttools/scan.py +++ b/srttools/scan.py @@ -828,8 +828,23 @@ def frequency_filter(dynamical_spectrum, mask): def _is_summary_file(fname): - """Check if a file name pattern is compatible with a summary file.""" - return fname[:4].lower() in ["summ", "sum_"] + """Check if a file name pattern is compatible with a summary file. + + Examples + -------- + >>> _is_summary_file("summary.fits") + True + >>> _is_summary_file(os.path.join("bubub", "SuMmary.fits")) + True + >>> _is_summary_file("SuM_fae02ef0fajdasj.fits") + True + >>> _is_summary_file(os.path.join("bubub", "SuM_fae02ef0fajdasj.fits")) + True + >>> # Here "sum" is in the directory name + >>> _is_summary_file(os.path.join("Summ", "afaskdjgahga.fits")) + False + """ + return os.path.basename(fname)[:4].lower() in ["summ", "sum_"] def find_summary_file_in_dir(directory, warn_if_absent=True): From 66bf97930cb76fef1d82d7c5cda2cb51a67064ff Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Wed, 17 Jul 2024 15:08:16 +0200 Subject: [PATCH 09/14] Fix import --- srttools/inspect_observations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srttools/inspect_observations.py b/srttools/inspect_observations.py index fcd6f80b..ccaee4ae 100644 --- a/srttools/inspect_observations.py +++ b/srttools/inspect_observations.py @@ -7,7 +7,7 @@ from astropy.time import Time import logging from .io import read_data, chan_re -from .scan import list_scans +from .scan import list_scans, _is_summary_file from .calibration import read_calibrator_config from .read_config import sample_config_file from .utils import remove_suffixes_and_prefixes From ee9e4b4f64926977f48944dee38e139b2c434903 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Wed, 17 Jul 2024 15:50:01 +0200 Subject: [PATCH 10/14] Fix Pathlib issue --- srttools/tests/test_io_and_scan.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/srttools/tests/test_io_and_scan.py b/srttools/tests/test_io_and_scan.py index 690369a6..055bfe18 100644 --- a/srttools/tests/test_io_and_scan.py +++ b/srttools/tests/test_io_and_scan.py @@ -458,12 +458,12 @@ def test_summary_nofiles(self): def test_summary_onefile(self): fname = os.path.join(self.testdir, "summary.fits") - Path.touch(fname) + Path(fname).touch() assert fname == find_summary_file_in_dir(self.testdir) def test_summary_multiple(self): - Path.touch(os.path.join(self.testdir, "summary.fits")) - Path.touch(os.path.join(self.testdir, "Sum_asdfhasldfjhal.fits")) + Path(os.path.join(self.testdir, "summary.fits")).touch() + Path(os.path.join(self.testdir, "Sum_asdfhasldfjhal.fits")).touch() with pytest.raises(ValueError, match="Multiple"): find_summary_file_in_dir(self.testdir) From 1ebe946c0a1a4f7b28ab28a72696858ff414a314 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Wed, 17 Jul 2024 15:50:11 +0200 Subject: [PATCH 11/14] Fix naming --- srttools/tests/test_imager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srttools/tests/test_imager.py b/srttools/tests/test_imager.py index 8ca4ed48..98ffbf26 100644 --- a/srttools/tests/test_imager.py +++ b/srttools/tests/test_imager.py @@ -97,14 +97,14 @@ def setup_class(klass): ) @pytest.mark.skipif("not HAS_SUNPY") - def test_sun_map_no_sunpy(self): + def test_sun_map_sunpy(self): files = main_inspector([os.path.join(self.simdir, "*"), "-d"]) main_imager(["-c", files[0], "--frame", "sun"]) for f in files: os.unlink(f) @pytest.mark.skipif("HAS_SUNPY") - def test_sun_map(self): + def test_sun_map_no_sunpy(self): with pytest.raises(ValueError) as excinfo: _ = main_inspector([os.path.join(self.simdir, "*"), "-d"]) assert "No valid observations found" in str(excinfo.value) From 339fcbed295988488b35574ce448b34d447a04f4 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Wed, 17 Jul 2024 16:52:59 +0200 Subject: [PATCH 12/14] Run more test cases --- .github/workflows/ci_tests.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 694eb9d0..d93a6637 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -109,11 +109,17 @@ jobs: toxenv: py311-test-alldeps-cov experimental: false - - name: OS X - Python 3.8 with all optional dependencies at their 3.8-compatible versions - os: macos-latest + - name: Linux - Python 3.8 with all optional dependencies at their 3.8-compatible versions + os: ubuntu-latest python: '3.8' toxenv: py38-test-alldeps - experimental: false + experimental: true + + - name: OS X - Python 3.10 with all optional dependencies + os: macos-latest + python: '3.10' + toxenv: py310-test-alldeps + experimental: true - name: Windows - Python 3.10 with all optional dependencies os: windows-latest From 16848f402da2637c8712d2d473d4de5b230e73c6 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Thu, 18 Jul 2024 09:25:03 +0200 Subject: [PATCH 13/14] Small bugfix --- srttools/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/srttools/utils.py b/srttools/utils.py index c74dc36b..d26a6d8f 100644 --- a/srttools/utils.py +++ b/srttools/utils.py @@ -448,8 +448,9 @@ def get_center_of_mass(im, radius=1, approx=None): npix = int(radius * min(im.shape)) xmin, xmax = max(0, approx[0] - npix), min(approx[0] + npix, im.shape[0]) ymin, ymax = max(0, approx[1] - npix), min(approx[1] + npix, im.shape[1]) - good_x = slice(xmin, xmax) - good_y = slice(ymin, ymax) + good_x = slice(xmin, max(xmax, xmin + 1)) + good_y = slice(ymin, max(ymax, ymin + 1)) + cm = np.asarray(scipy.ndimage.center_of_mass(im[good_x, good_y])) cm[0] += xmin cm[1] += ymin From 7848f6b26f5cf67ecec80c6a957e488b0af677de Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Thu, 18 Jul 2024 09:29:48 +0200 Subject: [PATCH 14/14] Calculate moments only for altaz images --- srttools/imager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srttools/imager.py b/srttools/imager.py index af33b675..91ef9cf3 100644 --- a/srttools/imager.py +++ b/srttools/imager.py @@ -1499,7 +1499,7 @@ def save_ds9_images( is_stokes = ("Q" in ch) or ("U" in ch) do_moments = not (is_sdev or is_expo or is_stokes or is_outl) - do_moments = do_moments and frame and HAS_MAHO + do_moments = do_moments and frame == "altaz" and HAS_MAHO if is_sdev and not save_sdev: continue