Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CTDAS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NearRealTimeCTDAS
CTDAS
Commits
13910270
Commit
13910270
authored
11 years ago
by
Peters, Wouter
Browse files
Options
Downloads
Patches
Plain Diff
first updates to function names
parent
c991da3c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
da/sf6/statevector.py
+17
-53
17 additions, 53 deletions
da/sf6/statevector.py
with
17 additions
and
53 deletions
da/sf6/statevector.py
+
17
−
53
View file @
13910270
...
...
@@ -14,9 +14,10 @@ import sys
sys
.
path
.
append
(
os
.
getcwd
())
import
logging
from
da.baseclasses.statevector
import
StateVector
import
numpy
as
np
from
da.baseclasses.statevector
import
StateVector
,
EnsembleMember
import
da.tools.io4
as
io
from
datetime
import
timedelta
identifier
=
'
SF6 Statevector
'
version
=
'
0.0
'
...
...
@@ -26,13 +27,11 @@ version = '0.0'
class
SF6StateVector
(
StateVector
):
"""
This is a StateVector object for CarbonTracker. It has a private method to make new ensemble members
"""
def
get_covariance
(
self
,
date
):
def
get_covariance
(
self
,
date
,
dacycle
):
"""
Make a new ensemble from specified matrices, the attribute lag refers to the position in the state vector.
Note that lag=1 means an index of 0 in python, hence the notation lag-1 in the indexing below.
The argument is thus referring to the lagged state vector as [1,2,3,4,5,..., nlag]
"""
import
da.tools.io4
as
io
try
:
import
matplotlib.pyplot
as
plt
except
:
...
...
@@ -46,7 +45,7 @@ class SF6StateVector(StateVector):
return
fullcov
def
Initialize
(
self
):
def
setup
(
self
):
"""
Initialize the object by specifying the dimensions.
There are two major requirements for each statvector that you want to build:
...
...
@@ -57,41 +56,40 @@ class SF6StateVector(StateVector):
An example is given below.
"""
self
.
nlag
=
int
(
self
.
DaC
ycle
[
'
time.nlag
'
])
self
.
nmembers
=
int
(
self
.
DaC
ycle
[
'
da.optimizer.nmembers
'
])
self
.
nparams
=
int
(
self
.
DaC
ycle
.
DaS
ystem
[
'
nparameters
'
])
self
.
nlag
=
int
(
dac
ycle
[
'
time.nlag
'
])
self
.
nmembers
=
int
(
dac
ycle
[
'
da.optimizer.nmembers
'
])
self
.
nparams
=
int
(
dac
ycle
.
das
ystem
[
'
nparameters
'
])
self
.
nobs
=
0
self
.
isOptimized
=
False
self
.
ObsToAssimmilate
=
()
# empty containter to hold observations to assimilate later on
self
.
obs_to_assimilate
=
()
# empty containter to hold observations to assimilate later on
# These list objects hold the data for each time step of lag in the system. Note that the ensembles for each time step consist
# of lists of EnsembleMember objects, we define member 0 as the mean of the distribution and n=1,...,nmembers as the spread.
self
.
E
nsemble
M
embers
=
range
(
self
.
nlag
)
self
.
e
nsemble
_m
embers
=
range
(
self
.
nlag
)
for
n
in
range
(
self
.
nlag
):
self
.
E
nsemble
M
embers
[
n
]
=
[]
self
.
e
nsemble
_m
embers
[
n
]
=
[]
# This specifies the file to read with the gridded mask at 1x1 degrees. Each gridbox holds a number that specifies the parametermember
# that maps onto it. From this map, a dictionary is created that allows a reverse look-up so that we can map parameters to a grid.
mapfile
=
os
.
path
.
join
(
self
.
DaC
ycle
.
DaS
ystem
[
'
regionsfile
'
])
ncf
=
io
.
CT_R
ead
(
mapfile
,
'
read
'
)
self
.
tcmap
=
ncf
.
G
et
V
ariable
(
'
transcom_regions
'
)
mapfile
=
os
.
path
.
join
(
dac
ycle
.
da
ystem
[
'
regionsfile
'
])
ncf
=
io
.
ct_r
ead
(
mapfile
,
'
read
'
)
self
.
tcmap
=
ncf
.
g
et
_v
ariable
(
'
transcom_regions
'
)
ncf
.
close
()
self
.
gridmap
=
np
.
ones
((
180
,
360
),
'
float
'
)
logging
.
debug
(
"
A TransCom map on 1x1 degree was read from file %s
"
%
self
.
DaC
ycle
.
DaS
ystem
[
'
regionsfile
'
])
logging
.
debug
(
"
A TransCom map on 1x1 degree was read from file %s
"
%
self
.
dac
ycle
.
das
ystem
[
'
regionsfile
'
])
logging
.
debug
(
"
A parameter map on 1x1 degree was created
"
)
# Create a dictionary for state <-> gridded map conversions
nparams
=
self
.
gridmap
.
max
()
self
.
griddict
=
{}
for
r
in
range
(
1
,
nparams
+
1
):
for
r
in
range
(
1
,
int
(
nparams
)
+
1
):
sel
=
(
self
.
gridmap
.
flat
==
r
).
nonzero
()
if
len
(
sel
[
0
])
>
0
:
self
.
griddict
[
r
]
=
sel
...
...
@@ -142,11 +140,10 @@ class SF6StateVector(StateVector):
In the future, this routine can incorporate a formal propagation of the statevector.
"""
from
datetime
import
timedelta
ensemble_deviations
=
np
.
array
([
p
.
P
aram
eterV
alues
for
p
in
self
.
E
nsemble
M
embers
[
0
]
])
ensemble_deviations
=
np
.
array
([
p
.
p
aram
_v
alues
for
p
in
self
.
e
nsemble
_m
embers
[
0
]
])
if
ensemble_deviations
.
std
(
axis
=
0
)
<
0.05
:
for
m
in
self
.
E
nsemble
M
embers
[
0
]:
for
m
in
self
.
e
nsemble
_m
embers
[
0
]:
m
=
3.0
*
m
# inflate deviations by a factor of 3.0
logging
.
info
(
'
The state vector covariance was inflated to 1-sigma of %5.2f
'
%
(
ensemble_deviations
.
std
(
axis
=
0
)
*
3.0
))
...
...
@@ -157,36 +154,3 @@ class SF6StateVector(StateVector):
################### End Class SF6StateVector ###################
if
__name__
==
"
__main__
"
:
from
da.tools.initexit
import
StartLogger
from
da.tools.pipeline
import
start_job
sys
.
path
.
append
(
os
.
getcwd
())
opts
=
[
'
-v
'
]
args
=
{
'
rc
'
:
'
da.rc
'
,
'
logfile
'
:
'
da_initexit.log
'
,
'
jobrcfilename
'
:
'
test.rc
'
}
StartLogger
()
DaCycle
=
start_job
(
opts
,
args
)
DaCycle
.
Initialize
()
StateVector
=
CtStateVector
()
StateVector
.
Initialize
()
for
n
in
range
(
dims
[
0
]):
cov
=
StateVector
.
get_covariance
()
dummy
=
StateVector
.
make_new_ensemble
(
n
+
1
,
cov
)
StateVector
.
propagate
()
savedir
=
DaCycle
[
'
dir.output
'
]
filename
=
os
.
path
.
join
(
savedir
,
'
savestate.nc
'
)
dummy
=
StateVector
.
WriteToFile
()
StateVector
.
ReadFromFile
(
filename
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment