Commit 56c60253 authored by Peters, Wouter's avatar Peters, Wouter
Browse files

first attempt for base class optimizer

parent c3b3a2fb
......@@ -14,13 +14,12 @@ import sys
import logging
import datetime
identifier = 'CarbonTracker CO2'
################### Begin Class CtOptimizer ###################
################### Begin Class Optimizer ###################
class CtOptimizer(object):
class Optimizer(object):
"""
This creates an instance of a CarbonTracker optimization object. It handles the minimum least squares optimization
of the CT state vector given a set of CT sample objects. Two routines will be implemented: one where the optimization
This creates an instance of an optimization object. It handles the minimum least squares optimization
of the state vector given a set of sample objects. Two routines will be implemented: one where the optimization
is sequential and one where it is the equivalent matrix solution. The choice can be made based on considerations of speed
and efficiency.
"""
......@@ -77,8 +76,7 @@ class CtOptimizer(object):
for m,mem in enumerate(StateVector.EnsembleMembers[-1]):
#self.HX_prime[:,m] = mem.ModelSample.MrData.getvalues('simulated')
self.HX_prime[:,m] = self.Hx + np.random.randn(self.nobs)*3.0
self.HX_prime[:,m] = mem.ModelSample.MrData.getvalues('simulated')
self.HX_prime = self.HX_prime - self.Hx[:,np.newaxis] # make a deviation matrix
......@@ -181,15 +179,11 @@ class CtOptimizer(object):
return None
def SetLocalization(self,type='None'):
def SetLocalization(self):
""" determine which localization to use """
if type == 'CT2007':
self.localization = True
self.localizetype = 'CT2007'
else:
self.localization = False
self.localizetype = 'None'
self.localization = True
self.localizetype = "None"
msg = "Current localization option is set to %s"%self.localizetype ; logging.info(msg)
......@@ -198,20 +192,10 @@ class CtOptimizer(object):
import numpy as np
if not self.localization: return
if self.localizetype == 'CT2007':
tvalue=1.97591
if np.sqrt(self.R[n,n]) >= 1.5:
for r in range(self.nlag*self.nparams):
corr=np.corrcoef(self.HX_prime[n,:],self.X_prime[r,:].squeeze())[0,1]
prob=corr/np.sqrt((1.0-corr**2)/(self.nmembers-2))
if abs(prob) < tvalue:
self.KG[r,n]=0.0
################### End Class CtOptimizer ###################
return
################### End Class Optimizer ###################
......
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