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

Add LI L2 reader #2271

Merged
merged 47 commits into from
Dec 15, 2022
Merged

Add LI L2 reader #2271

merged 47 commits into from
Dec 15, 2022

Conversation

seenno
Copy link
Contributor

@seenno seenno commented Nov 11, 2022

Add LI L2 reader and remove the old code as it's obsolete.
The reader handles both, LI L2 point products (LI-LE, LI-LEF, LI-LGR, LI-LFL) and LI L2 accumulated products (LI-AF, LI-AFR, LI-AFA). For the accumulated products, the reader supports the output as a gridded product. This can be activated by adding the reader kwarg with_area_definition=True.

@ameraner ameraner requested a review from sjoro November 11, 2022 11:26
@ameraner ameraner added enhancement code enhancements, features, improvements component:readers PCW Pytroll Contributors' Week pre-launch For instruments not yet launched labels Nov 11, 2022
@ameraner
Copy link
Member

ameraner commented Nov 14, 2022

The tests are failing with

self = <[RecursionError('maximum recursion depth exceeded') raised in repr()] DataArray object at 0x7feb90f7dc40>
data = dask.array<broadcast_to, shape=(123,), dtype=datetime64[ns], chunksize=(123,), chunktype=numpy.ndarray>
coords = Coordinates:
    *empty*, dims = ('scalar',), name = None, attrs = {}
indexes = Indexes:
    *empty*, fastpath = False

    def __init__(
        self,
        data: Any = dtypes.NA,
        coords: Sequence[Sequence[Any] | pd.Index | DataArray]
        | Mapping[Any, Any]
        | None = None,
        dims: Hashable | Sequence[Hashable] | None = None,
        name: Hashable = None,
        attrs: Mapping = None,
        # internal parameters
        indexes: dict[Hashable, Index] = None,
        fastpath: bool = False,
    ) -> None:
        if fastpath:
            variable = data
            assert dims is None
            assert attrs is None
            assert indexes is not None
        else:
            # TODO: (benbovy - explicit indexes) remove
            # once it becomes part of the public interface
            if indexes is not None:
>               raise ValueError("Providing explicit indexes is not supported yet")
E               ValueError: Providing explicit indexes is not supported yet

/usr/share/miniconda3/envs/test-environment/lib/python3.9/site-packages/xarray/core/dataarray.py:395: ValueError

at line https://github.com/pytroll/satpy/pull/2271/files#diff-3b2bff08b4001ec6f72cca67791cc4322b38e0db97e68f2109791093e56e6052R595
We actually need to define the indexes for the reader to work as intended...

It seems a regression of xarray, since the tests are passing e.g. with xarray-2022.3.0, but failing with 2022.11.0 and the current xarray master.
Any idea? @djhoese is this related to the RecursionError issues we saw for the ancillary_variables recently?

@djhoese
Copy link
Member

djhoese commented Nov 14, 2022

No this isn't related to my stuff at all. Did this work in the past? Why do you need to provide the indexes from the base DataArray?

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.

Some preliminary comments. Also, CodeScene makes good points

satpy/readers/li_base_nc.py Outdated Show resolved Hide resolved
satpy/readers/li_base_nc.py Outdated Show resolved Hide resolved
Comment on lines +333 to +337
lon, lat = da.map_blocks(self.inverse_projection, azimuth, elevation, proj_dict,
chunks=(2, azimuth.shape[0]),
meta=np.array((), dtype=azimuth.dtype),
dtype=azimuth.dtype,
)
Copy link
Member

Choose a reason for hiding this comment

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

don't we already have this implemented somewhere ? In pyresample maybe?

Copy link
Member

Choose a reason for hiding this comment

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

The code was inspired by this code snippet here https://github.com/pytroll/pyresample/blob/952cec6ee4bce55bb70f2c1237401356645bc3f6/pyresample/geometry.py#L2434-L2441, that is encapsulated in get_lonlats of AreaDefinition. As in the end it's only a simple map_blocks call, I would propose to leave it like this, if you agree.

satpy/readers/li_base_nc.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Nov 15, 2022

Codecov Report

Merging #2271 (fed60b7) into main (c81e02e) will increase coverage by 0.24%.
The diff coverage is 99.76%.

@@            Coverage Diff             @@
##             main    #2271      +/-   ##
==========================================
+ Coverage   94.32%   94.56%   +0.24%     
==========================================
  Files         308      313       +5     
  Lines       46168    47425    +1257     
