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

exposures-init-geometry #890

Merged
merged 66 commits into from
Oct 21, 2024
Merged

exposures-init-geometry #890

merged 66 commits into from
Oct 21, 2024

Conversation

emanuel-schmid
Copy link
Collaborator

@emanuel-schmid emanuel-schmid commented Jun 11, 2024

Changes proposed in this PR:

  • create geometry and crs within Exposures.init
  • get rid of raster data (exp.meta)
  • introduce properties for cover, deductible, region_id, category_id, geometry, value, latitude, longitude
  • introduce methods to get the values (as np.array) of the impact function and the assigned centroids by hazard type

This PR fixes #

PR Author Checklist

PR Reviewer Checklist

@emanuel-schmid emanuel-schmid marked this pull request as draft June 11, 2024 12:55
@emanuel-schmid emanuel-schmid marked this pull request as ready for review July 16, 2024 09:18
Copy link
Collaborator

@spjuhel spjuhel left a comment

Choose a reason for hiding this comment

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

Great job !

A few comments in addition to the suggestion:

  • I think it would be important to give a more detailed description of what this PR does here and in the changelog. From what I understand, there are more changes than initializing the geometry within the init of Exposure.
  • A test is failing, not sure why.

I have a set of conceptual question:

  • The different attributes are now accessed as properties (for instance region_id). This looks cleaner, but doesn't it limit the possibility of adding custom attributes? (Technically, no, because I suppose you can just add new columns to data, but then access become inconsistent). Maybe this isn't a problem.
  • Similarly, setting region_id or other attributes is not possible after instantiation (or only via exp.data["region_id"] = new_value not consistent)

CHANGELOG.md Outdated
@@ -23,6 +37,8 @@ Code freeze date: YYYY-MM-DD
- Remove content tables and make minor improvements (fix typos and readability) in
CLIMADA tutorials. [#872](https://github.com/CLIMADA-project/climada_python/pull/872)
- Centroids complete overhaul. Most function should be backward compatible. Internal data is stored in a geodataframe attribute. Raster are now stored as points, and the meta attribute is removed. Several methds were deprecated or removed. [#787](https://github.com/CLIMADA-project/climada_python/pull/787)
- Exposures complete overhaul. Notably the _geometry_ column of the inherent `GeoDataFrame` is set up at initialization, while
latitude and longitude column are no longer persent there (the according arrays can be retrieved as properties of the Exposures object: `exp.latitude` instead of `exp.gdf.latitude.values`).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
latitude and longitude column are no longer persent there (the according arrays can be retrieved as properties of the Exposures object: `exp.latitude` instead of `exp.gdf.latitude.values`).
latitude and longitude column are no longer present there (the according arrays can be retrieved as properties of the Exposures object: `exp.latitude` instead of `exp.gdf["latitude"].values`).

climada/entity/exposures/base.py Outdated Show resolved Hide resolved
climada/entity/exposures/base.py Outdated Show resolved Hide resolved
self.assertEqual(exp.gdf.shape[0], len(exp.gdf[INDICATOR_CENTR + 'FL']))
np.testing.assert_array_equal(exp.gdf[INDICATOR_CENTR + 'FL'].values, expected_result)
self.assertEqual(exp.gdf.shape[0], len(exp.hazard_centroids('FL')))
np.testing.assert_array_equal(exp.hazard_centroids('FL'), expected_result)

def test__init__meta_type(self):
""" Check if meta of type list raises a ValueError in __init__"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
""" Check if meta of type list raises a ValueError in __init__"""
""" Check if meta of type list raises a TypeError in __init__"""

@spjuhel
Copy link
Collaborator

spjuhel commented Aug 23, 2024

I realized you can actually change/add columns directly with .gdf["colname"] contrary to what I thought, so ignore this part of my comment. It is actually quite nice that you can't change the GeoDataFrame object as a whole, but that you can change its elements!

I still have a concern if a user tries to change region_id or any other property and faces a cold property 'region_id' of 'Hazard' object has no setter

Maybe a placeholder setter explaining that you can actually change it through exp.gdf["region_id"] = whatever (or another method) would be a nice way to solve this?

@emanuel-schmid
Copy link
Collaborator Author

Maybe a placeholder setter explaining that you can actually change it through exp.gdf["region_id"] = whatever (or another method) would be a nice way to solve this?

Actually I'd prefer users to exp.data["region_id"] = whatever, exp.gdf has changed the name and the property is kept for (better) backwards compatibility. 😉

But you're right, setter methods for 'region_id', 'category_id' and the other properties are something we should consider. I'd like to delegate this to another PR though.

Copy link
Collaborator

@spjuhel spjuhel left a comment

Choose a reason for hiding this comment

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

Apart from the small thing to clarify about which columns of the DataFrame are required or not, I think this is good :)

Great work!

Comment on lines 43 to 52
"| Column | Data Type | Description | Meaningful in |\n",
"| :-------------------- | :------------ | :------------------------------------------------------------------------------------- | - |\n",
"| `geometry` | Point | the geometry column of the `GeoDataFrame`, i.e., latitude (y) and longitude (x) | centroids assignment |\n",
"| `value` | float | a value for each exposure | impact calculation |\n",
"| `impf_*` | int | impact functions ids for hazard types.<br>important attribute, since it relates the exposures to the hazard by specifying the impf_act functions.<br>Ideally it should be set to the specific hazard (e.g. `impf_TC`) so that different hazards can be set<br>in the same Exposures (e.g. `impf_TC` and `impf_FL`). | impact calculation |\n",
"| `centr_*` | int | centroids index for hazard type.<br>There might be different hazards defined: centr_TC, centr_FL, ...<br>Computed in method `assign_centroids()` | impact calculation |\n",
"| `deductible` | float | deductible value for each exposure. <br>Used for insurance | impact calculation |\n",
"| `cover` | float | cover value for each exposure. <br>Used for insurance | impact calculation |\n",
"| `region_id` | int | region id (e.g. country ISO code) for each exposure | aggregation |\n",
"| `category_id` | int | category id (e.g. building code) for each exposure | aggregation |"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are all these columns required now? If not, maybe you could detail which one are optional.

@emanuel-schmid
Copy link
Collaborator Author

many thanks for the review @spjuhel ! 🙌

@emanuel-schmid emanuel-schmid merged commit 28f8f15 into develop Oct 21, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants