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
ce382ad7
Commit
ce382ad7
authored
10 years ago
by
Peters, Wouter
Browse files
Options
Downloads
Patches
Plain Diff
updated time_avg_fluxes to work properly during cycles
parent
b32c5216
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
da/analysis/time_avg_fluxes.py
+27
-9
27 additions, 9 deletions
da/analysis/time_avg_fluxes.py
with
27 additions
and
9 deletions
da/analysis/time_avg_fluxes.py
+
27
−
9
View file @
ce382ad7
...
...
@@ -30,13 +30,11 @@ def time_avg(dacycle,avg='transcom'):
daily_avg
(
dacycle
,
avg
)
if
new_month
(
dacycle
):
monthly_avg
(
dacycle
,
avg
)
monthly_avg
(
dacycle
,
avg
)
if
new_year
(
dacycle
):
yearly_avg
(
dacycle
,
avg
)
yearly_avg
(
dacycle
,
avg
)
longterm_avg
(
dacycle
,
avg
)
longterm_avg
(
dacycle
,
avg
)
def
new_month
(
dacycle
):
"""
check whether we just entered a new month
"""
...
...
@@ -105,6 +103,10 @@ def monthly_avg(dacycle,avg):
files
=
os
.
listdir
(
daydir
)
# get daily files
files
=
[
f
for
f
in
files
if
'
-
'
in
f
]
if
len
(
files
)
<
28
:
print
'
No month is yet complete, skipping monthly average
'
return
fileinfo
=
{}
for
filename
in
files
:
# parse date from each of them
date
=
datetime
.
datetime
.
strptime
(
filename
.
split
(
'
.
'
)[
-
2
],
'
%Y-%m-%d
'
)
...
...
@@ -119,12 +121,18 @@ def monthly_avg(dacycle,avg):
while
sd
<
ed
:
nd
=
sd
+
relativedelta
(
months
=+
1
)
ndays_in_month
=
(
nd
-
sd
).
days
avg_files
=
[
os
.
path
.
join
(
daydir
,
k
)
for
k
,
v
in
fileinfo
.
iteritems
()
if
v
<
nd
and
v
>=
sd
]
if
len
(
avg_files
)
>
0
:
if
len
(
avg_files
)
!=
ndays_in_month
:
# only once month complete
#print 'New month (%02d) is not yet complete, skipping monthly average'%(sd.month)
pass
else
:
targetfile
=
os
.
path
.
join
(
monthdir
,
'
%s_fluxes.%s.nc
'
%
(
avg
,
sd
.
strftime
(
'
%Y-%m
'
)))
if
not
os
.
path
.
exists
(
targetfile
):
print
"
New month (%02d) is complete, I have %d days for the next file
"
%
(
sd
.
month
,
ndays_in_month
)
command
=
[
'
ncra
'
,
'
-O
'
]
+
avg_files
+
[
targetfile
]
status
=
subprocess
.
check_call
(
command
)
else
:
...
...
@@ -149,13 +157,17 @@ def yearly_avg(dacycle,avg):
files
=
os
.
listdir
(
monthdir
)
# get monthly files
files
=
[
f
for
f
in
files
if
'
-
'
in
f
]
if
not
files
:
print
"
No full year finished yet, skipping yearly average...
"
return
fileinfo
=
{}
for
filename
in
files
:
date
=
datetime
.
datetime
.
strptime
(
filename
.
split
(
'
.
'
)[
-
2
],
'
%Y-%m
'
)
fileinfo
[
filename
]
=
date
years
=
set
([
d
.
year
for
d
in
fileinfo
.
values
()])
sd
=
datetime
.
datetime
(
min
(
years
),
1
,
1
)
ed
=
datetime
.
datetime
(
max
(
years
)
+
1
,
1
,
1
)
...
...
@@ -165,12 +177,14 @@ def yearly_avg(dacycle,avg):
avg_files
=
[
os
.
path
.
join
(
monthdir
,
k
)
for
k
,
v
in
fileinfo
.
iteritems
()
if
v
<
nd
and
v
>=
sd
]
if
len
(
avg_files
)
>
0
:
if
not
len
(
avg_files
)
==
12
:
print
"
Year %04d not finished yet, skipping yearly average...
"
%
sd
.
year
else
:
targetfile
=
os
.
path
.
join
(
yeardir
,
'
%s_fluxes.%s.nc
'
%
(
avg
,
sd
.
strftime
(
'
%Y
'
)))
if
not
os
.
path
.
exists
(
targetfile
):
print
"
Year %04d is complete, I have 12 months for the next file
"
%
sd
.
year
command
=
[
'
ncra
'
,
'
-O
'
]
+
avg_files
+
[
targetfile
]
print
command
status
=
subprocess
.
check_call
(
command
)
sd
=
nd
...
...
@@ -193,6 +207,10 @@ def longterm_avg(dacycle,avg):
files
=
os
.
listdir
(
yeardir
)
files
=
[
f
for
f
in
files
if
avg
in
f
]
if
not
files
:
print
"
No full year finished yet, skipping longterm average...
"
return
dates
=
[]
for
filename
in
files
:
date
=
datetime
.
datetime
.
strptime
(
filename
.
split
(
'
.
'
)[
-
2
],
'
%Y
'
)
...
...
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