def test_base_outputs(self): outputs = self.base.outputs() self.assertTrue(outputs == {}) geom = geometry.fromWKT('POINT(1 2)') unit = stdlib.Unit() unit.UnitAbbreviation('cm') unit.UnitName('centimeters') var = stdlib.Variable() var.VariableNameCV('my variable') var.VariableDefinition('this is my variable definition') oei = stdlib.ExchangeItem(name='output1', desc='my description', unit=unit, variable=var, geometry=geom, type=stdlib.ExchangeItemType.OUTPUT) outputs = self.base.outputs(oei) self.assertTrue(len(outputs.items()) == 1) # add duplicate outputs = self.base.outputs(oei) self.assertTrue(len(outputs.items()) == 1) # try to add an input type iei = stdlib.ExchangeItem(name='input1', desc='my description', unit=unit, variable=var, geometry=geom, type=stdlib.ExchangeItemType.INPUT) outputs = self.base.outputs(iei) self.assertTrue(len(outputs.items()) == 1)
def test_base_outputs(self): outputs = self.base.outputs() self.assertTrue(outputs == {}) geom = geometry.fromWKT('POINT(1 2)') unit = stdlib.Unit() unit.UnitAbbreviation('cm') unit.UnitName('centimeters') var = stdlib.Variable() var.VariableNameCV('my variable') var.VariableDefinition('this is my variable definition') oei = stdlib.ExchangeItem(name = 'output1', desc = 'my description', unit = unit, variable = var, geometry = geom, type = stdlib.ExchangeItemType.OUTPUT) outputs = self.base.outputs(oei) self.assertTrue(len(outputs.items()) == 1) # add duplicate outputs = self.base.outputs(oei) self.assertTrue(len(outputs.items()) == 1) # try to add an input type iei = stdlib.ExchangeItem(name = 'input1', desc = 'my description', unit = unit, variable = var, geometry = geom, type = stdlib.ExchangeItemType.INPUT) outputs = self.base.outputs(iei) self.assertTrue(len(outputs.items()) == 1)
def get_geometries(self, ID): """ Converts the geometry string to objects :param ID: Int :return: a list of geometry objects """ geometries = [] for item in self.geometries[ID]: geometries.append(geometry.fromWKT(item)[0]) return geometries
def __init__(self, args): super(Wrapper, self).__init__() self.args = args wsdl = self.args['wsdl'] network = self.args['network'] variable = '%s:%s' % (network, self.args['variable']) site = '%s:%s'%(network, self.args['site']) st = self.args['start'] et = self.args['end'] # make sure that start and end time are valid date time objects if not isinstance(st, datetime.datetime): st = parser.parse(st) if not isinstance(et, datetime.datetime): et = parser.parse(et) # format start and end datetime into wof acceptable format start = st.strftime('%Y-%m-%dT%H:%M:%S') end = et.strftime('%Y-%m-%dT%H:%M:%S') # connect to the server client = Client(wsdl) # get data queryInfo, timeSeries = client.service.GetValuesObject(site, variable, start, end) label, series = timeSeries # grab the first timeseries only ts = series[0] sourceInfo = ts['sourceInfo'] variable = ts['variable'] values = ts['values'][0] variableName = variable['variableName'] unitName = variable['unit']['unitName'] unitType = variable['unit']['unitType'] unitAbbreviation = variable['unit']['unitAbbreviation'] siteDescription = sourceInfo['siteName'] geolocation_x = sourceInfo['geoLocation']['geogLocation']['longitude'] geolocation_y = sourceInfo['geoLocation']['geogLocation']['latitude'] geolocation_z = sourceInfo['elevation_m'] # build unit unit = stdlib.Unit() unit.UnitName(unitName) unit.UnitAbbreviation(unitAbbreviation) unit.UnitTypeCV(unitType) # build variable var = stdlib.Variable() var.VariableNameCV(variableName) var.VariableDefinition(' ') # build geometry wkt = 'POINT(%s %s %s)' % (geolocation_x, geolocation_y, geolocation_z) geom = geometry.fromWKT(wkt) # build output exchange items oei = stdlib.ExchangeItem(name=variableName, desc=siteDescription, geometry=geom, unit=unit, variable=var, type=stdlib.ExchangeItemType.OUTPUT, # srs_epsg= '' ) qualityControlLevelId = values['qualityControlLevel'][0]['qualityControlLevelCode'] qualityControlLevelDef = values['qualityControlLevel'][0]['definition'] qualityControlLevelExp = values['qualityControlLevel'][0]['explanation'] dates = [] vals = [] # set data values for value in values.value: vals.append(float(value.value)) dates.append(value._dateTime) oei.setValues2(values=vals, timevalue=dates) # set output self.outputs(oei) # set component metadata self.description(siteDescription) self.name(variableName) self.simulation_start(start) self.simulation_end(end)