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()
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()
#from omuse.ext.eddy_tracker.track_eddy import * #mean_ssh = get_interpolated_mean_ssh(lon, lat) #mean_ssh.tofile("pop_mean_ssh.dat") #print "pop_mean_ssh file written" #mean_ssh = numpy.fromfile("pop_mean_ssh.dat").reshape(dims) #sla = ssh - mean_ssh ##### 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())
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()