Throw an error or a warning in this case. This will not actually handle the underlying issue: If subselecting a fraction matrix to values that are only zero, the fraction will suddenly be considered a fraction matrix of only ones (implicitly).
import numpy as np
from scipy.sparse import csr_matrix
from climada.hazard import Hazard, Centroids
centroids = Centroids(lat=np.zeros(2), lon=np.zeros(2), region_id=np.array([0, 1]))
hazard = Hazard(
centroids=centroids,
event_id=np.array([1, 2]),
intensity=csr_matrix([[1, 1], [1, 1]]),
fraction=csr_matrix([[0, 0], [1, 1]]),
)
hazard._get_fraction().toarray()
# array([[0, 0],
# [1, 1]])
hazard.select(reg_id=[0])._get_fraction().toarray()
# array([[0],
# [1]])
hazard.select(event_id=[1])._get_fraction()
# Returns None, equivalent to fraction of 1 everywhere, but should be
# array([[0, 0]])
Throw an error or a warning in this case. This will not actually handle the underlying issue: If subselecting a fraction matrix to values that are only zero, the fraction will suddenly be considered a fraction matrix of only ones (implicitly).
First reported in #838