Skip to content

Commit

Permalink
better error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
mammatus95 committed May 3, 2024
1 parent 2b41f96 commit 8318c34
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-nose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Unittest

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

jobs:
build-linux:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

**.ipynb_checkpoints/

**log.txt

*/*.png
*/*/*.png
Expand Down
31 changes: 17 additions & 14 deletions src/download_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# change configuration here
R=0 # select run 0 or 12z
D=$(date +"%Y%m%d") # date in format YYYYMMDD
D=20240502 # date in format YYYYMMDD
#D=20240502 # date in format YYYYMMDD

echo "Hodograph Maps"
echo "Script configurations:"
Expand Down Expand Up @@ -42,41 +42,41 @@ icon_pressure=icon-eu_europe_regular-lat-lon_pressure-level_${D}$(printf "%02d"



for fp in 3 #9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60
for fp in 15 #9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60
do
echo "Start downloading fp" ${fp}
T=$(printf "%03d" "$fp")
echo "Start downloading leadtime ${T}h"
# single level
for N in CAPE_ML CAPE_CON PS
do
typeset -l nvar
nvar=${N}
wget -q ${icon_model_pfad}/${nvar}/${icon_single}${T}_${N}.grib2.bz2 -P ${store_path}
bzip2 -dfq ${store_path}/${icon_single}${T}_${N}.grib2.bz2
wget -q ${icon_model_pfad}/${nvar}/${icon_single}${T}_${N}.grib2.bz2 -P ${store_path} 2>&1 log.txt
bzip2 -dfq ${store_path}/${icon_single}${T}_${N}.grib2.bz2 >> log.txt 2>&1
done

for H in 1000 950 925 900 875 850 825 800 775 700 600 500 400 300 250 200
for H in 1000 950 925 900 875 850 825 800 775 700 600 500 400 300
do
for N in U V
do
typeset -l nvar
nvar=${N}
wget -q ${icon_model_pfad}/${nvar}/${icon_pressure}${T}_${H}_${N}.grib2.bz2 -P ${store_path}
bzip2 -dfq ${store_path}/${icon_pressure}${T}_${H}_${N}.grib2.bz2
wget -q ${icon_model_pfad}/${nvar}/${icon_pressure}${T}_${H}_${N}.grib2.bz2 -P ${store_path} >> log.txt 2>&1
bzip2 -dfq ${store_path}/${icon_pressure}${T}_${H}_${N}.grib2.bz2 >> log.txt 2>&1
done
done

# ifs
ifs_file=${ifs_model_pfad}/${D}/$(printf "%02d" "$R")z/ifs/0p25/oper/${D}$(printf "%02d" "$R")0000-${fp}h-oper-fc.grib2
ifs_index=${ifs_model_pfad}/${D}/$(printf "%02d" "$R")z/ifs/0p25/oper/${D}$(printf "%02d" "$R")0000-${fp}h-oper-fc.index
wget ${ifs_file} -P ${store_path}/
wget ${ifs_index} -P ${store_path}/
wget ${ifs_file} -P ${store_path}/ >> log.txt 2>&1
wget ${ifs_index} -P ${store_path}/ >> log.txt 2>&1
mv ${store_path}/${D}$(printf "%02d" "$R")0000-${fp}h-oper-fc.grib2 ${store_path}/ifs_$(printf "%02d" "$R")z_${D}_f${T}.grib2
mv ${store_path}/${D}$(printf "%02d" "$R")0000-${fp}h-oper-fc.index ${store_path}/ifs_$(printf "%02d" "$R")z_${D}_f${T}.index

# gfs
gfs_file=${gfs_model_pfad}/gfs.${D}/$(printf "%02d" "$R")/atmos/gfs.t$(printf "%02d" "$R")z.pgrb2.0p25.f${T}
wget ${gfs_file} -P ${store_path}/
wget ${gfs_file} -P ${store_path}/ >> log.txt 2>&1
mv ${store_path}/gfs.t$(printf "%02d" "$R")z.pgrb2.0p25.f${T} ${store_path}/gfs_$(printf "%02d" "$R")z_${D}_f${T}.grib2
# Plot Hodograph
# write run.yml configuration
Expand All @@ -87,12 +87,15 @@ do
echo "Plot Hodograph Maps"
# run python script

python3 main.py IFS
python3 main.py GFS
python3 main.py ICON
python3 main.py IFS >> log.txt 2>&1
python3 main.py GFS >> log.txt 2>&1
python3 main.py ICON >> log.txt 2>&1

echo "done with leadtime ${T}h on $(date)"
ls ./images/*${fp}.png
done



# remove nwp files
rm -rf ${store_path}
20 changes: 13 additions & 7 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# ---------------------------------------------------------------------------------------------------------------------------


def run(model_obj, fp):
def run_plots(model_obj, fp):
config = ut.load_yaml('config.yml')
debug_flag = config['debugflag']

Expand All @@ -32,7 +32,6 @@ def run(model_obj, fp):

# replace space with underscores
fieldname = "CAPE_ML" # args.field.replace(" ", "_")
rundate = model_obj.getrundate()
if program_mode == "Test":
cape_fld, lats, lons = model_obj.open_icon_gribfile_single(fieldname, fp, path="./modeldata/")
assert cape_fld.shape == (model_obj.getnlat(), model_obj.getnlon()), "Shape inconsistency"
Expand Down Expand Up @@ -99,8 +98,7 @@ def main():
args.field = "CAPE ML"

if (args.field != "CAPE ML") and (args.field != "CAPE CON") and (args.field != "LPI") and (args.field != "WMAXSHEAR"):
print("Unknown field")
exit(-1)
raise ValueError(f"Unknown input field!\n Only CAPE ML works in the moment. Argument: {args.field}")

if args.Model is None:
model_obj = model.MODELIFNO("ICON EU", 1377, 657, 0.0625, "pres")
Expand All @@ -111,8 +109,7 @@ def main():
elif args.Model == "GFS":
model_obj = model.gfs
else:
print("Unkown model! Exit.")
exit(0)
raise ValueError(f"Got unkown model! Cannot proceed with model {args.Model}")

if args.date is None:
model_obj.setrundate(datetime.strptime(run_config["default_date"], "%Y-%m-%d"))
Expand All @@ -124,14 +121,23 @@ def main():
else:
fp = args.fp

if (fp < 0) or (fp > 240):
raise ValueError(f"Got wrong leadtime (fp) : {fp}")

if args.run is None:
model_obj.setrun(run_config["run"])
else:
run = int(args.run)
if run != 0 or run != 6 or run != 12 or run != 18:
raise ValueError(f"Got wrong model runtime : {run}")
model_obj.setrun(args.run)

if (fp < 0) or (fp > 240):
raise ValueError(f"Got wrong leadtime (fp) : {fp}")

print(f"\nArguments: {args}\n{model_obj}")

run(model_obj, fp)
run_plots(model_obj, fp)

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

Expand Down
7 changes: 5 additions & 2 deletions src/plotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def basic_plot(model_obj, cape_fld, u, v, lats, lons, hour, threshold=10., imfmt
ax.annotate(' 600-300 hPa in green', xy=(0.02, -0.09), xycoords='axes fraction', fontsize=13)
ax.annotate("grey circles are 10 and 30m/s", xy=(0.02, -0.12), xycoords='axes fraction', fontsize=13)

name = f"./images/hodographmap_{model_name}_{hour}.{imfmt}"
name = f"./images/hodographmap_{model_name.replace(' ', '_')}_{hour}.{imfmt}"
plt.savefig(name)
plt.close()

Expand Down Expand Up @@ -294,5 +294,8 @@ def basic_plot_custarea(model_obj, cape_fld, u, v, lats, lons, hour, threshold=1
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)
if imfmt == "png":
plt.savefig(name, dpi=800)
else:
plt.savefig(name)
plt.close()
4 changes: 2 additions & 2 deletions src/run.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
run: 0
fp: 3
default_date: "2024-05-02"
fp: 15
default_date: "2024-05-03"

0 comments on commit 8318c34

Please sign in to comment.