Commit 8726d7a6 authored by karolina's avatar karolina
Browse files

deleted unused functions as agreed in email #2

ct/tools.py (whole file)
tm5/observationoperator.py: WriteRunRc
tools/initexit.py: SubmitSubStep
tools/general.py: CreateLinks, ToDectime, StoreData, RestoreData
parent ab4590d0
#!/usr/bin/env python
# ct_tools.py
"""
Author : peters
Revision History:
File created on 12 Feb 2009.
"""
import sys
identifier = 'CarbonTracker CO2'
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
if __name__ == "__main__":
sys.path.append('../../')
from da.tools.initexit import StartLogger
from da.tools.initexit import CycleControl
from pylab import *
opts = ['-v']
args = {'rc':'da.rc','logfile':'da_initexit.log','jobrcfilename':'test.rc'}
StartLogger()
DaCycle = CycleControl(opts,args)
DaCycle.Initialize()
print DaCycle
# a=arange(240)+100
#b = StateToGrid(DaCycle.DaSystem,a)
#figure()
#imshow(b)
#colorbar()
#print b.max()
#c = StateToGrid(DaCycle.DaSystem,b,reverse=True,avg=True)
#figure()
#print c.max()
#plot(a,label='original')
#plot(c,label='reconstructed')
#legend(loc=0)
#show()
......@@ -321,42 +321,6 @@ class TM5ObservationOperator(ObservationOperator):
rc.write(tm5rcfilename, self.tm_settings)
logging.debug("Modified rc file for TM5 written (%s)" % tm5rcfilename)
def WriteRunRc(self):
"""
Create the tm5-runtime.rc file which is read by initexit.F90 to control time loop and restart from save files
"""
import da.tools.rc as rc
tm5rcfilename = os.path.join(self.tm_settings[self.rundirkey], 'tm5_runtime.rc')
rc.write(tm5rcfilename, self.tm_settings)
rc_runtm5 = {}
rc_runtm5['year1'] = self.tm_settings[self.timestartkey].year
rc_runtm5['month1'] = self.tm_settings[self.timestartkey].month
rc_runtm5['day1'] = self.tm_settings[self.timestartkey].day
rc_runtm5['hour1'] = self.tm_settings[self.timestartkey].hour
rc_runtm5['minu1'] = 0
rc_runtm5['sec1'] = 0
rc_runtm5['year2'] = self.tm_settings[self.timefinalkey].year
rc_runtm5['month2'] = self.tm_settings[self.timefinalkey].month
rc_runtm5['day2'] = self.tm_settings[self.timefinalkey].day
rc_runtm5['hour2'] = self.tm_settings[self.timefinalkey].hour
rc_runtm5['minu2'] = 0
rc_runtm5['sec2'] = 0
rc_runtm5[self.istartkey] = self.tm_settings[self.istartkey]
rc_runtm5[self.savedirkey] = self.tm_settings[self.savedirkey]
rc_runtm5[self.outputdirkey] = self.tm_settings[self.outputdirkey]
rc.write(tm5rcfilename, rc_runtm5)
logging.debug("Modified tm5_runtime.rc written (%s)" % tm5rcfilename)
def validate_input(self):
"""
Make sure that parameter files are written to the TM5 inputdir, and that observation lists are present
......
......@@ -50,26 +50,6 @@ def CreateDirs(dirname, forceclean=False):
logging.debug(msg)
return dirname
def CreateLinks(sourcedir, targetdir):
""" Create a symbolic link from, source to target and report success, note
that exisiting links are first removed and then recreated """
if os.path.exists(targetdir):
os.unlink(targetdir)
msg = 'Unlinking existing directory %s' % targetdir
logging.debug(msg)
try:
os.symlink(sourcedir, targetdir)
msg = 'Created new link from %s to %s' % (sourcedir, targetdir)
logging.debug(msg)
except OSError, msg:
msg = 'Failed to create link from %s to %s' % (sourcedir, targetdir)
logging.error(msg)
raise OSError
return None
def AdvanceTime(time_in, interval):
""" Advance time_in by a specified interval"""
......@@ -102,7 +82,6 @@ def ToDatetime(datestring, fmt=None):
else:
pass
try:
return datetime.datetime.strptime(datestring, '%Y-%m-%d %H:%M:%S')
except:
......@@ -111,40 +90,6 @@ def ToDatetime(datestring, fmt=None):
hour, minute, second = map(int, time.split(':'))
return datetime.datetime(year, month, day, hour, minute, second)
def ToDectime(dd):
""" convert a datetime object to a decimal date """
import calendar
from matplotlib.pylab import date2num
Days0 = date2num(datetime.datetime(dd.year, 1, 1))
if calendar.isleap(dd.year):
DaysPerYear = 366.
else:
DaysPerYear = 365.
DayFrac = date2num(dd)
return dd.year + (DayFrac - Days0) / DaysPerYear
def StoreData(pickleobject, filename):
""" pickle object into a specified file name """
import cPickle
f = open(filename, 'wb')
dummy = cPickle.dump(pickleobject, f, -1)
f.close()
return None
def RestoreData(filename):
""" unpickle object into a specified file name """
import cPickle
f = open(filename, 'rb')
pickleobject = cPickle.load(f)
f.close()
return pickleobject
def NameConvert(name=None, to=None):
""" Convert between old GLOBALVIEW-style and new ObsPack-style
......
......@@ -660,30 +660,6 @@ class CycleControl(dict):
logging.info('Final date reached, no new cycle started')
def SubmitSubStep(self, stepname):
"""
Submit the next substep of a DA cycle, this consists of
* getting a job template as returned by :meth:`~da.tools.baseclasses.platform.get_job_template`
* adding the lines needed to start a next run with a newly created rc-file
* Writing the jobfile as done by :meth:`~da.tools.baseclasses.platform.write_job`
* Submitting the jobfile as done by :meth:`~da.tools.baseclasses.platform.write_job`
"""
from string import join
DaPlatForm = self.DaPlatForm
jobparams = {'jobname':'das.%s' % stepname}
template = DaPlatForm.get_job_template(jobparams)
template += 'cd %s\n' % os.getcwd()
template += '%s rc=%s process=%s %s' % (sys.argv[0], self['jobrcfilename'], stepname, join(self.opts, ''),)
jobfile = DaPlatForm.write_job(self, template, stepname)
DaPlatForm.submit_job(jobfile)
def StartLogger(level=logging.INFO):
""" start the logging of messages to screen"""
......
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