Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Flex Extract
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Flexpart
Flex Extract
Commits
095dc73c
Commit
095dc73c
authored
6 years ago
by
Anne Philipp
Browse files
Options
Downloads
Patches
Plain Diff
added two new functions for grib information and updated commandline parameter for argparser
parent
b0cf1a68
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/python/mods/tools.py
+108
-16
108 additions, 16 deletions
source/python/mods/tools.py
with
108 additions
and
16 deletions
source/python/mods/tools.py
+
108
−
16
View file @
095dc73c
...
@@ -54,6 +54,7 @@ import glob
...
@@ -54,6 +54,7 @@ import glob
import
subprocess
import
subprocess
import
traceback
import
traceback
import
exceptions
import
exceptions
from
datetime
import
datetime
from
argparse
import
ArgumentParser
,
ArgumentDefaultsHelpFormatter
from
argparse
import
ArgumentParser
,
ArgumentDefaultsHelpFormatter
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
...
@@ -116,7 +117,7 @@ def get_cmdline_arguments():
...
@@ -116,7 +117,7 @@ def get_cmdline_arguments():
ECMWF MARS archive
'
,
ECMWF MARS archive
'
,
formatter_class
=
ArgumentDefaultsHelpFormatter
)
formatter_class
=
ArgumentDefaultsHelpFormatter
)
#
the most important argument
s
#
control parameters that override control file value
s
parser
.
add_argument
(
"
--start_date
"
,
dest
=
"
start_date
"
,
parser
.
add_argument
(
"
--start_date
"
,
dest
=
"
start_date
"
,
type
=
none_or_str
,
default
=
None
,
type
=
none_or_str
,
default
=
None
,
help
=
"
start date YYYYMMDD
"
)
help
=
"
start date YYYYMMDD
"
)
...
@@ -129,20 +130,6 @@ def get_cmdline_arguments():
...
@@ -129,20 +130,6 @@ def get_cmdline_arguments():
parser
.
add_argument
(
"
--controlfile
"
,
dest
=
"
controlfile
"
,
parser
.
add_argument
(
"
--controlfile
"
,
dest
=
"
controlfile
"
,
type
=
none_or_str
,
default
=
'
CONTROL.temp
'
,
type
=
none_or_str
,
default
=
'
CONTROL.temp
'
,
help
=
"
file with CONTROL parameters
"
)
help
=
"
file with CONTROL parameters
"
)
# parameter for extra output information
parser
.
add_argument
(
"
--debug
"
,
dest
=
"
debug
"
,
type
=
none_or_int
,
default
=
None
,
help
=
"
debug mode - leave temporary files intact
"
)
parser
.
add_argument
(
"
--request
"
,
dest
=
"
request
"
,
type
=
none_or_int
,
default
=
None
,
help
=
"
list all mars request in file mars_requests.dat
\
and skip submission to mars
"
)
parser
.
add_argument
(
"
--public
"
,
dest
=
"
public
"
,
type
=
none_or_int
,
default
=
None
,
help
=
"
public mode - retrieves the public datasets
"
)
# some arguments that override the default in the CONTROL file
parser
.
add_argument
(
"
--basetime
"
,
dest
=
"
basetime
"
,
parser
.
add_argument
(
"
--basetime
"
,
dest
=
"
basetime
"
,
type
=
none_or_int
,
default
=
None
,
type
=
none_or_int
,
default
=
None
,
help
=
"
base such as 00 or 12 (for half day retrievals)
"
)
help
=
"
base such as 00 or 12 (for half day retrievals)
"
)
...
@@ -156,7 +143,23 @@ def get_cmdline_arguments():
...
@@ -156,7 +143,23 @@ def get_cmdline_arguments():
type
=
none_or_str
,
default
=
None
,
type
=
none_or_str
,
default
=
None
,
help
=
"
area defined as north/west/south/east
"
)
help
=
"
area defined as north/west/south/east
"
)
# set the working directories
# some switches
parser
.
add_argument
(
"
--debug
"
,
dest
=
"
debug
"
,
type
=
none_or_int
,
default
=
None
,
help
=
"
debug mode - leave temporary files intact
"
)
parser
.
add_argument
(
"
--request
"
,
dest
=
"
request
"
,
type
=
none_or_int
,
default
=
None
,
help
=
"
list all mars requests in file mars_requests.dat
"
)
parser
.
add_argument
(
"
--public
"
,
dest
=
"
public
"
,
type
=
none_or_int
,
default
=
None
,
help
=
"
public mode - retrieves the public datasets
"
)
parser
.
add_argument
(
"
--rrint
"
,
dest
=
"
rrint
"
,
type
=
none_or_int
,
default
=
None
,
help
=
"
select old or new precipitation interpolation
\
0 - old method
\
1 - new method (additional subgrid points)
"
)
# set directories
parser
.
add_argument
(
"
--inputdir
"
,
dest
=
"
inputdir
"
,
parser
.
add_argument
(
"
--inputdir
"
,
dest
=
"
inputdir
"
,
type
=
none_or_str
,
default
=
None
,
type
=
none_or_str
,
default
=
None
,
help
=
"
root directory for storing intermediate files
"
)
help
=
"
root directory for storing intermediate files
"
)
...
@@ -633,3 +636,92 @@ def submit_job_to_ecserver(target, jobname):
...
@@ -633,3 +636,92 @@ def submit_job_to_ecserver(target, jobname):
sys
.
exit
(
'
... ECACCESS-JOB-SUBMIT FAILED!
'
)
sys
.
exit
(
'
... ECACCESS-JOB-SUBMIT FAILED!
'
)
return
job_id
return
job_id
def
get_informations
(
filename
):
'''
Gets basic information from an example grib file.
These information are important for later use and the
initialization of numpy arrays for data storing.
Parameters
----------
filename : :obj:`string`
Name of the file which will be opened to extract basic information.
Return
------
data : :obj:`dictionary`
Contains basic informations of the ECMWF grib files, e.g.
'
Ni
'
,
'
Nj
'
,
'
latitudeOfFirstGridPointInDegrees
'
,
'
longitudeOfFirstGridPointInDegrees
'
,
'
latitudeOfLastGridPointInDegrees
'
,
'
longitudeOfLastGridPointInDegrees
'
,
'
jDirectionIncrementInDegrees
'
,
'
iDirectionIncrementInDegrees
'
,
'
missingValue
'
'''
from
eccodes
import
*
data
=
{}
# --- open file ---
print
(
"
Opening file for getting information data --- %s
"
%
filename
)
with
open
(
filename
)
as
f
:
# load first message from file
gid
=
codes_grib_new_from_file
(
f
)
# information needed from grib message
keys
=
[
'
Ni
'
,
'
Nj
'
,
'
latitudeOfFirstGridPointInDegrees
'
,
'
longitudeOfFirstGridPointInDegrees
'
,
'
latitudeOfLastGridPointInDegrees
'
,
'
longitudeOfLastGridPointInDegrees
'
,
'
jDirectionIncrementInDegrees
'
,
'
iDirectionIncrementInDegrees
'
,
'
missingValue
'
,
]
print
(
'
\n
Informations are:
'
)
for
key
in
keys
:
# Get the value of the key in a grib message.
data
[
key
]
=
codes_get
(
gid
,
key
)
print
(
"
%s = %s
"
%
(
key
,
data
[
key
]))
# Free the memory for the message referred as gribid.
codes_release
(
gid
)
return
data
def
get_dimensions
(
c
,
info
):
'''
This function specifies the correct dimensions for x, y and t.
Parameters
----------
c : :obj:`ControlFile`
Contains all the parameters of CONTROL file and
command line.
info : :obj:`dictionary`
Contains basic informations of the ECMWF grib files, e.g.
'
Ni
'
,
'
Nj
'
,
'
latitudeOfFirstGridPointInDegrees
'
,
'
longitudeOfFirstGridPointInDegrees
'
,
'
latitudeOfLastGridPointInDegrees
'
,
'
longitudeOfLastGridPointInDegrees
'
,
'
jDirectionIncrementInDegrees
'
,
'
iDirectionIncrementInDegrees
'
,
'
missingValue
'
Return
------
(ix, jy, it) : :obj:`tuple` of :obj:`integer`
Dimension in x-direction, y-direction and in time.
'''
ix
=
info
[
'
Ni
'
]
jy
=
info
[
'
Nj
'
]
start
=
datetime
.
strptime
(
c
.
start_date
,
'
%Y%m%d
'
)
end
=
datetime
.
strptime
(
c
.
end_date
,
'
%Y%m%d
'
)
it
=
((
end
-
start
).
days
+
1
)
*
24
/
int
(
c
.
dtime
)
print
'
it
'
,
it
,
(
end
-
start
).
days
,
24
/
int
(
c
.
dtime
)
return
(
ix
,
jy
,
it
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment