Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mammatus95 committed Apr 8, 2024
1 parent a717f8e commit eb56a2a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-codecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: Codecheck

on:
push:
branches: [ "main" ]
branches: [ "main", "modellevel", "lint" ]

jobs:
build-linux:
Expand Down
10 changes: 5 additions & 5 deletions src/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
run: 0
fp: 9
default_date: "2024-03-16"
fp: 36
default_date: "2024-04-08"

levels: [74,20]
steps: 1 # level steps
Expand All @@ -10,14 +10,14 @@ soundmap : True

threshold: 0

fontsize: 12
fontsize: 14
titlesize: 18

# customize
customize: # east de
lon1: 10.7
lon2: 18
lat1: 49.8
lon2: 17
lat1: 50.1
lat2: 54.8

# 10.77, 18.92, 49.80, 55.06
4 changes: 2 additions & 2 deletions src/download_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ fi



for X in 9 #12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60
for X in 36 #9 #12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60
do
cd ${path_icon}
T=$(printf "%03d" "$X")
#single level
for N in CAPE_ML #CAPE_CON
for N in CAPE_ML CAPE_CON PS
do
typeset -l nvar
nvar=${N}
Expand Down
18 changes: 8 additions & 10 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def main():
# Add optional argument
parser.add_argument('-f', '--field', type=str,
help='Which background field: CAPE ML, CAPE CON or LPI ')

parser.add_argument('-d', '--date', type=str,
help='Date Format YYYY-MM-DD')

parser.add_argument('-fp', '--fp', type=str,
help='Leadtime or forecast periode')

parser.add_argument('-r', '--run', type=str,
help='Run (0,6,12,18,.. .etc)')

Expand Down Expand Up @@ -65,12 +65,10 @@ def main():
fieldname = args.field.replace(" ", "_")



print(f"\nDate: {rundate}\n Arguments: {args} \nConfig-File: {config}\n\n")

#ut.download_nwp(fieldname, datum="20240227", run="00", fp=0, store_path="./")



if args.mode == "Test":
cape_fld, lats, lons = ut.open_gribfile_single(fieldname, rundate, run, fp, path="./iconnest/")
Expand All @@ -88,7 +86,7 @@ def main():
q_fld.fill(np.nan)
p_fld = np.empty(nlvl*model.getpoints()).reshape((nlvl, model.getnlat(), model.getnlon()))
p_fld.fill(np.nan)

if config["levels"][0] > config["levels"][1]:
steps *= -1
elif config["levels"][0] == config["levels"][1]:
Expand All @@ -104,7 +102,7 @@ def main():
lvl_idx += 1
if lvl_idx >= nlvl:
break

print(np.nanmean(t_fld, axis=(1,2))-273.15)
plotlib.sounding_plot (cape_fld, t_fld, q_fld, p_fld, lats, lons, fp, run, titel='CAPE')
elif args.mode == "Basic":
Expand All @@ -116,7 +114,7 @@ def main():
u_fld.fill(np.nan)
v_fld = np.empty(nlvl*model.getpoints()).reshape((nlvl, model.getnlat(), model.getnlon()))
v_fld.fill(np.nan)

if config["levels"][0] > config["levels"][1]:
steps *= -1
elif config["levels"][0] == config["levels"][1]:
Expand Down Expand Up @@ -165,14 +163,14 @@ def main():
lvl_idx += 1
if lvl_idx >= nlvl:
break

print(np.nanmean(p_fld, axis=(1,2)))

du = np.subtract(u_fld[30,:,:], u_fld[0,:,:])
dv = np.subtract(v_fld[30,:,:], v_fld[0,:,:])
dls_fld = np.sqrt(np.add(np.square(du), np.square(dv)))
plotlib.nixon_proj(cape_fld, dls_fld, u_fld, v_fld, p_fld, h_fld, lats, lons, fp, run, imfmt="png")
else:
else:
print("Wrong command line argument")
exit(-1)

