Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
cerbere
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
8
Issues
8
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cerbere
cerbere
Commits
a1a6bda0
Commit
a1a6bda0
authored
Mar 04, 2016
by
Jeff Piollé
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop-jfp' into develop
parents
bd34f237
fc197b28
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
198 additions
and
91 deletions
+198
-91
abstractfeature.py
cerbere/datamodel/abstractfeature.py
+40
-30
ncfile.py
cerbere/mapper/ncfile.py
+158
-61
No files found.
cerbere/datamodel/abstractfeature.py
View file @
a1a6bda0
...
...
@@ -13,7 +13,7 @@ Abstract class for all data feature objects
import
logging
import
datetime
import
copy
import
collections
from
collections
import
OrderedDict
from
abc
import
ABCMeta
,
abstractmethod
import
netCDF4
...
...
@@ -34,8 +34,8 @@ class AbstractFeature(object):
Abstract class for all feature objects
Args:
fields (
dict): a dictionary of :class:`Field` objects to be added
to the feature content, where the key is a field identifier
fields (
OrderedDict): a dictionary of :class:`Field` objects to be
added
to the feature content, where the key is a field identifier
bbox (tuple): describes the limites of the covered geographical
area as a tuple (lonmin,latmin,lonmax,latmax)
...
...
@@ -55,16 +55,30 @@ class AbstractFeature(object):
"""
"""
object
.
__init__
(
self
)
if
fields
is
not
None
and
not
isinstance
(
fields
,
dict
):
raise
Exception
(
'fields must be a dictionary (use an OrderedDict '
'if you want to write fields in a specific order).'
)
# check type of fields
if
fields
is
not
None
:
if
isinstance
(
fields
,
dict
):
logging
.
warning
(
"Usage of dict for 'fields' is deprecated"
)
self
.
_fields
=
OrderedDict
(
fields
)
elif
not
isinstance
(
fields
,
OrderedDict
):
raise
TypeError
(
'fields must be a dictionary (use an OrderedDict '
'if you want to write fields in a specific order)'
)
else
:
self
.
_fields
=
fields
else
:
self
.
_fields
=
OrderedDict
()
self
.
_datastorage
=
None
# geolocation fields (time,lat,lon)
self
.
_geolocation_fields
=
{
'time'
:
None
,
'lat'
:
None
,
'lon'
:
None
,
'z'
:
None
}
self
.
_geolocation_fields
=
OrderedDict
([
(
'time'
,
None
),
(
'lat'
,
None
),
(
'lon'
,
None
),
(
'z'
,
None
)
])
self
.
spatial_resolution
=
spatial_resolution
if
longitudes
is
not
None
:
self
.
set_lon
(
longitudes
)
...
...
@@ -109,10 +123,6 @@ class AbstractFeature(object):
self
.
metadata
=
metadata
if
not
metadata
:
self
.
metadata
=
{}
self
.
_fields
=
fields
if
fields
is
None
:
self
.
_fields
=
collections
.
OrderedDict
()
return
def
__str__
(
self
):
result
=
'FEATURE :
%
s
\n
'
%
self
.
__class__
.
__name__
...
...
@@ -154,19 +164,19 @@ class AbstractFeature(object):
def
get_wkt_bbox
(
self
):
"""Return the bounding box in WKT format."""
#Generate a list of sensible names for the string format
#
Generate a list of sensible names for the string format
if
self
.
_wkt_bbox
is
None
:
cardinal_names
=
[
'lon_min'
,
'lat_min'
,
'lon_max'
,
'lat_max'
]
#Create empty WKT string
#
Create empty WKT string
polygon
=
'POLYGON (({lon_min} {lat_min}, {lon_max} '
\
'{lat_min}, {lon_max} {lat_max}, {lon_min} {lat_max}, '
\
'{lon_min} {lat_min}))'
#Generate a dictionary with these names and the bbox info
#
Generate a dictionary with these names and the bbox info
bbox
=
dict
(
zip
(
cardinal_names
,
self
.
get_bbox
()))
#Return the formated string as WKT.
#
Return the formated string as WKT.
self
.
_wkt_bbox
=
polygon
.
format
(
**
bbox
)
return
self
.
_wkt_bbox
...
...
@@ -208,7 +218,7 @@ class AbstractFeature(object):
dict: an ordered dictionary where key/values are the dimension
names and sizes
"""
dims
=
collections
.
OrderedDict
()
dims
=
OrderedDict
()
for
dim
in
list
(
self
.
get_geolocation_field_dimnames
(
fieldname
)):
dims
[
dim
]
=
self
.
get_geolocation_dimsizes
()[
dim
]
return
dims
...
...
@@ -413,11 +423,11 @@ class AbstractFeature(object):
OrderedDict<dimension name, dimension size>: dimensions of time
field for the feature class
"""
if
isinstance
(
values
,
numpy
.
ndarray
)
and
\
isinstance
(
values
[
0
],
datetime
.
datetime
):
return
collections
.
OrderedDict
([(
'time'
,
1
)])
if
(
isinstance
(
values
,
numpy
.
ndarray
)
and
isinstance
(
values
[
0
],
datetime
.
datetime
)
):
return
OrderedDict
([(
'time'
,
1
)])
else
:
dims
=
collections
.
OrderedDict
(
dims
=
OrderedDict
(
zip
(
list
(
self
.
get_geolocation_field_dimnames
(
'time'
)),
list
(
values
.
shape
))
)
...
...
@@ -502,7 +512,7 @@ class AbstractFeature(object):
authority
=
CF_AUTHORITY
,
standardname
=
'longitude'
)
dims
=
collections
.
OrderedDict
(
dims
=
OrderedDict
(
zip
(
list
(
self
.
get_geolocation_field_dimnames
(
'lon'
)),
list
(
values
.
shape
)
)
...
...
@@ -563,7 +573,7 @@ class AbstractFeature(object):
authority
=
CF_AUTHORITY
,
standardname
=
'latitude'
)
dims
=
collections
.
OrderedDict
(
dims
=
OrderedDict
(
zip
(
list
(
self
.
get_geolocation_field_dimnames
(
'lat'
)),
list
(
values
.
shape
))
)
...
...
@@ -602,7 +612,7 @@ class AbstractFeature(object):
authority
=
CF_AUTHORITY
,
standardname
=
ztype
)
dims
=
collections
.
OrderedDict
(
dims
=
OrderedDict
(
zip
(
list
(
self
.
get_geolocation_field_dimnames
(
'depth'
)),
list
(
values
.
shape
))
)
...
...
@@ -610,8 +620,8 @@ class AbstractFeature(object):
var
,
dims
,
values
=
values
,
attributes
=
{
'depth'
:
{
'positive'
:
'down'
},
'height'
:
{
'positive'
:
'up'
}}[
ztype
]
attributes
=
{
'depth'
:
{
'positive'
:
'down'
},
'height'
:
{
'positive'
:
'up'
}}[
ztype
]
)
field
.
units
=
'm'
self
.
_geolocation_fields
[
'z'
]
=
field
...
...
@@ -775,7 +785,7 @@ class AbstractFeature(object):
if
self
.
_datastorage
is
None
:
metadata
=
self
.
get_metadata
()
if
'time_coverage_start'
in
metadata
:
if
isinstance
(
metadata
[
'time_coverage_start'
],
if
isinstance
(
metadata
[
'time_coverage_start'
],
datetime
.
datetime
):
return
metadata
[
'time_coverage_start'
]
else
:
...
...
cerbere/mapper/ncfile.py
View file @
a1a6bda0
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment