Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CTDAS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
CTDAS
CTDAS
Commits
d2fcff9b
Commit
d2fcff9b
authored
2 years ago
by
Woude, Auke van der
Browse files
Options
Downloads
Patches
Plain Diff
Added functionality to write dictionaries to file; write GPP and TER separately
parent
56d15fda
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
da/preprocessing/classes.py
+25
-8
25 additions, 8 deletions
da/preprocessing/classes.py
da/preprocessing/upscale_bio.py
+9
-2
9 additions, 2 deletions
da/preprocessing/upscale_bio.py
with
34 additions
and
10 deletions
da/preprocessing/classes.py
+
25
−
8
View file @
d2fcff9b
...
@@ -35,9 +35,18 @@ class Regional(object):
...
@@ -35,9 +35,18 @@ class Regional(object):
self
.
name
=
'
Here goes the flux name
'
# Overwrite in the subclasses
self
.
name
=
'
Here goes the flux name
'
# Overwrite in the subclasses
def
create_filename
(
self
):
def
create_filename
(
self
,
change_name
=
None
,
outdir
=
None
):
"""
Create the filename for a regional file
"""
"""
Create the filename for a regional file
"""
return
'
{0}/regional.{1}.nc
'
.
format
(
self
.
dacycle
[
'
dir.output
'
],
self
.
name
)
# Add possibility to write to a different file than self.name
if
change_name
is
None
:
name
=
self
.
name
else
:
name
=
change_name
if
outdir
is
None
:
outdir
=
self
.
dacycle
[
'
dir.output
'
]
return
'
{0}/regional.{1}.nc
'
.
format
(
outdir
,
name
)
def
get_filenames
(
self
):
def
get_filenames
(
self
):
"""
Get all filenames for the current month
"""
"""
Get all filenames for the current month
"""
...
@@ -125,9 +134,12 @@ class Regional(object):
...
@@ -125,9 +134,12 @@ class Regional(object):
A
[
iy
,
:]
=
Alat
A
[
iy
,
:]
=
Alat
return
A
# m2
return
A
# m2
def
write
(
self
,
values
,
varname
=
None
):
def
write
(
self
,
values
,
varname
=
None
,
filename
=
None
,
outdir
=
None
):
# Write the biosphere fluxes to a file
# Write the biosphere fluxes to a file
filename
=
self
.
create_filename
()
if
outdir
is
None
:
outdir
=
self
.
dacycle
[
'
dir.output
'
]
filename
=
self
.
create_filename
(
change_name
=
filename
,
outdir
=
outdir
)
logging
.
debug
(
'
Writing fluxes to file {}
'
.
format
(
filename
))
logging
.
debug
(
'
Writing fluxes to file {}
'
.
format
(
filename
))
if
varname
is
None
:
if
varname
is
None
:
...
@@ -143,8 +155,8 @@ class Regional(object):
...
@@ -143,8 +155,8 @@ class Regional(object):
values
=
np
.
nan_to_num
(
values
)
values
=
np
.
nan_to_num
(
values
)
# Only make the file if this is the first variable to put there
# Only make the file if this is the first variable to put there
if
i
==
0
:
if
i
==
0
:
if
not
os
.
path
.
exists
(
self
.
dacycle
[
'
dir.output
'
]
):
if
not
os
.
path
.
exists
(
outdir
):
os
.
mkdir
(
self
.
dacycle
[
'
dir.output
'
]
)
os
.
mkdir
(
outdir
)
with
io
.
CT_CDF
(
filename
,
method
=
'
create
'
)
as
f
:
with
io
.
CT_CDF
(
filename
,
method
=
'
create
'
)
as
f
:
dimtime
,
dimlat
,
dimlon
=
f
.
add_dimensions
(
self
.
times
,
self
.
lats
,
self
.
lons
)
dimtime
,
dimlat
,
dimlon
=
f
.
add_dimensions
(
self
.
times
,
self
.
lats
,
self
.
lons
)
...
@@ -196,9 +208,14 @@ class Global(Regional):
...
@@ -196,9 +208,14 @@ class Global(Regional):
dtstart
=
self
.
startdate
,
until
=
self
.
enddate
))
# rrule includes until
dtstart
=
self
.
startdate
,
until
=
self
.
enddate
))
# rrule includes until
self
.
times
=
times
self
.
times
=
times
def
create_filename
(
self
):
def
create_filename
(
self
,
change_name
=
None
):
"""
Create the filename for a regional file
"""
"""
Create the filename for a regional file
"""
return
'
{0}/global.{1}_{2:%Y%m}.nc
'
.
format
(
self
.
dacycle
[
'
dir.output
'
],
self
.
name
,
self
.
dacycle
[
'
time.start
'
])
# Add possibility to write to a different file than self.name
if
change_name
is
None
:
name
=
self
.
name
else
:
name
=
change_name
return
'
{0}/global.{1}_{2:%Y%m}.nc
'
.
format
(
self
.
dacycle
[
'
dir.output
'
],
name
,
self
.
dacycle
[
'
time.start
'
])
def
combine_with_regional
(
self
):
def
combine_with_regional
(
self
):
"""
Combine the high resolution with global fluxes
"""
Combine the high resolution with global fluxes
...
...
This diff is collapsed.
Click to expand it.
da/preprocessing/upscale_bio.py
+
9
−
2
View file @
d2fcff9b
...
@@ -33,12 +33,17 @@ class SiBUpscaler(Regional):
...
@@ -33,12 +33,17 @@ class SiBUpscaler(Regional):
self
.
sibfile
=
self
.
sibdir
+
sibfile
self
.
sibfile
=
self
.
sibdir
+
sibfile
self
.
sibfile_avg
=
self
.
sibfile
.
replace
(
'
lu.qp3
'
,
'
g.qp2
'
)
self
.
sibfile_avg
=
self
.
sibfile
.
replace
(
'
lu.qp3
'
,
'
g.qp2
'
)
logging
.
debug
(
'
Reading SiB data from {}
'
.
format
(
self
.
sibfile
))
logging
.
debug
(
'
Reading SiB data from {}
'
.
format
(
self
.
sibfile
))
# Write GPP and TER
datadict
=
{}
datadict
=
{}
for
v
in
(
'
nee
'
,
'
resp_tot
'
,
'
assim
'
):
for
v
in
(
'
resp_tot
'
,
'
assim
'
):
logging
.
info
(
f
'
Getting high-res
{
v
}
'
)
logging
.
info
(
f
'
Getting high-res
{
v
}
'
)
data
=
self
.
load_biosphere_emissions
(
v
)
data
=
self
.
load_biosphere_emissions
(
v
)
datadict
[
v
]
=
data
datadict
[
v
]
=
data
outfile
=
self
.
write
(
datadict
)
outfile
=
self
.
write
(
datadict
,
filename
=
'
bio
'
)
# Write NEP seperately
data
=
self
.
load_biosphere_emissions
(
'
nee
'
)
outfile
=
self
.
write
(
data
)
return
outfile
,
self
.
name
return
outfile
,
self
.
name
def
load_biosphere_emissions
(
self
,
fluxname
):
def
load_biosphere_emissions
(
self
,
fluxname
):
...
@@ -93,6 +98,8 @@ class SiBUpscaler(Regional):
...
@@ -93,6 +98,8 @@ class SiBUpscaler(Regional):
fluxname
=
'
reco
'
fluxname
=
'
reco
'
elif
fluxname
==
'
assim
'
:
elif
fluxname
==
'
assim
'
:
fluxname
=
'
gpp
'
fluxname
=
'
gpp
'
elif
fluxname
==
'
nee
'
:
fluxname
==
'
nep
'
nee_averaged
=
ds
[
fluxname
]
nee_averaged
=
ds
[
fluxname
]
nee_averaged
=
nee_averaged
[
startindex
:
stopindex
,
:].
astype
(
np
.
float32
)
nee_averaged
=
nee_averaged
[
startindex
:
stopindex
,
:].
astype
(
np
.
float32
)
nee_averaged
=
np
.
flip
(
st
.
convert_2d
(
nee_averaged
,
latsib
,
lonsib
),
axis
=-
2
)
nee_averaged
=
np
.
flip
(
st
.
convert_2d
(
nee_averaged
,
latsib
,
lonsib
),
axis
=-
2
)
...
...
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