-
Notifications
You must be signed in to change notification settings - Fork 94
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 optional metadata to Pyresample 2.0 AreaDefinition #464
Changes from all commits
97660d1
d350168
2fcabc9
545c5c4
2869938
edebe75
2a1afb7
c4cc9bd
da6abd6
d624e3f
3d3c842
4e90852
1135ff5
f528ca8
d1c40c6
97dbf70
f90e95c
1e2f40d
d22502f
7d8b2b6
22c3964
2fb0611
8b2b32b
88eeb62
be2bf83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,7 +1,7 @@ | ||||||
#!/usr/bin/env python | ||||||
# -*- coding: utf-8 -*- | ||||||
# | ||||||
# Copyright (c) 2021 Pyresample developers | ||||||
# Copyright (c) 2021-2022 Pyresample developers | ||||||
# | ||||||
# This program is free software: you can redistribute it and/or modify it under | ||||||
# the terms of the GNU Lesser General Public License as published by the Free | ||||||
|
@@ -19,4 +19,106 @@ | |||||
|
||||||
from __future__ import annotations | ||||||
|
||||||
from pyresample.geometry import AreaDefinition, DynamicAreaDefinition # noqa | ||||||
from typing import Optional, Union | ||||||
|
||||||
from pyproj import CRS | ||||||
|
||||||
from pyresample.geometry import AreaDefinition as LegacyAreaDefinition # noqa | ||||||
from pyresample.geometry import ( # noqa | ||||||
DynamicAreaDefinition, | ||||||
get_full_geostationary_bounding_box_in_proj_coords, | ||||||
get_geostationary_angle_extent, | ||||||
get_geostationary_bounding_box_in_lonlats, | ||||||
get_geostationary_bounding_box_in_proj_coords, | ||||||
) | ||||||
|
||||||
|
||||||
class AreaDefinition(LegacyAreaDefinition): | ||||||
"""Uniformly-spaced grid of pixels on a coordinate referenced system. | ||||||
|
||||||
Args: | ||||||
crs: | ||||||
Dictionary of PROJ parameters or string of PROJ or WKT parameters. | ||||||
Can also be a :class:`pyproj.crs.CRS` object. | ||||||
width: | ||||||
x dimension in number of pixels, aka number of grid columns | ||||||
height: | ||||||
y dimension in number of pixels, aka number of grid rows | ||||||
area_extent: | ||||||
Area extent as a list (lower_left_x, lower_left_y, upper_right_x, upper_right_y) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
attrs: | ||||||
Arbitrary metadata related to the area. Some keys in this | ||||||
dictionary have special meaning and may be used for various | ||||||
logging or serialization processes. The primary special keys are: | ||||||
|
||||||
* name: The identifying name for this area. This is equivalent | ||||||
to 'area_id' in the legacy AreaDefinition class. It is used | ||||||
in YAML serialization if provided. Defaults to an empty string | ||||||
if not provided. Not providing this should not affect normal | ||||||
coordinate operations. | ||||||
* description: A human-readable description of the area. This is | ||||||
equivalent to 'description' in the legacy AreaDefinition class. | ||||||
It is used in YAML serialization if provided. | ||||||
|
||||||
Attributes: | ||||||
area_id (str): | ||||||
Identifier for the area. This is a convenience for backwards | ||||||
compatibility and accesses the ``.attrs['name']`` metadata. | ||||||
This will be set to an empty string if not provided. | ||||||
width (int): | ||||||
x dimension in number of pixels, aka number of grid columns | ||||||
height (int): | ||||||
y dimension in number of pixels, aka number of grid rows | ||||||
size (int): | ||||||
Number of points in grid | ||||||
area_extent_ll (tuple): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the attributes, it should be listed also the |
||||||
Area extent in lons lats as a tuple (lower_left_lon, lower_left_lat, upper_right_lon, upper_right_lat) | ||||||
pixel_size_x (float): | ||||||
Pixel width in projection units | ||||||
pixel_size_y (float): | ||||||
Pixel height in projection units | ||||||
upper_left_extent (tuple): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
Coordinates (x, y) of upper left corner of upper left pixel in projection units | ||||||
pixel_upper_left (tuple): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a thought: maybe |
||||||
Coordinates (x, y) of center of upper left pixel in projection units | ||||||
pixel_offset_x (float): | ||||||
x offset between projection center and upper left corner of upper | ||||||
left pixel in units of pixels. | ||||||
pixel_offset_y (float): | ||||||
y offset between projection center and upper left corner of upper | ||||||
left pixel in units of pixels. | ||||||
crs (CRS): | ||||||
Coordinate reference system object similar to the PROJ parameters in | ||||||
`proj_dict` and `proj_str`. This is the preferred attribute to use | ||||||
when working with the `pyproj` library. Note, however, that this | ||||||
object is not thread-safe and should not be passed between threads. | ||||||
attrs (dict): | ||||||
Arbitrary metadata related to the area. | ||||||
|
||||||
""" | ||||||
|
||||||
def __init__( | ||||||
self, | ||||||
crs: Union[str, int, dict, CRS], | ||||||
width: int, | ||||||
height: int, | ||||||
area_extent: tuple[float, float, float, float], | ||||||
attrs: Optional[dict] = None | ||||||
): | ||||||
# FUTURE: Maybe do `shape` instead of the separate height and width | ||||||
mraspaud marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
# FUTURE: Add 'to_legacy()' method | ||||||
# FUTURE: Add __slots__ | ||||||
# FUTURE: Convert this to new class that uses a legacy area internally | ||||||
# Use this to more easily deprecate usage of old properties | ||||||
attrs = attrs or {} | ||||||
area_id = attrs.get("name", "") | ||||||
super().__init__( | ||||||
area_id, | ||||||
"", | ||||||
area_id, | ||||||
crs, | ||||||
width, | ||||||
height, | ||||||
area_extent, | ||||||
) | ||||||
self.attrs = attrs | ||||||
mraspaud marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) 2021-2022 Pyresample developers | ||
# | ||
# This program is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU Lesser General Public License as published by the Free | ||
# Software Foundation, either version 3 of the License, or (at your option) any | ||
# later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License along | ||
# with this program. If not, see <http://www.gnu.org/licenses/>. | ||
"""Base geometry definitions and utility functions.""" | ||
|
||
from pyresample.geometry import BaseDefinition, get_array_hashable # noqa |
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.
Do we want the new area def to inherit all the methods of the legacy one, or do we want to split responsibility a bit?
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 struggled with this decision. Initially this class in the
future
subpackage didn't have anything custom about it so it was just a basic import. I think for ease of transitioning to future we might want it to be a subclass so thatisinstance
checks still work? Or maybe usages of stuff like that should be fixed to be more duck-typing-friendly?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 vote for more duck typing.
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.
Please read my other comments. That is the plan, but I don't want to throw that all into one PR and I also don't want to deal with all the tests failing because I didn't implement one of 50 methods on the legacy AreaDefinition class. The plan is to do this work in one of the next 2 or 3 PRs.