Skip to content

Commit

Permalink
smaller changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mammatus95 committed Apr 11, 2024
1 parent 90d49fc commit 0aa82e6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
12 changes: 7 additions & 5 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import plotlib
import modelinfolib as model

# ---------------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------------------


def run(model_obj, fp):
Expand All @@ -29,7 +29,7 @@ def run(model_obj, fp):
program_mode = config["program_mode"]

# replace space with underscores
fieldname = "CAPE_ML" #args.field.replace(" ", "_")
fieldname = "CAPE_ML" # args.field.replace(" ", "_")
rundate = model_obj.getrundate()
if program_mode == "Test":
cape_fld, lats, lons = ut.open_gribfile_single(fieldname, rundate, model_obj.getrun(), fp, path="./modeldata/")
Expand All @@ -48,8 +48,10 @@ def run(model_obj, fp):
lvl_idx = 0
pres_levels = model_obj.getlevels()
for level in pres_levels:
u_fld[lvl_idx, :, :] = ut.open_icon_gribfile_preslvl("U", level, rundate, model_obj.getrun(), fp, path="./modeldata/")
v_fld[lvl_idx, :, :] = ut.open_icon_gribfile_preslvl("V", level, rundate, model_obj.getrun(), fp, path="./modeldata/")
u_fld[lvl_idx, :, :] = ut.open_icon_gribfile_preslvl("U", level, rundate, model_obj.getrun(),
fp, path="./modeldata/")
v_fld[lvl_idx, :, :] = ut.open_icon_gribfile_preslvl("V", level, rundate, model_obj.getrun(),
fp, path="./modeldata/")

lvl_idx += 1
if lvl_idx >= nlvl:
Expand All @@ -64,7 +66,7 @@ def run(model_obj, fp):
print("Wrong command line argument")
exit(-1)

# ---------------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------------------------------


def main():
Expand Down
23 changes: 12 additions & 11 deletions src/modelinfolib.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@
('v', 'isobaricInhPa', 400),
('v', 'isobaricInhPa', 300),
('cape', 'pressureFromGroundLayer', 9000), # 9000 18000 25500
# ('cape', 'surface', 0),
# ('cape', 'pressureFromGroundLayer', 9000), # 9000 18000 25500
# ('10u', 'heightAboveGround', 10),
# ('10v', 'heightAboveGround', 10),
# ('100u', 'heightAboveGround', 100),
# ('100v', 'heightAboveGround', 100),
# ('cape', 'surface', 0),
# ('cape', 'pressureFromGroundLayer', 9000), # 9000 18000 25500
# ('10u', 'heightAboveGround', 10),
# ('10v', 'heightAboveGround', 10),
# ('100u', 'heightAboveGround', 100),
# ('100v', 'heightAboveGround', 100),
]
par_list_ifs = [
('u', 'isobaricInhPa', 1000),
Expand All @@ -94,10 +94,10 @@
('v', 'isobaricInhPa', 400),
('v', 'isobaricInhPa', 300),
('cape', 'entireAtmosphere', 0),
# ('10u', 'heightAboveGround', 10),
# ('10v', 'heightAboveGround', 10),
# ('100u', 'heightAboveGround', 100),
# ('100v', 'heightAboveGround', 100),
# ('10u', 'heightAboveGround', 10),
# ('10v', 'heightAboveGround', 10),
# ('100u', 'heightAboveGround', 100),
# ('100v', 'heightAboveGround', 100),
]

# ---------------------------------------------------------------------------------------------------------------------
Expand All @@ -106,7 +106,7 @@
class MODELIFNO:

def __init__(self, modelname, nlon, nlat, d_grad, levtyp):
config = load_yaml('config.yml')
# config = load_yaml('config.yml')
self.modelname = modelname
self.points = nlon*nlat
self.nlon = nlon
Expand Down Expand Up @@ -199,6 +199,7 @@ def getd_grad(self):
def create_plottitle(self):
return f"Hodographmap of {self.modelname}"


# Example usage:
icon_nest = MODELIFNO("ICON Nest", 1377, 657, 0.0625, "pres")
ifs = MODELIFNO("IFS", 1440, 721, 0.25, "pres")
Expand Down
21 changes: 9 additions & 12 deletions src/plotlib.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#!/usr/bin/python3
from copy import deepcopy

import numpy as np

# matplotlib
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap # ListedColormap, BoundaryNorm,
from matplotlib.projections import register_projection

