Skip to content
Snippets Groups Projects
Commit 975b0f18 authored by Peters, Wouter's avatar Peters, Wouter
Browse files

start of library for analysis, work in progress...

parent c662725c
Branches
No related tags found
No related merge requests found
! output naming scheme for CarbonTracker savestate files, version May 07 by Wouter Peters
! assimilated quantities, observation details
assimilated.co2_mixingratio.observed : co2_obs_fcast
assimilated.latitude.observed : lat_obs_fcast
assimilated.longitude.observed : lon_obs_fcast
assimilated.height.observed : height_obs_fcast
assimilated.code.observed : stationnames_obs_fcast
assimilated.time.observed : itau_obs_fcast
assimilated.eventnumber.observed : eventnumber_obs_fcast
! assimilated quantities, simulation details
assimilated.co2_mixingratio.simulated : co2_sim_fcast
assimilated.flag.simulated : flag_sim_fcast
assimilated.hphr.simulated : hqhr_sim_fcast
assimilated.modeldatamismatch.simulated : error_sim_fcast
assimilated.co2_mixingratio.ensemble.simulated : dF
! analysis quantities, sampled after each optimization and thus not necessarily final
analyzed.co2_mixingratio.simulated : co2_sim_ana
! same for quantities sampled from optimized/final results
final.co2_mixingratio.observed : co2_obs_final
final.latitude.observed : lat_obs_final
final.longitude.observed : lon_obs_final
final.height.observed : height_obs_final
final.code.observed : stationnames_obs_final
final.time.observed : itau_obs_final
final.eventnumber.observed : eventnumber_obs_final
! final optimized quantities, simulation details
final.co2_mixingratio.simulated : co2_sim_final
final.co2_bg_mixingratio.simulated : co2_bg_sim_final
final.co2_fossil_mixingratio.simulated : co2_ff_sim_final
final.co2_fires_mixingratio.simulated : co2_fires_sim_final
final.co2_bio_mixingratio.simulated : co2_bio_sim_final
final.co2_ocean_mixingratio.simulated : co2_ocean_sim_final
final.co2_mixingratio.ensemble.simulated : dF_f
! background fluxes
background.co2.fossil.flux : flux_ff_prior_mean
background.co2.fires.flux : flux_fires_prior_mean
background.co2.bio.flux : flux_bio_prior_mean
background.co2.ocean.flux : flux_ocean_prior_mean
background.co2.res.flux : flux_res_prior_mean
background.co2.gpp.flux : flux_gpp_prior_mean
! optimized fluxes
final.co2.fossil.flux : flux_ff_post_mean
final.co2.fires.flux : flux_fires_post_mean
final.co2.bio.flux : flux_bio_post_mean
final.co2.ocean.flux : flux_ocean_post_mean
final.co2.res.flux : flux_res_post_mean
final.co2.gpp.flux : flux_gpp_post_mean
! background parameters
background.param.mean : xpc
background.param.ensemble : pdX
! optimized parameters
final.param.mean : xac
final.param.ensemble : adX
final.param.mean.1x1 : flux_multiplier_m
This diff is collapsed.
#!/usr/bin/env python
# runinfo.py
"""
Author : peters
Revision History:
File created on 01 Mar 2011.
"""
import mysettings
import commands
import os
import sys
from datetime import datetime, timedelta
class RunInfo(object):
"""
This is a CarbonTracker run info object
Initialize it with the following keywords:
MANDATORY:
project = Name of project, should correspond to a directory [string]
sd = start date of project output [datetime object or integer yyyymmdd]
ed = end date of project output [datetime object or integer yyyymmdd]
OPTIONAL:
basedir = base directory of model output on your machine [string, default='~/Modeling/download']
outputdir= output directory for figures and summary files [string, default='~/Modeling/SEATA']
Tip: change the std_rundat dictionary in module filtertools to set new defaults for all values!
"""
def __init__(self,infodict={},rcfile=None):
""" Initialize from the name of an rcfile, or by passing the dictionary directly """
import da.tools.rc as rc
import da.tools.io4 as io
import copy
if rcfile:
infodict = rc.read(rcfile)
self.basedir = infodict['dir.da_run']
self.proj = os.path.split(self.basedir)[-1]
self.projdir = self.basedir
self.dir_scheme = mysettings.ct_dir_scheme
self.inputdir = os.path.join(self.basedir,'output')
self.outputdir = os.path.join(self.basedir,'analysis')
if not os.path.exists(self.outputdir):
os.makedirs(self.outputdir)
print "Creating new output directory "+self.outputdir
sd=infodict['time.start']
ed=infodict['time.finish']
dt=infodict['time.cycle']
self.dt = timedelta(days=int(dt))
if not isinstance(sd,datetime):
self.sd = datetime.strptime(sd,'%Y-%m-%d %H:%M:%S')
if not isinstance(ed,datetime):
self.ed = datetime.strptime(ed,'%Y-%m-%d %H:%M:%S')
dd = copy.deepcopy(self.sd)
self.inputfiles= []
self.weeks = []
self.inputdict = {}
while dd < self.ed:
filename = os.path.join(self.inputdir,'%s'%dd.strftime('%Y%m%d'),'savestate.nc')
if os.path.exists(filename):
self.inputfiles.append(filename)
self.weeks.append(dd)
self.inputdict[dd] = filename
else:
break
dd = dd+self.dt
self.ed = dd
self.nweeks = len(self.weeks)
# run parameters from file
ncf = io.CT_CDF(self.inputfiles[0],'read')
self.nlag = len(ncf.dimensions['nlag'])
self.nmembers = len(ncf.dimensions['nmembers'])
self.nparameters = len(ncf.dimensions['nparameters'])
ncf.close()
self.namingscheme = 'wp_Mar2011'
filename = os.path.join('NamingScheme.'+self.namingscheme+'.rc')
try:
rcinfo=rc.read(filename)
except IOError:
print '%s was specified as naming scheme, but no matching %s rc-file was found, exiting...'%(NamingScheme,filename,)
sys.exit(1)
except:
print 'Unknown error reading rc-file: %s, exiting...'%(filename,)
sys.exit(1)
self.namedict=rcinfo
def __str__(self):
return 'project : '+self.projdir+\
'\nstart date : '+str(self.sd)+\
'\nend date : '+str(self.ed)+\
'\ndelta date : '+str(self.dt)+\
'\nnweeks : '+str(self.nweeks)+\
'\nnparameters : '+str(self.nparameters)+\
'\nnmembers : '+str(self.nmembers)+\
'\nnlag : '+str(self.nlag)+\
'\nDA output dir : '+self.inputdir+\
'\nanalysis output dir : '+self.outputdir+\
'\nnaming scheme : '+self.namingscheme
def get_rundat_settings(args):
""" create settings dict for rundat from scripts arguments """
settings=std_rundat.copy() # start with defaults for rundat
for items in args:
items=items.lower()
k, v = items.split('=')
if settings.has_key(k):
if k in std_constructors:
settings[k] = std_constructors[k](v)
else:
settings[k] = v
else: raise IOError,'Parameter unknown:%s'%(v,)
return settings
if __name__ == "__main__":
import getopt
import sys
from string import *
sys.path.append('../../')
# Parse keywords
rundat=RunInfo(rcfile='../../da.rc')
print rundat
sys.exit(0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment