@@ -107,8 +107,8 @@ def __init__(
107107 crs = DEF_CRS ,
108108 eai_exp = None ,
109109 at_event = None ,
110- tot_value = 0. ,
111- aai_agg = 0. ,
110+ tot_value = 0.0 ,
111+ aai_agg = 0.0 ,
112112 unit = "" ,
113113 imp_mat = None ,
114114 haz_type = "" ,
@@ -564,23 +564,32 @@ def local_exceedance_impact(
564564
565565 # calculate local exceedance impact
566566 test_frequency = 1 / np .array (return_periods )
567- exceedance_impact = np .array (
568- [
569- u_interp .preprocess_and_interpolate_ev (
570- test_frequency ,
571- None ,
572- self .frequency ,
573- self .imp_mat .getcol (i_centroid ).toarray ().flatten (),
574- log_frequency = log_frequency ,
575- log_values = log_impact ,
576- value_threshold = min_impact ,
577- method = method ,
578- y_asymptotic = 0.0 ,
579- )
580- for i_centroid in range (self .imp_mat .shape [1 ])
581- ]
567+
568+ exceedance_impact = np .full (
569+ (self .imp_mat .shape [1 ], test_frequency .shape [0 ]),
570+ np .nan if method == "interpolate" else 0.0 ,
582571 )
583572
573+ nonzero_centroids = np .where (self .imp_mat .getnnz (axis = 0 ) > 0 )[0 ]
574+
575+ if not len (nonzero_centroids ) == 0 :
576+ exceedance_impact [nonzero_centroids , :] = np .array (
577+ [
578+ u_interp .preprocess_and_interpolate_ev (
579+ test_frequency ,
580+ None ,
581+ self .frequency ,
582+ self .imp_mat .getcol (i_centroid ).toarray ().flatten (),
583+ log_frequency = log_frequency ,
584+ log_values = log_impact ,
585+ value_threshold = min_impact ,
586+ method = method ,
587+ y_asymptotic = 0.0 ,
588+ )
589+ for i_centroid in nonzero_centroids
590+ ]
591+ )
592+
584593 # create the output GeoDataFrame
585594 gdf = gpd .GeoDataFrame (
586595 geometry = gpd .points_from_xy (self .coord_exp [:, 1 ], self .coord_exp [:, 0 ]),
@@ -683,23 +692,28 @@ def local_return_period(
683692 ]:
684693 raise ValueError (f"Unknown method: { method } " )
685694
695+ return_periods = np .full ((self .imp_mat .shape [1 ], len (threshold_impact )), np .nan )
696+
697+ nonzero_centroids = np .where (self .imp_mat .getnnz (axis = 0 ) > 0 )[0 ]
698+
686699 # calculate local return periods
687- return_periods = np .array (
688- [
689- u_interp .preprocess_and_interpolate_ev (
690- None ,
691- np .array (threshold_impact ),
692- self .frequency ,
693- self .imp_mat .getcol (i_centroid ).toarray ().flatten (),
694- log_frequency = log_frequency ,
695- log_values = log_impact ,
696- value_threshold = min_impact ,
697- method = method ,
698- y_asymptotic = np .nan ,
699- )
700- for i_centroid in range (self .imp_mat .shape [1 ])
701- ]
702- )
700+ if not len (nonzero_centroids ) == 0 :
701+ return_periods [nonzero_centroids , :] = np .array (
702+ [
703+ u_interp .preprocess_and_interpolate_ev (
704+ None ,
705+ np .array (threshold_impact ),
706+ self .frequency ,
707+ self .imp_mat .getcol (i_centroid ).toarray ().flatten (),
708+ log_frequency = log_frequency ,
709+ log_values = log_impact ,
710+ value_threshold = min_impact ,
711+ method = method ,
712+ y_asymptotic = np .nan ,
713+ )
714+ for i_centroid in nonzero_centroids
715+ ]
716+ )
703717 return_periods = safe_divide (1.0 , return_periods )
704718
705719 # create the output GeoDataFrame
0 commit comments