Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
AMBS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esde
machine-learning
AMBS
Commits
d038ab62
Commit
d038ab62
authored
4 years ago
by
BING GONG
Browse files
Options
Downloads
Patches
Plain Diff
add modular for calculating the climatorlogy
parent
0b1fe7c1
No related branches found
No related tags found
No related merge requests found
Pipeline
#68438
passed
4 years ago
Stage: build
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
video_prediction_tools/data_preprocess/calc_climatology.py
+104
-0
104 additions, 0 deletions
video_prediction_tools/data_preprocess/calc_climatology.py
video_prediction_tools/data_preprocess/prepare_era5_data.py
+1
-1
1 addition, 1 deletion
video_prediction_tools/data_preprocess/prepare_era5_data.py
with
105 additions
and
1 deletion
video_prediction_tools/data_preprocess/calc_climatology.py
0 → 100644
+
104
−
0
View file @
d038ab62
__email__
=
"
b.gong@fz-juelich.de
"
__author__
=
"
Yan Ji, Bing Gong
"
__date__
=
"
2021-05-26
"
"""
Use the monthly average vaules to calculate the climitological values from the datas sources that donwload from ECMWF : /p/fastdata/slmet/slmet111/met_data/ecmwf/era5/grib/monthly
"""
import
os
import
time
import
glob
import
json
class
Calc_climatology
(
object
):
def
__init__
(
self
,
input_dir
=
"
/p/fastdata/slmet/slmet111/met_data/ecmwf/era5/grib/monthly
"
,
output_clim
=
None
,
region
:
list
=
[
10
,
20
],
json_path
=
None
):
self
.
input_dir
=
input_dir
self
.
output_clim
=
output_clim
self
.
region
=
region
self
.
lats
=
None
self
.
lons
=
None
self
.
json_path
=
json_path
@staticmethod
def
calc_avg_per_year
(
grib_fl
:
str
=
None
):
"""
:param grib_fl: the relative path of the monthly average values
:return: None
"""
return
None
def
cal_avg_all_files
(
self
):
"""
Average by time for all the grib files
:return: None
"""
method
=
Calc_climatology
.
cal_avg_all_files
.
__name__
multiyears_path
=
os
.
path
.
join
(
self
.
output_clim
,
"
multiyears.grb
"
)
climatology_path
=
os
.
path
.
join
(
self
.
output_clim
,
"
climatology.grb
"
)
grib_files
=
glob
.
glob
(
os
.
path
.
join
(
self
.
input_dir
,
"
*t2m.grb
"
))
if
grib_files
:
print
(
"
{0}: There are {1} monthly years grib files
"
.
format
(
method
,
len
(
grib_files
)))
# merge all the files into one grib file
os
.
system
(
"
cdo mergetime {0} {1}
"
.
format
(
grib_files
,
multiyears_path
))
# average by time
os
.
system
(
"
cdo timavg {0} {1}
"
.
format
(
multiyears_path
,
climatology_path
))
else
:
FileExistsError
(
"
%{0}: The monthly years grib files do not exit in the input directory %{1}
"
.
format
(
method
,
self
.
input_dir
))
return
None
def
get_lat_lon_from_json
(
self
):
"""
Get lons and lats from json file
:return: list of lats, and lons
"""
method
=
Calc_climatology
.
get_lat_lon_from_json
.
__name__
if
not
os
.
path
.
exists
(
self
.
json_path
):
raise
FileExistsError
(
"
{0}: The json file {1} does not exist
"
.
format
(
method
,
self
.
json_path
))
with
open
(
self
.
json_path
)
as
fl
:
meta_data
=
json
.
load
(
fl
)
if
"
coordinates
"
not
in
list
(
meta_data
.
keys
()):
raise
KeyError
(
"
{0}:
'
coordinates
'
is not one of the keys for metadata,json
"
.
format
(
method
))
else
:
meta_coords
=
meta_data
[
"
coordinates
"
]
self
.
lats
=
meta_coords
[
"
lat
"
]
self
.
lons
=
meta_coords
[
"
lon
"
]
return
self
.
lats
,
self
.
lons
def
get_region_climate
(
self
):
"""
Get the climitollgical values from the selected regions
:return: None
"""
pass
def
__call__
(
self
,
*
args
,
**
kwargs
):
if
os
.
path
.
exists
(
os
.
path
.
join
(
self
.
output_clim
,
"
climatology.grb
"
)):
pass
else
:
self
.
cal_avg_all_files
()
self
.
get_lat_lon_from_json
()
self
.
get_region_climate
()
if
__name__
==
'
__main__
'
:
exp
=
Calc_climatology
(
json_path
=
"
/p/project/deepacf/deeprain/video_prediction_shared_folder/preprocessedData/era5-Y2007-2019M01to12-92x56-3840N0000E-2t_tcc_t_850/metadata.json
"
)
exp
()
This diff is collapsed.
Click to expand it.
video_prediction_tools/data_preprocess/prepare_era5_data.py
+
1
−
1
View file @
d038ab62
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