-
Notifications
You must be signed in to change notification settings - Fork 300
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
Allow custom dataset names in 'generic_image' reader and fix nodata handling #1560
Merged
djhoese
merged 20 commits into
pytroll:master
from
ch-k:fix-generic-image-reader-datasetname
Apr 30, 2021
Merged
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b876bb4
Fix: use same hardcoded dataset name for set and get
ch-k d1be050
Fix: use same hardcoded dataset name for set and get (unit test)
ch-k e8ffa2f
Handling of fill_value in GenericImageFileHandler
ch-k ab0e885
Fix codefactor suggestion
ch-k a582bb1
Merge branch 'orig-gh-master' into fix-generic-image-reader-datasetname
ch-k c01a798
Use file_content with default datasetname image
ch-k 579002a
Merge branch 'master' into fix-generic-image-reader-datasetname
ch-k b1ad1e0
Merge branch 'master' into fix-generic-image-reader-datasetname
ch-k e3ff310
Make handling of nodata in GenericImage reader configurable
ch-k 1b6a928
Fix deepcode hints
ch-k 081a59b
Fix flake8 hints
ch-k 632d8dc
Add more doc
ch-k 7ee8b86
Update style of code documentation
ch-k d643a51
Refactor unit test
ch-k 4db0a0b
Merge branch 'fix-generic-image-reader-datasetname' of https://github…
ch-k cd61f22
Make masking function private
ch-k b6b9f3c
Revert making mask_image_data a class method
ch-k 6bb1e8f
Update dataset attributes
ch-k b7b3a31
Cleanup fake reader
ch-k 0f93397
Fix deepcode and codebeat issues
ch-k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,3 +187,18 @@ def test_GenericImageFileHandler(self): | |
self.assertTrue(data.bands.size == 4) | ||
data = mask_image_data(data) | ||
self.assertTrue(data.bands.size == 3) | ||
|
||
def test_GenericImageFileHandler_datasetid(self): | ||
"""Test direct use of the reader.""" | ||
from satpy.readers.generic_image import GenericImageFileHandler | ||
from satpy.readers.generic_image import mask_image_data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. F401 'satpy.readers.generic_image.mask_image_data' imported but unused |
||
|
||
fname = os.path.join(self.base_dir, 'test_rgba.tif') | ||
fname_info = {'start_time': self.date} | ||
ftype_info = {} | ||
reader = GenericImageFileHandler(fname, fname_info, ftype_info) | ||
|
||
foo = make_dataid(name='image-custom') | ||
self.assertTrue(reader.file_content) | ||
dataset = reader.get_dataset(foo, None) | ||
self.assertTrue(isinstance(dataset, xr.DataArray)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. W292 no newline at end of file |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about you either:
self.file_content['image']
(with.copy()
method) and update the attributes with theinfo
dictionary. Likeimg_copy.attrs.update(info)
. I think this should update thename
and any otherDataID
information that someone might include in the YAML.key['name']
but update theread
method to write the file content to the rightfile_content
key.Option 1 is easiest. Option 2 provides the most flexibility in the future. @pnuu let us know if there is a reason not to move
.read
to theget_dataset
call as that also seems like it could help here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's wait for @pnuu 's input and I'll change it accordingly. Option 2 seems nicer to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
'image'
is there just to make things work with the existing way Satpy is designed to load data with a named dataset. In an image, there's only one dataset andscn.load()
should probably just load the image. But yeah, when loading data with multiple readers that'd not work.I think option 2 is the better way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to remove the
read()
completely as it is only used in the ctor and move the reading stuff toget_dataset()
. Then there's also no need to keep an attributeself.file_content
any longer. The "How-To for custom readers" (https://satpy.readthedocs.io/en/stable/dev_guide/custom_reader.html) only demands implementingget_dataset()
.And I couldn't find any other readers that use
GenericImageFileHandler
as base class.Keeping
self.file_content
seems only necessary for caching reasons. But I think there are other mechanisms in satpy that care about this, right?Okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding moving the functionality: sounds good as long as the code is clean.
Regarding file_content, that is likely just a common practice used from other readers. It also makes writing tests easier, at least in other readers, because complex NetCDF/HDF files can be described by a dictionary and put in
file_content
. For this reader, maybe that isn't necessary. As long as the tests can be made to work with whatever you do then 👍There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've decided to lease reading in ctor as it is because otherwise
get_area_def()
needs special treatment. The area is set during reading. Although it seems thatget_area_def()
is called afterget_dataset()
and therefore area should be already available in my tests - it don't know if it's the case in all situations..The latest commit introduces a class attribute
dataset_name
that is set to defaultimage
in the read function. In derived fake readers you can provide own file_content and leaveds_name
empty to work with multiple datasets - if somebody really wants to do this..There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI there was a semi-recent change in the base reader that changed the order of when the dataset was loaded and when the area was loaded. It used to be that the area was always loaded first (if I remember correctly), but now it is loaded after.