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
8eaef952
Commit
8eaef952
authored
3 years ago
by
Jacques Grelet
Browse files
Options
Downloads
Patches
Plain Diff
add CF global attributes, change to CF-1.7
parent
7c967932
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
netcdf.py
+16
-11
16 additions, 11 deletions
netcdf.py
tests/test.toml
+8
-2
8 additions, 2 deletions
tests/test.toml
with
24 additions
and
13 deletions
netcdf.py
+
16
−
11
View file @
8eaef952
import
logging
from
netCDF4
import
Dataset
from
numpy
import
arange
,
dtype
from
numpy
import
arange
,
complexfloating
,
dtype
import
os
from
datetime
import
datetime
...
...
@@ -13,7 +13,7 @@ def writeNetCDF(cfg, device, fe, r, variables_1D):
# variables and dimensions use for 1D and 2D variables
#variables_1D = ['TIME', 'LATITUDE', 'LONGITUDE']
variables
=
variables_1D
.
copy
()
dims_2D
=
[
'
TIME
'
,
'
depth
'
]
dims_2D
=
[
'
time
'
,
'
depth
'
]
# create netcdf file
fileName
=
"
{}/OS_{}_{}.nc
"
.
format
(
cfg
[
'
global
'
]
...
...
@@ -22,13 +22,13 @@ def writeNetCDF(cfg, device, fe, r, variables_1D):
os
.
makedirs
(
cfg
[
'
global
'
][
'
ascii
'
])
nc
=
Dataset
(
fileName
,
"
w
"
,
format
=
"
NETCDF3_CLASSIC
"
)
logging
.
debug
(
'
'
+
nc
.
data_model
)
print
(
'
writing netCDF file: {}
'
.
format
(
fileName
))
print
(
'
writing netCDF file: {}
'
.
format
(
fileName
)
,
end
=
''
)
# create dimensions
# n is number of profiles, m the max size of profiles
time
=
nc
.
createDimension
(
"
TIME
"
,
fe
.
n
)
lat
=
nc
.
createDimension
(
"
LATITUDE
"
,
fe
.
n
)
lon
=
nc
.
createDimension
(
"
LONGITUDE
"
,
fe
.
n
)
time
=
nc
.
createDimension
(
"
time
"
,
fe
.
n
)
lat
=
nc
.
createDimension
(
"
latitude
"
,
fe
.
n
)
lon
=
nc
.
createDimension
(
"
longitude
"
,
fe
.
n
)
depth
=
nc
.
createDimension
(
'
depth
'
,
fe
.
m
)
# debug
...
...
@@ -55,13 +55,13 @@ def writeNetCDF(cfg, device, fe, r, variables_1D):
# create the variable
if
any
(
key
in
item
for
item
in
variables_1D
):
try
:
# create variable whit same dimension name, as TIME(
TIME
)
# create variable whit same dimension name, as TIME(
time
)
ncvars
[
key
]
=
nc
.
createVariable
(
key
,
dtype
(
hash
[
'
types
'
]).
char
,
(
key
,),
fill_value
=
fillvalue
)
except
:
# for BATH(
TIME
), it's a mess !
# for BATH(
time
), it's a mess !
ncvars
[
key
]
=
nc
.
createVariable
(
key
,
dtype
(
hash
[
'
types
'
]).
char
,
'
TIME
'
,
fill_value
=
fillvalue
)
key
,
dtype
(
hash
[
'
types
'
]).
char
,
'
time
'
,
fill_value
=
fillvalue
)
else
:
ncvars
[
key
]
=
nc
.
createVariable
(
key
,
dtype
(
hash
[
'
types
'
]).
char
,
dims_2D
,
fill_value
=
fillvalue
)
...
...
@@ -74,7 +74,12 @@ def writeNetCDF(cfg, device, fe, r, variables_1D):
# add global attributes
nc
.
data_type
=
"
OceanSITES profile data
"
nc
.
Conventions
=
"
CF-1.8
"
nc
.
Conventions
=
"
CF-1.7
"
nc
.
title
=
cfg
[
'
global
'
][
'
title
'
]
nc
.
institution
=
cfg
[
'
global
'
][
'
institution
'
]
nc
.
source
=
cfg
[
'
global
'
][
'
source
'
]
nc
.
comment
=
cfg
[
'
global
'
][
'
comment
'
]
nc
.
references
=
cfg
[
'
global
'
][
'
references
'
]
nc
.
cycle_mesure
=
cfg
[
'
cruise
'
][
'
cycleMesure
'
]
nc
.
time_coverage_start
=
cfg
[
'
cruise
'
][
'
beginDate
'
]
nc
.
time_coverage_end
=
cfg
[
'
cruise
'
][
'
endDate
'
]
...
...
@@ -103,4 +108,4 @@ def writeNetCDF(cfg, device, fe, r, variables_1D):
# close the netcdf file
nc
.
close
()
print
(
'
done...
'
)
print
(
'
done...
'
)
This diff is collapsed.
Click to expand it.
tests/test.toml
+
8
−
2
View file @
8eaef952
...
...
@@ -2,11 +2,17 @@
author
=
"jgrelet IRD March 2019 PIRATA-FR29 cruise"
debug
=
false
echo
=
true
#
codeRoscop = 'C:\git\python\oceano2python\code_roscop.csv'
codeRoscop
=
'd:\Users\jgrelet\Documents\git\Python\oceano2python\code_roscop.csv'
codeRoscop
=
'C:\git\python\oceano2python\code_roscop.csv'
#
codeRoscop = 'd:\Users\jgrelet\Documents\git\Python\oceano2python\code_roscop.csv'
ascii
=
"ascii"
netcdf
=
"netcdf"
odv
=
"odv"
title
=
''
history
=
''
institution
=
'IRD'
source
=
''
comment
=
''
references
=
''
[cruise]
cycleMesure
=
"PIRATA-FR29"
...
...
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