@@ -155,8 +155,8 @@ def sal_structure(
155
155
observation_objects = _sal_detect_objects (
156
156
observation , thr_factor , thr_quantile , tstorm_kwargs
157
157
)
158
- prediction_volume = _sal_scaled_volume (prediction_objects ). sum ()
159
- observation_volume = _sal_scaled_volume (observation_objects ). sum ()
158
+ prediction_volume = _sal_scaled_volume (prediction_objects )
159
+ observation_volume = _sal_scaled_volume (observation_objects )
160
160
nom = prediction_volume - observation_volume
161
161
denom = prediction_volume + observation_volume
162
162
return np .divide (nom , (0.5 * denom ))
@@ -360,10 +360,10 @@ def _sal_detect_objects(precip, thr_factor, thr_quantile, tstorm_kwargs):
360
360
}
361
361
_ , labels = tstorm_detect .detection (precip , ** tstorm_kwargs )
362
362
labels = labels .astype (int )
363
- precip_objects = regionprops_table (
364
- labels , intensity_image = precip , properties = REGIONPROPS
363
+ precip_objects = pd . DataFrame (
364
+ regionprops_table ( labels , intensity_image = precip , properties = REGIONPROPS )
365
365
)
366
- return pd . DataFrame ( precip_objects )
366
+ return precip_objects
367
367
368
368
369
369
def _sal_scaled_volume (precip_objects ):
@@ -379,8 +379,8 @@ def _sal_scaled_volume(precip_objects):
379
379
380
380
Returns
381
381
-------
382
- object_volume: pd.Series
383
- A pandas Series with the scaled volume of each precipitation object .
382
+ total_scaled_volum: float
383
+ The total scaled volume of precipitation objects .
384
384
"""
385
385
if not PANDAS_IMPORTED :
386
386
raise MissingOptionalDependency (
@@ -389,13 +389,27 @@ def _sal_scaled_volume(precip_objects):
389
389
)
390
390
objects_volume_scaled = []
391
391
for _ , precip_object in precip_objects .iterrows ():
392
- intensity_sum = precip_object .intensity_image . sum ( )
392
+ intensity_sum = np . nansum ( precip_object .intensity_image )
393
393
max_intensity = precip_object .max_intensity
394
- volume_scaled = intensity_sum / max_intensity
395
- objects_volume_scaled .append (volume_scaled )
396
- return pd .Series (
397
- data = objects_volume_scaled , index = precip_objects .label , name = "scaled_volume"
398
- )
394
+ if intensity_sum == 0 :
395
+ intensity_vol = 0
396
+ else :
397
+ volume_scaled = intensity_sum / max_intensity
398
+ tot_vol = intensity_sum * volume_scaled
399
+ intensity_vol = tot_vol
400
+
401
+ objects_volume_scaled .append (
402
+ {"intensity_vol" : intensity_vol , "intensity_sum_obj" : intensity_sum }
403
+ )
404
+ df_vols = pd .DataFrame (objects_volume_scaled )
405
+
406
+ if df_vols .empty or (df_vols ["intensity_sum_obj" ] == 0 ).all ():
407
+ total_scaled_volum = 0
408
+ else :
409
+ total_scaled_volum = np .nansum (df_vols .intensity_vol ) / np .nansum (
410
+ df_vols .intensity_sum_obj
411
+ )
412
+ return total_scaled_volum
399
413
400
414
401
415
def _sal_weighted_distance (precip , thr_factor , thr_quantile , tstorm_kwargs ):
@@ -443,10 +457,10 @@ def _sal_weighted_distance(precip, thr_factor, thr_quantile, tstorm_kwargs):
443
457
yd = (precip_objects ["weighted_centroid-0" ][i ] - centroid_total [0 ]) ** 2
444
458
445
459
dst = sqrt (xd + yd )
446
- sumr = (precip_objects .intensity_image [i ]. sum ( )) * dst
460
+ sumr = (np . nansum ( precip_objects .intensity_image [i ])) * dst
447
461
448
- sump = precip_objects .intensity_image [i ]. sum ( )
462
+ sump = np . nansum ( precip_objects .intensity_image [i ])
449
463
450
464
r .append ({"sum_dist" : sumr , "sum_p" : sump })
451
465
rr = pd .DataFrame (r )
452
- return rr .sum_dist . sum () / (rr .sum_p . sum ( ))
466
+ return ( np . nansum ( rr .sum_dist )) / (np . nansum ( rr .sum_p ))
0 commit comments