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

cleaned the interface for io.py, renamed mysettings and limited it to variable names now

parent 69623e48
No related branches found
No related tags found
No related merge requests found
......@@ -9,17 +9,29 @@ File created on 15 Oct 2008.
File modified for CT data assimilation system in July 2010, Wouter Peters
"""
import mysettings
import standardvariables
import pycdf as CDF
import datetime as dt
import os
from numpy import array
import os
if 'CTE' in mysettings.ct_version:
from ct_europe_info import *
else:
from ct_northamerica_info import *
try:
import mysettings
disclaimer = open(os.path.join(mysettings.ctshareddir,'boilerplate','disclaimer_cte.txt'),'r').read()
email = "wouter.peters@wur.nl"
url = "http://carbontracker.wur.nl"
institution = "Wageningen University and Research Center"
source = "CarbonTracker release %s" % mysettings.ct_version
conventions = "CF-1.1"
historytext = 'Created on '+dt.datetime.now().strftime('%B %d, %Y')+' by %s'%os.environ['USER']
except:
disclaimer = "This data belongs to the CarbonTracker project"
email = "wouter.peters@wur.nl"
url = "http://carbontracker.wur.nl"
institution = "Wageningen University and Research Center"
source = "CarbonTracker release 2.0"
conventions = "CF-1.1"
historytext = 'Created on '+dt.datetime.now().strftime('%B %d, %Y')+' by %s'%os.environ['USER']
std_savedict={'name':'unknown','values':[],'dims':(0,0,),'units':'','long_name':'','_FillValue':float(-999.),'comment':''}
......@@ -116,45 +128,6 @@ class CT_CDF(CDF.CDF):
return (dimlat,dimlon,)
def AddRegionDim(self,rundat,type='eco'):
from tctools import olsonlabs, transnams, ext_transnams, ext_transcomps
from ecotools import ext_econams, ext_ecocomps
if type not in ['eco','eco_ext','tc','tc_ext','olson']: raise ValueError,'Type of dimension for regions requested (%s) is not possible' %type
dimname='regions_%s' % type
if dimname in self.dimensions(): return (self.dim(dimname),) # already exists
self.automode()
if type == 'olson':
dim = (self.def_dim(dimname,len(olsonlabs)),)
elif type == 'tc':
dim = (self.def_dim(dimname,len(transnams)),)
elif type == 'tc_ext':
dim = (self.def_dim(dimname,len(ext_transnams)),)
elif type == 'eco':
dim = (self.def_dim(dimname,rundat.ntotal_in_state),)
elif type == 'eco_ext':
dim = (self.def_dim(dimname,11*len(ext_econams)), )
# Automatically add region names as attributes
dummy = self.AddRegionDefs(rundat,type)
return dim
def AddDateDim(self):
self.automode()
......@@ -167,79 +140,6 @@ class CT_CDF(CDF.CDF):
if 'yyyymmddhhmmss' in self.dimensions(): return (self.dim('yyyymmddhhmmss'),) # already exists
return (self.def_dim('yyyymmddhhmmss',6),)
def AddRegionDefs(self,rundat,type='tc'):
""" add region definitions to NC file as global attributes """
from tctools import olsonnams, olsonlabs, transnams, ext_transnams, ext_transshort, ext_transcomps, LookUpName
from ecotools import ext_econams, ext_ecocomps
from oif import oifnams
import pyhdf.SD as HDF
n_land=rundat.n_land
n_ocean=rundat.n_ocean
if type not in ['tc','tc_ext','eco','eco_ext','olson']:
raise IOError,'Type (%s) not implemented in AddRegionDefs' % type
if type == 'olson':
# make attribute with olson ecoregion labels
for i,name in enumerate(olsonnams):
att = self.attr('OlsonEcosystem_%03d'%(i+1,))
att.put(CDF.NC.CHAR,name)
elif type == 'tc':
# make attribute with transcom region labels
for i,name in enumerate(transnams):
att = self.attr('TransComRegion_%03d'%(i+1,))
att.put(CDF.NC.CHAR,name)
elif type == 'tc_ext':
# get attributes from Andy's file and save to new file
for i,name in enumerate(ext_transnams):
lab='Aggregate_Region_%03d'%(i+1,)
setattr(self,lab,name)
for i,name in enumerate(ext_transcomps):
lab='Aggregate_Components_%03d'%(i+1,)
setattr(self,lab,name)
#
elif type == 'eco':
# make attribute with full eco region labels
for i in range(n_land):
att = self.attr('CarbonTrackerRegion_%03d'%(i+1,))
if i >= 209: i=i-19
name=transnams[i/19]+' : '+olsonlabs[i%19]
att.put(CDF.NC.CHAR,name)
for i in range(n_land,n_land+n_ocean):
att = self.attr('CarbonTrackerRegion_%03d'%(i+1,))
name=oifnams[i-n_land]
att.put(CDF.NC.CHAR,name)
att = self.attr('CarbonTrackerRegion_%03d'%(rundat.ntotal_in_state,))
name='Ice, Polar Desert, Unoptimized'
att.put(CDF.NC.CHAR,name)
elif type == 'eco_ext':
# make attribute with full extended eco region labels
for i,tcname in enumerate(transnams[0:11]):
for j in range(len(ext_econams)):
att = self.attr('Aggregate_Region_%02d'%(i*6+j+1,))
name=tcname+' : '+ext_econams[j]
att.put(CDF.NC.CHAR,name)
for i,tcname in enumerate(transnams[0:11]):
for j in range(len(ext_econams)):
lab = 'Aggregate_Components_%02d'%(i*6+j+1,)
setattr(self,lab,ext_ecocomps[j])
return None
def has_date(self,dd):
if self.inq_unlimlen() > 0:
......@@ -256,12 +156,12 @@ class CT_CDF(CDF.CDF):
def StandardVar(self,varname):
""" return properties of standard variables """
import mysettings
import standardvariables
if varname in mysettings.standard_variables.keys():
return mysettings.standard_variables[varname]
if varname in standardvariables.standard_variables.keys():
return standardvariables.standard_variables[varname]
else:
return mysettings.standard_variables['unknown']
return standardvariables.standard_variables['unknown']
def AddData(self,datadict,nsets=1,silent=True):
""" add fields to file, at end of unlimited dimension"""
......
from pylab import *
import os
import rc
from matplotlib.font_manager import FontProperties
homedir=os.environ["HOME"]
username=os.environ["USER"]
boilerplatedir='/ct/tools/shared/boilerplate'
rcinfo=rc.read(os.path.join(homedir,'.carbontrackerrc'))
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 ', \
......
......@@ -38,7 +38,6 @@ class CtMember():
def WriteToFile(self, outdir):
""" Write the information needed by an external model to a netcdf file for future use """
from da.ct.io import CT_CDF, std_savedict
import pycdf as cdf
import mysettings
import numpy as np
......@@ -193,7 +192,6 @@ class CtStateVector():
def WriteToFile(self):
""" Write the StateVector object to a netcdf file for future use """
from da.ct.io import CT_CDF
import pycdf as cdf
import da.ct.mysettings
import numpy as np
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment