Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
NearRealTimeCTDAS
CTDAS
Commits
f72f98d6
Commit
f72f98d6
authored
Jun 20, 2013
by
Peters, Wouter
Browse files
new mechanism to write time average fluxes while the run is ongoing
parent
7e7fcda8
Changes
4
Hide whitespace changes
Inline
Side-by-side
da/analysis/daily_fluxes.py
View file @
f72f98d6
...
@@ -23,10 +23,10 @@ def daily_avg(rundir,avg):
...
@@ -23,10 +23,10 @@ def daily_avg(rundir,avg):
if
not
os
.
path
.
exists
(
rundir
):
if
not
os
.
path
.
exists
(
rundir
):
raise
IOError
,
'rundir requested (%s) does not exist, exiting...'
%
rundir
raise
IOError
,
'rundir requested (%s) does not exist, exiting...'
%
rundir
weekdir
=
os
.
path
.
join
(
rundir
+
'data_%s_weekly'
%
avg
)
weekdir
=
os
.
path
.
join
(
rundir
,
'data_%s_weekly'
%
avg
)
files
=
os
.
listdir
(
weekdir
)
files
=
os
.
listdir
(
weekdir
)
daydir
=
os
.
path
.
join
(
rundir
+
'data_%s_daily'
%
avg
)
daydir
=
os
.
path
.
join
(
rundir
,
'data_%s_daily'
%
avg
)
if
not
os
.
path
.
exists
(
daydir
):
if
not
os
.
path
.
exists
(
daydir
):
print
"Creating new output directory "
+
daydir
print
"Creating new output directory "
+
daydir
os
.
makedirs
(
daydir
)
os
.
makedirs
(
daydir
)
...
...
da/analysis/monthly_fluxes.py
View file @
f72f98d6
...
@@ -23,7 +23,7 @@ def monthly_avg(rundir,avg):
...
@@ -23,7 +23,7 @@ def monthly_avg(rundir,avg):
if
not
os
.
path
.
exists
(
rundir
):
if
not
os
.
path
.
exists
(
rundir
):
raise
IOError
,
'rundir requested (%s) does not exist, exiting...'
%
rundir
raise
IOError
,
'rundir requested (%s) does not exist, exiting...'
%
rundir
daydir
=
rundir
+
'data_%s_daily'
%
avg
daydir
=
os
.
path
.
join
(
rundir
,
'data_%s_daily'
%
avg
)
files
=
os
.
listdir
(
daydir
)
files
=
os
.
listdir
(
daydir
)
monthdir
=
os
.
path
.
join
(
rundir
,
'data_%s_monthly'
%
avg
)
monthdir
=
os
.
path
.
join
(
rundir
,
'data_%s_monthly'
%
avg
)
if
not
os
.
path
.
exists
(
monthdir
):
if
not
os
.
path
.
exists
(
monthdir
):
...
...
da/analysis/time_avg_fluxes.py
0 → 100755
View file @
f72f98d6
#!/usr/bin/env python
# time_avg_fluxes.py
"""
Author : peters
Revision History:
File created on 20 Dec 2012.
"""
import
sys
sys
.
path
.
append
(
'../../'
)
import
os
import
sys
import
shutil
import
datetime
from
da.analysis.daily_fluxes
import
daily_avg
from
da.analysis.monthly_fluxes
import
monthly_avg
from
da.analysis.yearly_fluxes
import
yearly_avg
def
time_avg
(
dacycle
,
avg
=
'transcom'
):
""" Function to create a set of averaged files in a folder, needed to make longer term means """
if
avg
not
in
[
'transcom'
,
'olson'
,
'country'
]:
raise
IOError
,
'Choice of averaging invalid'
analysisdir
=
dacycle
[
'dir.analysis'
]
if
not
os
.
path
.
exists
(
analysisdir
):
raise
IOError
,
'analysis dir requested (%s) does not exist, exiting...'
%
analysisdir
daily_avg
(
analysisdir
,
avg
)
if
new_month
(
dacycle
):
monthly_avg
(
analysisdir
,
avg
)
if
new_year
(
dacycle
):
yearly_avg
(
analysisdir
,
avg
)
def
new_month
(
dacycle
):
""" check whether we just entered a new month"""
this_month
=
dacycle
[
'time.start'
].
month
prev_month
=
(
dacycle
[
'time.start'
]
-
dacycle
[
'cyclelength'
]).
month
return
(
this_month
!=
prev_month
)
def
new_year
(
dacycle
):
""" check whether we just entered a new year"""
this_year
=
dacycle
[
'time.start'
].
year
prev_year
=
(
dacycle
[
'time.start'
]
-
dacycle
[
'cyclelength'
]).
year
return
(
this_year
!=
prev_year
)
if
__name__
==
"__main__"
:
from
da.tools.initexit
import
CycleControl
sys
.
path
.
append
(
'../../'
)
dacycle
=
CycleControl
(
args
=
{
'rc'
:
'../../ctdas-ei-gfed2-glb6x4-griddedNH.rc'
})
dacycle
.
setup
()
dacycle
.
parse_times
()
while
dacycle
[
'time.end'
]
<
dacycle
[
'time.finish'
]:
time_avg
(
dacycle
,
avg
=
'transcom'
)
dacycle
.
advance_cycle_times
()
da/analysis/yearly_fluxes.py
View file @
f72f98d6
...
@@ -23,7 +23,7 @@ def yearly_avg(rundir,avg):
...
@@ -23,7 +23,7 @@ def yearly_avg(rundir,avg):
if
not
os
.
path
.
exists
(
rundir
):
if
not
os
.
path
.
exists
(
rundir
):
raise
IOError
,
'rundir requested (%s) does not exist, exiting...'
%
rundir
raise
IOError
,
'rundir requested (%s) does not exist, exiting...'
%
rundir
monthdir
=
rundir
+
'data_%s_monthly'
%
avg
monthdir
=
os
.
path
.
join
(
rundir
,
'data_%s_monthly'
%
avg
)
files
=
os
.
listdir
(
monthdir
)
files
=
os
.
listdir
(
monthdir
)
yeardir
=
os
.
path
.
join
(
rundir
,
'data_%s_yearly'
%
avg
)
yeardir
=
os
.
path
.
join
(
rundir
,
'data_%s_yearly'
%
avg
)
if
not
os
.
path
.
exists
(
yeardir
):
if
not
os
.
path
.
exists
(
yeardir
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment