aboutsummaryrefslogtreecommitdiff
path: root/plotter
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2023-11-07 20:53:30 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2023-11-07 20:53:30 +0100
commit1d321d169b2fc15d31c8187f7e6108e0ef8b1ad3 (patch)
tree0aae60ec0ebbac2e2d76df53f6243014aa50e2d7 /plotter
parent637edcf7b9da61edebfe5c8d0c7bafea3543ebba (diff)
downloadmeteo_toolbox-1d321d169b2fc15d31c8187f7e6108e0ef8b1ad3.tar.gz
meteogram info fields
Diffstat (limited to 'plotter')
-rwxr-xr-xplotter/meteogram.py39
1 files changed, 24 insertions, 15 deletions
diff --git a/plotter/meteogram.py b/plotter/meteogram.py
index c1dabee..ee8c7ea 100755
--- a/plotter/meteogram.py
+++ b/plotter/meteogram.py
@@ -25,9 +25,6 @@ def _plot(data, output, name, lat, lon):
data = data.sel(latitude=lat, longitude = lon, method='nearest')
- #data = data.assign_coords(step=(data.step / (10**9 * 3600)))
- data = data.assign_coords(step=(data.step.values.astype(float) * units('ns')).to('hour'))
-
init = misc.np_time_convert(data.time.values)
init_str = init.strftime('%d %b %Y - %HUTC')
@@ -41,34 +38,46 @@ def _plot(data, output, name, lat, lon):
ax.set_ylabel('Pressure level [hPa]')
- #clc = ax.plot(data.step.values.astype('float64'), data.isobaricInhPa, data.ccl.transpose())
- #clc = ax.imshow(data.ccl.transpose(), extent=(data.step.values.astype(float).min(), data.step.values.astype(float).max(), data.isobaricInhPa.min(), data.isobaricInhPa.max()), aspect='auto', cmap='Blues_r', vmin=0, vmax=100)
- #plt.colorbar(clc, label='clcov')
- # Blues_r
- clc = ax.contourf(data.step, data.isobaricInhPa, data.ccl.transpose(), cmap='clcov', vmin=0, vmax=100, levels=9)
+ clc = ax.contourf(data.valid_time, data.isobaricInhPa, data.ccl.transpose(), cmap='clcov', vmin=0, vmax=100, levels=9)
# use Format parameter for n/8
plt.colorbar(clc, label='cloudcov', extendfrac=None, ticks=[100*n/8 for n in range(9)], format=lambda x,_: f'{int(x/12.5)}/8', pad=0.0, fraction=0.015)
- cf = ax.contour(data.step, data.isobaricInhPa, data.t.metpy.convert_units('degC').transpose())
+ cf = ax.contour(data.valid_time, data.isobaricInhPa, data.t.metpy.convert_units('degC').transpose())
ax.clabel(cf, inline=True, fontsize=10)
- #plt.colorbar(cf, pad=0, aspect=50)
- #plt.colorbar(cf)
- barbs = ax.barbs(data.step, data.isobaricInhPa, data.u.transpose(), data.v.transpose())
- #ax.barbs(data.u, data.v, color='black', length=5, alpha=0.5)
+ barbs = ax.barbs(data.valid_time, data.isobaricInhPa, data.u.transpose(), data.v.transpose())
ax.invert_yaxis()
### Second plot
ax2 = fig.add_subplot(5,1,3,sharex=ax)
- ax2.plot(data.step, data.t2m.metpy.convert_units('degC').transpose(), color='red', label='Temperature (2m)')
- ax2.plot(data.step, mpcalc.dewpoint_from_relative_humidity(data.t2m, data.r2).transpose(), color='blue', label='Dewpoint (2m)')
+ ax2.plot(data.valid_time, data.t2m.metpy.convert_units('degC').transpose(), color='red', label='Temperature (2m)')
+ ax2.plot(data.valid_time, mpcalc.dewpoint_from_relative_humidity(data.t2m, data.r2).transpose(), color='blue', label='Dewpoint (2m)')
ax2.set_ylabel('Temperature [degC]')
ax2.legend(loc='lower right')
+ ### Info Lines
+
+ info_lines = []
+ init = misc.np_time_convert(data.time.values)
+ init_str = init.strftime('%d %b %Y - %HUTC')
+
+ info_lines.append(f'{name}')
+ info_lines.append(f"INIT : {init_str}")
+ info_lines.append(f"LAT {lat} LON {lon}")
+ if '_description' in data.attrs:
+ info_lines.append(data.attrs['_description'])
+
+ ax = fig.add_subplot(5, 1, 4)
+ ax.text(0, 0, '\n'.join(info_lines), ha='left', va='center',
+ size=10, fontfamily='monospace')
+ ax.axis("off")
+
+ ### Output
+
outname = f'{name}_{init_for_filename}.png'
plt.savefig(os.path.join(output, outname))
plt.close('all')