def test_station_profile(self):

        sp = StationProfile()
        sp.name = "Profile Station"
        sp.location = sPoint(-77, 33)
        sp.uid = "1234"
        sp.set_property("authority", "IOOS")

        # add a sequence of profiles
        for y in xrange(3):
            dt1 = datetime(2013, 1, 1, 12, 0, 10 * y)
            prof1          = Profile()
            prof1.location = sPoint(-77, 33)
            prof1.time     = dt1

            # add a string of points going down in z
            for x in xrange(5):
                p1 = Point()
                p1.time = dt1
                p1.location = sPoint(-77, 33, -5 * x)

                member1 = Member(value=30 - (2 * x), units='°C', name='Water Temperature', description='water temperature', standard='sea_water_temperature')
                member2 = Member(value=80 + (2 * x), units='PSU', name='Salinity', description='salinity', standard='salinity')
                p1.add_member(member1)
                p1.add_member(member2)

                prof1.add_element(p1)

            sp.add_element(prof1)

        sp.calculate_bounds()

        assert sp.size == 3
        assert len(sp.time_range) == 3

        assert sp.depth_range[0] == -20
        assert sp.depth_range[-1] == 0

        assert sp.get_property("authority") == "IOOS"
        assert sp.uid == "1234"

        assert len(sp.get_unique_members()) == 2
Пример #2
0
    def test_station_profile(self):

        sp = StationProfile()
        sp.name = "Profile Station"
        sp.location = sPoint(-77, 33)
        sp.uid = "1234"
        sp.set_property("authority", "IOOS")

        # add a sequence of profiles
        for y in range(3):
            dt1 = datetime(2013, 1, 1, 12, 0, 10 * y)
            prof1 = Profile()
            prof1.location = sPoint(-77, 33)
            prof1.time = dt1

            # add a string of points going down in z
            for x in range(5):
                p1 = Point()
                p1.time = dt1
                p1.location = sPoint(-77, 33, -5 * x)

                member1 = Member(value=30 - (2 * x),
                                 units='°C',
                                 name='Water Temperature',
                                 description='water temperature',
                                 standard='sea_water_temperature')
                member2 = Member(value=80 + (2 * x),
                                 units='PSU',
                                 name='Salinity',
                                 description='salinity',
                                 standard='salinity')
                p1.add_member(member1)
                p1.add_member(member2)

                prof1.add_element(p1)

            sp.add_element(prof1)

        sp.calculate_bounds()

        assert sp.size == 3
        assert len(sp.time_range) == 3

        assert sp.depth_range[0] == -20
        assert sp.depth_range[-1] == 0

        assert sp.get_property("authority") == "IOOS"
        assert sp.uid == "1234"

        assert len(sp.get_unique_members()) == 2
    def __init__(self, element):
        record = DataRecord(element)

        stations_field = record.get_by_name("stations")

        stations = {}
        sensors = {}

        for station in stations_field.content.field:
            s      = StationProfile()
            s.name = station.name
            s.uid  = station.content.get_by_name("stationID").content.value

            # Location
            vector  = station.content.get_by_name("platformLocation").content
            srss = vector.referenceFrame.split("&")
            hsrs = None
            try:
                hsrs = Crs(srss[0])
            except ValueError:
                pass

            vsrs = None
            try:
                vsrs = Crs(srss[-1].replace("2=http:", "http:"))
            except ValueError:
                pass

            s.set_property("horizontal_srs", hsrs)
            s.set_property("vertical_srs",   vsrs)
            s.set_property("localFrame",     vector.localFrame)

            lat = vector.get_by_name("latitude").content.value
            lon = vector.get_by_name("longitude").content.value
            z   = vector.get_by_name("height").content.value

            loc = [lon, lat]
            if z:
                loc.append(z)

            s.location = sPoint(*loc)

            # sensors
            for sensor in station.content.get_by_name("sensors").content.field:
                name           = sensor.name
                uri            = sensor.content.get_by_name("sensorID").content.value

                sensors[name] = {'station'        : s.uid,
                                 'name'           : name,
                                 'uri'            : uri}
                # orientation
                ori_el = sensor.content.get_by_name("sensorOrientation")
                if ori_el:
                    orientation = self._parse_sensor_orientation(ori_el)
                    sensors[name]['sensor_orientation'] = orientation

                # location
                loc_el = sensor.content.get_by_name("sensorLocation")
                if loc_el:
                    location = self._parse_location(loc_el, s.location)
                    sensors[name]['location'] = location

                # profile bins
                profbins_el = sensor.content.get_by_name("profileBins")
                if profbins_el:
                    profile_bins = self._parse_profile_bins(profbins_el)
                    sensors[name]['profile_bins'] = profile_bins

                # OR profile heights
                profheights_el = sensor.content.get_by_name('profileHeights')
                if profheights_el:
                    profile_heights = self._parse_profile_heights(profheights_el)
                    sensors[name]['profile_heights'] = profile_heights

            s.sensors = sensors

            stations[s.uid] = s

        sensor_data = self._parse_sensor_data(record.get_by_name('observationData'), sensors)

        # sensor data is dict of station id -> profile collection
        for station_id, sensor_profile_data in sensor_data.iteritems():
            stations[station_id].elements.extend(sensor_profile_data._elements)

        if len(stations) > 1:
            self.feature = StationCollection(elements=stations)
        elif len(stations) == 1:
            self.feature = next(stations.itervalues())
        else:
            print "No stations found!"
            self.feature = None