Skip to content
Snippets Groups Projects
Commit 5c372264 authored by Christoph.Knote's avatar Christoph.Knote
Browse files

Humongous reshuffling of modules and packages.

parent 2b24a485
No related branches found
No related tags found
No related merge requests found
# ICARTT reader
# ICARTT file format reader and writer
......@@ -7,12 +7,16 @@ class Variable:
'''
@property
def desc(self):
'''
Return variable description string as it appears in an ICARTT file
'''
return self.splitChar.join( [self.name, self.units, self.units ] )
def __init__(self, name, units, scale=1.0, miss=-9999999):
self.name = name
self.units = units
self.scale = scale
self.miss = str(miss)
self.splitChar = ','
class Dataset:
'''
......@@ -114,17 +118,22 @@ class Dataset:
nul = [ prnt(self.splitChar.join( [ str(y) for y in x ] )) for x in self.data ]
def make_filename(self):
'''
Create ICARTT-compliant file name based on the information contained in the dataset
'''
return self.dataID + "_" +self.locationID + "_" +datetime.datetime.strftime(self.dateValid, '%Y%m%d') + "_" +"R" + self.revision + ".ict"
# sanitize function
def __readline(self, do_split=True):
dmp = self.input_fhandle.readline().replace('\n', '').replace('\r','')
if do_split:
dmp = [word.strip(' ') for word in dmp.split(self.splitChar)]
dmp = [word.strip(' ') for word in dmp.split(self.splitChar) ]
return dmp
def read_header(self):
'''
Read the ICARTT header (from file)
'''
if self.input_fhandle.closed:
self.input_fhandle = open(self.input_fhandle.name)
......@@ -248,7 +257,9 @@ class Dataset:
return [ float(x.replace(self.VAR[i].miss, 'NaN')) for i, x in enumerate(raw) ]
def read_data(self):
'''
Read ICARTT data (from file)
'''
if self.input_fhandle.closed:
self.input_fhandle = open(self.input_fhandle.name)
......@@ -259,7 +270,10 @@ class Dataset:
self.input_fhandle.close()
def read_first_and_last(self):
'''
Read first and last ICARTT data line (from file). Useful for quick estimates e.g. of the time extent
of big ICARTT files, without having to read the whole thing, which would be slow.
'''
if self.input_fhandle.closed:
self.input_fhandle = open(self.input_fhandle.name)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment