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
Peters, Wouter
CTDAS
Commits
bb9a3efc
Commit
bb9a3efc
authored
11 years ago
by
Peters, Wouter
Browse files
Options
Downloads
Patches
Plain Diff
new functionality added
parent
0f291269
Branches
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
gridded/da/analysis/longterm_fluxes.py
+59
-0
59 additions, 0 deletions
gridded/da/analysis/longterm_fluxes.py
with
59 additions
and
0 deletions
gridded/da/analysis/longterm_fluxes.py
0 → 100755
+
59
−
0
View file @
bb9a3efc
#!/usr/bin/env python
# longterm_fluxes.py
"""
Author : peters
Revision History:
File created on 20 Dec 2012.
"""
import
os
import
sys
import
datetime
from
dateutil.relativedelta
import
relativedelta
import
subprocess
def
longterm_avg
(
rundir
,
avg
):
"""
Function to average a set of files in a folder from monthly to yearly means
"""
if
avg
not
in
[
'
transcom
'
,
'
olson
'
,
'
country
'
,
'
flux1x1
'
]:
raise
IOError
,
'
Choice of averaging invalid
'
if
not
os
.
path
.
exists
(
rundir
):
raise
IOError
,
'
rundir requested (%s) does not exist, exiting...
'
%
rundir
yeardir
=
os
.
path
.
join
(
rundir
,
'
data_%s_yearly
'
%
avg
)
files
=
os
.
listdir
(
yeardir
)
longtermdir
=
os
.
path
.
join
(
rundir
,
'
data_%s_longterm
'
%
avg
)
if
not
os
.
path
.
exists
(
longtermdir
):
print
"
Creating new output directory
"
+
longtermdir
os
.
makedirs
(
longtermdir
)
sd
=
datetime
.
datetime
(
1999
,
1
,
1
)
files
=
[
f
for
f
in
files
if
avg
in
f
]
dates
=
[]
for
filename
in
files
:
date
=
datetime
.
datetime
.
strptime
(
filename
.
split
(
'
.
'
)[
-
2
],
'
%Y
'
)
dates
.
append
(
date
)
avg_files
=
[
os
.
path
.
join
(
yeardir
,
k
)
for
k
in
files
]
if
len
(
avg_files
)
>
0
:
command
=
[
'
ncra
'
,
'
-O
'
]
+
avg_files
+
[
os
.
path
.
join
(
longtermdir
,
'
%s_fluxes.%04d-%04d.nc
'
%
(
avg
,
dates
[
0
].
year
,
dates
[
-
1
].
year
))]
status
=
subprocess
.
check_call
(
command
)
if
__name__
==
"
__main__
"
:
rundir
=
"
/Storage/CO2/peters/ctdas-ei-gfed2-glb6x4-griddedNH/analysis
"
try
:
avg
=
sys
.
argv
[
1
]
except
:
avg
=
'
transcom
'
longterm_avg
(
rundir
,
avg
)
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