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

Handle valid range and valid_range correctly for two types of HY2 SCAT l2b hdf5 data #2211

Closed

Conversation

TAlonglong
Copy link
Collaborator

@TAlonglong TAlonglong commented Sep 28, 2022

There was a mixture of where attributes were taken from, both data and self[key]
Adding keep_attrs when using xarray.where let us keep the attributes so we can use attributes from that instead of self[key]

gerritholl and others added 12 commits August 16, 2022 17:05
Add a corrected green composite for FCI and use this in the true color
RGB.  The problem is the same as for AHI, in that the "green" channel
misses the chlorophyl peak making our green planet look rather brown as
if all the forests have burnt :(
Move the GreenCorrector to the new module satpy.composites.spectral, as
it applies to FCI as well as to AHI.  Adapt AHI and FCI composites
using this corrector.  Improve documentation for the corrector.
Add the new file that was missing in the previous commit and that was
causing test failures.
Some small fixes for the green corrector based on feedback from Dave.
@TAlonglong
Copy link
Collaborator Author

Hm, I don't understand why the tests are failing. When I run the tests locally, they pass.

@pnuu pnuu added the cleanup Code cleanup but otherwise no change in functionality label Sep 29, 2022
@pnuu
Copy link
Member

pnuu commented Sep 29, 2022

Often that would mean missing dependencies on CI, but can't see how that would be the case in this one if the tests have been passing before the PR 🤔

@TAlonglong
Copy link
Collaborator Author

Ah, ok. Setting up python 3.8 I get the test to fail. Now I have something to debug.

@TAlonglong
Copy link
Collaborator Author

No, it is not the python version but xarray version. upgrading to xarray 2022.6.0 pyhd8ed1ab_1 conda-forge
gives the error. Looks like the keeps_attrs is not respected in xarray.where https://docs.xarray.dev/en/stable/generated/xarray.where.html

Hm, do I use it wrong or is there a bug in xarray?

@djhoese
Copy link
Member

djhoese commented Sep 29, 2022

In the docs it says it will take the attrs of the first array argument x. In both cases of your usage that DataArray doesn't have any .attrs I think:

data = xr.where(data > 180, data - 360., data, keep_attrs=True)

I think data - 360.0 resets the attrs, but I could be wrong.

In your other case:

data = xr.where(data < valid_range[0], np.nan, data, keep_attrs=True)

np.nan won't have any attrs either.

@TAlonglong
Copy link
Collaborator Author

Ah, thanks.

@TAlonglong
Copy link
Collaborator Author

Now the test for this change pass as far as I can see. But there is another test failing.

Hm what changed now?

@djhoese
Copy link
Member

djhoese commented Sep 29, 2022

This is a known failure that I need to fix. Someone already added an atol in one of the other active PRs. It seems numpy or other precision has changed in recent versions and now one of the tests is being too strict.

@TAlonglong
Copy link
Collaborator Author

Yeah, that was my guess also. Should I add this in this PR? Or does it need to be in a separate PR?

Then I can at least make an issue?

@djhoese
Copy link
Member

djhoese commented Sep 29, 2022

If this PR is straight forward and ready to be merged besides the failing test then I'm OK with you adding it here. I think 1e-4 is good enough, but I'd have to search for the other contributor who already fixed it. In another PR I saw yet another test failing, but I don't see that here so we'll have to see what happens.

@TAlonglong
Copy link
Collaborator Author

OK, I ran the reader tests locally, and a lot is failing, mainly the same issue:

============================================================================== short test summary info ==============================================================================
FAILED satpy/tests/reader_tests/test_seviri_l1b_calibration.py::TestSEVIRICalibrationAlgorithm::test_vis_calibrate - AssertionError: Left and right DataArray objects are not close
FAILED satpy/tests/reader_tests/test_seviri_l1b_hrit.py::TestHRITMSGCalibration::test_calibrate[VIS006-reflectance-NOMINAL-False] - AssertionError: Left and right DataArray objec...
FAILED satpy/tests/reader_tests/test_seviri_l1b_hrit.py::TestHRITMSGCalibration::test_calibrate[VIS006-reflectance-NOMINAL-True] - AssertionError: Left and right DataArray object...
FAILED satpy/tests/reader_tests/test_seviri_l1b_hrit.py::TestHRITMSGCalibration::test_calibrate[HRV-reflectance-NOMINAL-False] - AssertionError: Left and right DataArray objects ...
FAILED satpy/tests/reader_tests/test_seviri_l1b_hrit.py::TestHRITMSGCalibration::test_calibrate[HRV-reflectance-NOMINAL-True] - AssertionError: Left and right DataArray objects a...
FAILED satpy/tests/reader_tests/test_seviri_l1b_native.py::TestNativeMSGCalibration::test_calibrate[VIS006-reflectance-NOMINAL-False] - AssertionError: Left and right DataArray o...
FAILED satpy/tests/reader_tests/test_seviri_l1b_native.py::TestNativeMSGCalibration::test_calibrate[VIS006-reflectance-NOMINAL-True] - AssertionError: Left and right DataArray ob...
FAILED satpy/tests/reader_tests/test_seviri_l1b_native.py::TestNativeMSGCalibration::test_calibrate[HRV-reflectance-NOMINAL-False] - AssertionError: Left and right DataArray obje...
FAILED satpy/tests/reader_tests/test_seviri_l1b_native.py::TestNativeMSGCalibration::test_calibrate[HRV-reflectance-NOMINAL-True] - AssertionError: Left and right DataArray objec...
FAILED satpy/tests/reader_tests/test_seviri_l1b_nc.py::TestNCSEVIRIFileHandler::test_calibrate[VIS006-reflectance-False] - AssertionError: Left and right DataArray objects are no...
FAILED satpy/tests/reader_tests/test_seviri_l1b_nc.py::TestNCSEVIRIFileHandler::test_calibrate[VIS006-reflectance-True] - AssertionError: Left and right DataArray objects are not...
FAILED satpy/tests/reader_tests/test_seviri_l1b_nc.py::TestNCSEVIRIFileHandler::test_get_dataset[VIS006-reflectance] - AssertionError: Left and right DataArray objects are not close
FAILED satpy/tests/reader_tests/test_utils.py::TestSunEarthDistanceCorrection::test_apply_sunearth_corr - AssertionError: 
FAILED satpy/tests/reader_tests/test_utils.py::TestSunEarthDistanceCorrection::test_remove_sunearth_corr - AssertionError: 
FAILED satpy/tests/reader_tests/test_vii_l1b_nc.py::TestViiL1bNCFileHandler::test_calibration_functions - ValueError: ('The number of tie points in the along-route dimension must...
FAILED satpy/tests/reader_tests/test_vii_l1b_nc.py::TestViiL1bNCFileHandler::test_functions - ValueError: ('The number of tie points in the along-route dimension must be a multip...
============================================================== 16 failed, 874 passed, 269 warnings in 96.76s (0:01:36) ==============================================================

I think this is better cleaned up separately

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this. Could you add a test for this?

mraspaud and others added 4 commits October 6, 2022 13:21
Update seadas_l2 reader to handle alternative NetCDF file format
…rods

Fix CLAVR-x configuration in 'awips_tiled' writer to be backwards compatible
updates:
- [github.com/pre-commit/mirrors-mypy: v0.981 → v0.982](pre-commit/mirrors-mypy@v0.981...v0.982)
@TAlonglong
Copy link
Collaborator Author

TAlonglong commented Oct 11, 2022

So, I have come up with an idea to, what to call it, override __getitem__ for the class FakeHDF5FileHandler2 in test_hy2_scat_l2b_h5.py like this:

class FakeHDF5FileHandler2(FakeHDF5FileHandler):
    """Swap-in HDF5 File Handler."""

    def __getitem__(self, key):
        # https://stackoverflow.com/questions/2390827/how-to-properly-subclass-dict-and-override-getitem-setitem
        val = self.file_content.__getitem__(key)
        if isinstance(val, xr.core.dataarray.DataArray):
            val = val.copy()
        return val

By doing this the original test fails for none NSOAS data as they are expected to do.

I hope I can do this and adding my fix to the code as already in the PR.
Any comments on this?

@djhoese
Copy link
Member

djhoese commented Oct 11, 2022

I'm still not sure what the original issue is but if you think this helps then try it out and let's see how it goes. FYI val = self.file_content.__getitem__(key) is the same as val = self.file_content[key].

@TAlonglong TAlonglong requested a review from adybbroe as a code owner October 11, 2022 14:04
Trygve Aspenes added 2 commits October 11, 2022 16:08
@codecov
Copy link

codecov bot commented Oct 11, 2022

Codecov Report

Merging #2211 (4f269d7) into main (8c1ccdd) will increase coverage by 0.01%.
The diff coverage is 98.41%.

@@            Coverage Diff             @@
##             main    #2211      +/-   ##
==========================================
+ Coverage   94.13%   94.15%   +0.01%     
==========================================
  Files         293      294       +1     
  Lines       45079    45203     +124     
==========================================
+ Hits        42437    42559     +122     
- Misses       2642     2644       +2     
Flag Coverage Δ
behaviourtests 4.67% <0.00%> (-0.02%) ⬇️
unittests 94.80% <98.41%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
satpy/tests/test_utils.py 100.00% <ø> (ø)
satpy/readers/viirs_edr_active_fires.py 91.93% <50.00%> (ø)
satpy/readers/seadas_l2.py 96.84% <96.66%> (-1.28%) ⬇️
satpy/composites/ahi.py 100.00% <100.00%> (ø)
satpy/composites/spectral.py 100.00% <100.00%> (ø)
satpy/enhancements/viirs.py 100.00% <100.00%> (ø)
satpy/readers/abi_base.py 94.52% <100.00%> (+0.07%) ⬆️
satpy/readers/hy2_scat_l2b_h5.py 98.33% <100.00%> (+0.11%) ⬆️
satpy/scene.py 93.37% <100.00%> (+0.01%) ⬆️
satpy/tests/reader_tests/test_abi_l2_nc.py 100.00% <100.00%> (ø)
... and 5 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@coveralls
Copy link

coveralls commented Oct 11, 2022

Coverage Status

Coverage increased (+0.01%) to 94.75% when pulling 4f269d7 on TAlonglong:issue2208-hy2-scat-l2b-h5-valid-range into 8c1ccdd on pytroll:main.

@TAlonglong
Copy link
Collaborator Author

pre-commit.ci autofix

@TAlonglong TAlonglong requested review from mraspaud and removed request for adybbroe and djhoese October 12, 2022 06:14
@mraspaud
Copy link
Member

mraspaud commented Nov 9, 2022

@TAlonglong could you try to clean up the history here? there are a lot of old commits hanging around, and that makes is particularly difficult to review

@TAlonglong
Copy link
Collaborator Author

yeah, I think I did some merge from the main or rebase that messed this up. I never get these things right.

I don't understand how I could clean this up. I will need to have a look around to see if I can figure something out.

@djhoese
Copy link
Member

djhoese commented Nov 10, 2022

I would suggest maybe creating a new branch off of current main, then doing git cherry-pick <commit SHA> for each one of your actual commits in this PR. If you do them in order then it might not be too bad.

@TAlonglong TAlonglong mentioned this pull request Nov 10, 2022
3 tasks
@TAlonglong
Copy link
Collaborator Author

Okay, so I partly did what David suggested. But there was mess of try and fail code, so cherry picking became difficult. So I ended up to create a diff patch and apply that to a new branch #2268

Please feel free to close this PR if that work out.

@mraspaud
Copy link
Member

I merged #2268, so closing this

@mraspaud mraspaud closed this Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code cleanup but otherwise no change in functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hy2_scat_l2b_h5 reader does not work any more due to space in valid range attribute
6 participants