Skip to content

Commit

Permalink
Remove some missed accesses to dataset attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
luseverin committed Aug 29, 2024
1 parent 1071d57 commit 9b0092d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions climada/hazard/tc_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def get_track(self, track_name=None):
return self.data

for track in self.data:
if track.name == track_name:
if track.attrs['name'] == track_name:
return track
if hasattr(track, 'sid') and track.sid == track_name:
return track
Expand Down Expand Up @@ -932,7 +932,7 @@ def from_simulations_chaz(cls, file_names, year_range=None, ensemble_nums=None):
'orig_event_flag': True,
'data_provider': "CHAZ",
'id_no': track_ds['id_no'].item(),
'category': track_ds.category.item(),
'category': track_ds['category'].item(),
}))
if last_perc != 100:
LOGGER.info("Progress: 100%")
Expand Down Expand Up @@ -1556,7 +1556,7 @@ def _one_interp_data(track, time_step_h, land_geom=None):
.interpolate(method)
track_int.attrs['category'] = set_category(
track_int['max_sustained_wind'].values,
track_int.max_sustained_wind_unit)
track_int.attrs['max_sustained_wind_unit'])
# restrict to time steps within original bounds
track_int = track_int.sel(
time=(track['time'][0] <= track_int['time']) &
Expand Down
12 changes: 6 additions & 6 deletions climada/hazard/tc_tracks_synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def _one_rnd_walk(track, nb_synth_tracks, max_shift_ini, max_dspeed_rel, max_ddi
# end the track here
max_wind_end = i_track['max_sustained_wind'].values[last_idx]
ss_scale_end = climada.hazard.tc_tracks.set_category(max_wind_end,
i_track.max_sustained_wind_unit)
i_track.attrs['max_sustained_wind_unit'])
# TC category at ending point should not be higher than 1
cutoff_txt = (f"{i_track.attrs['name']}_gen{i_ens + 1}"
f" ({climada.hazard.tc_tracks.CAT_NAMES[ss_scale_end]})")
Expand Down Expand Up @@ -698,7 +698,7 @@ def _decay_values(track, land_geom, s_rel):
for sea_land, land_sea in zip(sea_land_idx, land_sea_idx):
v_landfall = track['max_sustained_wind'][sea_land - 1].values
ss_scale = climada.hazard.tc_tracks.set_category(v_landfall,
track.max_sustained_wind_unit)
track.attrs['max_sustained_wind_unit'])

v_land = track['max_sustained_wind'][sea_land - 1:land_sea].values
if v_land[0] > 0:
Expand Down Expand Up @@ -873,7 +873,7 @@ def _apply_decay_coeffs(track, v_rel, p_rel, land_geom, s_rel):
v_landfall = track['max_sustained_wind'][sea_land - 1].values
p_landfall = float(track['central_pressure'][sea_land - 1].values)
ss_scale = climada.hazard.tc_tracks.set_category(v_landfall,
track.max_sustained_wind_unit)
track.attrs['max_sustained_wind_unit'])
if land_sea - sea_land == 1:
continue
S = _calc_decay_ps_value(track, p_landfall, land_sea - 1, s_rel)
Expand Down Expand Up @@ -909,7 +909,7 @@ def _apply_decay_coeffs(track, v_rel, p_rel, land_geom, s_rel):
track['sid'])
v_decay[v_decay > 1] = (track['max_sustained_wind'][sea_land:land_sea][v_decay > 1]
/ v_landfall)
track.max_sustained_wind[sea_land:land_sea] = v_landfall * v_decay
track['max_sustained_wind'][sea_land:land_sea] = v_landfall * v_decay

# correct values of sea after a landfall (until next landfall, if any)
if land_sea < track['time'].size:
Expand All @@ -920,7 +920,7 @@ def _apply_decay_coeffs(track, v_rel, p_rel, land_geom, s_rel):
else:
# if there is no further landfall, correct until the end of
# the track
end_cor = track.time.size
end_cor = track['time'].size
rndn = 0.1 * float(np.abs(np.random.normal(size=1) * 5) + 6)
r_diff = track['central_pressure'][land_sea].values - \
track['central_pressure'][land_sea - 1].values + rndn
Expand All @@ -938,7 +938,7 @@ def _apply_decay_coeffs(track, v_rel, p_rel, land_geom, s_rel):
track['max_sustained_wind'][track['max_sustained_wind'] < 0] = 0

track.attrs['category'] = climada.hazard.tc_tracks.set_category(
track['max_sustained_wind'].values, track.max_sustained_wind_unit)
track['max_sustained_wind'].values, track.attrs['max_sustained_wind_unit'])
return track


Expand Down
10 changes: 5 additions & 5 deletions climada/hazard/trop_cyclone/trop_cyclone.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,9 @@ def video_intensity(

tc_tmp = cls.from_tracks(tr_sel, centroids=centroids)
tc_tmp.event_name = [
track.name + ' ' + time.strftime(
track['name'] + ' ' + time.strftime(
"%d %h %Y %H:%M",
time.gmtime(tr_sel.data[0].time[1].values.astype(int)
time.gmtime(tr_sel.data[0]['time'][1].values.astype(int)
/ 1000000000)
)
]
Expand Down Expand Up @@ -610,16 +610,16 @@ def from_single_track(
new_haz.centroids = centroids
new_haz.event_id = np.array([1])
new_haz.frequency = np.array([1])
new_haz.event_name = [track.sid]
new_haz.event_name = [track.attrs['sid']]
new_haz.fraction = sparse.csr_matrix(new_haz.intensity.shape)
# store first day of track as date
new_haz.date = np.array([
dt.datetime(track['time'].dt.year.values[0],
track['time'].dt.month.values[0],
track['time'].dt.day.values[0]).toordinal()
])
new_haz.orig = np.array([track.orig_event_flag])
new_haz.category = np.array([track.category])
new_haz.orig = np.array([track.attrs['orig_event_flag']])
new_haz.category = np.array([track.attrs['category']])
# users that pickle TCTracks objects might still have data with the legacy basin attribute,
# so we have to deal with it here
new_haz.basin = [track['basin'] if isinstance(track['basin'], str)
Expand Down

0 comments on commit 9b0092d

Please sign in to comment.