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
06940dab
Commit
06940dab
authored
5 years ago
by
jacques.grelet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
add __getitem__
parent
79377696
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
file_extractor.py
+8
-0
8 additions, 0 deletions
file_extractor.py
netcdf.py
+19
-9
19 additions, 9 deletions
netcdf.py
oceano.py
+2
-2
2 additions, 2 deletions
oceano.py
with
29 additions
and
11 deletions
file_extractor.py
+
8
−
0
View file @
06940dab
...
...
@@ -40,7 +40,15 @@ class FileExtractor:
self
.
__data
=
{}
# replace this constante with roscop fill value
self
.
__FillValue
=
1e36
# overloading operators
def
__getitem__
(
self
,
key
):
'''
overload r[key]
'''
if
key
not
in
self
.
__data
:
logging
.
error
(
"
file_extractor.py: invalid key:
\"
{}
\"
"
.
format
(
key
))
else
:
return
self
.
__data
[
key
]
def
__str__
(
self
):
'''
overload string representation
'''
...
...
This diff is collapsed.
Click to expand it.
netcdf.py
+
19
−
9
View file @
06940dab
...
...
@@ -7,10 +7,9 @@ from physicalParameter import Roscop
def
writeNetCDF
(
fileName
,
fe
):
data
=
{}
dims
=
[
'
TIME
'
,
'
LATITUDE
'
,
'
LONGITUDE
'
]
variables
=
dims
.
copy
()
dims_4d
=
dims
.
copy
()
dims_4d
=
dims_4d
.
append
(
'
DEPTH
'
)
variables_1D
=
[
'
TIME
'
,
'
LATITUDE
'
,
'
LONGITUDE
'
]
variables
=
variables_1D
.
copy
()
dims_2D
=
[
'
TIME
'
,
'
DEPTH
'
]
# move to main after tests
r
=
Roscop
(
"
code_roscop.csv
"
)
...
...
@@ -26,6 +25,7 @@ def writeNetCDF(fileName, fe):
lon
=
nc
.
createDimension
(
"
LONGITUDE
"
,
fe
.
n
)
depth
=
nc
.
createDimension
(
'
DEPTH
'
,
fe
.
m
)
# debug
logging
.
debug
(
"
depth: {}, time: {}, lat: {}, lon: {}
"
.
format
(
len
(
depth
),
len
(
time
),
len
(
lat
),
len
(
lon
)))
...
...
@@ -34,7 +34,6 @@ def writeNetCDF(fileName, fe):
for
k
in
fe
.
keys
:
variables
.
append
(
k
)
# variables.extend(fe.keys())
print
(
variables
)
for
key
in
variables
:
# for each variables get the attributes list
hash
=
r
.
returnCode
(
key
)
...
...
@@ -47,19 +46,30 @@ def writeNetCDF(fileName, fe):
else
:
fillvalue
=
None
# create the variable
print
(
key
)
if
any
(
key
in
item
for
item
in
dims
):
if
any
(
key
in
item
for
item
in
variables_1D
):
data
[
key
]
=
nc
.
createVariable
(
key
,
dtype
(
hash
[
'
types
'
]).
char
,
(
key
,),
fill_value
=
fillvalue
)
else
:
data
[
key
]
=
nc
.
createVariable
(
key
,
dtype
(
hash
[
'
types
'
]).
char
,
dims_
4d
,
fill_value
=
fillvalue
)
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
])
nc
.
_enddef
()
# debug
for
key
in
variables
:
print
(
data
[
key
])
logging
.
debug
(
"
var: {}, dims: {}, shape: {}, dtype: {}, ndim: {}
"
.
format
(
key
,
data
[
key
].
dimensions
,
data
[
key
].
shape
,
data
[
key
].
dtype
,
data
[
key
].
ndim
))
# write the data
for
key
in
variables
:
if
any
(
key
in
item
for
item
in
variables_1D
):
data
[
key
][:]
=
fe
[
key
]
else
:
data
[
key
][:,
:]
=
fe
[
key
]
# close the netcdf file
nc
.
close
()
This diff is collapsed.
Click to expand it.
oceano.py
+
2
−
2
View file @
06940dab
...
...
@@ -230,9 +230,9 @@ if __name__ == "__main__":
fe
=
process
(
args
,
cfg
,
values
[
'
_COMBO_
'
])
# display result in popup GUI
dims
=
"
Dimensions: {} x {}
"
.
format
(
n
,
m
)
dims
=
"
Dimensions: {} x {}
"
.
format
(
fe
.
n
,
fe
.
m
)
sg
.
PopupScrolled
(
'
Oceano2python
'
,
dims
,
fe
.
disp
(
args
.
keys
),
size
=
(
80
,
40
))
fe
.
disp
(),
size
=
(
80
,
40
))
# It will output to a debug window. Bug ? debug windows xas closed before exiting program
# print = sg.Print
...
...
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