Commit 37ba0d6f authored by Peters, Wouter's avatar Peters, Wouter
Browse files

project ready to go

parent d1c3556b
! 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
# mysettings.py
"""
.. module:: mysettings
.. moduleauthor:: Wouter Peters
Revision History:
File created on 06 Sep 2010.
"""
import os
import sys
sys.path.append('../../')
import da.tools.rc as rc
from matplotlib.font_manager import FontProperties
homedir=os.environ["HOME"]
username=os.environ["USER"]
boilerplatedir='/ct/tools/shared/boilerplate'
rcinfo=rc.read('mysettings.rc')
ct_inputdir=''
ct_outputdir=''
ct_pylibdir=''
ct_version=''
ct_dir_scheme='wouter'
unicodefontfilename=None
if rcinfo.has_key('carbontracker.std.inputdir'): ct_inputdir=rcinfo['carbontracker.std.inputdir']
if rcinfo.has_key('carbontracker.std.outputdir'): ct_outputdir=rcinfo['carbontracker.std.outputdir']
if rcinfo.has_key('ct.shared.dir'): ctshareddir=rcinfo['ct.shared.dir']
if rcinfo.has_key('python.std.libdir'): pylibdir=rcinfo['python.std.libdir']
if rcinfo.has_key('unicodefont'): unicodefontfilename=rcinfo['unicodefont']
if rcinfo.has_key('carbontracker.version'): ct_version=rcinfo['carbontracker.version']
if rcinfo.has_key('carbontracker.dir.scheme'): ct_dir_scheme=rcinfo['carbontracker.dir.scheme']
if not os.path.exists(boilerplatedir):
if rcinfo.has_key('boilerplate.dir'): boilerplatedir=rcinfo['boilerplate.dir']
unicodefont=FontProperties(fname=unicodefontfilename)
standard_variables = { 'bio_flux_prior' : {'name' : 'bio_flux_prior',\
'units' : 'mol m-2 s-1' ,\
'long_name' : 'Surface flux of carbon dioxide, terrestrial vegetation, not optimized ', \
'comment' : 'time-interval average, centered on times in the date axis', \
'standard_name' : 'surface_carbon_dioxide_mole_flux', \
'dims' : (), \
'values' : [], \
'count' : 0 \
} , \
'bio_flux_opt' : {'name' : 'bio_flux_opt',\
'units' : 'mol m-2 s-1' ,\
'long_name' : 'Surface flux of carbon dioxide, terrestrial biosphere , optimized ', \
'comment' : 'time-interval average, centered on times in the date axis', \
'standard_name' : 'surface_carbon_dioxide_mole_flux', \
'dims' : (), \
'values' : [], \
'count' : 0 \
} , \
'ocn_flux_prior' : {'name' : 'ocn_flux_prior',\
'units' : 'mol m-2 s-1' ,\
'long_name' : 'Surface flux of carbon dioxide, open ocean , not optimized ', \
'comment' : 'time-interval average, centered on times in the date axis', \
'standard_name' : 'surface_carbon_dioxide_mole_flux', \
'dims' : (), \
'values' : [], \
'count' : 0 \
} , \
'ocn_flux_opt' : {'name' : 'ocn_flux_opt',\
'units' : 'mol m-2 s-1' ,\
'long_name' : 'Surface flux of carbon dioxide, open ocean , optimized ', \
'comment' : 'time-interval average, centered on times in the date axis', \
'standard_name' : 'surface_carbon_dioxide_mole_flux', \
'dims' : (), \
'values' : [], \
'count' : 0 \
} , \
'fossil_flux_imp' : {'name' : 'fossil_flux_imp',\
'units' : 'mol m-2 s-1' ,\
'long_name' : 'Surface flux of carbon dioxide, fossil fuel burning , imposed ', \
'comment' : 'time-interval average, centered on times in the date axis', \
'standard_name' : 'surface_carbon_dioxide_mole_flux', \
'dims' : (), \
'values' : [], \
'count' : 0 \
} , \
'fire_flux_imp' : {'name' : 'fire_flux_imp',\
'units' : 'mol m-2 s-1' ,\
'long_name' : 'Surface flux of carbon dioxide, biomass burning , imposed ', \
'comment' : 'time-interval average, centered on times in the date axis', \
'standard_name' : 'surface_carbon_dioxide_mole_flux', \
'dims' : (), \
'values' : [], \
'count' : 0 \
} , \
'bio_flux_prior_cov' : {'name' : 'bio_flux_prior_cov',\
'units' : 'mol2 region-2 s-2' ,\
'long_name' : 'Covariance of surface flux of carbon dioxide, terrestrial vegetation , not optimized ', \
'comment' : 'time-interval average, centered on times in the date axis', \
'standard_name' : '', \
'dims' : (), \
'values' : [], \
'count' : 0 \
} , \
'bio_flux_opt_cov' : {'name' : 'bio_flux_opt_cov',\
'units' : 'mol2 region-2 s-2' ,\
'long_name' : 'Covariance of surface flux of carbon dioxide, terrestrial vegetation , optimized ', \
'comment' : 'time-interval average, centered on times in the date axis', \
'standard_name' : '', \
'dims' : (), \
'values' : [], \
'count' : 0 \
} , \
'ocn_flux_prior_cov' : {'name' : 'ocn_flux_prior_cov',\
'units' : 'mol2 region-2 s-2' ,\
'long_name' : 'Covariance of surface flux of carbon dioxide, open ocean , not optimized ', \
'comment' : 'time-interval average, centered on times in the date axis', \
'standard_name' : '', \
'dims' : (), \
'values' : [], \
'count' : 0 \
} , \
'ocn_flux_opt_cov' : {'name' : 'ocn_flux_opt_cov',\
'units' : 'mol2 region-2 s-2' ,\
'long_name' : 'Covariance of surface flux of carbon dioxide, open ocean , optimized ', \
'comment' : 'time-interval average, centered on times in the date axis', \
'standard_name' : '', \
'dims' : (), \
'values' : [], \
'count' : 0 \
} , \
'decimal_date' : {'name' : 'decimal_date',\
'units' : 'years' ,\
'long_name' : 'dates and times', \
'comment' : 'time-interval average, centered on times in the date axis', \
'standard_name' : 'date', \
'dims' : (), \
'dtype' : 'double', \
'values' : [], \
'count' : 0 \
} , \
'date' : {'name' : 'date',\
'units' : 'days since 2000-01-01 00:00:00 UTC' ,\
'long_name' : 'UTC dates and times', \
'comment' : 'time-interval average, centered on times in the date axis', \
'standard_name' : 'date', \
'dims' : (), \
'dtype' : 'double', \
'values' : [], \
'count' : 0 \
} , \
'idate' : {'name' : 'idate',\
'units' : 'yyyy MM dd hh mm ss ' ,\
'long_name' : 'integer components of date and time', \
'standard_name' : 'calendar_components', \
'comment' : 'time-interval average, centered on times in the date axis', \
'dims' : (), \
'dtype' : 'int', \
'values' : [], \
'count' : 0 \
} , \
'latitude' : {'name' : 'latitude',\
'units' : 'degrees_north ' ,\
'long_name' : 'latitude', \
'standard_name' : 'latitude', \
'comment' : 'center of interval',\
'dims' : (), \
'values' : [], \
'count' : 0 \
} , \
'longitude' : {'name' : 'longitude',\
'units' : 'degrees_east ' ,\
'long_name' : 'longitude', \
'standard_name' : 'longitude', \
'comment' : 'center of interval',\
'dims' : (), \
'values' : [], \
'count' : 0 \
} , \
'height' : {'name' : 'height',\
'units' : 'masl ' ,\
'long_name' : 'height_above_ground_level', \
'standard_name' : 'height_above_ground_level', \
'comment' : 'value is meters above sea level',\
'dims' : (), \
'values' : [], \
'count' : 0 \
} , \
'co2' : {'name' : 'co2',\
'units' : 'micromol mol-1 ' ,\
'long_name' : 'mole_fraction_of_carbon_dioxide_in_air', \
'standard_name' : 'mole_fraction_of_carbon_dioxide_in_air', \
'comment' : '',\
'dims' : (), \
'values' : [], \
'count' : 0 \
} , \
'unknown' : {'name' : '',\
'units' : '' ,\
'long_name' : '', \
'standard_name' : '', \
'comment' : '',\
'dims' : (), \
'values' : [], \
'count' : 0 \
} , \
}
homedir : ${HOME}
datadir : /Storage/CO2/peters/carbontracker
carbontracker.std.inputdir : ${datadir}/raw
carbontracker.std.outputdir : ${datadir}/analysis
!carbontracker.version : CTE2008
carbontracker.version : CT2009
unicodefont : /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/fonts/LucidaSansRegular.ttf
!unicodefont : /sw/lib/python2.5/site-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf
1 CONIFOR "Conifer Forest"
2 BRODLFOR "Broadleaf Forest: temperate, subtropical drought"
3 MIXEDFOR "Mixed Forest: conifer/broadleaf; so. Boreal"
4 GRASSHRB "Grassland +/- Shrub or Tree"
5 TROPICFR "Tropical/subtr. Forest: montane, seasonal, rainforest "
6 SCRUBWDS "Scrub +/- Woodland &/or fields (evergreen/decid.) "
7 SEMIDTUN "Semidesert shrub/steppe; Tundra (polar, alpine) "
8 FLDWDSAV "Field/Woods complex &/or Savanna, tallgrass "
9 NORTAIGA "Northern Boreal Taiga woodland/tundra"
10 FORFDREV "Forest/Field; Dry Evergreen broadleaf woods "
11 WETLAND "Wetlands: mires (bog/fen); marsh/swamp +/- mangrove "
12 DESERTS "Desert: bare/alpine; sandy; salt/soda "
13 SHRBTRST "Shrub/Tree: succulent/thorn "
14 CROPSETL "Crop/Settlement (irrigated or not) "
15 CONIFRFC "Conifer snowy Rainforest, coastal "
27 WTNDMHTH "Wooded Tundra Margin; Heath/moorland "
19 MANGROVE "Mangrove/wet forest/thicket + tidal flat "
25 ICEPLDE "Ice and Polar Desert"
19 WATER "Water bodies"
#!/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)
1 T-NABR "North American Boreal"
2 T-NATM "North American Temperate"
3 T-SATR "South American Tropical"
4 T-SATM "South American Temperate"
5 T-NAFR "Northern Africa"
6 T-SAFR "Southern Africa"
7 T-EUBR "Eurasia Boreal"
8 T-EUTM "Eurasia Temperate"
9 T-ASTR "Tropical Asia"
10 T-AUST "Australia"
11 T-EURO "Europe"
12 O-NPTM "North Pacific Temperate"
13 O-WPTR "West Pacific Tropical"
14 O-EPTR "East Pacific Tropical"
15 O-SPTM "South Pacific Temperate"
16 O-NOCN "Northern Ocean"
17 O-NATM "North Atlantic Temperate"
18 O-SATR "Atlantic Tropical"
19 O-SATM "South Atlantic Temperate"
20 O-SOCN "Southern Ocean"
21 O-INTR "Indian Tropical"
22 O-INTM "Indian Temperate"
#!/usr/bin/env python
import commands
import os
import sys
from da.analysis.tools_transcom import *
# Aggregated olson ecosystem regions for CT Europe
aggregates=[\
("Forests/Wooded" , (1, 2, 3, 5, 8, 10,) ) ,\
("Grass/Shrubs" , (4, 6, 13) ) ,\
("Crops/Agriculture", (14,) ) ,\
("Tundra/Taiga" , (7,9,16) ) ,\
("Coastal/Wet" , (11,15,17) ) ,\
("Ice/Water/Deserts" , (12,18,19) ) \
]
agg_dict={}
for k,v in aggregates:
agg_dict[k]=v
ext_econams=[a for a,b in aggregates]
ext_ecocomps=[b for a,b in aggregates]
eco19_to_ecosums = zeros((19, 6),float)
for i,k in enumerate(ext_ecocomps):
indices = [x-1 for x in k]
eco19_to_ecosums[:,i].put(indices,1.0)
##### END OF REGION DEFINITIONS
def StateToGrid(values,regionmap,reverse=False,avg=False):
"""
This method converts parameters from a CarbonTracker StateVector object to a gridded map of linear multiplication values. These
can subsequently be used in the transport model code to multiply/manipulate fluxes
"""
import numpy as np
nregions = regionmap.max()
# dictionary for region <-> map conversions
regs={}
for r in np.arange(1,nregions+1):
sel=(regionmap.flat == r).nonzero()
if len(sel[0])>0: regs[r]=sel
regionselect=regs
if reverse:
""" project 1x1 degree map onto ecoregions """
result=np.zeros(nregions,float)
for k,v in regionselect.iteritems():
if avg:
result[k-1]=values.ravel().take(v).mean()
else :
result[k-1]=values.ravel().take(v).sum()
return result
else:
""" project ecoregion properties onto 1x1 degree map """
result=np.zeros((180,360,),float)
for k,v in regionselect.iteritems():
result.put(v,values[k-1])
return result
def globarea(im=360,jm=180,silent=True):
""" Function calculates the surface area according to TM5 definitions"""
import numpy as np
radius = 6.371e6 # the earth radius in meters
deg2rad = np.pi/180.
g = 9.80665