# cartopy
import cartopy.crs as crs
Expand Down Expand Up @@ -81,7 +78,6 @@ def customize_area(hour, start, datetime_obj, model_name, projection=crs.EuroPP(
ax.coastlines('10m', linewidth=1.2)
ax.add_feature(states_provinces, edgecolor='black')
string1, string2 = ut.datum(hour, start, datetime_obj)
plt.annotate(model_name, xy=(0.02, -0.04), xycoords='axes fraction', fontsize=10)
plt.annotate(string1, xy=(0.82, 1.01), xycoords='axes fraction', fontsize=fontsize)
plt.annotate(string2, xy=(0, 1.01), xycoords='axes fraction', fontsize=fontsize)
return fig, ax
Expand Down Expand Up @@ -203,7 +199,7 @@ def hodopoint(point, u, v, pres_levels, ax, width=0.1, clim=40, proj='polar', sm
wdir_mean = met.uv2spddir(u_mean, v_mean)[0]
ax2.plot(np.linspace(wdir_mean-np.pi/8,
wdir_mean+np.pi/8, 100),
np.zeros(100)+30, '-k', alpha=.3, lw=0.8)
np.zeros(100)+30, '-k', alpha=.3, lw=0.8)
# plot data
idx_low = pres_levels.index(850)
idx_mid = pres_levels.index(600)
Expand Down Expand Up @@ -286,15 +282,16 @@ def basic_plot_custarea(model_obj, cape_fld, u, v, lats, lons, hour, threshold=1
np.mean(u[:, i-1:i+1, j-1:j+1], axis=(1, 2)),
np.mean(v[:, i-1:i+1, j-1:j+1], axis=(1, 2)), pres_levels, ax, width=0.1) # proj=crs.PlateCarree()

cax = fig.add_axes([0.27, 0.05, 0.35, 0.05])
cax = fig.add_axes([0.44, 0.03, 0.35, 0.05])
fig.colorbar(wx, cax=cax, orientation='horizontal')


ax.annotate(r'$J/kg$', xy=(0.65, -0.04), xycoords='axes fraction', fontsize=14)
ax.annotate('red: srf-850hPa', xy=(0.75, -0.04), xycoords='axes fraction', fontsize=14)
ax.annotate('green: 850-600hPa', xy=(0.75, -0.07), xycoords='axes fraction', fontsize=14)
ax.annotate('blue: above 600hPa', xy=(0.75, -0.1), xycoords='axes fraction', fontsize=14)
ax.annotate("grey circles are 10 and 30m/s", xy=(0.02, -0.07), xycoords='axes fraction', fontsize=10)
ax.annotate("CAPE ML(contour plot)", xy=(0.8, -0.07), xycoords='axes fraction', fontsize=14)
ax.annotate(r'in $J/kg$', xy=(0.8, -0.1), xycoords='axes fraction', fontsize=14)

ax.annotate('1000-850 hPa in red', xy=(0.02, -0.03), xycoords='axes fraction', fontsize=13)
ax.annotate(' 850-600 hPa in green', xy=(0.02, -0.06), xycoords='axes fraction', fontsize=13)
ax.annotate(' 600-250 hPa in blue', xy=(0.02, -0.09), xycoords='axes fraction', fontsize=13)
ax.annotate("grey circles are 10 and 30m/s", xy=(0.02, -0.11), xycoords='axes fraction', fontsize=13)

name = f"./images/hodographmap_area_{model_name.replace(' ', '_')}_{hour}.{imfmt}"
plt.savefig(name)
Expand Down
3 changes: 2 additions & 1 deletion src/utilitylib.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def open_icon_gribfile_preslvl(fieldname, lvl, datetime_obj, run, fp, path="./mo
print("Maximum:", np.nanmax(data))
return data


def open_gribfile_preslvl(model_obj, fp, path="./modeldata/"):
date_string = model_obj.getrundate_as_str("%Y%m%d")

Expand All @@ -121,7 +122,7 @@ def open_gribfile_preslvl(model_obj, fp, path="./modeldata/"):

for par in model_obj.getParamter():
try:
grb_message = gribidx.select(shortName=par[0], typeOfLevel=par[1], level=par[2])[0] # takes the matching grib message
grb_message = gribidx.select(shortName=par[0], typeOfLevel=par[1], level=par[2])[0]
if par[0] == "cape":
cape_fld = grb_message.values
lats, lons = grb_message.latlons()
Expand Down

0 comments on commit 0aa82e6

Please sign in to comment.