diff --git a/CHANGELOG.md b/CHANGELOG.md index 2060e68e2..173230606 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/climada_petals/hazard/low_flow.py b/climada_petals/hazard/low_flow.py index a017ee5f1..f110f50eb 100644 --- a/climada_petals/hazard/low_flow.py +++ b/climada_petals/hazard/low_flow.py @@ -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 diff --git a/climada_petals/hazard/test/test_wildfire.py b/climada_petals/hazard/test/test_wildfire.py index 1ad875d3e..aa159769f 100644 --- a/climada_petals/hazard/test/test_wildfire.py +++ b/climada_petals/hazard/test/test_wildfire.py @@ -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) diff --git a/climada_petals/hazard/wildfire.py b/climada_petals/hazard/wildfire.py index a74720119..a10609985 100644 --- a/climada_petals/hazard/wildfire.py +++ b/climada_petals/hazard/wildfire.py @@ -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):