示例#1
0
    def test_trajectory(self):
        dt1 = datetime(2012, 4, 1, 0)
        p1 = Point()
        p1.time = dt1
        p1.location = sPoint(-121, 49, 40)
        member1 = Member(value=random.uniform(30,40), unit='°C', name='Water Temperatire', description='water temperature', standard='sea_water_temperature')
        member2 = Member(value=random.uniform(80,100), unit='PSU', name='Salinity', description='salinity', standard='salinity')
        p1.add_member(member1)
        p1.add_member(member2)

        dt2 = datetime(2012, 4, 1, 1)
        p2 = Point()
        p2.time = dt2
        p2.location = sPoint(-120, 50, 60)
        member3 = Member(value=random.uniform(30,40), unit='°C', name='Water Temperatire', description='water temperature', standard='sea_water_temperature')
        member4 = Member(value=random.uniform(80,100), unit='PSU', name='Salinity', description='salinity', standard='salinity')
        p2.add_member(member3)
        p2.add_member(member4)

        tr = Trajectory(elements=[p1,p2])
        tr.calculate_bounds()

        assert len(tr.get_path()) == 2
        assert tr.size == 2
        assert tr.type == "Trajectory"
        assert tr.time_range[0] == dt1
        assert tr.time_range[-1] == dt2
        assert tr.depth_range[0] == p1.location.z
        assert tr.depth_range[-1] == p2.location.z
        assert tr.upper_right().equals(sPoint(p2.location.x, p2.location.y))
        assert tr.lower_left().equals(sPoint(p1.location.x, p1.location.y))
        
示例#2
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
示例#3
0
    def test_section_collection(self):

        s_collection = SectionCollection()

        # 20 sections
        for x in xrange(0,20):

            day = 1
            hour = 0
            sc = Section()
            dt = None

            # 10 profiles per section
            for x in xrange(0,10):
                lat = random.randint(40,44)
                lon = random.randint(-74,-70)
                loc = sPoint(lon,lat,0)
                minute = 0
                dt = datetime(2012, 4, day, hour, minute)
                hour += 1

                prof = Profile()
                prof.location = loc
                prof.time = dt

                # Each with 20 depths
                for y in xrange(0,20):
                    p = Point()
                    p.time = dt
                    p.location = sPoint(loc.x, loc.y, y)
                    m1 = Member(value=random.uniform(30,40), unit='°C', name='Water Temperatire', description='water temperature', standard='sea_water_temperature')
                    m2 = Member(value=random.uniform(80,100), unit='PSU', name='Salinity', description='salinity', standard='salinity')
                    p.add_member(m1)
                    p.add_member(m2)
                    prof.add_element(p)
                    # Next depth is 2 minutes from now
                    dt = dt + timedelta(minutes=2)

                sc.add_element(prof)
                
            s_collection.add_element(sc)

        s_collection.calculate_bounds()

        assert s_collection.depth_range[0] == 0
        assert s_collection.depth_range[-1] == 19
        assert s_collection.time_range[0] == datetime(2012, 4, 1, 0)

        for section in s_collection:
            assert section.type == "Section"
            for profile in section:
                assert profile.type == "Profile"
                for point in profile:
                    assert point.type == "Point"

        for point in s_collection.flatten():
            assert point.type == "Point"
示例#4
0
    def __init__(self, **kwargs):
        super(SweTimeSeries,self).__init__(**kwargs)

        # Parse out GML point.  Defaults to 0 depth if none specified
        self.geo_srs = Crs(testXMLAttribute(self._location.find(nsp("Point", self.GML_NS)), 'srsName'))
        geo = [float(v) for v in testXMLValue(self._location.find(nsp("Point/pos", self.GML_NS))).split(" ")]

        if self.geo_srs.axisorder == "yx":
            self.geo = sPoint(geo[1], geo[0])
        else:
            self.geo = sPoint(geo[0], geo[1])

        try:
            self.geo.z = geo[2]
        except:
            pass


        pc = PointCollection()

        for row in self.results.data:
            p = Point()

            time = None
            z = None
            lat = None
            lon = None

            for field in row:

                if field.axis == "time":
                    t = dateutil.parser.parse(field.value)
                    p.time = t.astimezone(dateutil.tz.tzutc())
                elif field.axis == "Long":
                    lon = field
                elif field.axis == "Lat":
                    lat = field
                elif field.axis == "h":
                    z = field
                else:
                    m = Member(value=field.value,
                               unit=field.units,
                               units_definition=field.units_url,
                               name=field.name,
                               definition=field.definition,
                               standard=field.definition)
                    p.add_member(m)

            # Set the spatial point
            if lon.srs != lat.srs:
                raise ValueError("Longitude and Latitude need to have the same SRS/CRS!")
            p.location = sPoint(float(lon.value), float(lat.value), float(z.value))
            pc.add_element(p)


        self.data = pc
示例#5
0
    def test_point(self):
        dt = datetime.utcnow()
        p = Point()
        p.location = sPoint(-123.17, 48.33, 10)
        p.time = dt

        assert p.location.x == -123.17
        assert p.location.y == 48.33
        assert p.location.z == 10
        assert p.time == dt
        assert p.type == "Point"
示例#6
0
    def test_profile_collection(self):

        day = 1
        pc = ProfileCollection()
        dt = None

        # 10 profiles
        for x in xrange(0,10):
            lat = random.randint(40,44)
            lon = random.randint(-74,-70)
            loc = sPoint(lon,lat,0)
            hour = 0
            minute = 0
            dt = datetime(2012, 4, day, hour, minute)

            prof = Profile()
            prof.location = loc
            prof.time = dt

            # Each with 20 depths
            for y in xrange(0,20):
                p = Point()
                p.time = dt
                p.location = sPoint(loc.x, loc.y, y)
                m1 = Member(value=random.uniform(30,40), unit='°C', name='Water Temperatire', description='water temperature', standard='sea_water_temperature')
                m2 = Member(value=random.uniform(80,100), unit='PSU', name='Salinity', description='salinity', standard='salinity')
                p.add_member(m1)
                p.add_member(m2)
                prof.add_element(p)
                # Next depth is 2 minutes from now
                dt = dt + timedelta(minutes=2)

            pc.add_element(prof)

        pc.calculate_bounds()

        assert pc.size == 10
        assert pc.point_size == 200

        assert len(pc.time_range) == 200
        assert pc.time_range[0] == datetime(2012, 4, 1, 0, 0)
        assert pc.time_range[-1] == dt - timedelta(minutes=2)

        assert len(pc.depth_range) == 200
        assert pc.depth_range[0] == 0
        assert pc.depth_range[-1] == 19

        for profile in pc:
            assert profile.type == "Profile"
            for point in profile:
                assert point.type == "Point"

        for point in pc.flatten():
            assert point.type == "Point"
    def test_trajectory_collection(self):

        t_collection = TrajectoryCollection()

        # 20 trajectories
        for x in xrange(0,20):

            tr = Trajectory()

            month = random.randint(1,12)
            dt = datetime(2012, month, 1, 0)

            # Starting point
            lat = random.randint(40,44)
            lon = random.randint(-74,-70)
            depth = 0

            # 100 points in each trajectory
            for l in xrange(0,100):

                lat += random.uniform(-0.25,0.25)
                lon += random.uniform(-0.25,0.25)
                depth += random.randint(-4,4)
                if depth < 0:
                    depth = 0

                p1 = Point()
                p1.location = sPoint(lon,lat,depth)
                dt += timedelta(hours=1)
                p1.time = dt
                member1 = Member(value=random.uniform(30,40), unit='°C', name='Water Temperature', description='water temperature', standard='sea_water_temperature')
                member2 = Member(value=random.uniform(80,100), unit='PSU', name='Salinity', description='salinity', standard='salinity')
                p1.add_member(member1)
                p1.add_member(member2)

                tr.add_element(p1)
        
            t_collection.add_element(tr)

        t_collection.calculate_bounds()

        assert len(t_collection.time_range) == 2000
        assert len(t_collection.depth_range) == 2000

        for trajectory in t_collection:
            assert trajectory.type == "Trajectory"
            for point in trajectory:
                assert point.type == "Point"

        for point in t_collection.flatten():
            assert point.type == "Point"
示例#8
0
    def test_profile(self):
        dt1 = datetime(2012, 1, 1, 12, 0)
        p1 = Point()
        p1.time = dt1
        p1.location = sPoint(-120, 50, 0)
        member1 = Member(
            value=34.7,
            unit="°C",
            name="Water Temperatire",
            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
        p2.location = sPoint(-120, 50, 10)
        member3 = Member(
            value=34.1,
            unit="°C",
            name="Water Temperatire",
            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
        p3.location = sPoint(-120, 50, 20)
        member5 = Member(
            value=32.6,
            unit="°C",
            name="Water Temperatire",
            description="water temperature",
            standard="sea_water_temperature",
        )
        member6 = Member(value=60, unit="PSU", name="Salinity", description="salinity", standard="salinity")
        p3.add_member(member5)
        p3.add_member(member6)

        pc = Profile(elements=[p1, p2, p3])
        pc.location = sPoint(-120, 50)
        pc.time = dt1
        pc.calculate_bounds()

        assert pc.size == 3
        assert pc.time == dt1
        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.depth_range[-1] == p3.location.z
        assert pc.upper_right().equals(pc.location)
        assert pc.lower_left().equals(pc.location)