def run(self): """ Run this step of the test case """ config = self.config logger = self.logger section = config['gotm'] nx = section.getint('nx') ny = section.getint('ny') dc = section.getfloat('dc') dsMesh = make_planar_hex_mesh(nx=nx, ny=ny, dc=dc, nonperiodic_x=False, nonperiodic_y=False) write_netcdf(dsMesh, 'grid.nc') dsMesh = cull(dsMesh, logger=logger) dsMesh = convert(dsMesh, graphInfoFileName='graph.info', logger=logger) write_netcdf(dsMesh, 'mesh.nc') replacements = dict() replacements['config_periodic_planar_vert_levels'] = \ config.get('gotm', 'vert_levels') replacements['config_periodic_planar_bottom_depth'] = \ config.get('gotm', 'bottom_depth') self.update_namelist_at_runtime(options=replacements) run_model(self)
def run(self): """ Run this step of the test case """ for suffix in self.suffixes: run_model(step=self, namelist='namelist.{}'.format(suffix), streams='streams.{}'.format(suffix))
def run(self): """ Run this step of the testcase """ run_model(self) add_mesh_and_init_metadata(self.outputs, self.config, init_filename='init.nc')
def run(self): """ Run this step of the test case """ if self.restart_filename is not None: self._update_surface_air_temperature() run_model(self)
def run(self): """ Run this step of the test case """ make_graph_file(mesh_filename=self.mesh_file, graph_filename='graph.info') for suffix in self.suffixes: run_model(step=self, namelist='namelist.{}'.format(suffix), streams='streams.{}'.format(suffix))
def run(self): """ Run this step of the test case """ _setup_eismint2_initial_conditions(self.logger, self.experiment, filename='initial_condition.nc') for suffix in self.suffixes: run_model(self, namelist='namelist.{}'.format(suffix), streams='streams.{}'.format(suffix))
def run(self): """ Run this step of the test case """ run_model(self) if self.name == 'performance': # plot a few fields plot_folder = '{}/plots'.format(self.work_dir) if os.path.exists(plot_folder): shutil.rmtree(plot_folder) dsMesh = xarray.open_dataset(os.path.join(self.work_dir, 'init.nc')) ds = xarray.open_dataset(os.path.join(self.work_dir, 'output.nc')) section_y = self.config.getfloat('isomip_plus_viz', 'section_y') # show progress only if we're not writing to a log file show_progress = self.log_filename is None plotter = MoviePlotter(inFolder=self.work_dir, streamfunctionFolder=self.work_dir, outFolder=plot_folder, sectionY=section_y, dsMesh=dsMesh, ds=ds, expt=self.experiment, showProgress=show_progress) plotter.plot_3d_field_top_bot_section(ds.temperature, nameInTitle='temperature', prefix='temp', units='C', vmin=-2., vmax=1., cmap='cmo.thermal') plotter.plot_3d_field_top_bot_section(ds.salinity, nameInTitle='salinity', prefix='salin', units='PSU', vmin=33.8, vmax=34.7, cmap='cmo.haline') if self.name == 'simulation': update_evaporation_flux(in_forcing_file='forcing_data_init.nc', out_forcing_file='forcing_data_updated.nc', out_forcing_link='forcing_data.nc') replacements = { 'config_do_restart': '.true.', 'config_start_time': "'file'" } self.update_namelist_at_runtime(replacements)
def run(self): """ Run this step of the test case """ cores = self.cores partition(cores, self.config, self.logger) particles.write(init_filename='init.nc', particle_filename='particles.nc', graph_filename='graph.info.part.{}'.format(cores), types='buoyancy') run_model(self, partition_graph=False)
def run(self): """ Run this step of the testcase """ config = self.config dt = self.get_timestep_str() self.update_namelist_at_runtime( options={ 'config_dt': dt, 'config_time_integrator': config.get( 'nondivergent_2d', 'time_integrator')}, out_name='namelist.ocean') run_model(self)
def run(self): """ Run this step of the testcase """ namelist_options, stream_replacements = self.get_dt_duration() self.update_namelist_at_runtime( options=namelist_options, out_name='namelist.ocean') self.update_streams_at_runtime( 'compass.ocean.tests.planar_convergence', 'streams.template', template_replacements=stream_replacements, out_name='streams.ocean') run_model(self)
def run(self): """ Run this step of the testcase """ config = self.config interfaces = generate_1d_grid(config=config) write_1d_grid(interfaces=interfaces, out_filename='vertical_grid.nc') plot_vertical_grid(grid_filename='vertical_grid.nc', config=config, out_filename='vertical_grid.png') run_model(self) add_mesh_and_init_metadata(self.outputs, config, init_filename='initial_state.nc') plot_initial_state(input_file_name='initial_state.nc', output_file_name='initial_state.png')
def run(self): """ Run this step of the test case """ cores = self.cores partition(cores, self.config, self.logger) if self.with_particles: section = self.config['soma'] min_den = section.getfloat('min_particle_density') max_den = section.getfloat('max_particle_density') nsurf = section.getint('surface_count') build_particle_simple( f_grid='mesh.nc', f_name='particles.nc', f_decomp='graph.info.part.{}'.format(cores), buoySurf=np.linspace(min_den, max_den, nsurf)) run_model(self, partition_graph=False)
def run(self): """ Run this step of the test case """ config = self.config section = config['soma'] options = dict( config_eos_linear_alpha=section.get('eos_linear_alpha'), config_soma_density_difference=section.get('density_difference'), config_soma_surface_temperature=section.get('surface_temperature'), config_soma_surface_salinity=section.get('surface_salinity'), config_soma_salinity_gradient=section.get('salinity_gradient'), config_soma_thermocline_depth=section.get('thermocline_depth'), config_soma_density_difference_linear=section.get( 'density_difference_linear'), config_soma_phi=section.get('phi'), config_soma_shelf_depth=section.get('shelf_depth'), config_soma_bottom_depth=section.get('bottom_depth')) for out_name in ['namelist_mark_land.ocean', 'namelist.ocean']: self.update_namelist_at_runtime(options=options, out_name=out_name) ds_mesh = convert(xarray.open_dataset('base_mesh.nc'), graphInfoFileName='base_graph.info', logger=self.logger) write_netcdf(ds_mesh, 'mesh.nc') run_model(self, namelist='namelist_mark_land.ocean', streams='streams_mark_land.ocean', graph_file='base_graph.info') ds_mesh = cull(xarray.open_dataset('masked_initial_state.nc'), graphInfoFileName='graph.info', logger=self.logger) write_netcdf(ds_mesh, 'culled_mesh.nc') run_model(self, namelist='namelist.ocean', streams='streams.ocean', graph_file='graph.info')
def run(self): """ Run this step of the test case """ run_model(self)
def adjust_ssh(variable, iteration_count, step): """ Adjust the sea surface height or land-ice pressure to be dynamically consistent with one another. A series of short model runs are performed, each with Parameters ---------- variable : {'ssh', 'landIcePressure'} The variable to adjust iteration_count : int The number of iterations of adjustment step : compass.Step the step for performing SSH or land-ice pressure adjustment """ cores = step.cores config = step.config logger = step.logger out_filename = None if variable not in ['ssh', 'landIcePressure']: raise ValueError("Unknown variable to modify: {}".format(variable)) step.update_namelist_pio('namelist.ocean') partition(cores, config, logger) for iterIndex in range(iteration_count): logger.info(" * Iteration {}/{}".format(iterIndex + 1, iteration_count)) in_filename = 'adjusting_init{}.nc'.format(iterIndex) out_filename = 'adjusting_init{}.nc'.format(iterIndex + 1) symlink(in_filename, 'adjusting_init.nc') logger.info(" * Running forward model") run_model(step, update_pio=False, partition_graph=False) logger.info(" - Complete") logger.info(" * Updating SSH or land-ice pressure") with xarray.open_dataset(in_filename) as ds: # keep the data set with Time for output ds_out = ds ds = ds.isel(Time=0) on_a_sphere = ds.attrs['on_a_sphere'].lower() == 'yes' initSSH = ds.ssh if 'minLevelCell' in ds: minLevelCell = ds.minLevelCell - 1 else: minLevelCell = xarray.zeros_like(ds.maxLevelCell) with xarray.open_dataset('output_ssh.nc') as ds_ssh: # get the last time entry ds_ssh = ds_ssh.isel(Time=ds_ssh.sizes['Time'] - 1) finalSSH = ds_ssh.ssh topDensity = ds_ssh.density.isel(nVertLevels=minLevelCell) mask = numpy.logical_and(ds.maxLevelCell > 0, ds.modifyLandIcePressureMask == 1) deltaSSH = mask * (finalSSH - initSSH) # then, modify the SSH or land-ice pressure if variable == 'ssh': ssh = finalSSH.expand_dims(dim='Time', axis=0) ds_out['ssh'] = ssh # also update the landIceDraft variable, which will be used to # compensate for the SSH due to land-ice pressure when # computing sea-surface tilt ds_out['landIceDraft'] = ssh # we also need to stretch layerThickness to be compatible with # the new SSH stretch = ((finalSSH + ds.bottomDepth) / (initSSH + ds.bottomDepth)) ds_out['layerThickness'] = ds_out.layerThickness * stretch landIcePressure = ds.landIcePressure.values else: # Moving the SSH up or down by deltaSSH would change the # land-ice pressure by density(SSH)*g*deltaSSH. If deltaSSH is # positive (moving up), it means the land-ice pressure is too # small and if deltaSSH is negative (moving down), it means # land-ice pressure is too large, the sign of the second term # makes sense. gravity = constants['SHR_CONST_G'] deltaLandIcePressure = topDensity * gravity * deltaSSH landIcePressure = numpy.maximum( 0.0, ds.landIcePressure + deltaLandIcePressure) ds_out['landIcePressure'] = \ landIcePressure.expand_dims(dim='Time', axis=0) finalSSH = initSSH write_netcdf(ds_out, out_filename) # Write the largest change in SSH and its lon/lat to a file with open('maxDeltaSSH_{:03d}.log'.format(iterIndex), 'w') as \ log_file: mask = landIcePressure > 0. iCell = numpy.abs(deltaSSH.where(mask)).argmax().values ds_cell = ds.isel(nCells=iCell) if on_a_sphere: coords = 'lon/lat: {:f} {:f}'.format( numpy.rad2deg(ds_cell.lonCell.values), numpy.rad2deg(ds_cell.latCell.values)) else: coords = 'x/y: {:f} {:f}'.format( 1e-3 * ds_cell.xCell.values, 1e-3 * ds_cell.yCell.values) string = 'deltaSSHMax: {:g}, {}'.format( deltaSSH.isel(nCells=iCell).values, coords) logger.info(' {}'.format(string)) log_file.write('{}\n'.format(string)) string = 'ssh: {:g}, landIcePressure: {:g}'.format( finalSSH.isel(nCells=iCell).values, landIcePressure.isel(nCells=iCell).values) logger.info(' {}'.format(string)) log_file.write('{}\n'.format(string)) logger.info(" - Complete\n") if out_filename is not None: shutil.copy(out_filename, 'adjusted_init.nc')