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 attrs to future swath definition #578

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion pyresample/future/geometry/swath.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,40 @@

from __future__ import annotations

from pyresample.geometry import CoordinateDefinition, SwathDefinition # noqa
from pyresample.geometry import CoordinateDefinition # noqa
from pyresample.geometry import SwathDefinition as LegacySwathDefinition


class SwathDefinition(LegacySwathDefinition):
"""Swath defined by lons and lats.

Parameters
----------
lons : numpy array
lats : numpy array
crs: pyproj.CRS,
The CRS to use. longlat on WGS84 by default.
nprocs : int, optional
Number of processor cores to be used for calculations.
attrs: dict,
A dictionary made to store metadata.

Attributes
----------
shape : tuple
Swath shape
size : int
Number of elements in swath
ndims : int
Swath dimensions
lons : object
Swath lons
lats : object
Swath lats
cartesian_coords : object
Swath cartesian coordinates
"""

def __init__(self, lons, lats, crs=None, nprocs=1, attrs=None):
Copy link
Member

Choose a reason for hiding this comment

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

Please remove nprocs. The commit message says "for backwards compatibility". There is no backwards compatibility in the future modules...at least let's try really hard to avoid it. If it is going to be here then it at least needs a warning or something about it being deprecated. But I'd rather have a create_swath_def pytest fixture that excludes nprocs from the kwargs when creating the new version of the swath class.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I didn't understand the gist of your previous comments obviously. Removing.

Copy link
Member Author

Choose a reason for hiding this comment

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

done, ready for rereview :)

super().__init__(lons, lats, crs=crs, nprocs=nprocs)
self.attrs = attrs or {}
8 changes: 8 additions & 0 deletions pyresample/test/test_geometry/test_swath.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,11 @@ def assert_np_dict_allclose(dict1, dict2):
np.testing.assert_allclose(val, dict2[key])
except TypeError:
assert val == dict2[key]


def test_future_swath_has_attrs():
"""Test that future SwathDefinition has attrs."""
from pyresample.future.geometry import SwathDefinition
lons, lats = _gen_swath_lons_lats()
swath = SwathDefinition(lons, lats)
assert isinstance(swath.attrs, dict)
Loading