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
Container registry
Model registry
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
Tsurata, Aki
CTDAS
Commits
9d264ea6
Commit
9d264ea6
authored
15 years ago
by
Peters, Wouter
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
da/ct/io.py
+23
-123
23 additions, 123 deletions
da/ct/io.py
da/ct/standardvariables.py
+0
-30
0 additions, 30 deletions
da/ct/standardvariables.py
da/ct/statevector.py
+0
-2
0 additions, 2 deletions
da/ct/statevector.py
with
23 additions
and
155 deletions
da/ct/io.py
+
23
−
123
View file @
9d264ea6
...
...
@@ -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
mysetting
s
import
standardvariable
s
if
varname
in
mysetting
s
.
standard_variables
.
keys
():
return
mysetting
s
.
standard_variables
[
varname
]
if
varname
in
standardvariable
s
.
standard_variables
.
keys
():
return
standardvariable
s
.
standard_variables
[
varname
]
else
:
return
mysetting
s
.
standard_variables
[
'
unknown
'
]
return
standardvariable
s
.
standard_variables
[
'
unknown
'
]
def
AddData
(
self
,
datadict
,
nsets
=
1
,
silent
=
True
):
"""
add fields to file, at end of unlimited dimension
"""
...
...
This diff is collapsed.
Click to expand it.
da/ct/
mysetting
s.py
→
da/ct/
standardvariable
s.py
+
0
−
30
View file @
9d264ea6
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
'
,
\
...
...
This diff is collapsed.
Click to expand it.
da/ct/statevector.py
+
0
−
2
View file @
9d264ea6
...
...
@@ -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
...
...
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