Skip to content

Commit 0b6a81e

Browse files
fix typeError
1 parent 9919d11 commit 0b6a81e

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

climada/hazard/tc_tracks.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,12 +3029,12 @@ def compute_track_density(
30293029

30303030
limit_ratio = 1.12 * 1.1 # record tc speed 112km/h -> 1.12°/h + 10% margin
30313031

3032-
#if tc_track.data[0].time_step[0].item() > res / limit_ratio:
3033-
# warnings.warn(
3034-
# "The time step is too big for the current resolution. For the desired resolution, \n"
3035-
# f"apply a time step of {res/limit_ratio}h."
3036-
#)
3037-
if res < 0.1:
3032+
if tc_track.data[0].time_step[0].values > res / limit_ratio:
3033+
warnings.warn(
3034+
"The time step is too big for the current resolution. For the desired resolution, \n"
3035+
f"apply a time step of {res/limit_ratio}h."
3036+
)
3037+
elif res < 0.1:
30383038
warnings.warn(
30393039
"The resolution is too high. The computation might take several minutes \n"
30403040
"to hours. Consider using a resolution below 0.1°."
@@ -3069,7 +3069,31 @@ def compute_track_density(
30693069
hist_count += hist_new
30703070

30713071
if density:
3072-
grid_area, _ = u_coord.compute_grid_cell_area(res=res)
3073-
hist_count = hist_count / grid_area
3072+
hist_count = normalize_density()
30743073

30753074
return hist_count, lat_bins, lon_bins
3075+
3076+
3077+
def compute_genesis_index(track, lat_bins, lon_bins):
3078+
3079+
# Extract the first lat and lon from each dataset
3080+
first_lats = np.array([ds.lat.values[0] for ds in track])
3081+
first_lons = np.array([ds.lon.values[0] for ds in track])
3082+
3083+
# compute 2D density of genesis points
3084+
hist_count, _, _ = np.histogram2d(
3085+
first_lats,
3086+
first_lons,
3087+
bins=[lat_bins, lon_bins],
3088+
density=False,
3089+
)
3090+
3091+
return hist_count
3092+
3093+
3094+
def normalize_density(res):
3095+
3096+
grid_area, _ = u_coord.compute_grid_cell_area(res=res)
3097+
hist_count = hist_count / grid_area
3098+
3099+
pass

0 commit comments

Comments
 (0)