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 'day_night' flag to DayNightCompositor for day-only or night-only results #1816
Conversation
satpy/composites/__init__.py
Outdated
"""Collect custom configuration values. | ||
|
||
Args: | ||
lim_low (float): lower limit of Sun zenith angle for the | ||
blending of the given channels | ||
lim_high (float): upper limit of Sun zenith angle for the | ||
blending of the given channels | ||
chose_day_night (string): "day_and_night" means both day and night parts will be kept |
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.
What do you think about day_night
for the keyword argument (otherwise is should be choose_
not chose_
)?
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.
Sorry for the spell...
satpy/composites/__init__.py
Outdated
super(DayNightCompositor, self).__init__(name, **kwargs) | ||
|
||
def __call__(self, projectables, **kwargs): | ||
"""Generate the composite.""" | ||
projectables = self.match_data_arrays(projectables) | ||
|
||
day_data = projectables[0] | ||
night_data = projectables[1] | ||
data_1 = projectables[0] |
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.
Is there a more descriptive name for this? I suppose "foreground" isn't really correct 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.
I think you are right. Whatever you choose, you need a 'foreground' image at least. So 'foreground' and 'background' are more suitable.
satpy/composites/__init__.py
Outdated
@@ -585,43 +588,99 @@ def __call__(self, projectables, **kwargs): | |||
LOG.debug("Computing sun zenith angles.") | |||
# Get chunking that matches the data | |||
try: | |||
chunks = day_data.sel(bands=day_data['bands'][0]).chunks | |||
chunks = data_1.sel(bands=data_1['bands'][0]).chunks |
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.
Github won't let me comment on it, but the coszen =
line above uses projectables[2]
which may or may not exist depending on the day/night mode.
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.
This projectables[2]
remains in the original one. I actually don't know what it's for...May be it's waiting for a solar zenith angle band/dataset from the satellite data?
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.
🤦 Oh duh. That is if the YAML file specifies the solar_zenith_angle dataset from the reader (ex. for viirs_sdr
). Geostationary satellites don't typically have that provided by the file/reader so it isn't specified. You may want this to be projectables[2 if self.day_night == "day_night" else 1]
.
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.
😊OK It's late night here so I'll do these changes tomorrow.
satpy/composites/__init__.py
Outdated
# Blend the two images together | ||
data = (1 - coszen) * night_data + coszen * day_data | ||
data.attrs = attrs | ||
elif self.chose_day_night == "only_night": |
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.
Can the day/night only modes be combined with if statements for the things that are different? You could also ignore the 0
parameters in the logic so that extra computation isn't done when it isn't needed. Oh you might be able to combine all three day/night modes...
day_data = projectables[0] if "day" in self.day_night else None
night_data = projectables[0] if self.day_night == "night_only" else None
night_data = projectables[1] if self.day_night == "day_night" else night_data
day_portion = coszen * (day_data if day_data is not None else 0)
night_portion = (1 - coszen) * (night_data if night_data is not None else 0)
data = night_portion + day_portion
You'd need some more logic for handling the add_bands
and zero_missing_data
stuff, but it may actually make the code a lot smaller. Maybe not clearer though... 😨
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.
Yeah I also think there's something need to be improved in the logic structure. I'll go look into this.
I've made some fixes on the variable names and the whole IF structure. |
😕 How did you get appveyor to start running again? 😕 |
Oh I'm still waiting if there are more changes need to be done then I'll get the tests and documents. |
Sorry, what I mean is that "appveyor" is one of the checks being run. We haven't used appveyor for years so it is very strange that it is even trying to run. That said, you will need to merge with upstream |
Yeah...This's my first PR so I don't know how it happened. I do have a conflict warning saying "Only those with write access to this repository can merge pull requests." How can I resolve it? |
That is not a warning about the conflict. That is message telling you that you can't merge your pull request into upstream Satpy. Only the Satpy maintainers/core developers have permissions to do that. You should see a message saying "Conflicting files"...nevermind, I checked and the conflicts were fairly simple. I just fixed them with GitHub's editor. You should make sure to run |
Thanks but I'm still confused. How this happened and how to avoid it in the future? I'm using GitHub Desktop. |
There are two things that happened:
Probably more info that you wanted, but here we are. |
Ok I got it. Thanks a lot for these details. That's exactly what I need.😁 |
@djhoese Current tests are just for "day_night". Do you think we need more other ones for "only_day" or “only_night”? |
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 had a few small changes and questions. As for the tests, I think you need to have them for both day_only and night_only too. Lastly, why did the test_add_bands_l_rgb
test have to change to get A
added? That sounds like a bug. The existing behavior should not have changed.
satpy/composites/__init__.py
Outdated
@@ -551,69 +551,79 @@ def _insert_palette_colors(channels, palette): | |||
class DayNightCompositor(GenericCompositor): | |||
"""A compositor that blends a day data with night data.""" | |||
|
|||
def __init__(self, name, lim_low=85., lim_high=88., **kwargs): | |||
def __init__(self, name, lim_low=85., lim_high=88., day_night="day_only", **kwargs): |
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.
Shouldn't the default be day_night
? And could you mention that it is the default in the docstring below. Something simple like (default)
next to the name.
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.
Yep.
satpy/composites/__init__.py
Outdated
@@ -678,7 +688,7 @@ def add_bands(data, bands): | |||
data['bands'] = new_bands | |||
data.attrs['mode'] = mode | |||
# Add alpha band | |||
if 'A' not in data['bands'].data and 'A' in bands.data: | |||
if ('A' not in data['bands'].data and 'A' in bands.data) or ('A' not in data['bands'].data): |
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.
Unless I'm reading this wrong, is the first expression the same as the last one? If so then logically this just becomes if 'A' not in data['bands'].data:
which I don't think is what is wanted, right?
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.
Oops that's for the previous structure. I'll fix it.
I change the |
day_data = projectables[0] | ||
night_data = projectables[1] | ||
# At least one composite is requested. | ||
foreground_data = projectables[0] |
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.
match_data_arrays
should always be called. You can do projectables = self.match_data_arrays(projectables)
just above this line. match_data_arrays
checks a lot of various things and modifies the provided DataArrays as needed to make them compatible with the compositor or with the rest of Satpy.
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.
Well when I tested true_color_with_night_ir_alpha
I got errors saying Dimension 'bands' size mismatch: 3 != 4
with match_data_arrays
. This even occurred under original version. I didn't know what happened...
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.
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.
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.
Ok so I'll just put match_data_arrays
back here.
@yukaribbba The PRs we mentioned before have been merged to main. Please try merging with the pytroll upstream main branch and see how things run for you. |
Flake8 issues from CI:
|
@djhoese OK got it. But there're some errors running my script.
|
You'll need to reinstall the library, so |
@djhoese Several combinations tested, and no problems there. So I'm moving forward to documents. |
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
@yukaribbba is this ready for merging? |
@mraspaud I just updated the documentation for review. After that, I think it would be ready. |
perfect, I'm looking now |
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
@djhoese are you good with the PR? |
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.
Looks good to me! Thanks for all the work @yukaribbba. I'll merge this when the tests finish and pass.
… results (pytroll#1816) * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * tests * Revert "tests" This reverts commit 630baaf. * Revert "Merge branch 'main' into feature-daynightcompositor" This reverts commit 80ed09a, reversing changes made to 2ceb218. * Revert "Revert "Merge branch 'main' into feature-daynightcompositor"" This reverts commit baf8501. * update add_bands_test * update DayNightCompositor test * update DayNightCompositor test * new structure * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update test_composites.py * Update satpy/composites/__init__.py Co-authored-by: David Hoese <david.hoese@ssec.wisc.edu> * Update satpy/composites/__init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update composites.rst * Update AUTHORS.md * Update doc/source/composites.rst Co-authored-by: David Hoese <david.hoese@ssec.wisc.edu>
As discussed in #1780 , I want to make some enhancements on
DayNightCompositor
so that we can chose which side (day/night or both) we want to keep in the final output image. Thank @djhoese and @pnuu for their suggestions.AUTHORS.md
if not there already