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

Only assign csr matrices to Hazard objects #129

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ Code freeze date: YYYY-MM-DD
### Changed

- Adaptations to refactoring of the `climada.hazard.Centroids` class, to be compatible with `climada>=5.0` [#122](https://github.com/CLIMADA-project/climada_petals/pull/122)
- Always assign `csr_matrix` to `Hazard.intensity` [#129](https://github.com/CLIMADA-project/climada_petals/pull/129)

### Fixed

- Fix `climada.hazard.tc_rainfield` for TC tracks crossing the antimeridian [#105](https://github.com/CLIMADA-project/climada_petals/pull/105)
- Update the table of content for the tutorials [#125](https://github.com/CLIMADA-project/climada_petals/pull/125)
- Store all-zero fraction matrices in `LowFlow` and `WildFire` hazards [#129](https://github.com/CLIMADA-project/climada_petals/pull/129)

### Deprecated

Expand Down
7 changes: 3 additions & 4 deletions climada_petals/hazard/low_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,11 @@ def events_from_clusters(self, centroids):
self.orig = np.ones(uniq_ev.size)
self.set_frequency()

self.intensity = self._intensity_loop(uniq_ev, centroids.coord, res_centr, num_centr)
intensity = self._intensity_loop(uniq_ev, centroids.coord, res_centr, num_centr)

# Following values are defined for each event and centroid
self.intensity = self.intensity.tocsr()
self.fraction = self.intensity.copy()
self.fraction.data.fill(1.0)
self.intensity = intensity.tocsr()
self.fraction = sparse.csr_matrix(self.intensity.shape)

def identify_clusters(self, clus_thresh_xy=None, clus_thresh_t=None, min_samples=None):
"""call clustering functions to identify the clusters inside the dataframe
Expand Down
2 changes: 1 addition & 1 deletion climada_petals/hazard/test/test_wildfire.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def test_calc_bright_pass(self):
self.assertTrue(isinstance(wf.fraction, sparse.csr_matrix))
self.assertEqual(wf.intensity.shape, (7, 19454))
self.assertEqual(wf.fraction.shape, (7, 19454))
self.assertEqual(wf.fraction.max(), 1.0)
self.assertEqual(wf.fraction.nnz, 0) # Zero everywhere means 1 everywhere
self.assertAlmostEqual(wf.intensity[0, 16618], firms.loc[100].brightness)
self.assertAlmostEqual(wf.intensity[1, 123], max(firms.loc[6721].brightness, firms.loc[6722].brightness))
self.assertAlmostEqual(wf.intensity[2, :].max(), firms.loc[8105].brightness)
Expand Down
9 changes: 4 additions & 5 deletions climada_petals/hazard/wildfire.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,12 +899,11 @@ def _calc_brightness(self, df_firms, centroids, res_centr):
self._set_frequency()

# Following values are defined for each fire and centroid
self.intensity = sparse.lil_matrix(np.zeros((num_ev, num_centr)))
intensity = sparse.lil_matrix(np.zeros((num_ev, num_centr)))
for idx, ev_bright in enumerate(bright_list):
self.intensity[idx] = ev_bright
self.intensity = self.intensity.tocsr()
self.fraction = self.intensity.copy()
self.fraction.data.fill(1.0)
intensity[idx] = ev_bright
self.intensity = intensity.tocsr()
self.fraction = sparse.csr_matrix(self.intensity.shape)

@staticmethod
def _brightness_one_fire(df_firms, tree_centr, ev_id, res_centr, num_centr):
Expand Down