Example #1
0
    def __init__(self, **kwargs):

        if 'json' in kwargs or 'data' in kwargs:
            data = {}
            try:
                data = json.loads(kwargs['json'])
            except Exception:
                try:
                    data = kwargs.get('data')
                except Exception:
                    pass

            self.name = data.get('name', None)
            self.linear_a = data.get('linear_a', None)
            self.linear_b = data.get('linear_b', None)
            # duration is in days
            self.duration = data.get('duration', None)
            self.diel = [Diel(data=d) for d in data.get('diel')]
            self.taxis = [Taxis(data=t) for t in data.get('taxis')]
            self.capability = None
            if data.get('capability', None) is not None:
                self.capability = Capability(data=data.get('capability'))
            self.settlement = None
            if data.get('settlement', None) is not None:
                self.settlement = Settlement(data=data.get('settlement'))
Example #2
0
    def test_attempts(self):
        start_lat = 38
        start_lon = -76

        settle = Settlement(
            json='{"upper": 100.0, "lower": 200.0, "type": "benthic"}')
        # Particle above the upper bound
        particle = LarvaParticle()
        particle.location = Location4D(latitude=start_lat,
                                       longitude=start_lon,
                                       depth=-50,
                                       time=self.start_time)
        # Set bathymetry BETWEEN lower (200) and upper (100)
        settle.attempt(particle, -150)
        # We should have moved vertically to the bottom and settled
        assert particle.location.depth == -150
        assert particle.location.latitude == particle.locations[-2].latitude
        assert particle.location.longitude == particle.locations[-2].longitude
        assert particle.location.time == particle.locations[-2].time
        assert particle.settled

        settle = Settlement(
            json='{"upper": 100.0, "lower": 200.0, "type": "benthic"}')
        # Particle above the upper bound
        particle = LarvaParticle()
        particle.location = Location4D(latitude=start_lat,
                                       longitude=start_lon,
                                       depth=-250,
                                       time=self.start_time)
        # Set bathymetry BELOW lower (200) and upper (100)
        settle.attempt(particle, -400)
        # We should not have moved
        assert len(particle.locations) == 1
        assert not particle.settled

        settle = Settlement(
            json='{"upper": 100.0, "lower": 200.0, "type": "pelagic"}')
        # Particle above the upper bound
        particle = LarvaParticle()
        particle.location = Location4D(latitude=start_lat,
                                       longitude=start_lon,
                                       depth=-50,
                                       time=self.start_time)
        # Set bathymetry BELOW lower (200) and upper (100)
        settle.attempt(particle, -400)
        # We should not have moved
        assert len(particle.locations) == 1
        assert not particle.settled

        settle = Settlement(
            json='{"upper": 100.0, "lower": 200.0, "type": "pelagic"}')
        # Particle is between the upper and lower bounds
        particle = LarvaParticle()
        particle.location = Location4D(latitude=start_lat,
                                       longitude=start_lon,
                                       depth=-150,
                                       time=self.start_time)
        # Set bathymetry BELOW lower (200) and upper (100)
        settle.attempt(particle, -400)
        # We should have settled, but not moved anywhere
        assert len(particle.locations) == 1
        assert particle.settled
Example #3
0
    def test_from_dict(self):
        d = Settlement(data=json.loads(self.data))

        assert d.type == 'benthic'
        assert d.upper == -100.0
        assert d.lower == -200.0
Example #4
0
    def test_from_json(self):
        d = Settlement(json=self.data)

        assert d.type == 'benthic'
        assert d.upper == -100.0
        assert d.lower == -200.0
Example #5
0
    def test_attempts(self):
        start_lat = 38
        start_lon = -76

        settle = Settlement(json='{"upper": 100.0, "lower": 200.0, "type": "benthic"}')
        # Particle above the upper bound
        particle = LarvaParticle()
        particle.location = Location4D(latitude=start_lat, longitude=start_lon, depth=-50, time=self.start_time)
        # Set bathymetry BETWEEN lower (200) and upper (100)
        settle.attempt(particle, -150)
        # We should have moved vertically to the bottom and settled
        assert particle.location.depth == -150
        assert particle.location.latitude == particle.locations[-2].latitude
        assert particle.location.longitude == particle.locations[-2].longitude
        assert particle.location.time == particle.locations[-2].time
        assert particle.settled

        settle = Settlement(json='{"upper": 100.0, "lower": 200.0, "type": "benthic"}')
        # Particle above the upper bound
        particle = LarvaParticle()
        particle.location = Location4D(latitude=start_lat, longitude=start_lon, depth=-250, time=self.start_time)
        # Set bathymetry BELOW lower (200) and upper (100)
        settle.attempt(particle, -400)
        # We should not have moved
        assert len(particle.locations) == 1
        assert not particle.settled

        settle = Settlement(json='{"upper": 100.0, "lower": 200.0, "type": "pelagic"}')
        # Particle above the upper bound
        particle = LarvaParticle()
        particle.location = Location4D(latitude=start_lat, longitude=start_lon, depth=-50, time=self.start_time)
        # Set bathymetry BELOW lower (200) and upper (100)
        settle.attempt(particle, -400)
        # We should not have moved
        assert len(particle.locations) == 1
        assert not particle.settled

        settle = Settlement(json='{"upper": 100.0, "lower": 200.0, "type": "pelagic"}')
        # Particle is between the upper and lower bounds
        particle = LarvaParticle()
        particle.location = Location4D(latitude=start_lat, longitude=start_lon, depth=-150, time=self.start_time)
        # Set bathymetry BELOW lower (200) and upper (100)
        settle.attempt(particle, -400)
        # We should have settled, but not moved anywhere
        assert len(particle.locations) == 1
        assert particle.settled