Exemplo n.º 1
0
    def test_timeseries_profile_single_station(self):
        swe = open(
            resource_file(
                'ioos_swe/SWE-SingleStation-TimeSeriesProfile_QC.xml')).read()
        data_record = etree.fromstring(swe)
        station = TimeSeriesProfile(data_record).feature

        assert isinstance(station, StationProfile)

        assert station.uid == "urn:ioos:station:wmo:41001"
        assert station.name == "wmo_41001"
        assert station.location.x == -75.415
        assert station.location.y == 32.382
        assert station.location.z == 0.5

        # should have three profiles
        assert len(station.elements) == 3
        station.calculate_bounds()

        # should all be at the same point
        bounds = station.get_bbox()
        assert isinstance(bounds, Point)
        assert bounds.x == -75.415
        assert bounds.y == 32.382

        # time
        time_range = station.get_time_range()
        assert time_range[0].strftime(
            "%Y-%m-%dT%H:%M:%SZ") == "2009-05-23T00:00:00Z"
        assert time_range[-1].strftime(
            "%Y-%m-%dT%H:%M:%SZ") == "2009-05-23T02:00:00Z"

        # depth bounds
        depth_range = station.get_depth_range()
        assert depth_range[0] == -39.5
        assert depth_range[-1] == -4.5

        # spot check values
        profile = station.elements[0]

        assert profile.time.strftime(
            "%Y-%m-%dT%H:%M:%SZ") == "2009-05-23T00:00:00Z"
        assert len(profile.elements) == 4
        assert [e.location.z
                for e in profile.elements] == [-39.5, -19.5, -9.5, -4.5]

        assert len(profile.elements[0].members) == 2
        assert [m['name'] for m in profile.elements[0].members
                ] == ['direction_of_sea_water_velocity', 'sea_water_speed']
        assert [m['value']
                for m in profile.elements[0].members] == [352.0, 9.6]

        sensor = station.sensors['wmo_41001_sensor1']
        assert 'sensor_orientation' in sensor
        assert sensor['sensor_orientation']['X'][
            'name'] == 'platform_pitch_angle'
        assert sensor['sensor_orientation']['Y'][
            'name'] == 'platform_roll_angle'
        assert sensor['sensor_orientation']['Z'][
            'name'] == 'platform_orientation'
Exemplo n.º 2
0
    def test_timeseries_profile_single_station(self):
        swe = open(resource_file('ioos_swe/SWE-SingleStation-TimeSeriesProfile_QC.xml'), 'rb').read()
        data_record = etree.fromstring(swe)
        station = TimeSeriesProfile(data_record).feature

        assert isinstance(station, StationProfile)

        assert station.uid        == "urn:ioos:station:wmo:41001"
        assert station.name       == "wmo_41001"
        assert station.location.x == -75.415
        assert station.location.y == 32.382
        assert station.location.z == 0.5

        # should have three profiles
        assert len(station.elements) == 3
        station.calculate_bounds()

        # should all be at the same point
        bounds = station.get_bbox()
        assert isinstance(bounds, Point)
        assert bounds.x == -75.415
        assert bounds.y == 32.382

        # time
        time_range = station.get_time_range()
        assert time_range[0].strftime("%Y-%m-%dT%H:%M:%SZ") == "2009-05-23T00:00:00Z"
        assert time_range[-1].strftime("%Y-%m-%dT%H:%M:%SZ") == "2009-05-23T02:00:00Z"

        # depth bounds
        depth_range = station.get_depth_range()
        assert depth_range[0] == -39.5
        assert depth_range[-1] == -4.5

        # spot check values
        profile = station.elements[0]

        assert profile.time.strftime("%Y-%m-%dT%H:%M:%SZ") == "2009-05-23T00:00:00Z"
        assert len(profile.elements) == 4
        assert [e.location.z for e in profile.elements] == [-39.5, -19.5, -9.5, -4.5]

        assert len(profile.elements[0].members) == 2
        assert [m['name'] for m in profile.elements[0].members] == ['direction_of_sea_water_velocity', 'sea_water_speed']
        assert [m['value'] for m in profile.elements[0].members] == [352.0, 9.6]

        sensor = station.sensors['wmo_41001_sensor1']
        assert 'sensor_orientation' in sensor
        assert sensor['sensor_orientation']['X']['name'] == 'platform_pitch_angle'
        assert sensor['sensor_orientation']['Y']['name'] == 'platform_roll_angle'
        assert sensor['sensor_orientation']['Z']['name'] == 'platform_orientation'
