From 332caff490e838539d31e246c77ea193cd038b80 Mon Sep 17 00:00:00 2001 From: John Truckenbrodt Date: Mon, 11 Dec 2023 11:09:21 +0100 Subject: [PATCH 1/2] [S1.OSV.catch] fixed bug in finding files starting in previous month --- pyroSAR/S1/auxil.py | 12 ++++++------ tests/test_osv.py | 9 +++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pyroSAR/S1/auxil.py b/pyroSAR/S1/auxil.py index 79b480e1..5118f4d1 100644 --- a/pyroSAR/S1/auxil.py +++ b/pyroSAR/S1/auxil.py @@ -1,7 +1,7 @@ ############################################################################### # general utilities for Sentinel-1 -# Copyright (c) 2016-2021, the pyroSAR Developers. +# Copyright (c) 2016-2023, the pyroSAR Developers. # This file is part of the pyroSAR Project. It is subject to the # license terms in the LICENSE.txt file found in the top-level @@ -21,6 +21,7 @@ from io import BytesIO from datetime import datetime, timedelta from dateutil import parser as dateutil_parser +from dateutil.relativedelta import relativedelta import xml.etree.ElementTree as ET import numpy as np from osgeo import gdal @@ -234,6 +235,7 @@ def __catch_step_auxdata(self, sensor, start, stop, osvtype='POE'): date_search = datetime(year=start.year, month=start.month, day=1) + date_search -= relativedelta(months=1) busy = True while busy: url_sub = skeleton.format(url=url, @@ -258,11 +260,9 @@ def __catch_step_auxdata(self, sensor, start, stop, osvtype='POE'): 'auth': None}) if start2 >= stop: busy = False - if date_search.month < 12: - date_search = date_search.replace(month=date_search.month + 1) - else: - date_search = date_search.replace(year=date_search.year + 1, month=1) - + date_search += relativedelta(months=1) + if date_search > datetime.now(): + busy = False return files def __catch_gnss(self, sensor, start, stop, osvtype='POE'): diff --git a/tests/test_osv.py b/tests/test_osv.py index 718555f3..a87c28bf 100644 --- a/tests/test_osv.py +++ b/tests/test_osv.py @@ -37,7 +37,12 @@ def test_scene_osv(tmpdir, testdata): os.remove(item) assert len(osv.getLocals('POE')) == 1 res = osv.catch(sensor='S1A', osvtype='RES', start='20210201T00000', stop='20210201T150000', url_option=1) - assert len(res) == 9 + assert len(res) == 11 osv.retrieve(res[0:3]) assert len(osv.getLocals('RES')) == 3 - res = osv.catch(sensor='S1A', osvtype='POE', start=time.strftime('%Y%m%dT%H%M%S')) + # check retrieving files for the current day (e.g. to ensure that search is not extended to the future) + poe = osv.catch(sensor='S1A', osvtype='POE', start=time.strftime('%Y%m%dT%H%M%S')) + assert len(poe) == 0 + # check retrieving files whose start is in the previous month of the search start + poe = osv.catch(sensor='S1A', osvtype='POE', start='20220201T163644', stop='20220201T163709') + assert len(poe) == 1 From f19c683e15532aa0e819ee9883d6201cae95d89c Mon Sep 17 00:00:00 2001 From: John Truckenbrodt Date: Mon, 11 Dec 2023 11:59:04 +0100 Subject: [PATCH 2/2] [S1.OSV.retrieve] extract tmp file to memory, not cwd --- pyroSAR/S1/auxil.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyroSAR/S1/auxil.py b/pyroSAR/S1/auxil.py index 5118f4d1..15a3660e 100644 --- a/pyroSAR/S1/auxil.py +++ b/pyroSAR/S1/auxil.py @@ -611,8 +611,8 @@ def retrieve(self, products, pbar=False): members = tmp.namelist() target = [x for x in members if re.search(basename, x)][0] with zf.ZipFile(tmp_path, 'w') as outfile: - outfile.write(filename=tmp.extract(target), - arcname=basename) + outfile.writestr(data=tmp.read(target), + zinfo_or_arcname=basename) else: with zf.ZipFile(file=tmp_path, mode='w',