Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MAR - CARAIB
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dethinne Thomas
MAR - CARAIB
Commits
910764ae
Commit
910764ae
authored
7 months ago
by
Dethinne Thomas
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
cc2afc62
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
couplage/make_climatology_for_CARAIB.py
+149
-0
149 additions, 0 deletions
couplage/make_climatology_for_CARAIB.py
with
149 additions
and
0 deletions
couplage/make_climatology_for_CARAIB.py
0 → 100644
+
149
−
0
View file @
910764ae
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 26 09:50:43 2024
@author: Thomas
"""
#
# ----------------------------------------------------------------------------------------------------------------------
#
# Title of script
#
# ----------------------------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------
#
# Imports and global variables
# \**********************************/
#
import
numpy
as
np
import
time
import
xarray
as
xr
import
os
import
sys
import
matplotlib.pyplot
as
plt
# ----------------------------------------------------------------------------------------------------------------------
#
# Functions
# \***************/
#
#
# Here you can define usefull functions to be used in the main
#
"""
##############################################################################################################
"""
def
ti
():
return
time
.
time
()
"""
##############################################################################################################
"""
def
open_mar
(
path
):
return
xr
.
open_mfdataset
(
path
)
"""
##############################################################################################################
"""
def
group_per_day
(
sa
):
return
sa
.
groupby
(
"
time.dayofyear
"
).
mean
()
"""
##############################################################################################################
"""
def
resample
(
sa
,
var
):
dico
=
{
"
TTmin
"
:
sa
.
resample
(
time
=
'
1D
'
).
min
(),
"
TTmax
"
:
sa
.
resample
(
time
=
'
1D
'
).
max
(),
"
TT
"
:
sa
.
resample
(
time
=
'
1D
'
).
mean
(),
"
MBrr
"
:
sa
.
resample
(
time
=
'
1D
'
).
sum
(),
"
RH
"
:
sa
.
resample
(
time
=
'
1D
'
).
mean
(),
"
UV
"
:
sa
.
resample
(
time
=
'
1D
'
).
mean
(),
"
SWD
"
:
sa
.
resample
(
time
=
'
1D
'
).
mean
()
}
return
dico
[
var
]
#.get(var,print("no good key"))
"""
##############################################################################################################
"""
def
get_name
(
var
):
dico
=
{
"
TTmin
"
:
"
tminyyyy
"
,
"
TTmax
"
:
"
tmaxyyyy
"
,
"
TT
"
:
"
temyyyy
"
,
"
MBrr
"
:
"
prcyyyy
"
,
"
RH
"
:
"
ruhyyyy
"
,
"
UV
"
:
"
wndyyyy
"
,
"
SWD
"
:
"
fsolyyyy
"
}
return
dico
[
var
]
#.get(var,print("no good key"))
"""
##############################################################################################################
"""
def
write_clim
(
sa
,
longitude
,
latitude
,
var
):
var_values
=
sa
.
values
name_of_file
=
get_name
(
var
)
print
(
"
Start writing the file
"
)
for
i
in
np
.
arange
(
0
,
np
.
shape
(
lon
)[
1
]):
for
j
in
np
.
arange
(
0
,
np
.
shape
(
lon
)[
0
]):
lo
=
longitude
[
j
,
i
]
la
=
latitude
[
j
,
i
]
try
:
va
=
var_values
[:,
0
,
j
,
i
]
except
:
va
=
var_values
[:,
j
,
i
]
f
=
open
(
name_of_file
+
"
.dat
"
,
"
a
"
)
text
=
str
(
round
(
lo
,
3
))
+
'
\t
'
+
str
(
round
(
la
,
3
))
+
'
\t
'
+
'
\t
'
.
join
(
str
(
round
(
x
,
3
))
for
x
in
va
)
+
"
\n
"
f
.
write
(
text
)
f
.
close
()
"""
##############################################################################################################
"""
# Main
# \**********/
#
#
# Here you can define the instructions that are called when you execute this file
#
if
__name__
==
'
__main__
'
:
t0
=
ti
()
variable_to_clim
=
[
"
MBrr
"
,
"
RH
"
,
"
UV
"
,
"
SWD
"
]
#"TTmin","TTmax","TT",
path_to_MAR
=
"
F:/MAR_data_raw_BE/MERRA/*.nc
"
print
(
"
open data
"
)
MAR
=
open_mar
(
path_to_MAR
)
lon
=
MAR
.
LON
.
isel
(
time
=
0
).
values
lat
=
MAR
.
LAT
.
isel
(
time
=
0
).
values
for
var
in
variable_to_clim
:
print
(
"
Extract
"
,
var
)
MAR_var
=
MAR
[
var
]
print
(
"
Resample to daily
"
)
MAR_daily
=
resample
(
MAR_var
,
var
)
print
(
"
Group by doy
"
)
MAR_clim
=
group_per_day
(
MAR_var
)
print
(
"
Write climatology
"
)
write_clim
(
MAR_clim
,
lon
,
lat
,
var
)
# sys.exit()
t1
=
ti
()
print
(
'
Programme compiled in
'
,
t1
-
t0
,
'
sec
'
)
\ No newline at end of file
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