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

Centroids.set_geometry_points is now missing in develop without deprecation warning #884

Open
ThomasRoosli opened this issue May 23, 2024 · 4 comments

Comments

@ThomasRoosli
Copy link
Collaborator

ThomasRoosli commented May 23, 2024

Problem:
I wanted to rerun a previously working code (e.g. on the current main branch) using the develop branch and it suddenly failed.

import xarray as xr
import numpy as np
import datetime as dt
from climada.hazard import Hazard
"""Write a simple NetCDF file to read"""
netcdf_path = "default.nc"
intensity = np.array([[[0, 1, 2], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]]])
time = np.array([dt.datetime(1999, 1, 1), dt.datetime(2000, 1, 1)])
latitude = np.array([0, 1])
longitude = np.array([0, 1, 2])
dset = xr.Dataset(
    {
        "intensity": (["time", "latitude", "longitude"], intensity),
    },
    dict(time=time, latitude=latitude, longitude=longitude),
)
dset.to_netcdf(netcdf_path)

hazard = Hazard.from_xarray_raster_file(netcdf_path, "", "")

hazard.centroids.geometry
# output:
# GeoSeries([], dtype: geometry)
hazard.centroids.set_geometry_points() # <- this line fails in current develop branch
hazard.centroids.geometry
# output:
# 0    POINT (0.00000 0.00000)
# 1    POINT (1.00000 0.00000)
# 2    POINT (2.00000 0.00000)
# 3    POINT (0.00000 1.00000)
# 4    POINT (1.00000 1.00000)
# 5    POINT (2.00000 1.00000)
# dtype: geometry

Possible solution:
Have you considered keeping an "empty" set_geometry_points method instead of just removing it and issuing a deprecated warning informing the user that this function is now useless?
The code would run through smoothly and the result would be correct because now the geometry is already correctly set automatically...

Alternative solution:
I assume the next release would be a major release, so maybe keeping such functionality is not important?

@peanutfun
Copy link
Member

Indeed. During the refactoring of Centroids, many methods have been removed, see https://github.com/CLIMADA-project/climada_python/blob/develop/CHANGELOG.md#removed

We tried to deprecate methods that should not be used anymore, and immediately removed methods that have no use anymore. However, for methods like set_geometry_points we could indeed retain a stub that does nothing and issues a deprecation warning. We will go through this again and update Centroids accordingly.

Indeed, the next release will be a major, breaking release for these reasons.

@peanutfun
Copy link
Member

Methods for which we could provide deprecation warnings:

Method to deprecate Action it takes
Hazard.clear creates new, empty hazard
Centroids.check nothing
Centroids.clear clears GDF
Centroids.read_hdf5 Calls read_hdf5 on GDF
Centroids.set_elevation nothing
Centroids.set_geometry_points nothing
Centroids.set_lat_lon nothing

@chahank

@peanutfun
Copy link
Member

Centroids.calc_pixels_polygons is used in #857 and might need to be re-introduced.

@chahank
Copy link
Member

chahank commented Jun 14, 2024

Looking at the proposed changes in #587 I fail to see why this method would actually be needed. My understanding is that #857 is trying to use the now-refactored and deprecated raster and pixel logic. But I do not see why this would be necessary for achieving the goal of #857 which to allow the computation, visualization and storage of local frequency exceedance intensities of hazards. So, we might first try to bring #857 up to date with the refactored centroids, and then see whether Centroids.calc_pixels_polygons is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants