def get_last_value(self, granule): stream_resource_id = granule.stream_resource_id if not self.def_cache.has_key(stream_resource_id): stream_def = self.ps_cli.find_stream_definition( stream_id=stream_resource_id, id_only=False) self.def_cache[stream_resource_id] = stream_def.container definition = self.def_cache[stream_resource_id] psp = PointSupplementStreamParser(stream_definition=definition, stream_granule=granule) fields = psp.list_field_names() lu = LastUpdate() lu.timestamp = granule.identifiables[ granule.data_stream_id].timestamp.value for field in fields: range_id = definition.identifiables[field].range_id lu.variables[field] = Variable() if definition.identifiables.has_key(field): lu.variables[field].definition = definition.identifiables[ field].definition if definition.identifiables.has_key(range_id): lu.variables[field].units = definition.identifiables[ range_id].unit_of_measure.code lu.variables[field].value = float( psp.get_values(field_name=field)[-1]) return lu
def _load_variables(self): self._variables = [] for vn in self._ds.variables.keys(): var = self._ds.variables[vn] newvar = Variable() newvar.index_key = vn newvar.name = vn newvar.attributes = [] for ak in var.ncattrs(): att = var.getncattr(ak) if ak == "units": newvar.units = att attr = Attribute() attr.name = ak attr.value = att newvar.attributes.append(attr) self._variables.append(newvar)
def _parse_attribute(self, line='', correct_table_type=False, variables=None, attributes=None): #strip out leading % new_line = line.replace('%', '') parsed_line = new_line.partition(':') if parsed_line[0] == 'TableColumnTypes' and correct_table_type: cols = parsed_line[2].split(' ') index = 0 for col in cols: if not col == '' and not col == '\n': var = Variable() var.attributes = [] var.name = col var.index_key = str(index) self._variables.append(var) index += 1 elif not parsed_line[0].startswith('Table'): if not parsed_line[2] == '': att = Attribute() att.name = parsed_line[0] att.value = parsed_line[2].replace('\n', '') attributes.append(att)
def _parse_attribute(self, line="", correct_table_type=False, variables=None, attributes=None): # strip out leading % new_line = line.replace("%", "") parsed_line = new_line.partition(":") if parsed_line[0] == "TableColumnTypes" and correct_table_type: cols = parsed_line[2].split(" ") index = 0 for col in cols: if not col == "" and not col == "\n": var = Variable() var.attributes = [] var.name = col var.index_key = str(index) self._variables.append(var) index += 1 elif not parsed_line[0].startswith("Table"): if not parsed_line[2] == "": att = Attribute() att.name = parsed_line[0] att.value = parsed_line[2].replace("\n", "") attributes.append(att)
def _load_variables(self): self._variables = [] for vn in self._ds.variables.keys(): var = self._ds.variables[vn] newvar = Variable() newvar.index_key = vn newvar.name = vn newvar.attributes = [] for ak in var.ncattrs(): att = var.getncattr(ak) if ak == 'units': newvar.units = att attr = Attribute() attr.name = ak attr.value = att newvar.attributes.append(attr) self._variables.append(newvar)