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

Improve handling of missing file requirements in readers #452

Merged
merged 18 commits into from
Dec 19, 2018

Conversation

sfinkens
Copy link
Member

@sfinkens sfinkens commented Oct 9, 2018

Improve the warning about a missing requirement (e.g. Epilogue, Prologue) and abort if there are insufficient requirements to read any data.

  • Make it a user warning (instead of a logger warning)
  • Include the name of the requirement into the message
  • Raise a RuntimeError if there are insufficient requirements to read any data -> No more Start time unknown until files are selected errors. In particular it ensures a consistent exception if
    • all requirements are missing
    • at least one requirement is present and at least one is missing but alltogether that is not enough to read any images. Example: Epilog present, Prolog missing. Currently this case passes silently until the user tries to access the data.

The modifications still allow to read as much data as possible. E.g. missing requirements for one out of 10 images will trigger warnings, but no exceptions.

Example output:

/cmsaf/nfshome/sfinkens/software/devel/satpy/satpy/readers/yaml_reader.py:406: UserWarning: Missing requirement 'HRIT_PRO' for /cmsaf/cmsaf-ops6/precip/data/geo/east_atlantic/2018/01/18/H-000-MSG3__-MSG3________-IR_097___-000002___-201801181800-__
/cmsaf/nfshome/sfinkens/software/devel/satpy/satpy/readers/yaml_reader.py:406: UserWarning: Missing requirement 'HRIT_PRO' for /cmsaf/cmsaf-ops6/precip/data/geo/east_atlantic/2018/01/18/H-000-MSG3__-MSG3________-IR_097___-000003___-201801181800-__
Traceback (most recent call last):
  File "test.py", line 16, in <module>
    scene = Scene(filenames=filenames, reader='hrit_msg')
  File "/cmsaf/nfshome/sfinkens/software/devel/satpy/satpy/scene.py", line 152, in __init__
    reader_kwargs=reader_kwargs)
  File "/cmsaf/nfshome/sfinkens/software/devel/satpy/satpy/scene.py", line 197, in create_reader_instances
    ppp_config_dir=self.ppp_config_dir)
  File "/cmsaf/nfshome/sfinkens/software/devel/satpy/satpy/readers/__init__.py", line 602, in load_readers
    reader_instance.create_filehandlers(loadables)
  File "/cmsaf/nfshome/sfinkens/software/devel/satpy/satpy/readers/yaml_reader.py", line 528, in create_filehandlers
    raise RuntimeError('Insufficient requirements (e.g. Prolog, '
RuntimeError: Insufficient requirements (e.g. Prolog, Epilog) to read any data

On-the-fly decompression is addressed by #436.

@mraspaud mraspaud added enhancement code enhancements, features, improvements component:readers labels Oct 9, 2018
@coveralls
Copy link

Coverage Status

Coverage increased (+0.009%) to 72.975% when pulling 2dc8aca on sfinkens:fix-missing-requirements into 2f45b54 on pytroll:master.

@coveralls
Copy link

coveralls commented Oct 9, 2018

Coverage Status

Coverage increased (+0.2%) to 77.029% when pulling a72d4e5 on sfinkens:fix-missing-requirements into 2f931e3 on pytroll:master.

@codecov
Copy link

codecov bot commented Oct 9, 2018

Codecov Report

Merging #452 into master will increase coverage by 0.2%.
The diff coverage is 94.54%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #452     +/-   ##
=========================================
+ Coverage   76.81%   77.02%   +0.2%     
=========================================
  Files         136      136             
  Lines       19029    19076     +47     
=========================================
+ Hits        14618    14694     +76     
+ Misses       4411     4382     -29
Impacted Files Coverage Δ
satpy/readers/yaml_reader.py 92.57% <100%> (+3.57%) ⬆️
satpy/readers/__init__.py 94.38% <66.66%> (+0.03%) ⬆️
satpy/tests/test_readers.py 98.16% <95.34%> (-0.44%) ⬇️
satpy/readers/hrit_base.py 80.74% <0%> (+1.24%) ⬆️
satpy/readers/seviri_l1b_hrit.py 51.41% <0%> (+6.77%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f931e3...a72d4e5. Read the comment docs.

Copy link
Member

@djhoese djhoese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good attempt. I'm a little worried about some wasteful checks and a few other choices you made. I'm being really picky about things because of how much this code is used and how important it is since almost every reader uses this code

satpy/readers/yaml_reader.py Outdated Show resolved Hide resolved
satpy/readers/yaml_reader.py Outdated Show resolved Hide resolved
satpy/readers/yaml_reader.py Outdated Show resolved Hide resolved
satpy/readers/yaml_reader.py Outdated Show resolved Hide resolved
satpy/scene.py Outdated
@@ -150,6 +150,12 @@ def __init__(self, filenames=None, reader=None, filter_parameters=None, reader_k
self.readers = self.create_reader_instances(filenames=filenames,
reader=reader,
reader_kwargs=reader_kwargs)

if filenames and not self.available_dataset_ids(reader_name=reader):
Copy link
Member Author

@sfinkens sfinkens Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only problem I could not resolve is: If no file matches the filter_parameters the exception is triggered mistakenly. But I would expect create_reader_instances to throw an exception in this case? Similar to No supported files found raised by find_files_and_readers. At the moment you would run into the Start time unknown until files are selected error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I'm a little confused. So if none of the files match (due to filter_parameters or other reasons) then create_reader_instances isn't raising an exception or it is?

Also, you should probably remove the reader_name=reader part since filenames can be a dictionary mapping reader: [filenames]. Just to check if there are any available datasets for any possible readers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create_reader_instances does not raise an exception in this case. Instead the subsequent call to _compute_metadata_from_readers causes the following exception:

Traceback (most recent call last):
  File "test.py", line 21, in <module>
    end_time=datetime.datetime(2010, 1, 2)
  File "/cmsaf/nfshome/sfinkens/software/devel/satpy/satpy/scene.py", line 159, in __init__
    self.attrs.update(self._compute_metadata_from_readers())
  File "/cmsaf/nfshome/sfinkens/software/devel/satpy/satpy/scene.py", line 177, in _compute_metadata_from_readers
    for x in self.readers.values())
  File "/cmsaf/nfshome/sfinkens/software/devel/satpy/satpy/scene.py", line 177, in <genexpr>
    for x in self.readers.values())
  File "/cmsaf/nfshome/sfinkens/software/devel/satpy/satpy/readers/yaml_reader.py", line 296, in start_time
    raise RuntimeError("Start time unknown until files are selected")
RuntimeError: Start time unknown until files are selected

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe load_readers (in satpy/readers/__init__.py which is called by create_reader_instances) should change:

    if not reader_instances:
        raise ValueError("No supported files found")

to something like:

if not reader_instances or all(reader.available_dataset_ids for reader in reader_instances):
    raise ValueError("No supported files found")

Then I think you could remove the scene.py change. If the error messages would be clearer I suppose the above if statement could be split in to if not reader_instances: and elif all(...): so that it is more clear "you gave valid files, but not enough, or not useable ones" or something like what you had.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I moved the check & exception to load_readers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You said you moved this, but it still exists and doesn't seem to exist in load_readers. Forgot to push something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange, my local and remote branch are up-to-date. Also, the Files Changed tab shows the diffs I commited, especially no changes to scene.py. Maybe if I fix the typo and push again, it will be updated...

satpy/tests/test_scene.py Outdated Show resolved Hide resolved
satpy/tests/test_scene.py Outdated Show resolved Hide resolved
satpy/tests/test_scene.py Outdated Show resolved Hide resolved
satpy/readers/yaml_reader.py Outdated Show resolved Hide resolved
satpy/scene.py Outdated
@@ -150,6 +150,12 @@ def __init__(self, filenames=None, reader=None, filter_parameters=None, reader_k
self.readers = self.create_reader_instances(filenames=filenames,
reader=reader,
reader_kwargs=reader_kwargs)

if filenames and not self.available_dataset_ids(reader_name=reader):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You said you moved this, but it still exists and doesn't seem to exist in load_readers. Forgot to push something?

@djhoese djhoese changed the title Improve handling of missing requirements Improve handling of missing file requirements in readers Nov 9, 2018
satpy/readers/__init__.py Outdated Show resolved Hide resolved
sfinkens and others added 16 commits December 19, 2018 12:02
When the exception is catched, redirect the message into the
warning.

To improve readability, make the warning statement fit in one line
and don't exclude the source line from the message.
BaseException.message was removed in python3
This reverts commit 177593d.
If valid files were given but no dataset could be loaded, raise
an exception.
1) There is no handler for reading a requirement
2) There is a handler but it doesn't match the current file
satpy/tests/test_scene.py Outdated Show resolved Hide resolved
satpy/tests/test_scene.py Outdated Show resolved Hide resolved
satpy/tests/test_scene.py Outdated Show resolved Hide resolved
satpy/tests/test_scene.py Outdated Show resolved Hide resolved
The hrit_msg reader is now called seviri_l1b_hrit
@djhoese djhoese merged commit d55a23e into pytroll:master Dec 19, 2018
@sfinkens sfinkens deleted the fix-missing-requirements branch April 5, 2019 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:readers enhancement code enhancements, features, improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants