class Importer(dataio.Importer): extensions = ['sif'] author = "Niklas Volbers" blurb = "SloppyPlot Internal Format" filemode = 'b' column_props = pList(types=dict) def read_table_from_stream(self, fd): raise RuntimeError("Please call 'read_table_from_file'.") def read_table_from_file(self, fd): if not isinstance(fd, basestring): raise RuntimeError("You must supply a filename.") nc = CDF(fd) # global attributes #attr = nc.attributes(full=1) # unused dims = nc.dimensions(full=1) ncols = len(nc.variables()) # create new table according to dimension information self.table = Table(nrows=0, ncols=ncols) # vars => columns j = 0 for column in self.table.get_columns(): v = nc.var(j) column.data = array(v[:]) # Read attributes from netCDF file. This _should_ only # be the key right now. attributes = v.attributes(full=1) for k,v in attributes.iteritems(): column.set_value(k, v[0]) # Set properties which can be passed via 'column_props'. for k,v in self.column_props[j].iteritems(): column.set_value(k,v) j += 1 nc.close() self.table.update_cols() self.table.update_rows() return self.table
class Importer(dataio.Importer): extensions = ['sif'] author = "Niklas Volbers" blurb = "SloppyPlot Internal Format" filemode = 'b' def read_table_from_stream(self, fd): raise RuntimeError("Please call 'read_table_from_file'.") def read_table_from_file(self, fd): if not isinstance(fd, basestring): raise RuntimeError("You must supply a filename.") nc = CDF(fd) # global attributes #attr = nc.attributes(full=1) # unused dims = nc.dimensions(full=1) ncols = len(nc.variables()) # create new table according to dimension information self.table = Table(rowcount=0, colcount=ncols) # vars => columns j = 0 for column in self.table.get_columns(): v = nc.var(j) column.data = array(v[:]) attributes = v.attributes(full=1) for k,v in attributes.iteritems(): column.set_value(k, v[0]) j += 1 nc.close() self.table.update_cols() self.table.update_rows() return self.table