Пример #1
0
	def parse_station(self, metadata, data):
		"""
			Creates a Station object from metadata and data for the station
			- metadata: NerrStation object
			- data: list of NerrData objects
			returns a Station object
		"""
		if not isinstance(metadata, NerrStation) or not isinstance(data, list) or len(data) < 1:
			return None

		retval = Station()
		retval.uid = metadata.code
		retval.name = metadata.name
		retval.description = str('%s-%s' % (metadata.id,metadata.code))
		point_dict = dict()
		for d in data:
			for value_date in d.value_and_utc():
				if value_date[0] is not None:
					param = d.get_top_param()
					if value_date[1] not in point_dict:
						point_dict[value_date[1]] = Point()
						point_dict[value_date[1]].time = value_date[1]
					if param.upper() == 'DEPTH':
						point_dict[value_date[1]].location = Location(metadata.location.longitude, metadata.location.latitude, float(value_date[0]))
					else:
						point_dict[value_date[1]].add_member(dict(name=param,value=value_date[0],unit=unit(param)))

		for point in point_dict.values():
			retval.add_element(point)

		retval.set_location(Location(metadata.location.longitude, metadata.location.latitude))

		return retval
Пример #2
0
    def __init__(self, wqx_metadata, wqx_data):
        if not isinstance(wqx_metadata, WqxOutbound):
            wqx_metadata = WqxOutbound(wqx_metadata)

        if not isinstance(wqx_data, WqxOutbound):
            wqx_data = WqxOutbound(wqx_data)

        if wqx_data.failed or wqx_metadata.failed:
            self.feature = None
        else:
            s = Station()
            s.uid = wqx_metadata.location.id
            s.name = wqx_metadata.location.name
            s.set_property("station_type", wqx_metadata.location.type)
            s.set_property("location_description", wqx_metadata.location.description)
            s.set_property("huc", wqx_metadata.location.huc)
            s.set_property("county", wqx_metadata.location.county)
            s.set_property("state", wqx_metadata.location.state)
            s.set_property("country", wqx_metadata.location.country)
            s.set_property("organization_id", wqx_metadata.organization.id)
            s.set_property("organization_name", wqx_metadata.organization.name)
            s.set_property("vertical_units", wqx_metadata.location.vertical_measure_units)
            s.set_property("horizontal_crs", wqx_metadata.location.horizontal_crs_name)
            s.set_property("vertical_crs", wqx_metadata.location.vertical_crs_name)

            for a in wqx_data.activities:
                p = Point()
                p.time = a.start_time

                for r in a.results:
                    p.add_member(Member(value=r.value, unit=r.units, name=r.name, description=r.short_name, standard=None, quality=r.quality, method_id=a.method_id, method_name=a.method_name))

                s.add_element(p)

            # Now set the station's location
            vertical = 0
            try:
                vertical = float(wqx_metadata.location.vertical_measure_value)
            except:
                pass

            # convert the vertical to meters if it is ft (which it always is)
            if wqx_metadata.location.vertical_measure_units == "ft":
                vertical /= 3.28084
                s.set_property("vertical_units", "m")
            s.location = sPoint(float(wqx_metadata.location.longitude), float(wqx_metadata.location.latitude), vertical)

            self.feature = s
Пример #3
0
    def test_station(self):
        dt1 = datetime(2012, 1, 1, 12, 0)
        p1 = Point()
        p1.time = dt1
        member1 = Member(value=34.7, unit='°C', name='Water Temperature', description='water temperature', standard='sea_water_temperature')
        member2 = Member(value=80, unit='PSU', name='Salinity', description='salinity', standard='salinity')
        p1.add_member(member1)
        p1.add_member(member2)

        dt2 = datetime(2012, 1, 1, 12, 10)
        p2 = Point()
        p2.time = dt2
        member3 = Member(value=34.1, unit='°C', name='Water Temperature', description='water temperature', standard='sea_water_temperature')
        member4 = Member(value=70, unit='PSU', name='Salinity', description='salinity', standard='salinity')
        p2.add_member(member3)
        p2.add_member(member4)

        dt3 = datetime(2012, 1, 1, 12, 20)
        p3 = Point()
        p3.time = dt3
        member5 = Member(value=32.6, unit='°C', name='Water Temperature', description='water temperature', standard='sea_water_temperature')
        member6 = Member(value=60, unit='PSU', name='Salinity', description='salinity', standard='salinity')
        member6 = Member(value=112, unit='%', name='DO', description='do', standard='do')
        p3.add_member(member5)
        p3.add_member(member6)

        pc = Station(elements=[p1,p2,p3])
        pc.name = "Super Station"
        pc.location = sPoint(-120, 50, 0)
        pc.location_name = "Just south of the super pier"
        pc.uid = "123097SDFJL2"
        pc.set_property("authority", "IOOS")
        pc.calculate_bounds()

        assert pc.size == 3
        assert len(pc.time_range) == 3
        assert pc.time_range[0] == dt1
        assert pc.time_range[-1] == dt3
        assert len(pc.depth_range) == 3
        assert pc.depth_range[0] == p1.location.z
        assert pc.upper_right().equals(pc.location)
        assert pc.lower_left().equals(pc.location)

        assert pc.get_property("authority") == "IOOS"
        assert pc.uid == "123097SDFJL2"
        assert pc.location_name == "Just south of the super pier"

        assert len(pc.get_unique_members()) == 3

        filtered_elements = pc.filter_by_time(starting=dt1, ending=dt2)
        assert len(list(filtered_elements)) == 2

        filtered_variables = pc.filter_by_variable("sea_water_temperature")
        assert len(list(filtered_variables)) == 3

        filtered_variables = pc.filter_by_variable("do")
        assert len(list(filtered_variables)) == 1