Commit 2138a0ff authored by SemjonSchimanke's avatar SemjonSchimanke
Browse files

To get forecast data valid on 00 UTC on 1 January we fetch now data from the previous year.

parent 9f5e03b3
......@@ -4,6 +4,7 @@ cdo=Cdo()
import shutil
import os
import glob
import sys
# What needs to be done with the raw data?
......@@ -78,6 +79,7 @@ def param_with_analysis(yearStart, monthStart, yearEnd, monthEnd, workdir, downd
# for month in list(range(monthStart, monthEnd + 1)):
for month in list(range(monthStart, 13)):
print "month: ", month
sys.stdout.flush()
if year == yearStart and month < monthStart:
# Before the start date.
continue
......@@ -102,11 +104,15 @@ def param_with_analysis(yearStart, monthStart, yearEnd, monthEnd, workdir, downd
# Merge monthly files to a yearly file.
print "Merge ", year, "and finalize the preparation."
sys.stdout.flush()
outfile3=workdir+"UERRA_analysis_%04d.nc" % (year)
cdo.mergetime(input=workdir+"UERRA_fc_%04d??.nc" % (year)+" "+workdir+"UERRA_an_%04d??.nc" % (year),
output=outfile3, options = '-O')
# Make sure it is really only one year.
yearfile=workdir+"UERRA_exact_one_year_%04d.nc" % (year)
cdo.selyear(year, input=outfile3, output=yearfile, options = '-O')
cdo.splitname(input=outfile3, output=workdir+"UERRA_analysis_%04d_" % (year))
cdo.splitname(input=yearfile, output=workdir+"UERRA_analysis_%04d_" % (year))
### T2m
# Change the parameter name and copy to final destination.
......@@ -137,6 +143,7 @@ def param_with_analysis(yearStart, monthStart, yearEnd, monthEnd, workdir, downd
input=wfile, output=zzfile)
shutil.copy(zzfile, finaldir+"Wind/")
sys.stdout.flush()
for fl in glob.glob(workdir+"UERRA*.nc"):
os.remove(fl)
......@@ -152,6 +159,7 @@ def radiation(yearStart, monthStart, yearEnd, monthEnd, workdir, downdir, finald
for month in list(range(monthStart, 13)):
# for month in list(range(monthStart, monthEnd + 1)):
print "month: ", month
sys.stdout.flush()
if year == yearStart and month < monthStart:
# Before the start date.
continue
......@@ -162,7 +170,12 @@ def radiation(yearStart, monthStart, yearEnd, monthEnd, workdir, downdir, finald
input=" -setgridtype,curvilinear -selname,ssrd,strd "+infile2,
output=outfile2, options = '-f nc')
cdo.splithour(input=outfile2, output=workdir+"hour_")
# Make sure it is really only one year.
yearfile=workdir+"UERRA_exact_one_year_%04d.nc" % (year)
cdo.selyear(year, input=outfile2, output=yearfile, options = '-O')
cdo.splithour(input=yearfile, output=workdir+"hour_")
cdo.sub(input=workdir+"hour_02.nc"+" "+workdir+"hour_01.nc", output=workdir+"hourly_02.nc")
cdo.sub(input=workdir+"hour_03.nc"+" "+workdir+"hour_02.nc", output=workdir+"hourly_03.nc")
......@@ -196,6 +209,9 @@ def radiation(yearStart, monthStart, yearEnd, monthEnd, workdir, downdir, finald
if year == yearEnd and month == monthEnd:
# Done with the last month.
break
print ("Almost done... merge and then copy.")
sys.stdout.flush()
infile=workdir+"hourly_%04d??.nc" % (year)
allrad=cdo.mergetime(input=infile)
......
......@@ -19,7 +19,7 @@ MM2 =8 # last month
workdir="/scratch/local/"
# finaldir: That's where the final data will be placed.
finaldir="/nobackup/smhid14/precise/data/UERRA/NEMO-Nordic_TEST/"
finaldir="/nobackup/smhid14/precise/data/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.
......@@ -46,7 +46,7 @@ import Convert_for_NEMO
#########################################
### Create cataloges if needed
### Create directories if needed
#########################################
if not os.path.isdir(download_dir):
os.makedirs(download_dir)
......
......@@ -23,8 +23,6 @@ def retrieve_uerra_forecasts(yearStart, monthStart, yearEnd, monthEnd, download_
for year in list(range(yearStart, yearEnd + 1)):
for month in list(range(1, 13)):
sys.stdout.flush()
if year == yearStart and month < monthStart:
# Before the start date.
continue
......@@ -40,12 +38,25 @@ def retrieve_uerra_forecasts(yearStart, monthStart, yearEnd, monthEnd, download_
print target + " is already on place."
continue
startDate = '%04d%02d%02d' % (year, month, 1)
### get forecast valid at 00UTC on 1st of January from previous year
if month == 1:
syear = year - 1
smonth = 12
sday = 31
startDate = '%04d%02d%02d' % (syear, smonth, sday)
else:
startDate = '%04d%02d%02d' % (year, month, 1)
numberOfDays = calendar.monthrange(year, month)[1]
lastDate = '%04d%02d%02d' % (year, month, numberOfDays)
requestDates = (startDate + "/TO/" + lastDate)
print "retrieve forecast data for ", requestDates
print (" ")
print ("***")
print "Submit request for forecast data, dates: ", requestDates
sys.stdout.flush()
server.retrieve({
"class": "ur",
"stream": "oper",
......
......@@ -19,7 +19,8 @@ Then, all you have to do is to run the main script...
Create_NEMO_forcing_from_UERRA.py
The scripts need some time to run. Especially the downloading of data
from the MARS archive takes time...
from the MARS archive takes time. Here, we are talking about days if
you want to produce forcing data for longer periods (several years).
Technical details
......@@ -29,11 +30,16 @@ namely the cluster called "Bi".
Here, we used Python 2.7.9.
We involve also CDO commands to a large degree. These need to be compiled
into your python version.
On Bi, you actually have to load the CDO module
cdo/1.7.0-i1501-netcdf-4.3.2-hdf5-1.8.14-grib_api-1.14.0
Moreover, to fetch data from the MARS archive, you will need the
corresponding modules. Please find out on ECMWF's websides.
Otherwise, used modules should be standard.
Overview on the order of called routines
----------------------------------------
Create_NEMO_forcing_from_UERRA.py
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment