Skip to content

Commit

Permalink
ENH: Updates for plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamTheisen committed Sep 8, 2023
1 parent ac14d05 commit d510ca6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
30 changes: 25 additions & 5 deletions act/plotting/skewtdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,33 +339,47 @@ def plot_from_u_and_v(
# Get pressure and smooth if not in order
p = self._ds[dsname][p_field]
if not all(p[i] <= p[i + 1] for i in range(len(p) - 1)):
self._ds[dsname][p_field] = (
self._ds[dsname][p_field].rolling(time=smooth_p, min_periods=1, center=True).mean()
)
p = self._ds[dsname][p_field]
if 'time' in self._ds:
self._ds[dsname][p_field] = (
self._ds[dsname][p_field].rolling(time=smooth_p, min_periods=1, center=True).mean()
)
p = self._ds[dsname][p_field]

p_units = self._ds[dsname][p_field].attrs['units']
p = p.values * getattr(units, p_units)
if len(np.shape(p)) == 2:
p = np.reshape(p, p.shape[0] * p.shape[1])

T = self._ds[dsname][t_field]
T_units = self._ds[dsname][t_field].attrs['units']
if T_units == 'C':
T_units = 'degC'

T = T.values * getattr(units, T_units)
if len(np.shape(T)) == 2:
T = np.reshape(T, T.shape[0] * T.shape[1])

Td = self._ds[dsname][td_field]
Td_units = self._ds[dsname][td_field].attrs['units']
if Td_units == 'C':
Td_units = 'degC'

Td = Td.values * getattr(units, Td_units)
if len(np.shape(Td)) == 2:
Td = np.reshape(Td, Td.shape[0] * Td.shape[1])

u = self._ds[dsname][u_field]
u_units = self._ds[dsname][u_field].attrs['units']
u = u.values * getattr(units, u_units)
if len(np.shape(u)) == 2:
u = np.reshape(u, u.shape[0] * u.shape[1])

v = self._ds[dsname][v_field]
v_units = self._ds[dsname][v_field].attrs['units']
v = v.values * getattr(units, v_units)
if len(np.shape(v)) == 2:
v = np.reshape(v, v.shape[0] * v.shape[1])


u_red = np.zeros_like(p_levels_to_plot) * getattr(units, u_units)
v_red = np.zeros_like(p_levels_to_plot) * getattr(units, v_units)
Expand Down Expand Up @@ -412,11 +426,17 @@ def plot_from_u_and_v(

# Set Title
if set_title is None:
if 'time' in self._ds[dsname]:
title_time = dt_utils.numpy_to_arm_date(self._ds[dsname].time.values[0]),
elif '_file_dates' in self._ds[dsname].attrs:
title_time = self._ds[dsname].attrs['_file_dates'][0]
else:
title_time = ''
set_title = ' '.join(
[
dsname,
'on',
dt_utils.numpy_to_arm_date(self._ds[dsname].time.values[0]),
title_time
]
)

Expand Down
7 changes: 6 additions & 1 deletion act/plotting/timeseriesdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,12 @@ def plot(
if force_line_plot is True:
if labels is True:
labels = [' '.join([str(d), units]) for d in ydata.values]
ytitle = f"({data.attrs['units']})"
if 'units' in data.attrs.keys():
units = data.attrs['units']
ytitle = ''.join(['(', units, ')'])
else:
units = ''
ytitle = dim[1]
ydata = None
else:
ydata = None
Expand Down

0 comments on commit d510ca6

Please sign in to comment.