示例#1
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"
    def test_profile_collection(self):

        day = 1
        pc = ProfileCollection()
        dt = None

        # 10 profiles
        for x in range(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 range(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 Temperature', 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 _get_profile(self, sensor, t):
        sens_loc_tuple = (sensor['location']['point'].x, sensor['location']['point'].y, sensor['station'])
        profile_od     = self._cache[sens_loc_tuple]

        if t not in profile_od:
            profile          = Profile()
            profile.location = sPoint(*sens_loc_tuple[0:2])
            profile.time     = t

            # @TODO this is a hack until we can figure out how to assoc stations properly
            profile.station  = sensor['station']

            profile_od[t]    = profile
            return profile

        return profile_od[t]
    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
示例#5
0
    def test_section(self):

        day = 1
        hour = 0
        sc = Section()
        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)
            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)

        sc.calculate_bounds()

        assert len(sc.get_path()) == 10

        assert sc.size == 10
        assert sc.point_size == 200
        assert sc.type == "Section"

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

        assert len(sc.depth_range) == 200
        assert sc.depth_range[0] == 0
        assert sc.depth_range[-1] == 19
示例#6
0
    def test_section_collection(self):

        s_collection = SectionCollection()

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

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

            # 10 profiles per section
            for x in range(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 range(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 Temperature', 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"
示例#7
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
示例#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)
示例#9
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)
示例#10
0
    def test_section(self):

        day = 1
        hour = 0
        sc = Section()
        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)
            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)

        sc.calculate_bounds()

        assert len(sc.get_path()) == 10

        assert sc.size == 10
        assert sc.point_size == 200
        assert sc.type == "Section"

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

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