Create_NEMO_forcing_from_UERRA.py 3.7 KB
Newer Older
Ludvig Isaksson's avatar
Ludvig Isaksson committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python

#########################################
### Configure section
#########################################
YYYY1=2017  # first year
MM1  =1     # first month
YYYY2=2017  # last year
MM2  =12    # last month

# workdir: a directory where the processing takes place and
# intermediate data is stored.
# ATTENTION: The workdir will be cleaned while running the script!!!
workdir="/scratch/local/"

# finaldir: That's where the final data will be placed.
finaldir="UERRA/NEMO-Nordic/"

# download_dir: A directory where the raw data downloaded from MARS will be stored.
# This needs to be cleaned manually if you do not want to keep it.
download_dir="Download/For_NEMO/"



#########################################
### Import modules
#########################################

import sys
import os

# This is needed if the job is sent via slurm.
# At least at the NSC HPC centre in Linkoping/Sweden.
if not '' in sys.path:
    sys.path.insert(0,'')

# Modules written for NEMO-Nordic conversion
import Get_UERRA_data
import Convert_for_NEMO


#########################################
### Create directories if needed
#########################################
if not os.path.isdir(download_dir):
    os.makedirs(download_dir)
    print ("Download directory %s created." % download_dir)
else:
    print ("Download directory %s exists already." % download_dir)

if not os.path.isdir(finaldir):
    os.makedirs(finaldir)
    print ("Final directory %s created." % finaldir)
if not os.path.exists(finaldir+'Humidity'):
    os.makedirs(finaldir+'Humidity')
if not os.path.exists(finaldir+'MSLP'):
    os.makedirs(finaldir+'MSLP')
if not os.path.exists(finaldir+'Precip'):
    os.makedirs(finaldir+'Precip')
if not os.path.exists(finaldir+'Radiation'):
    os.makedirs(finaldir+'Radiation')
if not os.path.exists(finaldir+'Snow'):
    os.makedirs(finaldir+'Snow')
if not os.path.exists(finaldir+'T2m'):
    os.makedirs(finaldir+'T2m')
if not os.path.exists(finaldir+'Wind'):
    os.makedirs(finaldir+'Wind')
if not os.path.isdir(workdir):
    os.makedirs(workdir)
    print ("Work directory %s created." % workdir)
else:
    print ("Work directory %s exists already." % workdir)


#########################################
### # Getting forecasts, analysis and precipitation from the MARS archive.
#########################################
Get_UERRA_data.retrieve_uerra_forecasts(YYYY1, MM1, YYYY2, MM2, download_dir)
sys.stdout.flush()   # Write output to standard out immediately - otherwise,
                     # there might be some internal storage before writing the output.
Get_UERRA_data.retrieve_uerra_analyses(YYYY1, MM1, YYYY2, MM2, download_dir)
sys.stdout.flush()
Get_UERRA_data.retrieve_uerra_precip(YYYY1, MM1, YYYY2, MM2, download_dir)
sys.stdout.flush()



#########################################
### Prepare the data for NEMO-Nordic
#########################################
Convert_for_NEMO.precipitation     (YYYY1, MM1, YYYY2, MM2, workdir, download_dir, finaldir)
sys.stdout.flush()
Convert_for_NEMO.radiation (YYYY1, MM1, YYYY2, MM2, workdir, download_dir, finaldir)
sys.stdout.flush()
Convert_for_NEMO.param_with_analysis (YYYY1, MM1, YYYY2, MM2, workdir, download_dir, finaldir)
sys.stdout.flush()
Convert_for_NEMO.humidity (YYYY1, MM1, YYYY2, MM2, workdir, download_dir, finaldir)
sys.stdout.flush()




#########################################
### Remove height dimension for temperature, wind and humidity
#########################################
# Use the bash script with NCO commands to remove the height dimension
script=os.getcwd()+"/remove_height.sh"
print "If you want to remove the height dimension you can use the bash-script remove_height.sh."
print "You can call it as follows..."
print script, finaldir, str(YYYY1), str(YYYY2)