Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[S1.OSV.catch] fixed bug in finding files starting in previous month #286

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pyroSAR/S1/auxil.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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'):
Expand Down Expand Up @@ -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',
Expand Down
9 changes: 7 additions & 2 deletions tests/test_osv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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