Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions nefis/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
MAXDIMS = 5
MAXGROUPS = 100
MAXELEMENTS = 1000
DTYPES = {
'REAL': np.float32,
'INTEGER': np.int32,
'CHARACTE': bytes
}


dump_tmpl = """
nefis ${ds.def_file} {
Expand All @@ -48,6 +42,7 @@

class NefisException(Exception):
"""A nefis exception"""

def __init__(self, message, status):
super(Exception, self).__init__(message)
self.status = status
Expand Down Expand Up @@ -87,7 +82,6 @@ def flat(self):
)



def wrap_error(func):
"""wrap a nefis function to raise an error"""
@functools.wraps(func)
Expand Down Expand Up @@ -120,6 +114,7 @@ def default(self, obj):

class Nefis(object):
"""Nefis file"""

def __init__(self, def_file, ac_type=b'r', coding=b' '):
"""dat file is expected to be named .dat instead of .def"""

Expand Down Expand Up @@ -346,7 +341,6 @@ def get_data(self, group, element, t=0):
elm_count,
elm_dimensions) = result
logger.info('got info: %s', result)

usr_index = np.zeros((5, 3), dtype=np.int32)
# first timestep: 0 -> 1 based
usr_index[0, 0] = t + 1
Expand Down Expand Up @@ -375,7 +369,21 @@ def get_data(self, group, element, t=0):
length
)
# lookup data type
dtype = DTYPES[elm_type.strip()]
datatype = elm_type.strip().upper()
if datatype == 'CHARACTE':
dtype = bytes
elif datatype == 'REAL':
if elm_single_byte == 4:
dtype = np.float32
elif elm_single_byte == 8:
dtype = np.float64
elif datatype == 'INTEGER':
if elm_single_byte == 4:
dtype = np.int32
elif elm_single_byte == 8:
dtype = np.int64
else:
raise ValueError('Invalid Datatype: {} {}'.format(elm_type.strio(), elm_single_byte))
if dtype is bytes:
# return bytes
return buffer_res.rstrip()
Expand Down