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

Fix osisaf SST reader #1410

Merged
merged 21 commits into from Apr 14, 2022
Merged

Fix osisaf SST reader #1410

merged 21 commits into from Apr 14, 2022

Conversation

adybbroe
Copy link
Contributor

@adybbroe adybbroe commented Oct 20, 2020

Adding support for reading OSISAF GHRSST formattet SST data.
There was some code to read the OSISAF SST but wasn't really finished. Further the SLSTR-L2 reader was actually a GHRSST reader, and both OSISAF and SLSTR-L2 follow the GHRSST format standard. So we can make use of the same code.

  • The satpy/etc/readers/ghrsst_l3c_sst.yamlhas been removed and replaced by ghrsst_l2.yaml
  • The reader slstr_l2.py has been replaced by ghrsst_l2.py, which is only a slightly modified/enhanced compared to slstr_l2.py
  • Renamed the test module test_slstr_l2.py to test_ghrsst_l2.py
  • And finally I have added an enhancement in generic.yaml to display the SST using a colormap - I suppose we should remove that and instead suggest how to do this via the documentation or the pytroll-examples?
  • Closes #xxxx
  • Tests added
  • Passes flake8 satpy
  • Fully documented

Adam.Dybbroe added 2 commits October 20, 2020 13:08
@adybbroe adybbroe self-assigned this Oct 20, 2020
@adybbroe adybbroe added bug enhancement code enhancements, features, improvements hacktoberfest labels Oct 20, 2020
@adybbroe
Copy link
Contributor Author

I have two yaml files, one for OSISAF (ghrsst_l2.yaml) and one for SLSTR (the old name slstr_l2). Both use the same python code. But the SLSTR one has sensors = slstr obviously. The OSISAF SST is one product but from either VIIRS or AVHRR.
Should we try have one yaml file anyhow, and how do we deal with the sensors attribute then? Or should we keep two yaml files? If yes to the latter I guess we/I should rename them?

@mraspaud
Copy link
Member

iirc you can add a sensor property to the file handler, so you would need only one yaml file.

@adybbroe adybbroe removed the request for review from simonrp84 October 21, 2020 09:41
@adybbroe
Copy link
Contributor Author

Ok, thanks @mraspaud
But wouldn't that mean I would have two entries for the same sea_surface_temperature filed?
Or do you mean something like this:

  sea_surface_temperature_osisaf:
    name: sea_surface_temperature
    coordinates: [longitude_osisaf, latitude_osisaf]
    file_type: GHRSST_OSISAF
    resolution: 2000
    units: kelvin
    standard_name: sea_surface_temperature

  sea_surface_temperature_slstr:
    name: sea_surface_temperature
    sensor: slstr
    coordinates: [longitude_slstr, latitude_slstr]
    file_type: SLSTR
    resolution: 1000
    view: nadir
    units: kelvin
    standard_name: sea_surface_temperature

?

@mraspaud
Copy link
Member

no I mean in the filehandler python code

…th SLSTR and OSISAF

Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
@ghost
Copy link

ghost commented Oct 21, 2020

DeepCode's analysis on #1d2e85 found:

  • ℹ️ 1 minor issue. 👇

Top issues

Description Example fixes
standard import "import tarfile" should be placed before "from satpy.readers.file_handlers import BaseFileHandler" Occurrences: 🔧 Example fixes

👉 View analysis in DeepCode’s Dashboard | Configure the bot

@adybbroe
Copy link
Contributor Author

I see what you mean @mraspaud
Not sure though how that is then used with advantage in the yaml file.
Have created one yaml file for both products (OSISAF & SLSTR) ad I can read and project and display both.
But the yaml file seems a bit clumsy still

Adam.Dybbroe added 4 commits March 22, 2022 16:15
# Conflicts:
#	satpy/etc/readers/slstr_l2.yaml
#	satpy/readers/ghrsst_l2.py

Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Color legend originally provided by MET Norway and the OSISAF
@adybbroe
Copy link
Contributor Author

adybbroe commented Mar 25, 2022

This code now produce the image below:

    scn = Scene(filenames=OSISAF_SST_FILES, reader='ghrsst_l2')
    scn.load(['sea_surface_temperature'])
    local_scn = scn.resample('euron1')
    local_scn.show('sea_surface_temperature')

osisaf_sst_smhi_palette_20220321_1126_small

Using the enhancement here:

  osisaf_sst_smhi_colormap:
    standard_name: sea_surface_subskin_temperature
    operations:
    - name: osisaf_sst
      method: !!python/name:satpy.enhancements.colorize
      kwargs:
          palettes:
            - colors: [
              [255, 0, 255],
              [195, 0, 129],
              [129, 0, 47],
              [195, 0, 0],
              [255, 0, 0],
              [236, 43, 0],
              [217, 86, 0],
              [200, 128, 0],
              [211, 154, 13],
              [222, 180, 26],
              [233, 206, 39],
              [244, 232, 52],
              [255.99609375, 255.99609375, 63.22265625],
              [203.125, 255.99609375, 52.734375],
              [136.71875, 255.99609375, 27.34375],
              [0, 255.99609375, 0],
              [0, 207.47265625, 0],
              [0, 158.94921875, 0],
              [0, 110.42578125, 0],
              [0, 82.8203125, 63.99609375],
              [0, 55.21484375, 127.9921875],
              [0, 27.609375, 191.98828125],
              [0, 0, 255.99609375],
              [100.390625, 100.390625, 255.99609375],
              [150.5859375, 150.5859375, 255.99609375]]
              min_value: 296.55
              max_value: 273.55

It is supposed to look as similar as possible to the imagery we currently produce at SMHI with mpop. The corresponding image and its diff is added below:

osisaf_sst_noaa-20_20220321_12_euron1_small

diff_sst_small

Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
@adybbroe adybbroe marked this pull request as ready for review March 30, 2022 13:44
@adybbroe adybbroe requested a review from djhoese as a code owner March 30, 2022 13:44
@adybbroe
Copy link
Contributor Author

