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", diff --git a/trollsched/tests/test_schedule.py b/trollsched/tests/test_schedule.py index 609a1db..7f9cf7e 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: @@ -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,13 +364,82 @@ 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)) 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 = ("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" + 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=["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), + "noaa 20": dict(schedule_name="noaa 20", + 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) + 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