Commit f72f98d6 authored by Peters, Wouter's avatar Peters, Wouter
Browse files

new mechanism to write time average fluxes while the run is ongoing

parent 7e7fcda8
......@@ -23,10 +23,10 @@ def daily_avg(rundir,avg):
if not os.path.exists(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)
daydir = os.path.join(rundir + 'data_%s_daily'%avg)
daydir = os.path.join(rundir , 'data_%s_daily'%avg)
if not os.path.exists(daydir):
print "Creating new output directory " + daydir
os.makedirs(daydir)
......
......@@ -23,7 +23,7 @@ def monthly_avg(rundir,avg):
if not os.path.exists(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)
monthdir = os.path.join(rundir,'data_%s_monthly'%avg)
if not os.path.exists(monthdir):
......
#!/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()
......@@ -23,7 +23,7 @@ def yearly_avg(rundir,avg):
if not os.path.exists(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)
yeardir = os.path.join(rundir,'data_%s_yearly'%avg)
if not os.path.exists(yeardir):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment