Exemple #1
0
    def test9(self):
        p = POP(**default_options)

        shf = p.elements.shf

        print "SHF:"
        print shf
        shf_values = shf.value_in(units.W / units.m**2).flatten()
        print shf_values
        self.assertTrue(
            any(s != 0.0 for s in shf_values),
            msg="Expect at least one value to be not equal to zero")

        p.stop()
Exemple #2
0
    def test6(self):
        p = POP(**default_options)

        #check if we can write and again read what was written
        bogus3d = numpy.random.random(p.nodes3d.shape) | units.cm / units.s
        p.nodes3d.xvel = bogus3d
        xvel3d = p.nodes3d.xvel
        self.assertEquals(xvel3d, bogus3d)

        #check if we can write and again read what was written
        bogus3d = numpy.random.random(p.nodes3d.shape) | units.cm / units.s
        p.nodes3d.yvel = bogus3d
        yvel3d = p.nodes3d.yvel
        self.assertEquals(yvel3d, bogus3d)

        p.stop()
Exemple #3
0
    def test7(self):
        p = POP(**default_options)

        #test whether the getters for depth are working as expected
        dzt = p.elements3d.z
        dzu = p.nodes3d.z

        km = p.get_number_of_vertical_levels()

        for i in range(0, km - 1):
            self.assertTrue(
                dzu[5, 5, i] <= dzt[5, 5, i],
                msg='expect dzu to be equal to or smaller than dzt')
            self.assertTrue(dzt[5, 5, i] > (0.0 | units.cm),
                            msg='expect dzt to be larger than 0.0')

        p.stop()
Exemple #4
0
    def test8(self):
        p = POP(**default_options)

        #run for some time to ensure UVEL and VVEL contain something
        time = p.get_model_time()
        tend = time + (1.0 | units.day)
        p.evolve_model(tend)

        #test whether the getter for vertical velocity is working correctly
        xvel = p.nodes3d.xvel
        yvel = p.nodes3d.yvel
        zvel = p.nodes3d.zvel

        km = p.get_number_of_vertical_levels()
        size = p.get_domain_size()
        depth = p.nodes.depth.value_in(units.cm)

        #look for a non-land ocean cell with some depth
        for i in range(0, size[0] - 1):
            for j in range(0, size[1] - 1):
                if (depth[i, j] > 1000.0):
                    break

        print "Printing info for gridpoint " + str(i) + "," + str(
            j) + " with depth " + str(depth[i, j])
        #        i=1
        #        j=127

        print "XVEL:"
        print xvel[i, j, 0:km - 1]
        print "YVEL:"
        print yvel[i, j, 0:km - 1]
        print "ZVEL:"
        print zvel[i, j, 0:km - 1]

        self.assertTrue(
            any(zv != (0.0 | units.cm / units.s)
                for zv in zvel[i, j, 0:km - 1]),
            msg="Expect at least one value to be not equal to zero")

        p.stop()
Exemple #5
0
    def test5(self):
        p = POP(**default_options)

        temp3d = p.elements3d.temp.value_in(units.C)
        self.assertTrue(
            temp3d.all() < 50.,
            msg='Less than 50 degrees seems reasonable for temperature')
        self.assertTrue(
            temp3d.all() > -10.,
            msg='More than -10 degrees seems reasonable for temperature')

        salt3d = p.elements3d.salt.value_in(units.g / units.kg)

        self.assertTrue(
            salt3d.all() < 1.,
            msg=
            'Less than one gram of salt per kg of water seems reasonable for salinity'
        )
        self.assertTrue(salt3d.all() >= 0.,
                        msg='Salinity should be positive or 0')

        #check if we can write and again read what was written
        bogus3d = numpy.random.random(p.elements3d.shape) | units.C
        p.elements3d.temp = bogus3d
        temp3d = p.elements3d.temp
        self.assertEquals(temp3d, bogus3d)

        #check if we can write and again read what was written
        bogus3d = numpy.random.random(p.elements3d.shape) | units.g / units.kg
        p.elements3d.salt = bogus3d
        salt3d = p.elements3d.salt
        self.assertEquals(salt3d, bogus3d)

        #check if we can write and again read what was written
        bogus3d = numpy.random.random(
            p.elements3d.shape) | units.g / units.cm**3
        p.elements3d.rho = bogus3d
        rho3d = p.elements3d.rho
        self.assertEquals(rho3d, bogus3d)

        p.stop()