I have added a PR (#2075) documenting how the use of a colorize enhancement as above can be done. So I am ready to remove the part in the enhancement.yaml file. I have, however, also asked the OSISAF if they could confirm the coloring above or provide what they regard as the standard. In which case I think it would be fair to include it among the default enhancements. Agree?

@adybbroe
Copy link
Contributor Author

adybbroe commented Apr 2, 2022

Got an answer from our colleagues in the OSISAF. There is yet no standard/official OSISAF color scale to refer to, so I suggest we remove it from the general.yaml file in this PR.

@adybbroe adybbroe requested a review from simonrp84 April 4, 2022 12:55
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 this PR, looks promising. Some inline comments.

satpy/etc/enhancements/generic.yaml Outdated Show resolved Hide resolved
satpy/readers/ghrsst_l2.py Outdated Show resolved Hide resolved
satpy/readers/ghrsst_l2.py Outdated Show resolved Hide resolved
satpy/etc/readers/ghrsst_l2.yaml Show resolved Hide resolved
adybbroe and others added 3 commits April 6, 2022 09:21
Follow Python 3 standard for class inherritance

Co-authored-by: Martin Raspaud <martin.raspaud@smhi.se>
… reading

Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
@codecov
Copy link

codecov bot commented Apr 6, 2022

Codecov Report

Merging #1410 (e3d7dda) into main (d4c4332) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1410      +/-   ##
==========================================
+ Coverage   93.86%   93.89%   +0.02%     
==========================================
  Files         283      283              
  Lines       42379    42583     +204     
==========================================
+ Hits        39781    39985     +204     
  Misses       2598     2598              
Flag Coverage Δ
behaviourtests 4.70% <0.00%> (-0.03%) ⬇️
unittests 94.45% <100.00%> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
satpy/composites/__init__.py 89.94% <ø> (ø)
satpy/readers/ghrsst_l2.py 100.00% <100.00%> (ø)
satpy/tests/reader_tests/test_ghrsst_l2.py 100.00% <100.00%> (ø)
satpy/readers/ghrsst_l3c_sst.py 0.00% <0.00%> (-7.05%) ⬇️
satpy/modifiers/_crefl.py 92.40% <0.00%> (-0.62%) ⬇️
satpy/tests/test_crefl_utils.py 100.00% <0.00%> (ø)
satpy/readers/seviri_l1b_hrit.py 90.14% <0.00%> (ø)
satpy/tests/reader_tests/test_utils.py 100.00% <0.00%> (ø)
satpy/tests/reader_tests/test_fci_l1c_nc.py 100.00% <0.00%> (ø)
satpy/tests/reader_tests/test_viirs_l1b.py 97.26% <0.00%> (+0.06%) ⬆️
... and 7 more

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 d4c4332...e3d7dda. Read the comment docs.

@coveralls
Copy link

coveralls commented Apr 6, 2022

Coverage Status

Coverage increased (+0.03%) to 94.397% when pulling e3d7dda on adybbroe:fix-osisaf-reader into d4c4332 on pytroll:main.

… object instead

Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
@adybbroe
Copy link
Contributor Author

adybbroe commented Apr 7, 2022

I tested the reader on the SLSTR files of this type: S3A_SL_2_WST____20220406T095733_20220406T100033_20220406T120437_0179_084_022_2340_ MAR_O_NR_003.SEN3.tar

and on the OSISAF netCDF files of this type: S-OSI_-FRA_-MTOP-NARSST_FIELD-202204061000Z.nc

Here are the results of both at the approximate same time morning April 6th, 2022 over Scandinavia (SLSTR to the right):
osisaf_and_slstr_sst_20220406_1000_and_0942

Copy link
Member

@sfinkens sfinkens left a comment

Choose a reason for hiding this comment

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

Nice work! Just a couple questions about readability.

with tempfile.TemporaryDirectory() as tempdir:
with tarfile.open(name=filename, mode='r') as tf:
sst_filename = next((name for name in tf.getnames()
if name.endswith('nc') and 'GHRSST-SSTskin' in name))
if name.endswith('nc') and 'GHRSST-SSTskin' in name))
Copy link
Member

Choose a reason for hiding this comment

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

You could move the if condition to a separate method, _is_sst_file for instance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion, I will fix

mocked_dataset.assert_called()
mocked_dataset.reset_mock()

with patch('tarfile.open') as tf:
Copy link
Member

Choose a reason for hiding this comment

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

Instead of mocking, would it be possible to write such a tarfile during test setup?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think this is a good idea. I will come back with a proposal

satpy/tests/reader_tests/test_ghrsst_l2.py Outdated Show resolved Hide resolved
satpy/tests/reader_tests/test_ghrsst_l2.py Outdated Show resolved Hide resolved
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Copy link
Member

@sfinkens sfinkens left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for refactoring the tests! Just two tiny comments

satpy/tests/reader_tests/test_ghrsst_l2.py Outdated Show resolved Hide resolved
satpy/readers/ghrsst_l2.py Outdated Show resolved Hide resolved
Adam.Dybbroe added 5 commits April 11, 2022 13:04
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
@adybbroe
Copy link
Contributor Author

@mraspaud Are my updates satisfactory do you think?

@mraspaud
Copy link
Member

yes, it look good now, but the tests are failing on windows, because of the classical permission error. However, as we are moving to pytest more now, I would suggest to transition the tests to pytest here too, and use the tmp_path fixture to handle temporary data and let pytest handle the removal of the temporary files/directories to come around the problem.

In an attempt to make the tests pass on Windows

Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
@adybbroe
Copy link
Contributor Author

Okay, so now the tests pass! There is a 0.02% decrease in test coverage. But the Coveralls page is not very friendly - don't see where this decrease sits?
I am off tomorrow, but hopefully it is good enough?

@adybbroe adybbroe requested a review from mraspaud April 13, 2022 21:49
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.

LGTM, much nicer with pytest!

@mraspaud mraspaud merged commit 37e77dd into pytroll:main Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug component:readers enhancement code enhancements, features, improvements hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants