Skip to content
2 changes: 1 addition & 1 deletion climada/entity/exposures/litpop/nightlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def unzip_tif_to_py(file_gz):
nightlight = sparse.csc_matrix(plt.imread(file_name))
# flip X axis
nightlight.indices = -nightlight.indices + nightlight.shape[0] - 1
nightlight = nightlight.tocsr()
nightlight = sparse.csr_matrix(nightlight.tocsr())
Comment thread
spjuhel marked this conversation as resolved.
Outdated
file_name.unlink()
file_path = SYSTEM_DIR.joinpath(file_name.stem + ".p")
save(file_path, nightlight)
Expand Down
3 changes: 2 additions & 1 deletion climada/entity/measures/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import numpy as np
import pandas as pd
from geopandas import GeoDataFrame
from scipy.sparse import csr_matrix
Comment thread
peanutfun marked this conversation as resolved.
Outdated

import climada.util.checker as u_check
from climada.entity.exposures.base import INDICATOR_CENTR, INDICATOR_IMPF, Exposures
Expand Down Expand Up @@ -565,6 +566,6 @@ def _filter_exposures(
centr = np.delete(np.arange(hazard.intensity.shape[1]), np.unique(centr))
new_haz_inten = new_haz.intensity.tolil()
new_haz_inten[:, centr] = hazard.intensity[:, centr]
new_haz.intensity = new_haz_inten.tocsr()
new_haz.intensity = csr_matrix(new_haz_inten.tocsr())

return new_exp, new_impfs, new_haz
4 changes: 3 additions & 1 deletion climada/hazard/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def _to_csr_matrix(array: xr.DataArray) -> sparse.csr_matrix:
output_dtypes=[array.dtype],
)
sparse_coo = array.compute().data # Load into memory
return sparse_coo.tocsr() # Convert sparse.COO to scipy.sparse.csr_array
return sparse.csr_matrix(
sparse_coo.tocsr()
) # Convert sparse.COO to scipy.sparse.csr_array
Comment thread
spjuhel marked this conversation as resolved.
Outdated


# Define accessors for xarray DataArrays
Expand Down
8 changes: 5 additions & 3 deletions climada/util/hdf5_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ def get_sparse_csr_mat(mat_dict, shape):
if ("data" not in mat_dict) or ("ir" not in mat_dict) or ("jc" not in mat_dict):
raise ValueError("Input data is not a sparse matrix.")

return sparse.csc_matrix(
(mat_dict["data"], mat_dict["ir"], mat_dict["jc"]), shape
).tocsr()
return sparse.csr_matrix(
sparse.csc_matrix(
(mat_dict["data"], mat_dict["ir"], mat_dict["jc"]), shape
).tocsr()
)


def to_string(str_or_bytes):
Expand Down
Loading