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

Fix datetime-based file selection when filename only has a start time #349

Merged
merged 2 commits into from
Jun 29, 2018
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
7 changes: 7 additions & 0 deletions satpy/readers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,13 @@ def find_files_and_readers(start_time=None, end_time=None, base_dir=None,
The returned dictionary can be passed directly to the `Scene` object
through the `filenames` keyword argument.

The behaviour of time-based filtering depends on whether or not the filename
contains information about the end time of the data or not:

- if the end time is not present in the filename, the start time of the filename
is used and has to fall between (inclusive) the requested start and end times
- otherwise, the timespan of the filename has to overlap the requested timespan

Args:
start_time (datetime): Limit used files by starting time.
end_time (datetime): Limit used files by ending time.
Expand Down
1 change: 1 addition & 0 deletions satpy/readers/yaml_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ def new_filehandler_instances(self, filetype_info, filename_items):
def time_matches(self, fstart, fend):
start_time = self.filter_parameters.get('start_time')
end_time = self.filter_parameters.get('end_time')
fend = fend or fstart
if start_time and fend and fend < start_time:
return False
if end_time and fstart and fstart > end_time:
Expand Down
4 changes: 4 additions & 0 deletions satpy/tests/test_yaml_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ def test_filter_fh_by_time(self):
# only the first one should be false
self.assertEqual(res, idx not in [0, 4])

for idx, fh in enumerate([fh0, fh1, fh2, fh3, fh4, fh5]):
res = self.reader.time_matches(fh.start_time, None)
self.assertEqual(res, idx not in [0, 1, 4, 5])

@patch('satpy.readers.yaml_reader.get_area_def')
@patch('satpy.readers.yaml_reader.AreaDefBoundary')
@patch('satpy.readers.yaml_reader.Boundary')
Expand Down