Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Oceano2python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
US191
Oceano2python
Commits
bcbe6fe6
Commit
bcbe6fe6
authored
5 years ago
by
jacques.grelet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
rename data by ncvars
parent
2d5c5dbf
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
netcdf.py
+11
-8
11 additions, 8 deletions
netcdf.py
with
11 additions
and
8 deletions
netcdf.py
+
11
−
8
View file @
bcbe6fe6
...
...
@@ -6,7 +6,10 @@ from physicalParameter import Roscop
def
writeNetCDF
(
fileName
,
fe
):
data
=
{}
# ncvars is a dictionary that store a netcdf variable for each physical parameter key
ncvars
=
{}
# variables and dimensions use for 1D and 2D variables
variables_1D
=
[
'
TIME
'
,
'
LATITUDE
'
,
'
LONGITUDE
'
]
variables
=
variables_1D
.
copy
()
dims_2D
=
[
'
TIME
'
,
'
DEPTH
'
]
...
...
@@ -47,29 +50,29 @@ def writeNetCDF(fileName, fe):
fillvalue
=
None
# create the variable
if
any
(
key
in
item
for
item
in
variables_1D
):
data
[
key
]
=
nc
.
createVariable
(
ncvars
[
key
]
=
nc
.
createVariable
(
key
,
dtype
(
hash
[
'
types
'
]).
char
,
(
key
,),
fill_value
=
fillvalue
)
else
:
data
[
key
]
=
nc
.
createVariable
(
ncvars
[
key
]
=
nc
.
createVariable
(
key
,
dtype
(
hash
[
'
types
'
]).
char
,
dims_2D
,
fill_value
=
fillvalue
)
# remove from the dictionary
hash
.
pop
(
'
types
'
)
# create dynamically variable attributes
for
k
in
hash
.
keys
():
setattr
(
data
[
key
],
k
,
hash
[
k
])
setattr
(
ncvars
[
key
],
k
,
hash
[
k
])
nc
.
_enddef
()
# debug
for
key
in
variables
:
logging
.
debug
(
"
var: {}, dims: {}, shape: {}, dtype: {}, ndim: {}
"
.
format
(
key
,
data
[
key
].
dimensions
,
data
[
key
].
shape
,
data
[
key
].
dtype
,
data
[
key
].
ndim
))
key
,
ncvars
[
key
].
dimensions
,
ncvars
[
key
].
shape
,
ncvars
[
key
].
dtype
,
ncvars
[
key
].
ndim
))
# write the
data
# write the
ncvars
for
key
in
variables
:
if
any
(
key
in
item
for
item
in
variables_1D
):
data
[
key
][:]
=
fe
[
key
]
ncvars
[
key
][:]
=
fe
[
key
]
else
:
data
[
key
][:,
:]
=
fe
[
key
]
ncvars
[
key
][:,
:]
=
fe
[
key
]
# close the netcdf file
nc
.
close
()
...
...
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