def test(self): self.assertEqual(namelist([{'name': 'Bart'},{'name': 'Lisa'},{'name': 'Maggie'},{'name': 'Homer'},{'name': 'Marge'}]), 'Bart, Lisa, Maggie, Homer & Marge', "Must work with many names") self.assertEqual(namelist([{'name': 'Bart'},{'name': 'Lisa'},{'name': 'Maggie'}]), 'Bart, Lisa & Maggie', "Must work with many names") self.assertEqual(namelist([{'name': 'Bart'},{'name': 'Lisa'}]), 'Bart & Lisa', "Must work with two names") self.assertEqual(namelist([{'name': 'Bart'}]), 'Bart', "Wrong output for a single name") self.assertEqual(namelist([]), '', "Must work with no names")
def test_many_names(self): names = [{ 'name': 'Bart' }, { 'name': 'Lisa' }, { 'name': 'Maggie' }, { 'name': 'Homer' }, { 'name': 'Marge' }] self.assertEqual(namelist(names), 'Bart, Lisa, Maggie, Homer & Marge') names = [{'name': 'Bart'}, {'name': 'Lisa'}, {'name': 'Maggie'}] self.assertEqual(namelist(names), 'Bart, Lisa & Maggie')
def test_rand(self): def solist(names): return (lambda z: ", ".join(z[:-1])+" & "+z[-1] if len(z)>1 else "".join(z))((lambda y: [x['name'] for x in y])(names)) base=[{'name': 'Bart'},{'name': 'Lisa'},{'name': 'Maggie'},{'name': 'Homer'},{'name': 'Marge'},{'name': 'Moe'},{'name': 'Barney'},{'name': 'Maude'},{'name': 'Ned'},{'name': 'Seymour'}] for _ in range(40): shuffle(base) testmat=base[:randint(0,9)] solution=solist(testmat) self.assertEqual(namelist(deepcopy(testmat)),solution,"It should work for random tests too")
def test_3(self): result = namelist([{ "name": "Bart" }, { "name": "Lisa" }, { "name": "Maggie" }]) self.assertEqual(result, "Bart, Lisa & Maggie")
def setvertlevs(vfile, orog): txt = open(vfile).read() vertlevs = namelist.namelist(txt,1) # Only a single namelist, second elment is the dictionary vertlevs = vertlevs.next()[1] print "VERTLEVS", vertlevs eta_theta_levels = np.array(vertlevs['eta_theta']) # (0:model_levels) eta_rho_levels = np.array([-1e20] + vertlevs['eta_rho']) # (1:model_levels) z_top_of_model = vertlevs['z_top_of_model'] first_constant_r_rho_level = vertlevs['first_constant_r_rho_level'] print eta_rho_levels ashape = (len(eta_theta_levels),) + orog.shape print "ASHAPE", ashape r_theta_levels = np.zeros(ashape) r_rho_levels = np.zeros(ashape) r_ref_theta = eta_theta_levels * z_top_of_model r_ref_rho = eta_rho_levels * z_top_of_model # set bottom level, ie: orography r_theta_levels[0] = orog[:] # + Earth_radius # For constant levels set r to be a constant on the level if len(orog.shape) == 2: r_theta_levels[first_constant_r_rho_level:] = r_ref_theta[first_constant_r_rho_level:,np.newaxis,np.newaxis] r_rho_levels[first_constant_r_rho_level:] = r_ref_rho[first_constant_r_rho_level:,np.newaxis,np.newaxis] else: r_theta_levels[first_constant_r_rho_level:] = r_ref_theta[first_constant_r_rho_level:,np.newaxis] r_rho_levels[first_constant_r_rho_level:] = r_ref_rho[first_constant_r_rho_level:,np.newaxis] # Case( height_gen_smooth ) # A smooth quadratic height generation for k in range(1, first_constant_r_rho_level): r_rho_levels[k] = eta_rho_levels[k] * z_top_of_model + \ orog * (1.0 - eta_rho_levels[k]/eta_rho_levels[first_constant_r_rho_level])**2 r_theta_levels[k] = eta_theta_levels[k] * z_top_of_model + \ orog * (1.0 - eta_theta_levels[k]/eta_rho_levels[first_constant_r_rho_level])**2 return r_theta_levels, r_rho_levels
import multigrid as mgmpi #routines for the parallel multigrid pressure solver import explicit_schemes as expl #routines to calculate all the explicit tendendies in the Navier-Stokes equations from rk_tables import rk_coef #coefficients table for the explicit time scheme import output_fields as out #routines to deal with model output import namelist #read in the pre-edited namelist file (./namelist.py) from init_grid import init_grid #read in the grid information from init_emiss import get_emissions #read in the emission file (optionally) import coupling as cpl #routines for mesoscale coupling and lateral boundary conditions #MPI communicator mpicomm = MPI.COMM_WORLD nproc = mpicomm.Get_size() rank = mpicomm.Get_rank() #read namelist (default path is ./namelist) param_dict = namelist.namelist() if rank == 0: print "SIMULATION SETTINGS:" print "" for param in param_dict: print param + ': ' + str(param_dict[param]) print "" print "Simulation initializing..." npc = int(param_dict['npc']) npr = int(param_dict['npr']) ng = int(param_dict['n_ghost']) ng1 = ng - 1 if nproc != npc * npr:
def test_no_names(self): names = [] self.assertEqual(namelist(names), '')
def test_one_name(self): names = [{'name': 'Bart'}] self.assertEqual(namelist(names), 'Bart')
def test_two_names(self): names = [{'name': 'Bart'}, {'name': 'Lisa'}] self.assertEqual(namelist(names), 'Bart & Lisa')
try: if (sys.argv[1] == "-nc"): filetype = "netcdf" elif (sys.argv[1] == "-grib"): filetype = "grib" else: print "Not valid filetype, use -h or --help to get help" except IndexError: pass if filetype == "netcdf": print "nothing here yet" if filetype == "grib": data_path, fileprefix, filepostfix, startdate, enddate, timestep = namelist.namelist() m = Basemap(llcrnrlon=-15,llcrnrlat=45,urcrnrlon=30,urcrnrlat=68, resolution='i',projection='stere', lat_0=50,lon_0=6) dl = startdate indx = 0 locs = [] xlocs = [] ylocs = [] latlocs = [] lonlocs = []
def test_2(self): result = namelist([{"name": "Bart"}, {"name": "Lisa"}]) self.assertEqual(result, "Bart & Lisa")
def test_1(self): result = namelist([{"name": "Bart"}]) self.assertEqual(result, "Bart")