Skip to content

Commit aead47b

Browse files
committed
fixes numpy.warnings error with recent numpy
1 parent 11b3430 commit aead47b

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

climada/hazard/tc_tracks_synth.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
track parameters"""
139139

140140
NEGLECT_LANDFALL_DURATION_HOUR = 4.5
141-
"""Minimum landfall duration in hours from which to correct intensity. Perturbed systems
141+
"""Minimum landfall duration in hours from which to correct intensity. Perturbed systems
142142
spending less time than this over land will not be adjusted for landfall effects"""
143143

144144
TRACK_EXTENSION_PARS = {
@@ -320,9 +320,9 @@ def calc_perturbed_trajectories(
320320
max_sustained_wind) should be modelled. One of 'explicit',
321321
'legacy_decay', or 'none'.
322322
For 'explicit', intensity as well as radius_oci (outermost closed isobar)
323-
and radius_max_wind are statistically modelled depending on landfalls in
324-
historical and synthetic tracks (track intensification, peak intensity
325-
duration as well as intensity decay over the ocean and over land are
323+
and radius_max_wind are statistically modelled depending on landfalls in
324+
historical and synthetic tracks (track intensification, peak intensity
325+
duration as well as intensity decay over the ocean and over land are
326326
explicitly modelled).
327327
For 'legacy_decay', a landfall decay is applied when a synthetic track
328328
reached land; however when a synthetic track is over the ocean while its
@@ -366,12 +366,12 @@ def calc_perturbed_trajectories(
366366
adjust_intensity = 'legacy_decay'
367367
else:
368368
LOGGER.warning('decay is set to False - this sets adjust_intensity to "none" (as a string)')
369-
adjust_intensity = 'none'
369+
adjust_intensity = 'none'
370370
if adjust_intensity is None:
371371
adjust_intensity = 'explicit'
372372
if adjust_intensity not in ['explicit', 'legacy_decay', 'none']:
373373
raise ValueError("adjust_intensity should be one of 'explicit', 'legacy_decay', 'none', or None")
374-
374+
375375
LOGGER.info('Computing %s synthetic tracks.', nb_synth_tracks * tracks.size)
376376

377377
pool = tracks.pool if pool is None else pool
@@ -554,7 +554,7 @@ def calc_perturbed_trajectories(
554554
(
555555
ocean_modelled_tracks,
556556
sid_extended_tracks_intensity,
557-
sid_outside_lat_range,
557+
sid_outside_lat_range,
558558
sid_outside_intensity_range
559559
) = _model_synth_tc_intensity(
560560
tracks_list=tracks_list,
@@ -744,7 +744,7 @@ def _get_random_trajectories_perts(tracks,
744744
autocorr_dspeed,
745745
decay_ddirection_hourly):
746746
"""Generate random numbers for random walk
747-
747+
748748
Parameters
749749
----------
750750
tracks : List
@@ -873,7 +873,7 @@ def _apply_random_walk_pert(track: xr.Dataset,
873873
# apply initial location shift
874874
new_lon[0] = track.lon.values[0] + xy_ini[0]
875875
new_lat[0] = track.lat.values[0] + xy_ini[1]
876-
876+
877877
# apply perturbations along the track segments
878878
for i in range(n_seg):
879879
new_lon[i + 1], new_lat[i + 1] = \
@@ -1147,9 +1147,9 @@ def _get_shift_idx_start(on_land_hist, on_land_synth, time_step_h, shift_values_
11471147
first_sea_hist = np.where(~on_land_hist)[0][0]
11481148
first_sea_synth = np.where(~on_land_synth)[0][0]
11491149
if on_land_synth[0] and on_land_hist[0]:
1150-
1150+
11511151
# 0) Both tracks start over land: shift values such as to match first point over the ocean.
1152-
1152+
11531153
shift_first_sea = first_sea_synth - first_sea_hist
11541154
# no modelling needed before first synth landfall or first hist landfall.
11551155
idx_start_model_hist = idx_lf_hist[0]
@@ -1257,7 +1257,7 @@ def _get_shift_idx_start(on_land_hist, on_land_synth, time_step_h, shift_values_
12571257
# else:
12581258
# idx_start_model = ftr_hist -
12591259
# np.floor(TIME_MODEL_BEFORE_HIST_LF_H/time_step_h)
1260-
1260+
12611261
# account for shift and buffer for historical landfall
12621262
if idx_start_model_hist < nts:
12631263
idx_start_model_hist = max(0, min(
@@ -1320,7 +1320,7 @@ def _create_raw_track_extension(track,
13201320
time_step_h,
13211321
values_df: pd.DataFrame=None):
13221322
"""Append new time steps to a track.
1323-
1323+
13241324
For a TC track, create a new track starting at the end of the original
13251325
track, with a given number of time steps and optionally some variables
13261326
values set. Longitude/Latitude are all constant and set to the last values
@@ -1732,7 +1732,7 @@ def _add_fits_to_track(track: xr.Dataset, central_pressure_pert: float):
17321732
attributes to track.
17331733
17341734
The input 'track' is modified in-place!
1735-
1735+
17361736
The following variables are fitted: Maximum sustained wind, radius of
17371737
maximum winds and radius of outmost closed isobar.
17381738
@@ -1745,11 +1745,11 @@ def _add_fits_to_track(track: xr.Dataset, central_pressure_pert: float):
17451745
A single TC track.
17461746
central_pressure_pert : float
17471747
Maximum perturbations in central pressure. Used to determine the range
1748-
of pressure values over which to fit data.
1748+
of pressure values over which to fit data.
17491749
17501750
Returns
17511751
-------
1752-
track : xr.Dataset
1752+
track : xr.Dataset
17531753
Same as input parameter track but with additional attributes 'fit_intens' and
17541754
'fit_decay' (see _get_fit_single_phase). If intensification and/or decay
17551755
consist of less than 3 data points, the corresponding attribute is not set.
@@ -1765,7 +1765,7 @@ def _add_fits_to_track(track: xr.Dataset, central_pressure_pert: float):
17651765
track.attrs['fit_intens'] = fit_attrs_intens
17661766
if warning_slope_intens is not None:
17671767
warning_slope += ["%s intensification %s" % (track.sid, warning_slope_intens)]
1768-
if where_max_intensity[-1] < len(pcen) - 4:
1768+
if where_max_intensity[-1] < len(pcen) - 4:
17691769
track_decay = track[dict(time=slice(where_max_intensity[-1],None))]
17701770
fit_attrs_decay, warning_slope_decay = _get_fit_single_phase(track_decay, central_pressure_pert)
17711771
track.attrs['fit_decay'] = fit_attrs_decay
@@ -1780,7 +1780,7 @@ def _add_fits_to_track(track: xr.Dataset, central_pressure_pert: float):
17801780
def _get_fit_single_phase(track_sub, central_pressure_pert):
17811781
"""Calculate order and fit of variables to be modelled for a temporal subset
17821782
of a track.
1783-
1783+
17841784
The following variables are fitted: Maximum sustained wind, radius of
17851785
maximum winds and radius of outmost closed isobar.
17861786
@@ -1793,7 +1793,7 @@ def _get_fit_single_phase(track_sub, central_pressure_pert):
17931793
A temporal subset of a single TC track.
17941794
central_pressure_pert : float
17951795
Maximum perturbations in central pressure. Used to determine the range
1796-
of pressure values over which to fit data.
1796+
of pressure values over which to fit data.
17971797
17981798
Returns
17991799
-------
@@ -2334,7 +2334,7 @@ def _add_id_synth_chunks_shift_init(track: xr.Dataset,
23342334
23352335
Returns
23362336
-------
2337-
track : xr.Dataset
2337+
track : xr.Dataset
23382338
as input parameter track but with additional variable 'id_chunk'
23392339
(ID of chunks value per track point) and, if shift_values_init is True,
23402340
with variables shifted in time if the first track point over the ocean
@@ -2432,7 +2432,7 @@ def _one_model_synth_tc_intensity(track: xr.Dataset,
24322432
Sequentially moves over each unique track["id_chunk"] and applies the following:
24332433
* If id_chunk is negative, i.e. over land, applies landfall decay logic
24342434
* if id_chunk is positive, i.e. over sea, applies intensification/peak duration/decay logic
2435-
2435+
24362436
# TODO update docstring
24372437
24382438
Parameters
@@ -2463,15 +2463,15 @@ def _one_model_synth_tc_intensity(track: xr.Dataset,
24632463
check_id_chunk(track['id_chunk'].values, track.sid, allow_missing=False)
24642464
if np.all(track['id_chunk'] == 0):
24652465
return track, values_ext_df
2466-
2466+
24672467
# organise chunks to be processed in temporal sequence
24682468
chunk_index = np.unique(track.id_chunk.values, return_index=True)[1]
24692469
id_chunk_sorted = [track.id_chunk.values[index] for index in sorted(chunk_index)]
24702470
# track_orig = track.copy()
24712471

24722472
last_pcen = track.central_pressure.values[-1]
24732473
track_orig = track.copy(deep=True)
2474-
2474+
24752475
for id_chunk in id_chunk_sorted:
24762476
if id_chunk == 0:
24772477
continue
@@ -2539,7 +2539,7 @@ def _model_synth_tc_intensity(tracks_list,
25392539
for (track,_) in tracks_intensified
25402540
]
25412541
return (
2542-
new_tracks_list,
2542+
new_tracks_list,
25432543
sid_extended_tracks,
25442544
sid_outside_lat_range,
25452545
sid_outside_intensity_range
@@ -2581,7 +2581,7 @@ def _model_synth_tc_intensity(tracks_list,
25812581
if track.orig_event_flag:
25822582
tracks_intensified_new2.append(track)
25832583
continue
2584-
2584+
25852585
if np.sum(np.isnan(track['id_chunk'].values)) == 0:
25862586
# no track extension
25872587
_estimate_params_track(track)
@@ -2637,7 +2637,7 @@ def _model_synth_tc_intensity(tracks_list,
26372637
f'Central pressure: {pcen_extend[-1]}.'
26382638
)
26392639
_estimate_params_track(track)
2640-
2640+
26412641
# cutoff track end?
26422642
extended_cat = np.array([
26432643
climada.hazard.tc_tracks.set_category(
@@ -2647,7 +2647,7 @@ def _model_synth_tc_intensity(tracks_list,
26472647
for idx in range(track.time.size)
26482648
])
26492649

2650-
if np.any(extended_cat >= 0):
2650+
if np.any(extended_cat >= 0):
26512651
# Kill the extended track 12 hours after dropping below Cat 1
26522652
buffer_frames = int(np.ceil(12/time_step_h))
26532653
cutoff_idx = min(np.where(extended_cat >= 0)[0][-1] + buffer_frames, extended_cat.size-1)
@@ -2662,7 +2662,7 @@ def _model_synth_tc_intensity(tracks_list,
26622662
track = track.isel(time=slice(None, advisory_range_et_idx))
26632663
sid_outside_intensity_range.append(track.sid)
26642664
sid_outside_intensity_range = list(set(sid_outside_intensity_range))
2665-
2665+
26662666
# If the child storm weakens below the parent's final strength, kill it
26672667
intensityrange_out_idx = _get_finalintensity_idx(track, original_track=tracks_list[i])
26682668
intensityrange_out_idx = max(original_size, intensityrange_out_idx)
@@ -2671,13 +2671,13 @@ def _model_synth_tc_intensity(tracks_list,
26712671
track = track.isel(time=slice(None, intensityrange_out_idx))
26722672
sid_outside_intensity_range.append(track.sid)
26732673
sid_outside_intensity_range = list(set(sid_outside_intensity_range))
2674-
2674+
26752675
tracks_intensified_new2.append(track)
26762676
tracks_intensified_new2[i].attrs['category'] = climada.hazard.tc_tracks.set_category(
26772677
tracks_intensified_new2[i].max_sustained_wind.values,
26782678
tracks_intensified_new2[i].max_sustained_wind_unit
26792679
)
2680-
2680+
26812681
LOGGER.debug('dropping temporary variables')
26822682
new_tracks_list = [
26832683
drop_temporary_variables(track, track_vars_attrs)
@@ -2760,11 +2760,11 @@ def intensity_evolution_sea(track, id_chunk, central_pressure_pert, rnd_pars_i):
27602760
track['central_pressure'][in_chunk] = track['central_pressure'].values[in_chunk-1]
27612761
return pcen_extend
27622762
track_stage_end = 'intens'
2763-
2763+
27642764
# taking last value before the chunk as a starting point from where to model intensity
27652765
if in_chunk[0] > 0:
27662766
in_chunk = np.append(in_chunk[0]-1, in_chunk)
2767-
2767+
27682768
track_chunk = track.isel(time = in_chunk)
27692769
pcen = track_chunk.central_pressure.values
27702770
time_days = np.append(0, np.cumsum(track_chunk.time_step.values[1:] / 24))
@@ -2773,7 +2773,7 @@ def intensity_evolution_sea(track, id_chunk, central_pressure_pert, rnd_pars_i):
27732773
# perturb target central pressure: truncated normal distribution
27742774
target_peak_pert = central_pressure_pert / 2 * scipy.stats.truncnorm.ppf(rnd_pars_i[0], -2, 2)
27752775
target_peak = track_chunk.target_central_pressure.values[0] + target_peak_pert
2776-
2776+
27772777
if os.getenv('TRACKGEN_TEST_BIAS_TARGET_PRESSURE'):
27782778
target_pressure_bias = float(os.getenv('TRACKGEN_TEST_BIAS_TARGET_PRESSURE'))
27792779
if target_pressure_bias > 0:
@@ -3083,7 +3083,7 @@ def intensity_evolution_land(track, id_chunk, v_rel, p_rel, s_rel):
30833083
pcen_extend = p_landfall * p_decay_extend
30843084

30853085
# correct limits
3086-
np.warnings.filterwarnings('ignore')
3086+
warnings.filterwarnings('ignore')
30873087
cor_p = track_chunk.central_pressure.values > track_chunk.environmental_pressure.values
30883088
track_chunk.central_pressure[cor_p] = track_chunk.environmental_pressure[cor_p]
30893089
track_chunk.max_sustained_wind[track_chunk.max_sustained_wind < 0] = 0
@@ -3179,7 +3179,7 @@ def _get_peak_idx(pcen):
31793179

31803180
def _get_outside_lat_idx(track):
31813181
"""Get the index of the first track point located too poleward or equatorward
3182-
3182+
31833183
A track point with unrealistically high wind speed for its latitude is
31843184
considered to be too poleward or too equatorward.
31853185
@@ -3219,9 +3219,9 @@ def _get_outside_lat_idx(track):
32193219
return latrange_out_idx
32203220

32213221
def _get_finalintensity_idx(track, original_track):
3222-
'''Get the index of the frame where the synthetic track's central
3223-
pressure first goes above source track's final central pressure (or
3224-
the source track's maximum pressure reacheed after its minimum pressure,
3222+
'''Get the index of the frame where the synthetic track's central
3223+
pressure first goes above source track's final central pressure (or
3224+
the source track's maximum pressure reacheed after its minimum pressure,
32253225
whichever is higher). This is usually the last frame.'''
32263226
original_pres = original_track.central_pressure.values
32273227
min_idx = np.where(original_pres == np.min(original_pres))[0][-1]

0 commit comments

Comments
 (0)