Exemple #6
0
    def test1(self):
        instance = POP(**default_options)

        self.assertEquals(instance.state_machine._current_state.name,
                          'UNINITIALIZED')

        #a read of a parameter requires the state to be either EDIT or RUN, which means we pass through INITIALIZED
        fcor = instance.forcings.coriolis_f

        #check if we are in the expected state
        self.assertEquals(instance.state_machine._current_state.name, 'RUN')

        #check if we read a sensible value
        print 'fcor[1,1] = ', fcor[1, 1]
        self.assertTrue(
            fcor[1, 1] != 0 | units.s**-1,
            msg='Expected coriolis force to be not equal to zero for node 1,1')

        #proceed to evolve
        time = instance.get_model_time()
        tend = time + instance.get_timestep_next()
        instance.evolve_model(tend)

        #check if we are in the expected state
        self.assertEquals(instance.state_machine._current_state.name,
                          'EVOLVED')

        #try to read something again, should cause a state transition to RUN
        fcor = instance.forcings.coriolis_f

        #check if we are in the expected state
        self.assertEquals(instance.state_machine._current_state.name, 'RUN')

        #check if we can write to coriolis_f
        instance.forcings.coriolis_f = fcor

        #check if we are in the expected state
        self.assertEquals(instance.state_machine._current_state.name, 'EDIT')

        instance.stop()



##### eddy tracking part

start_time = p.get_model_time()

from omuse.ext.eddy_tracker.interface import EddyTracker

days_between = 1
tracker = EddyTracker(grid=p.nodes, domain='Regional',
     lonmin=0., lonmax=50., latmin=-45., latmax=-20., days_between=days_between)
tracker.find_eddies(p.nodes.ssh, rtime=start_time)

tend = p.get_model_time() + (1.0 | units.day)
stop_time = start_time + (60.0 | units.day)

while (tend < stop_time):
    p.evolve_model(tend)

    tracker.find_eddies(ssh=p.nodes.ssh, rtime=p.get_model_time())
    tracker.plot_eddies(rtime=tend)
    tend = p.get_model_time() + (days_between | units.day)

#stop tracking, ensure output is written
tracker.stop(tend)
p.stop()

print "online eddy tracking successfully completed!"
Exemple #8
0
    def test2(self):
        instance = POP(**default_options)

        #proceed to evolve
        #time = instance.get_model_time()
        #tend = time + (1 | units.day)
        #instance.evolve_model(tend)

        #extract the tau_x and tau_y from POP
        tau_x = instance.forcings.tau_x
        tau_y = instance.forcings.tau_y

        print 'tau_x='
        print tau_x[range(1, 5), 1]
        #        print tau_x
        print 'tau_y='
        print tau_y[range(1, 5), 1]
        #        print tau_y

        #check if tau_x and tau_y are not only zeroes, this also fails for things like NaN and Inf
        self.assertTrue(numpy.sum(numpy.abs(tau_x)) > (0.0 | units.Pa),
                        msg='Expected tau_x to contain some actual values')
        self.assertTrue(numpy.sum(numpy.abs(tau_y)) > (0.0 | units.Pa),
                        msg='Expected tau_x to contain some actual values')

        #check to see if we can set and retrieve the same wind stress
        size = instance.get_domain_size()
        tau_x = numpy.random.random(size) | units.Pa
        tau_y = numpy.random.random(size) | units.Pa

        #cannot write to forcings directly unfortunately
        #instance.forcings.tau_x = tau_x
        #instance.forcings.tau_y = tau_y
        forcings = instance.forcings.empty_copy()
        forcings.tau_x = tau_x
        forcings.tau_y = tau_y
        forcings.new_channel_to(instance.forcings).copy_attributes(
            ["tau_x", "tau_y"])

        self.assertEquals(instance.state_machine._current_state.name,
                          'EDIT_FORCINGS')

        #now retrieve the wind stress from the model
        tau_x_returned = instance.forcings.tau_x
        tau_y_returned = instance.forcings.tau_y

        self.assertEquals(instance.state_machine._current_state.name, 'RUN')

        #almost equals
        self.assertAlmostRelativeEqual(tau_x, tau_x_returned, places=10)
        self.assertAlmostRelativeEqual(tau_y, tau_y_returned, places=10)

        #check to see if the forcings we have set are not overwritten by internal routines,
        #evolve the model
        time = instance.get_model_time()
        tend = time + instance.get_timestep_next()
        instance.evolve_model(tend)

        #check if wind stress is still the same
        tau_x_returned = instance.forcings.tau_x
        tau_y_returned = instance.forcings.tau_y
        self.assertAlmostRelativeEqual(tau_x, tau_x_returned, places=10)
        self.assertAlmostRelativeEqual(tau_y, tau_y_returned, places=10)

        instance.stop()