Skip to content

Commit

Permalink
Merge pull request #286 from johntruckenbrodt/bugfix/osv_month
Browse files Browse the repository at this point in the history
[S1.OSV.catch] fixed bug in finding files starting in previous month
  • Loading branch information
johntruckenbrodt authored Dec 11, 2023
2 parents 4544604 + f19c683 commit 176c52e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
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

0 comments on commit 176c52e

Please sign in to comment.