Skip to content

Commit

Permalink
Deprecate superfluous classmethods of Centroids (#721)
Browse files Browse the repository at this point in the history
* Deprecate superfluous classmethods of Centroids

* Update CHANGELOG.md

* Mention dropping support for non-regular grids

---------

Co-authored-by: Chahan Kropf <chahan.kropf@posteo.com>
  • Loading branch information
peanutfun and Chahan Kropf authored May 15, 2023
1 parent c480111 commit 76d6d36
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ Removed:

### Deprecated

- `Centroids.from_geodataframe` and `Centroids.from_pix_bounds` [#721](https://github.com/CLIMADA-project/climada_python/pull/721)

### Removed

- `Centroids.set_raster_from_pix_bounds` [#721](https://github.com/CLIMADA-project/climada_python/pull/721)

- `requirements/env_developer.yml` environment specs. Use 'extra' requirements when installing the Python package instead [#712](https://github.com/CLIMADA-project/climada_python/pull/712)

## v3.3.2
Expand Down
25 changes: 19 additions & 6 deletions climada/hazard/centroids/centr.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ def from_base_grid(land=False, res_as=360, base_file=None):
def from_geodataframe(cls, gdf, geometry_alias='geom'):
"""Create Centroids instance from GeoDataFrame.
.. deprecated:: 3.3
This method will be removed in a future version. Pass the data you want to
construct the Centroids with to the constructor instead.
The geometry, lat, and lon attributes are set from the GeoDataFrame.geometry attribute,
while the columns are copied as attributes to the Centroids object in the form of
numpy.ndarrays using pandas.Series.to_numpy. The Series dtype will thus be respected.
Expand Down Expand Up @@ -274,6 +278,11 @@ def from_geodataframe(cls, gdf, geometry_alias='geom'):
centr : Centroids
Centroids with data from given GeoDataFrame
"""
LOGGER.warning(
"Centroids.from_geodataframe has been deprecated and will be removed in a "
"future version. Use ther default constructor instead."
)

geometry = gdf.geometry
lat = gdf.geometry.y.to_numpy(copy=True)
lon = gdf.geometry.x.to_numpy(copy=True)
Expand All @@ -293,16 +302,15 @@ def from_geodataframe(cls, gdf, geometry_alias='geom'):

return centroids

def set_raster_from_pix_bounds(self, *args, **kwargs):
"""This function is deprecated, use Centroids.from_pix_bounds instead."""
LOGGER.warning("The use of Centroids.set_raster_from_pix_bounds is deprecated. "
"Use Centroids.from_pix_bounds instead.")
self.__dict__ = Centroids.from_pix_bounds(*args, **kwargs).__dict__

@classmethod
def from_pix_bounds(cls, xf_lat, xo_lon, d_lat, d_lon, n_lat, n_lon, crs=DEF_CRS):
"""Create Centroids object with meta attribute according to pixel border data.
.. deprecated:: 3.3
This method will be removed in a future version. CLIMADA will only support
regular grids with a constant lat/lon resolution then. Use
:py:meth:`from_pnt_bounds` instead.
Parameters
----------
xf_lat : float
Expand All @@ -325,6 +333,11 @@ def from_pix_bounds(cls, xf_lat, xo_lon, d_lat, d_lon, n_lat, n_lon, crs=DEF_CRS
centr : Centroids
Centroids with meta according to given pixel border data.
"""
LOGGER.warning(
"Centroids.from_pix_bounds has been deprecated and will be removed in a "
"future version. Use Centroids.from_pnt_bounds instead."
)

meta = {
'dtype': 'float32',
'width': n_lon,
Expand Down

0 comments on commit 76d6d36

Please sign in to comment.