==========================================
+ Hits        43546    44849    +1303     
+ Misses       2622     2576      -46     
Flag Coverage Δ
behaviourtests 4.51% <0.00%> (-0.10%) ⬇️
unittests 95.20% <99.76%> (+0.24%) ⬆️

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

Impacted Files Coverage Δ
satpy/tests/reader_tests/_li_test_utils.py 99.23% <99.23%> (ø)
satpy/tests/reader_tests/test_li_l2_nc.py 99.75% <99.75%> (ø)
satpy/readers/li_base_nc.py 100.00% <100.00%> (ø)
satpy/readers/li_l2_nc.py 100.00% <100.00%> (ø)
satpy/readers/netcdf_utils.py 98.32% <0.00%> (-1.68%) ⬇️
satpy/tests/test_resample.py 88.90% <0.00%> (-0.37%) ⬇️
satpy/readers/yaml_reader.py 97.49% <0.00%> (-0.01%) ⬇️
satpy/tests/test_utils.py 100.00% <0.00%> (ø)
satpy/readers/seviri_base.py 100.00% <0.00%> (ø)
satpy/tests/reader_tests/test_fci_l1c_nc.py 100.00% <0.00%> (ø)
... and 18 more

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

…r class call in `li_base_nc.py`; Remove `get_area_definition()` and `get_bounding_box()` overriding in `li_base_nc.py`.
@ameraner
Copy link
Member

ameraner commented Nov 15, 2022

Sorry @djhoese, I just noticed that the code formatting in my comment swallowed the first line (edited now), which somehow points to a RecursionError.. that's why I was asking about the RecursionErrors we saw lately.

But the issue seems actually to be in the passing of the indexes. The reader actually works without it, so we just removed it (note that this code has been written by external contractors, so we are not fully aware of all the code details).

More info on the indexes if you're interested, from my investigation:
In old-ish versions of xarray (<=2022.03), xr.DataArray was accepting indexes in the init, but I think it was not actually using it unless when passing fastpath=True (see this bit from 2022.03 https://github.com/pydata/xarray/blob/v2022.03.0/xarray/core/dataarray.py#L404-L416, the docstring doesn't mention this..). From 2022.06.0rc0 on, they implemented the ValueError check referenced above, I suppose to avoid this silent ignoring.. However, it seems that xarray devs are picking up this again in the last weeks, see pydata/xarray#7214.

@coveralls
Copy link

coveralls commented Nov 15, 2022

Coverage Status

Coverage increased (+0.2%) to 95.149% when pulling fed60b7 on seenno:add_lil2_reader into c81e02e on pytroll:main.

Copy link
Member

@pnuu pnuu left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@sjoro sjoro left a comment

Choose a reason for hiding this comment

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

a small request to maybe define a new constant in order to avoid hard coding 5568 in various places in the code.

satpy/readers/li_l2_nc.py Show resolved Hide resolved
satpy/readers/li_l2_nc.py Outdated Show resolved Hide resolved
satpy/tests/reader_tests/test_li_l2_nc.py Outdated Show resolved Hide resolved
satpy/tests/reader_tests/test_li_l2_nc.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@sjoro sjoro left a comment

Choose a reason for hiding this comment

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

only one comment to clarify, otherwise looks good to me! thanks for your efforts on this reader @seenno and @ameraner !

satpy/readers/li_l2_nc.py Outdated Show resolved Hide resolved
@ameraner
Copy link
Member

ameraner commented Dec 7, 2022

So we added some new tests to improve coverage (now we're at 100% for both the reader files 🙂). Also most CodeScene comments were addressed, the few remaining ones complain about the tests setup file, that contains the mocked files structures... I don't think it makes sense to improve this further.
So from our side this is ready now.

@sjoro sjoro self-requested a review December 12, 2022 10:07
Copy link
Collaborator

@sjoro sjoro left a comment

Choose a reason for hiding this comment

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

LGTM!

@pnuu pnuu merged commit c339a33 into pytroll:main Dec 15, 2022
@seenno
Copy link
Contributor Author

seenno commented Dec 15, 2022

Thank you everyone who contributed, either as a reviewer or helping me to understand Satpy and its coding style :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:readers enhancement code enhancements, features, improvements PCW Pytroll Contributors' Week pre-launch For instruments not yet launched
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Update li_l2-reader to read MTG LI L2 test data
7 participants