From abaeda774486ff0d1cf0a481532ba2ed192a0226 Mon Sep 17 00:00:00 2001 From: Trygve Aspenes Date: Wed, 8 May 2024 13:53:11 +0200 Subject: [PATCH 1/5] adjust isoformat to just use second resolution --- trollsched/satpass.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trollsched/satpass.py b/trollsched/satpass.py index 689b806..1f36c1d 100644 --- a/trollsched/satpass.py +++ b/trollsched/satpass.py @@ -113,8 +113,8 @@ def __eq__(self, other): def __str__(self): """Give a string version of the pass.""" - return (self.satellite.name + " " + self.risetime.isoformat() + " " + - self.falltime.isoformat()) + return (self.satellite.name + " " + self.risetime.isoformat(timespec='seconds') + " " + + self.falltime.isoformat(timespec='seconds')) def __repr__(self): """Represent the pass.""" From b0e1350461cb375e1dd6e58034a7a82c83a81dcf Mon Sep 17 00:00:00 2001 From: Trygve Aspenes Date: Wed, 8 May 2024 13:54:27 +0200 Subject: [PATCH 2/5] handle avoid command line argument as list of files --- trollsched/schedule.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/trollsched/schedule.py b/trollsched/schedule.py index 3924bec..68c82b5 100644 --- a/trollsched/schedule.py +++ b/trollsched/schedule.py @@ -505,19 +505,20 @@ def save_passes(allpasses, poly, output_dir, plot_parameters=None, plot_title=No logger.info("All plots saved!") -def get_passes_from_xml_file(filename): - """Read passes from aquisition xml file.""" +def get_passes_from_xml_file(filenames): + """Read passes from aquisition xml files.""" import defusedxml.ElementTree as ET - tree = ET.parse(filename) - root = tree.getroot() pass_list = [] - for overpass in root.iter("pass"): - start_time = datetime.strptime( - overpass.attrib["start-time"], "%Y-%m-%d-%H:%M:%S") - end_time = datetime.strptime( - overpass.attrib["end-time"], "%Y-%m-%d-%H:%M:%S") - pass_list.append(SimplePass( - overpass.attrib["satellite"], start_time, end_time)) + for filename in filenames: + tree = ET.parse(filename) + root = tree.getroot() + for overpass in root.iter("pass"): + start_time = datetime.strptime( + overpass.attrib["start-time"], "%Y-%m-%d-%H:%M:%S") + end_time = datetime.strptime( + overpass.attrib["end-time"], "%Y-%m-%d-%H:%M:%S") + pass_list.append(SimplePass( + overpass.attrib["satellite"], start_time, end_time)) return pass_list @@ -535,7 +536,7 @@ def send_file(url, file): """Send a file through ftp.""" pathname, filename = os.path.split(file) del pathname - if url.scheme in ["file", ""]: + if url.scheme in ["file", "", b""]: pass elif url.scheme in ["ftp", b"ftp"]: import ftplib @@ -820,7 +821,9 @@ def parse_args(args=None): group_spec = parser.add_argument_group(title="special", description="(additional parameter changing behaviour)") group_spec.add_argument("-a", "--avoid", - help="xml request file with passes to avoid") + default=[], + nargs='*', + help="xml request file(s) with passes to avoid") group_spec.add_argument("--no-aqua-terra-dump", action="store_false", help="do not consider Aqua/Terra-dumps") group_spec.add_argument("--multiproc", action="store_true", From c769f4a5b4660c6b828f2b30b86427df89e63c62 Mon Sep 17 00:00:00 2001 From: Trygve Aspenes Date: Wed, 8 May 2024 13:55:17 +0200 Subject: [PATCH 3/5] add test for schedule with avoid --- trollsched/tests/test_schedule.py | 63 ++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/trollsched/tests/test_schedule.py b/trollsched/tests/test_schedule.py index 609a1db..fedac83 100644 --- a/trollsched/tests/test_schedule.py +++ b/trollsched/tests/test_schedule.py @@ -31,7 +31,7 @@ import yaml from trollsched.satpass import get_aqua_terra_dumps, get_metopa_passes, get_next_passes -from trollsched.schedule import build_filename, conflicting_passes, fermia, fermib, run +from trollsched.schedule import build_filename, conflicting_passes, fermia, fermib, run, get_passes_from_xml_file class TestTools: @@ -377,3 +377,64 @@ def test_pyorbitals_platform_name(tmp_path): run(["-c", os.fspath(config_file), "-x", "-t", os.fspath(tle_file)]) assert sched_file in tmp_path.iterdir() + +avoid=""" + + + +""" +# + +def test_schedule_avoid(tmp_path): + """Test that schedule can handle avoid list.""" + tle = ("NOAA 20\n" + "1 43013U 17073A 24093.57357837 .00000145 00000+0 86604-4 0 9999\n" + "2 43013 98.7039 32.7741 0007542 324.8026 35.2652 14.21254587330172\n") + + config_file = tmp_path / "config.yaml" + tle_file = tmp_path / "test.tle" + area_file = tmp_path / "areas.yaml" + sched_file = tmp_path / "sched-with-avoid.xml" + avoid_file = tmp_path / "avoid.xml" + + with open(area_file, "w") as fd: + fd.write(euron1) + + with open(tle_file, "w") as fd: + fd.write(tle) + + with open(avoid_file, "w") as fd: + fd.write(avoid) + + config = dict(default=dict(station=["nrk"], + forward=12, + start=0, + center_id="SMHI"), + stations=dict(nrk=dict(name="nrk", + longitude=16, + latitude=58, + altitude=0, + satellites=["noaa-20"], + area="euron1", + area_file=os.fspath(area_file))), + + pattern=dict(dir_output=os.fspath(tmp_path), + file_xml=os.fspath(sched_file)), + satellites={"noaa-20": dict(schedule_name="noaa-20", + international_designator="43013", + night=0.4, + day=0.9)} + ) + + with open(config_file, "w") as fd: + fd.write(yaml.dump(config)) + + start_time = datetime(2024,5,8,0,0,0) + run(["-c", os.fspath(config_file), "-x", "-v", "-t", os.fspath(tle_file), + "--start-time", start_time.strftime("%Y-%m-%dT%H:%M:%S"), "--avoid", os.fspath(avoid_file)]) + assert sched_file in tmp_path.iterdir() + + sched_file_passes = get_passes_from_xml_file([sched_file]) + avoid_file_passes = get_passes_from_xml_file([avoid_file]) + for avoid_pass in avoid_file_passes: + assert avoid_pass not in sched_file_passes From 32b8b20e1f1f3e3949d2d5299c403118dd1181e2 Mon Sep 17 00:00:00 2001 From: Trygve Aspenes Date: Tue, 21 May 2024 10:46:04 +0200 Subject: [PATCH 4/5] revert isoformat, improve test --- trollsched/satpass.py | 4 ++-- trollsched/tests/test_schedule.py | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/trollsched/satpass.py b/trollsched/satpass.py index 1f36c1d..689b806 100644 --- a/trollsched/satpass.py +++ b/trollsched/satpass.py @@ -113,8 +113,8 @@ def __eq__(self, other): def __str__(self): """Give a string version of the pass.""" - return (self.satellite.name + " " + self.risetime.isoformat(timespec='seconds') + " " + - self.falltime.isoformat(timespec='seconds')) + return (self.satellite.name + " " + self.risetime.isoformat() + " " + + self.falltime.isoformat()) def __repr__(self): """Represent the pass.""" diff --git a/trollsched/tests/test_schedule.py b/trollsched/tests/test_schedule.py index fedac83..04c1514 100644 --- a/trollsched/tests/test_schedule.py +++ b/trollsched/tests/test_schedule.py @@ -380,16 +380,18 @@ def test_pyorbitals_platform_name(tmp_path): avoid=""" - + """ -# def test_schedule_avoid(tmp_path): """Test that schedule can handle avoid list.""" - tle = ("NOAA 20\n" - "1 43013U 17073A 24093.57357837 .00000145 00000+0 86604-4 0 9999\n" - "2 43013 98.7039 32.7741 0007542 324.8026 35.2652 14.21254587330172\n") + tle = ("SUOMI NPP\n" + "1 37849U 11061A 24128.72979065 .00000000 00000+0 12832-3 0 00014\n" + "2 37849 98.7205 67.3215 0001498 76.6175 303.3589 14.19560637649138\n" + "NOAA 20\n" + "1 37849U 11061A 24128.72979065 .00000000 00000+0 12832-3 0 00014\n" + "2 37849 98.7205 67.3215 0001498 76.6175 303.3589 14.19560637649138\n") config_file = tmp_path / "config.yaml" tle_file = tmp_path / "test.tle" @@ -414,16 +416,20 @@ def test_schedule_avoid(tmp_path): longitude=16, latitude=58, altitude=0, - satellites=["noaa-20"], + satellites=["suomi npp","noaa 20"], area="euron1", area_file=os.fspath(area_file))), pattern=dict(dir_output=os.fspath(tmp_path), file_xml=os.fspath(sched_file)), - satellites={"noaa-20": dict(schedule_name="noaa-20", - international_designator="43013", - night=0.4, - day=0.9)} + satellites={"suomi npp": dict(schedule_name="suomi npp", + international_designator="37849", + night=0.4, + day=0.9), + "noaa 20": dict(schedule_name="noaa 20", + international_designator="99999", + night=0.4, + day=0.9)} ) with open(config_file, "w") as fd: From e0f2bbc75c95d35db0d1af54b6dac5bd5de995b1 Mon Sep 17 00:00:00 2001 From: Trygve Aspenes Date: Tue, 21 May 2024 10:57:33 +0200 Subject: [PATCH 5/5] flake8 --- trollsched/tests/test_schedule.py | 33 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/trollsched/tests/test_schedule.py b/trollsched/tests/test_schedule.py index 04c1514..7f9cf7e 100644 --- a/trollsched/tests/test_schedule.py +++ b/trollsched/tests/test_schedule.py @@ -332,14 +332,12 @@ def test_get_metopa_passes(self, exists): """ - def test_pyorbitals_platform_name(tmp_path): """Test that using pyorbital's platform name allows spurious names in the TLE data.""" spurious_tle = ("NOAA 20 (JPSS-1)\n" "1 43013U 17073A 24093.57357837 .00000145 00000+0 86604-4 0 9999\n" "2 43013 98.7039 32.7741 0007542 324.8026 35.2652 14.21254587330172\n") - config_file = tmp_path / "config.yaml" tle_file = tmp_path / "test.tle" area_file = tmp_path / "areas.yaml" @@ -351,7 +349,6 @@ def test_pyorbitals_platform_name(tmp_path): with open(tle_file, "w") as fd: fd.write(spurious_tle) - config = dict(default=dict(station=["nrk"], forward=12, start=0, @@ -367,10 +364,10 @@ def test_pyorbitals_platform_name(tmp_path): pattern=dict(dir_output=os.fspath(tmp_path), file_xml=os.fspath(sched_file)), satellites={"noaa-20": dict(schedule_name="noaa20", - international_designator="43013", - night=0.4, - day=0.9)} - ) + international_designator="43013", + night=0.4, + day=0.9)} + ) with open(config_file, "w") as fd: fd.write(yaml.dump(config)) @@ -378,12 +375,14 @@ def test_pyorbitals_platform_name(tmp_path): run(["-c", os.fspath(config_file), "-x", "-t", os.fspath(tle_file)]) assert sched_file in tmp_path.iterdir() -avoid=""" + +avoid = """ """ + def test_schedule_avoid(tmp_path): """Test that schedule can handle avoid list.""" tle = ("SUOMI NPP\n" @@ -416,26 +415,26 @@ def test_schedule_avoid(tmp_path): longitude=16, latitude=58, altitude=0, - satellites=["suomi npp","noaa 20"], + satellites=["suomi npp", "noaa 20"], area="euron1", area_file=os.fspath(area_file))), pattern=dict(dir_output=os.fspath(tmp_path), file_xml=os.fspath(sched_file)), satellites={"suomi npp": dict(schedule_name="suomi npp", - international_designator="37849", - night=0.4, - day=0.9), + international_designator="37849", + night=0.4, + day=0.9), "noaa 20": dict(schedule_name="noaa 20", - international_designator="99999", - night=0.4, - day=0.9)} - ) + international_designator="99999", + night=0.4, + day=0.9)} + ) with open(config_file, "w") as fd: fd.write(yaml.dump(config)) - start_time = datetime(2024,5,8,0,0,0) + start_time = datetime(2024, 5, 8, 0, 0, 0) run(["-c", os.fspath(config_file), "-x", "-v", "-t", os.fspath(tle_file), "--start-time", start_time.strftime("%Y-%m-%dT%H:%M:%S"), "--avoid", os.fspath(avoid_file)]) assert sched_file in tmp_path.iterdir()