Expand Down
25 changes: 15 additions & 10 deletions src/plotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def customize_area(hour, start, projection=crs.EuroPP(), lon1=10.7, lon2=18, lat
ax.add_feature(states_provinces, edgecolor='black')
string1, string2 = ut.datum(hour, start)
plt.annotate("ICON Nest (DWD)", xy=(0.02, -0.04), xycoords='axes fraction', fontsize=10)
plt.annotate(string1, xy=(0.835, 1), xycoords='axes fraction', fontsize=fontsize)
plt.annotate(string2, xy=(0, 1), xycoords='axes fraction', fontsize=fontsize)
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 @@ -298,12 +298,14 @@ def hodopoint(point, u, v, ax, width=0.1, clim=40, proj='polar', smooth=False):
ax2.plot(np.linspace(np.mean(wdir[np.where(spd[:-20] > 25)])-np.pi/8,
np.mean(wdir[np.where(spd[:-20] > 25)])+np.pi/8, 100),
np.zeros(100)+30, '-k', alpha=.3, lw=0.8)

ax2.plot(wdir[:10:1], spd[:10:1], 'r-', lw=1.5)
ax2.plot(wdir[9:21:2], spd[9:21:2], 'g-', lw=1.5)
ax2.plot(wdir[19:-20:2], spd[19:-20:2], 'b-', lw=1.5)
ax2.scatter(0, 0, c="k", s=10, marker='x', alpha=0.75)

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


def basic_plot(cape_fld, u, v, lats, lons, hour, start, titel='CAPE', threshold=10., imfmt="png"):
"""
Expand Down Expand Up @@ -352,10 +354,10 @@ def basic_plot(cape_fld, u, v, lats, lons, hour, start, titel='CAPE', threshold=

def basic_plot_custarea(cape_fld, u, v, lats, lons, hour, start, titel='CAPE', threshold=10., imfmt="png"):

lon1=config["customize"]["lon1"]
lon2=config["customize"]["lon2"]
lat1=config["customize"]["lat1"]
lat2=config["customize"]["lat2"]
lon1 = config["customize"]["lon1"]
lon2 = config["customize"]["lon2"]
lat1 = config["customize"]["lat1"]
lat2 = config["customize"]["lat2"]
fig, ax = customize_area(hour, start, projection=crs.PlateCarree(), lon1=lon1, lon2=lon2, lat1=lat1, lat2=lat2)
plt.title(titel, fontsize=titlesize)

Expand All @@ -365,13 +367,16 @@ def basic_plot_custarea(cape_fld, u, v, lats, lons, hour, start, titel='CAPE', t
for j in range(555, 665, 5):
if np.mean(cape_fld[i-1:i+1, j-1:j+1]) > threshold:
hodopoint((lons[i, j], lats[i, j]),
np.mean(u[::-1, i-1:i+1, j-1:j+1], axis=(1, 2)),
np.mean(v[::-1, i-1:i+1, j-1:j+1], axis=(1, 2)), ax, width=0.1) # , proj=crs.PlateCarree()
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)), ax, width=0.1) # , proj=crs.PlateCarree()

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

ax.annotate(r'$m^2/s^2$', xy=(0.65, -0.04), xycoords='axes fraction', fontsize=14)
if "CAPE" in titel:
ax.annotate(r'$J/kg$', xy=(0.65, -0.04), xycoords='axes fraction', fontsize=14)
else:
ax.annotate(r'$m^2/s^2$', xy=(0.65, -0.04), xycoords='axes fraction', fontsize=14)
ax.annotate('red: 1-10 model level', xy=(0.75, -0.04), xycoords='axes fraction', fontsize=14)
ax.annotate('green: 10-20 model level', xy=(0.75, -0.07), xycoords='axes fraction', fontsize=14)
ax.annotate('blue: 20-50 model level', xy=(0.75, -0.1), xycoords='axes fraction', fontsize=14)
Expand Down
2 changes: 1 addition & 1 deletion src/utilitylib.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import requests
import yaml
import pygrib
#from netCDF4 import Dataset
import numpy as np

# ---------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -105,6 +104,7 @@ def open_gribfile_multi(fieldname, lvl, datetime_obj, run, fp, path="./iconnest/


def open_netcdf(fieldname, path="./iconnest/"):
from netCDF4 import Dataset
data = Dataset(f"{path}{fieldname}", 'r')

lat = data.variables['lat'][:]
Expand Down

0 comments on commit eb56a2a

Please sign in to comment.