Exemplo n.º 3
0
    def __init__(self, element):
        self._root = element

        self.description = testXMLValue(
            self._root.find(nspv("gml311:description")))

        self.begin_position = extract_time(
            self._root.find(
                nspv('om10:samplingTime/gml311:TimePeriod/gml311:beginPosition'
                     )))

        self.end_position = extract_time(
            self._root.find(
                nspv(
                    'om10:samplingTime/gml311:TimePeriod/gml311:endPosition')))

        self.procedures = [
            testXMLAttribute(e, nspv("xlink:href"))
            for e in self._root.findall(
                nspv("om10:procedure/om10:Process/gml311:member"))
        ]

        self.observedProperties = [
            testXMLAttribute(e, nspv("xlink:href"))
            for e in self._root.findall(
                nspv(
                    "om10:observedProperty/swe101:CompositePhenomenon/swe101:component"
                ))
        ]

        # Can't use a full Xpath expression, so iterate over all metaDataProperties to find the IOOS FeatureType
        self.feature_type = None
        ft = self._root.findall(
            nspv(
                "om10:featureOfInterest/gml311:FeatureCollection/gml311:metaDataProperty/gml311:GenericMetaData/gml311:name"
            ))
        ft.extend(
            self._root.findall(
                nspv(
                    "om10:featureOfInterest/gml311:FeatureCollection/gml311:metaDataProperty/gml311:name"
                )))
        ft_def = "http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.6/cf-conventions.html#discrete-sampling-geometries"
        for f in ft:
            if testXMLAttribute(f, "codeSpace") == ft_def:
                self.feature_type = testXMLValue(f)

        # BBOX
        envelope = self._root.find(
            nspv(
                "om10:featureOfInterest/gml311:FeatureCollection/gml311:boundedBy/gml311:Envelope"
            ))
        self.bbox_srs = Crs(testXMLAttribute(envelope, 'srsName'))
        lower_left_corner = testXMLValue(
            envelope.find(nspv('gml311:lowerCorner'))).split(" ")
        upper_right_corner = testXMLValue(
            envelope.find(nspv('gml311:upperCorner'))).split(" ")
        if self.bbox_srs.axisorder == "yx":
            self.bbox = box(float(lower_left_corner[1]),
                            float(lower_left_corner[0]),
                            float(upper_right_corner[1]),
                            float(upper_right_corner[0]))
        else:
            self.bbox = box(float(lower_left_corner[0]),
                            float(lower_left_corner[1]),
                            float(upper_right_corner[0]),
                            float(upper_right_corner[1]))

        # LOCATION
        location = self._root.find(
            nspv(
                "om10:featureOfInterest/gml311:FeatureCollection/gml311:location"
            ))
        # Should only have one child
        geo = list(location)[-1]
        self.location = {}

        def get_point(element, srs):
            name = testXMLValue(element.find(nspv("gml311:name")))
            point = testXMLValue(element.find(nspv("gml311:pos"))).split(" ")
            if srs.axisorder == "yx":
                point = Point(float(point[1]), float(point[0]))
            else:
                point = Point(float(point[0]), float(point[1]))
            return name, point

        self.location_srs = Crs(testXMLAttribute(geo, "srsName"))
        if geo.tag == nspv("gml311:Point"):
            n, p = get_point(geo, self.location_srs)
            self.location[n] = p
        elif geo.tag == nspv("gml311:MultiPoint"):
            for point in geo.findall(nspv("gml311:pointMembers/gml311:Point")):
                n, p = get_point(point, self.location_srs)
                self.location[n] = p

        # Now the fields change depending on the FeatureType
        self.results = self._root.find(nspv("om10:result"))

        # TODO: This should be implemented as a Factory
        self.feature = None
        data = self.results.find(nspv("swe20:DataRecord"))
        if data is not None:
            if self.feature_type == 'timeSeries':
                self.feature = TimeSeries(data).feature
            elif self.feature_type == 'timeSeriesProfile':
                self.feature = TimeSeriesProfile(data).feature
            else:
                print("No feature type found.")