Skip to content

Commit

Permalink
Several changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mammatus95 committed Feb 27, 2024
1 parent fa2f7f5 commit 835666f
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 124 deletions.
11 changes: 4 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@

.ipynb_checkpoints/
*/.ipynb_checkpoints/
*/*/.ipynb_checkpoints/

*/*.csv
*/*/*.csv

*/*.png
*/*/*.png

*/*.svg
*/*/*.svg

*/*.jpg
*/*/*.jpg

*.log
*/*.log

*.pyc
*/*.pyc
*/*/*.pyc

src/invariant
src/iconnest
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,26 @@ conda activate HodographMaps
```


# Example Image
## Example Image

![Example](images/test_ce_9.png)
![Example](images/example.png)

![Example](images/hodographmap_ce_9.png)


## How to run

```bash
cd src
bash download_script.sh
conda activate HodographMaps
```

## Cartopy?

https://github.com/mammatus95/cartopy
https://scitools.org.uk/cartopy/docs/latest/#

## Datasource
ICON Nest: https://opendata.dwd.de/weather/nwp/icon-eu/
IFS: https://www.ecmwf.int/en/forecasts/datasets/open-data
Binary file added images/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/hodographmap_ce_9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/test_ce_9.png
Binary file not shown.
Binary file removed src/__pycache__/plotlib.cpython-311.pyc
Binary file not shown.
Binary file removed src/__pycache__/utilitylib.cpython-311.pyc
Binary file not shown.
12 changes: 12 additions & 0 deletions src/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
run: 0
fp: 9
default_date: "2024-02-27"

levels: [60,10]
steps: 1 # level steps

threshold: 0

fontsize: 12
titlesize: 18

4 changes: 2 additions & 2 deletions src/download_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ do
cd ${path_icon}
T=$(printf "%03d" "$X")
#single level
for N in CAPE_ML
for N in CAPE_ML #CAPE_CON
do
typeset -l nvar
nvar=${N}
Expand All @@ -83,7 +83,7 @@ do
done

#rm -f

python3 main.py Basic --fp ${X} --run ${R} --date $(date)

echo "done with ${T}"
done
Expand Down
73 changes: 67 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#!/usr/bin/python3

from datetime import datetime


import argparse

import numpy as np

# own moduls
import utilitylib as ut
import plotlib

import modelinfolib as model
model = model.icon_nest
# ---------------------------------------------------------------------------------------------------------------------

def main():
# config = ul.load_yaml('config.yml')
config = ut.load_yaml('config.yml')

# command line arguments
parser = argparse.ArgumentParser(description="Hodograph Maps")
Expand All @@ -20,6 +26,15 @@ 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)')

# Parse the command line arguments
args = parser.parse_args()
Expand All @@ -31,20 +46,66 @@ def main():
print("Unknown field")
exit(-1)

if args.date == None:
rundate = datetime.strptime(config["default_date"], "%Y-%m-%d")
else:
rundate = datetime.strptime(args.date, "%Y-%m-%d")

if args.fp == None:
fp = config["fp"]
else:
fp = args.fp

if args.run == None:
run = config["run"]
else:
run = args.run

# replace space with underscores
fieldname = args.field.replace(" ", "_")



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

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


cape_fld, lats, lons = ut.open_gribfile(fieldname, path="./iconnest/")
print(lats.shape)

if args.mode == "Test":
plotlib.test_plot (cape_fld, lats, lons, 9, 0, titel='CAPE')
cape_fld, lats, lons = ut.open_gribfile_single(fieldname, rundate, run, fp, path="./iconnest/")
assert cape_fld.shape == (model.getnlat, model.getnlon), "Shape inconsistency"
plotlib.test_plot (cape_fld, lats, lons, fp, run, titel='CAPE')
else:
cape_fld, lats, lons = ut.open_gribfile_single(fieldname, rundate, run, fp, path="./iconnest/")

steps=config["steps"]
nlvl = int(model.getnlev()/steps)
u_fld = np.empty(nlvl*model.getpoints()).reshape((nlvl, model.getnlat(), model.getnlon()))
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]:
print("Wrong levels in config.yml!")
exit(0)

lvl_idx = 0
for level in range(config["levels"][0], config["levels"][1], steps):
u_fld[lvl_idx,:,:] = ut.open_gribfile_multi("U", level, rundate, run, fp, path="./iconnest/")
v_fld[lvl_idx,:,:] = ut.open_gribfile_multi("V", level, rundate, run, fp, path="./iconnest/")

lvl_idx += 1
if lvl_idx >= nlvl:
break

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

plotlib.basic_plot (cape_fld, u_fld, v_fld, lats, lons, 9, 0, titel='CAPE', threshold=config["threshold"])



if __name__ == "__main__":
main()
Expand Down
116 changes: 116 additions & 0 deletions src/modelinfolib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/python3
"""
## COSMO-REA2
points = 564720 #(724x780)
nlon = 724
nlat = 780
nlev = 50
lonmin = -7.5
lonmax = 5.514
latmin = -6.0
latmax = 8.022
##gradients
d_grad = 0.018
#nortpole
#north_lon=
#noth_lat=
## COSMO-RE6
points = 698752 #(848x824)
nlon = 848
nlat = 824
nlev = 40
lonmin = -28.403
lonmax = 18.182
latmin = -23.403
latmax = 21.862
##gradients
d_grad = 0.055
#nortpole
#north_lon=
#noth_lat=
## ICON Nest
points = 904689 #(1377x657)
nlon = 1377
nlat = 657
nlev = 51
lonmin = -23.5
lonmax = 45.0
latmin = 29.5
latmax = 70.5
##gradients
d_grad = 0.0625
## COSMO D2
points = 466116 #(651x716)
nlon = 651
nlat = 716
nlev = 65
lonmin = -7.5
lonmax = 5.5
latmin = -6.3
latmax = 8.0
##gradients
d_grad = 0.02
#nortpole
north_lon=-170
noth_lat=40
##ERAINTERIM
points=115680 #(480x241)
nlon=480
nlat=241
nlev=23
lonmin = -180.0
lonmax = 179.25
latmin = -90
latmax = 90
d_grad = 0.75
"""

class MODELIFNO:
def __init__(self, nlon, nlat, nlev, d_grad):
self.points = nlon*nlat
self.nlon = nlon
self.nlat = nlat
self.nlev = nlev
self.d_grad = d_grad

def __init__(self, nlon, nlat, nlev, lonmin, lonmax, latmin, latmax, d_grad):
self.points = nlon*nlat
self.nlon = nlon
self.nlat = nlat
self.nlev = nlev
self.d_grad = d_grad
print(lonmin, lonmax, latmin, latmax)

def __str__(self):
return (
f"Model Information:\nPoints: {self.points}\n"
f"Number of Longitudes: {self.nlon}\nNumber of Latitudes: {self.nlat}\n"
f"Number of Levels: {self.nlev}\nGradient: {self.d_grad}"
)

def getpoints(self):
return self.points

def getnlon(self):
return self.nlon

def getnlat(self):
return self.nlat

def getnlev(self):
return self.nlev

def getd_grad(self):
return self.d_grad

# Example usage:
icon_nest = MODELIFNO(1377, 657, 51, -23.5, 45.0, 29.5, 70.5, 0.0625)
cosmo_d2 = MODELIFNO(651, 716, 65, 0.02)
ifs = MODELIFNO(450, 900, 10, 0.4)
Loading

0 comments on commit 835666f

Please sign in to comment.