# Path: paegan/cdm/dsg/member.py
# class Member(dict):
#     def __init__(self, *args, **kwargs):
#         super(Member, self).__init__(*args, **kwargs)
# 
# Path: paegan/cdm/dsg/features/station_profile.py
# class StationProfile(ProfileCollection):
#     """
#     A collection of Profiles at a single location.
# 
#     This mimics the Station class API, they should likely be merged somehow.
#     """
#     def __init__(self, **kwargs):
#         super(StationProfile, self).__init__(**kwargs)
# 
#         self._type       = "timeSeriesProfile"
#         self._properties = {}
#         self._location   = None
#         self.uid         = None
#         self.name        = None
#         self.description = None
# 
#     @property
#     def location(self):
#         return self._location
# 
#     @location.setter
#     def location(self, value):
#         self._location = value
# 
#         # Sets the location of every Profile in this station if it is not already set
#         for profile in self._elements:
#             if profile.location is None:
#                 profile.location == value
# 
#     def get_properties(self):
#         return self._properties
# 
#     def get_property(self, prop):
#         return self._properties.get(prop, None)
# 
#     def set_property(self, prop, value):
#         self._properties[prop] = value
# 
#     def get_unique_members(self):
#         all_members = [pt.members for prof in self._elements
#                                   for pt in prof._elements]
# 
#         keys = ["name", "description", "standard", "units"]
#         mwhat = []
#         for mg in all_members:
#             for m in mg:
#                 mwhat.append( { key: m[key] for key in keys if key in m } )
# 
#         # Now unique them on name
#         mwhat = { x['name']:x for x in mwhat }.values()
# 
#         return mwhat
# 
#     def calculate_bounds(self):
#         """
#             Calculate the time_range, depth_range, bbox, and size of this collection.
#             Will scan all data.
#             Ensures that .size, .bbox and .time_range return non-null.
# 
#             If the collection already knows its bbox; time_range; and/or size,
#             they are recomputed.
#         """
#         # tell all contained profiles to calculate their bounds
#         map(lambda x: x.calculate_bounds(), self._elements)
# 
#         # @TODO size is just number of timesteps?
#         self.size = len(self._elements)
# 
#         # bbox is just this point
#         self.bbox = MultiPoint([self.location, self.location]).envelope
# 
#         time_set = set()
#         map(time_set.add, AsaList.flatten([p.time for p in self._elements]))
#         self.time_range = sorted(list(time_set))
# 
#         depth_set = set()
#         map(depth_set.add, AsaList.flatten([p.depth_range for p in self._elements]))
#         self.depth_range = sorted(list(depth_set))
# 
# Path: paegan/cdm/dsg/features/base/profile.py
# class Profile(PointCollection):
#     """
#         A collection of points along a vertical (z) access
#         ie. A single profile from an ADCP or CTD
# 
#         A profile has a nominal lat/lon and time.
#         Actual time may be constant, or vary with z.
#         The z coordinates are monotonic, and may be increasing or decreasing.
#     """
#     def __init__(self, **kwargs):
#         super(Profile,self).__init__(**kwargs)
#         self._type = "Profile"
# 
#     def get_location(self):
#         return self._location
#     def set_location(self, location):
#         self._location = location
#     location = property(get_location, set_location)
# 
#     def get_time(self):
#         """
#             Nominal time of the profile.  This is usually the first time a reading was taken,
#             since a profile's time can be constant or vary with z.
#         """
#         return self._time
#     def set_time(self, time):
#         self._time = time
#     time = property(get_time, set_time)


import unittest
from datetime import datetime
from shapely.geometry import Point as sPoint
from paegan.cdm.dsg.member import Member
from paegan.cdm.dsg.features.station_profile import StationProfile
from paegan.cdm.dsg.features.base.point import Point
from paegan.cdm.dsg.features.base.profile import Profile
# -*- coding: utf-8 -*-



class StationProfileTest(unittest.TestCase):
    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)


