Esempio n. 1
0
def syncvesk():
    sensors = {}
    service = SensorObservationService(SOSURL, version=SOSVERSION)
    get_obs = service.get_operation_by_name('GetObservation')
    describe_sensor = service.get_operation_by_name('DescribeSensor')
    sensor_ids = describe_sensor.parameters['procedure']['values']
    for sensor_id in sensor_ids:
        response = service.describe_sensor(
            outputFormat='http://www.opengis.net/sensorML/1.0.1',
            procedure=sensor_id)
        tr = etree.fromstring(response)
        element = tr.find('.//' + nspath_eval('sml:SensorML', namespaces))
        ds = SensorML(element)
        name = ds.members[0].name
        sensors[sensor_id] = name

    offerings = [off.id for off in service.offerings]
    _observed_properties = list(
        set(op for off in service.offerings for op in off.observed_properties))
    observed_properties = SOS_PARAMS.keys()
    end_time = datetime.now()  # - timedelta(hours=120*10)
    start_time = end_time - timedelta(hours=12)
    temporalFilter = "om:phenomenonTime,{}/{}".format(start_time.isoformat(),
                                                      end_time.isoformat())
    response_format = 'application/json'
    _namespaces = "xmlns(om,http://www.opengis.net/om/2.0)"

    _response = service.get_observation(offerings=offerings,
                                        responseFormat=response_format,
                                        observedProperties=observed_properties,
                                        namespaces=_namespaces,
                                        temporalFilter=temporalFilter)
    response = json.loads(_response)
    for obs in response['observations']:
        location = obs['featureOfInterest']['name']['value']
        _parameter = obs['observableProperty']
        parameter = SOS_PARAMS.get(_parameter)
        timestamp = obs['phenomenonTime']
        network = 'CNR'
        value = float(obs['result']['value'])
        rjson = {
            'location': location,
            'parameter': parameter,
            "timestamp": timestamp,
            'network': network,
            "value": value
        }
        _write([rjson])

        pass
    pass
def test_sos_20_bom_gov_au():
    # Setup
    service = SensorObservationService(SERVICE_URL, version='2.0.0')
    id = service.identification
    # Check basic service metadata
    assert id.service == 'SOS'
    assert id.title == 'KISTERS KiWIS SOS2'
    assert id.keywords == []
    assert service.provider.name == 'Provider Name'
    assert service.provider.contact.name == 'Name'
    assert service.provider.contact.position is None
    assert len(service.operations) == 5
    assert service.get_operation_by_name('GetObservation').methods[0]['url'] == \
        'http://bom.gov.au/waterdata/services?datasource=0'
    response = service.get_observation(
        featureOfInterest='http://bom.gov.au/waterdata/services/stations/181.1',
        offerings=['http://bom.gov.au/waterdata/services/tstypes/Pat4_PC_1'],
        observedProperties=['http://bom.gov.au/waterdata/services/parameters/Water Course Discharge'],
        eventTime='om:phenomenonTime,2016-01-01T00:00:00+10/2016-03-05T00:00:00+10')
    # Process WaterML Response
    from owslib.etree import etree
    from owslib.swe.observation.sos200 import SOSGetObservationResponse
    from owslib.swe.observation.waterml2 import MeasurementTimeseriesObservation

    et = etree.fromstring(response)
    parsed_response = SOSGetObservationResponse(et)
    assert len(parsed_response.observations) > 0
    for o in parsed_response.observations:
        assert isinstance(o, MeasurementTimeseriesObservation)
Esempio n. 3
0
class CoopsSos(Collector):
    def __init__(self, **kwargs):
        super(CoopsSos,self).__init__()
        url = 'http://opendap.co-ops.nos.noaa.gov/ioos-dif-sos/SOS'

        self.server = Sos(url)

    def get_metadata(self, **kwargs):
        response = self.server.describe_sensor(**kwargs)
        return IoosDescribeSensor(response)

    def get_describe_sensor_output_formats(self):
        return self.server.get_operation_by_name('DescribeSensor').parameters['outputFormat']['values']

    #def get_data(self, **kwargs):
    #    response = self.get_raw_data(**kwargs)
    #    return IoosDif(response)
        
    def get_raw_data(self, **kwargs):
        res = self.server.get_observation(**kwargs)
        if res[41:56] == "ExceptionReport":
            res = -1
        return res
Esempio n. 4
0
class NdbcSos(Collector):
    def __init__(self, **kwargs):
        super(NdbcSos,self).__init__()
        if kwargs.get('test') is True:
            url = 'http://sdftest.ndbc.noaa.gov/sos/server.php'
        else:
            url = 'http://sdf.ndbc.noaa.gov/sos/server.php'

        self.server = Sos(url)

    def get_metadata(self, **kwargs):
        response = self.server.describe_sensor(**kwargs)
        return IoosDescribeSensor(response)

    def get_describe_sensor_output_formats(self):
        return self.server.get_operation_by_name('DescribeSensor').parameters['outputFormat']['values']

    def get_data(self, **kwargs):
        response = self.get_raw_data(**kwargs)
        return IoosSwe(response)
        
    def get_raw_data(self, **kwargs):
        return self.server.get_observation(**kwargs)
Esempio n. 5
0
class CoopsSos(Collector):
    def __init__(self, **kwargs):
        super(CoopsSos, self).__init__()
        url = 'http://opendap.co-ops.nos.noaa.gov/ioos-dif-sos/SOS'

        self.server = Sos(url)

    def get_metadata(self, **kwargs):
        response = self.server.describe_sensor(**kwargs)
        return IoosDescribeSensor(response)

    def get_describe_sensor_output_formats(self):
        return self.server.get_operation_by_name(
            'DescribeSensor').parameters['outputFormat']['values']

    #def get_data(self, **kwargs):
    #    response = self.get_raw_data(**kwargs)
    #    return IoosDif(response)

    def get_raw_data(self, **kwargs):
        res = self.server.get_observation(**kwargs)
        if res[41:56] == "ExceptionReport":
            res = -1
        return res
Esempio n. 6
0
class NdbcSos(Collector):
    def __init__(self, **kwargs):
        super(NdbcSos, self).__init__()
        if kwargs.get('test') is True:
            url = 'http://sdftest.ndbc.noaa.gov/sos/server.php'
        else:
            url = 'http://sdf.ndbc.noaa.gov/sos/server.php'

        self.server = Sos(url)

    def get_metadata(self, **kwargs):
        response = self.server.describe_sensor(**kwargs)
        return IoosDescribeSensor(response)

    def get_describe_sensor_output_formats(self):
        return self.server.get_operation_by_name(
            'DescribeSensor').parameters['outputFormat']['values']

    def get_data(self, **kwargs):
        response = self.get_raw_data(**kwargs)
        return IoosSwe(response)

    def get_raw_data(self, **kwargs):
        return self.server.get_observation(**kwargs)