-
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
Add compositor for adding an image as a background #804
Add compositor for adding an image as a background #804
Conversation
I need some help to figure out how to make Satpy to recognize the composites based on background:
compositor: !!python/name:satpy.composites.StaticImageCompositor
standard_name: background
fname: /tmp/overview.tif
# Optional for non-GeoTIFF image file
# area: euro4 And here's a test script (use whatever data and area available): import glob
from satpy import Scene
fnames = glob.glob('/home/lahtinep/data/satellite/new/H*201409040500*')
glbl = Scene(reader='seviri_l1b_hrit', filenames=fnames)
glbl.load(['background'])
lcl = glbl.resample('euro4')
lcl.save_dataset('background', filename='/tmp/test.tif') I get this stack trace: Traceback (most recent call last):
File "/home/lahtinep/Software/pytroll/packages/satpy/satpy/readers/__init__.py", line 335, in __getitem__
return super(DatasetDict, self).__getitem__(item)
KeyError: 'background'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/test.py", line 14, in <module>
lcl.save_dataset('background', filename='/tmp/test.png')
File "/home/lahtinep/Software/pytroll/packages/satpy/satpy/scene.py", line 1257, in save_dataset
return writer.save_dataset(self[dataset_id],
File "/home/lahtinep/Software/pytroll/packages/satpy/satpy/scene.py", line 680, in __getitem__
return self.datasets[key]
File "/home/lahtinep/Software/pytroll/packages/satpy/satpy/readers/__init__.py", line 337, in __getitem__
key = self.get_key(item)
File "/home/lahtinep/Software/pytroll/packages/satpy/satpy/readers/__init__.py", line 326, in get_key
best=best, **dfilter)
File "/home/lahtinep/Software/pytroll/packages/satpy/satpy/readers/__init__.py", line 277, in get_key
raise KeyError("No dataset matching '{}' found".format(str(key)))
KeyError: "No dataset matching 'DatasetID(name='background', wavelength=None, resolution=None, polarization=None, calibration=None, level=None, modifiers=None)' found" If I instead use the compositor directly and place the composite to the scene resampling and saving works: import glob
from satpy import Scene
from satpy.composites import StaticImageCompositor
comp = StaticImageCompositor('static', fname='/tmp/overview.tif')
foo = comp()
fnames = glob.glob('/home/lahtinep/data/satellite/new/H*201409040500*')
glbl = Scene(reader='seviri_l1b_hrit', filenames=fnames)
glbl['foo'] = foo
lcl = glbl.resample('euro4')
lcl.save_dataset('foo', filename='/tmp/test.tif') |
So I've tracked down the issue for why this doesn't behave the way you expect. The main issue is that the dependency tree, once constructed, is used in two ways:
We have three easy options and one "No please don't make me do it" option for a fix.
I vote for 1 which I can try to implement if you and @mraspaud agree. Also, could you rename |
Handles the special case of compositors with no required dependencies
I've pushed fixes for option 1 above to your branch. Tests that need to be added and I think using your compositor is the best way to test them:
|
Couldn't yet figure out what and how to mock to get real results from the |
Check available and all composite ids
Codecov Report
@@ Coverage Diff @@
## master #804 +/- ##
=========================================
+ Coverage 82.26% 83.2% +0.93%
=========================================
Files 159 163 +4
Lines 22998 23829 +831
=========================================
+ Hits 18920 19826 +906
+ Misses 4078 4003 -75
Continue to review full report at Codecov.
|
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.
LGTM. So what does this mean for the start_time
issue? If the image doesn't have a time in the filename that can be picked up by the reader then users are screwed? Could someone provide a datetime as a keyword argument to the compositor?
If the image file has no |
@pnuu I'm not sure I understand how it would be used by other compositors, but waiting for a later PR seems fine. Actually, it may even be possible to just add |
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.
LGTM
This PR adds two compositors that makes it possible to use pre-made images as a part of other composites:
StaticImageCompositor
- load image and use it as a part of other compositesBackgroundCompositor
- use a composite as a background for other compositesAdd compositor for loading pre-made images as part of a composite.
flake8 satpy