Commit 99a96009 authored by Peters, Wouter's avatar Peters, Wouter
Browse files

new averaging option

parent f2d7336f
#!/usr/bin/env python
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
sd = datetime.datetime(1999,1,1)
files = [f for f in files if avg in f]
dates = []
for filename in files:
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,''%(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"
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