# Path: paegan/cdm/dsg/member.py
# class Member(dict):
#     def __init__(self, *args, **kwargs):
#         super(Member, self).__init__(*args, **kwargs)
# 
# Path: paegan/cdm/dsg/features/station_profile.py
# class StationProfile(ProfileCollection):
#     """
#     A collection of Profiles at a single location.
# 
#     This mimics the Station class API, they should likely be merged somehow.
#     """
#     def __init__(self, **kwargs):
#         super(StationProfile, self).__init__(**kwargs)
# 
#         self._type       = "timeSeriesProfile"
#         self._properties = {}
#         self._location   = None
#         self.uid         = None
#         self.name        = None
#         self.description = None
# 
#     @property
#     def location(self):
#         return self._location
# 
#     @location.setter
#     def location(self, value):
#         self._location = value
# 
#         # Sets the location of every Profile in this station if it is not already set
#         for profile in self._elements:
#             if profile.location is None:
#                 profile.location == value
# 
#     def get_properties(self):
#         return self._properties
# 
#     def get_property(self, prop):
#         return self._properties.get(prop, None)
# 
#     def set_property(self, prop, value):
#         self._properties[prop] = value
# 
#     def get_unique_members(self):
#         all_members = [pt.members for prof in self._elements
#                                   for pt in prof._elements]
# 
#         keys = ["name", "description", "standard", "units"]
#         mwhat = []
#         for mg in all_members:
#             for m in mg:
#                 mwhat.append( { key: m[key] for key in keys if key in m } )
# 
#         # Now unique them on name
#         mwhat = { x['name']:x for x in mwhat }.values()
# 
#         return mwhat
# 
#     def calculate_bounds(self):
#         """
#             Calculate the time_range, depth_range, bbox, and size of this collection.
#             Will scan all data.
#             Ensures that .size, .bbox and .time_range return non-null.
# 
#             If the collection already knows its bbox; time_range; and/or size,
#             they are recomputed.
#         """
#         # tell all contained profiles to calculate their bounds
#         map(lambda x: x.calculate_bounds(), self._elements)
# 
#         # @TODO size is just number of timesteps?
#         self.size = len(self._elements)
# 
#         # bbox is just this point
#         self.bbox = MultiPoint([self.location, self.location]).envelope
# 
#         time_set = set()
#         map(time_set.add, AsaList.flatten([p.time for p in self._elements]))
#         self.time_range = sorted(list(time_set))
# 
#         depth_set = set()
#         map(depth_set.add, AsaList.flatten([p.depth_range for p in self._elements]))
#         self.depth_range = sorted(list(depth_set))
# 
# Path: paegan/cdm/dsg/features/base/profile.py
# class Profile(PointCollection):
#     """
#         A collection of points along a vertical (z) access
#         ie. A single profile from an ADCP or CTD
# 
#         A profile has a nominal lat/lon and time.
#         Actual time may be constant, or vary with z.
#         The z coordinates are monotonic, and may be increasing or decreasing.
#     """
#     def __init__(self, **kwargs):
#         super(Profile,self).__init__(**kwargs)
#         self._type = "Profile"
# 
#     def get_location(self):
#         return self._location
#     def set_location(self, location):
#         self._location = location
#     location = property(get_location, set_location)
# 
#     def get_time(self):
#         """
#             Nominal time of the profile.  This is usually the first time a reading was taken,
#             since a profile's time can be constant or vary with z.
#         """
#         return self._time
#     def set_time(self, time):
#         self._time = time
#     time = property(get_time, set_time)


# Path: tests/cdm/dsg/features/test_station_profile.py
import unittest
from datetime import datetime
from shapely.geometry import Point as sPoint
from paegan.cdm.dsg.member import Member
from paegan.cdm.dsg.features.station_profile import StationProfile
from paegan.cdm.dsg.features.base.point import Point
from paegan.cdm.dsg.features.base.profile import Profile

# -*- coding: utf-8 -*-



class StationProfileTest(unittest.TestCase):
    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')