def test_configuration(shinnecock_mesh_directory): output_directory = OUTPUT_DIRECTORY / 'test_configuration' reference_directory = REFERENCE_DIRECTORY / 'test_configuration' if not output_directory.exists(): output_directory.mkdir(parents=True, exist_ok=True) mesh = AdcircMesh.open(shinnecock_mesh_directory / 'fort.14', crs=4326) spinup_time = timedelta(days=2) start_date = datetime(2015, 12, 14) + spinup_time end_date = start_date + timedelta(days=3) wind_forcing = AtmosphericMeshForcing( filename='Wind_HWRF_SANDY_Nov2018_ExtendedSmoothT.nc', nws=17, interval_seconds=3600, ) wave_forcing = WaveWatch3DataForcing( filename='ww3.HWRF.NOV2018.2012_sxy.nc', nrs=5, interval_seconds=3600, ) mesh.add_forcing(wind_forcing) mesh.add_forcing(wave_forcing) driver = AdcircRun(mesh, start_date, end_date, spinup_time,) driver.write(output_directory, overwrite=True, nproc=2) check_reference_directory( output_directory, reference_directory, skip_lines={'fort.15': [0]}, )
def driver(self): driver = AdcircRun(self.mesh, self.start_date, self.end_date, self.spinup_time, server_config=self.server_config) self._enable_outputs(driver) if self.args.timestep: driver.timestep = self.args.timestep driver.gwce_solution_scheme = self.args.gwce_solution_scheme return driver
def main(): if not FORT14.is_file(): url = 'https://www.dropbox.com/s/1wk91r67cacf132/NetCDF_shinnecock_inlet.tar.bz2?dl=1' g = urllib.request.urlopen(url) tmpfile = tempfile.NamedTemporaryFile() with open(tmpfile.name, 'b+w') as f: f.write(g.read()) with tarfile.open(tmpfile.name, "r:bz2") as tar: tar.extractall(PARENT / "data/NetCDF_Shinnecock_Inlet/") mesh = AdcircMesh.open(FORT14, crs=4326) tidal_forcing = Tides() tidal_forcing.use_all() wind_forcing = AtmosphericMeshForcing( filename='Wind_HWRF_SANDY_Nov2018_ExtendedSmoothT.nc', nws=17, interval_seconds=3600, ) wave_forcing = WaveWatch3DataForcing( filename='ww3.HWRF.NOV2018.2012_sxy.nc', nrs=5, interval_seconds=3600, ) mesh.add_forcing(tidal_forcing) mesh.add_forcing(wind_forcing) mesh.add_forcing(wave_forcing) slurm = SlurmConfig( account='account', ntasks=1000, run_name='AdcircPy/examples/example_3.py', partition='partition', walltime=timedelta(hours=8), mail_type='all', mail_user='******', log_filename='example_3.log', modules=['intel/2020', 'impi/2020', 'netcdf/4.7.2-parallel'], path_prefix='$HOME/adcirc/build') driver = AdcircRun( mesh=mesh, start_date=datetime.now(), end_date=timedelta(days=7), spinup_time=timedelta(days=5), server_config=slurm, ) driver.write(PARENT / "outputs/example_4", overwrite=True)
def test_slurm_driver(self): output_directory = OUTPUT_DIRECTORY / 'test_slurm_driver' reference_directory = REFERENCE_DIRECTORY / 'test_slurm_driver' output_directory.mkdir(parents=True, exist_ok=True) # open mesh file mesh = AdcircMesh.open(FORT14_FILENAME, crs=4326) # instantiate AdcircRun object. slurm = SlurmConfig( account='account', ntasks=1000, run_name='AdcircPy/examples/example_3.py', partition='partition', walltime=timedelta(hours=8), mail_type='all', mail_user='******', log_filename='example_3.log', modules=['intel/2020', 'impi/2020', 'netcdf/4.7.2-parallel'], path_prefix='$HOME/adcirc/build') driver = AdcircRun(mesh=mesh, start_date=datetime.now(), end_date=timedelta(days=7), spinup_time=timedelta(days=5), server_config=slurm) DriverFile(driver).write(output_directory / 'slurm.job', overwrite=True) with open(output_directory / 'slurm.job') as generated_file: with open(reference_directory / 'slurm.job') as reference_file: assert generated_file.read() == reference_file.read()
def test_slurm_driver(shinnecock_mesh_directory): output_directory = OUTPUT_DIRECTORY / 'test_slurm_driver' reference_directory = REFERENCE_DIRECTORY / 'test_slurm_driver' if not output_directory.exists(): output_directory.mkdir(parents=True, exist_ok=True) mesh = AdcircMesh.open(shinnecock_mesh_directory / 'fort.14', crs=4326) slurm = SlurmConfig( account='account', ntasks=1000, run_name='adcircpy/tests/test_configuration.py', partition='partition', walltime=timedelta(hours=8), mail_type='all', mail_user='******', log_filename='test_configuration.log', modules=['intel/2020', 'impi/2020', 'netcdf/4.7.2-parallel'], path_prefix='$HOME/adcirc/build', ) driver = AdcircRun( mesh=mesh, start_date=datetime.now(), end_date=timedelta(days=7), spinup_time=timedelta(days=5), server_config=slurm, ) DriverFile(driver).write(output_directory / 'slurm.job', overwrite=True) check_reference_directory(output_directory, reference_directory)
def test_configuration(self): output_directory = OUTPUT_DIRECTORY / 'test_configuration' reference_directory = REFERENCE_DIRECTORY / 'test_configuration' output_directory.mkdir(parents=True, exist_ok=True) # open mesh file mesh = AdcircMesh.open(FORT14_FILENAME, crs=4326) # set simulation dates spinup_time = timedelta(days=2) start_date = datetime(2015, 12, 14) + spinup_time end_date = start_date + timedelta(days=3) wind_forcing = AtmosphericMeshForcing( filename='Wind_HWRF_SANDY_Nov2018_ExtendedSmoothT.nc', nws=17, interval_seconds=3600, ) wave_forcing = WaveWatch3DataForcing( filename='ww3.HWRF.NOV2018.2012_sxy.nc', nrs=5, interval_seconds=3600, ) mesh.add_forcing(wind_forcing) mesh.add_forcing(wave_forcing) # instantiate AdcircRun object. driver = AdcircRun( mesh, start_date, end_date, spinup_time, ) driver.write(output_directory, overwrite=True) for reference_filename in reference_directory.iterdir(): generated_filename = output_directory / reference_filename.name with open(generated_filename) as generated_file, \ open(reference_filename) as reference_file: self.assertMultiLineEqual( ''.join(generated_file.readlines()[1:]), ''.join(reference_file.readlines()[1:]))
def main(): # fetch shinnecock inlet test data if not FORT14.is_file(): url = "https://www.dropbox.com/s/1wk91r67cacf132/" url += "NetCDF_shinnecock_inlet.tar.bz2?dl=1" g = urllib.request.urlopen(url) tmpfile = tempfile.NamedTemporaryFile() with open(tmpfile.name, 'b+w') as f: f.write(g.read()) with tarfile.open(tmpfile.name, "r:bz2") as tar: tar.extractall(PARENT / "data/NetCDF_Shinnecock_Inlet/") # open mesh file mesh = AdcircMesh.open(FORT14, crs=4326) # init tidal forcing and setup requests tidal_forcing = Tides() tidal_forcing.use_all() mesh.add_forcing(tidal_forcing) # Add wind forcing to model wind_forcing = BestTrackForcing('Sandy2012') mesh.add_forcing(wind_forcing) # instantiate AdcircRun object. slurm = SlurmConfig( account='account', ntasks=1000, run_name='AdcircPy/examples/example_3.py', partition='partition', walltime=timedelta(hours=8), mail_type='all', mail_user='******', log_filename='example_3.log', modules=['intel/2020', 'impi/2020', 'netcdf/4.7.2-parallel'], path_prefix='$HOME/adcirc/build') driver = AdcircRun(mesh, spinup_time=timedelta(days=15), server_config=slurm) # Write driver state to file. driver.write(PARENT / "outputs/example_3", overwrite=True)
def test_configuration(self): output_directory = OUTPUT_DIRECTORY / 'test_configuration' reference_directory = REFERENCE_DIRECTORY / 'test_configuration' output_directory.mkdir(parents=True, exist_ok=True) # open mesh file mesh = AdcircMesh.open(FORT14_FILENAME, crs=4326) # let's generate the tau0 factor mesh.generate_tau0() # let's also add a mannings to the domain (constant for this example) mesh.mannings_n_at_sea_floor = numpy.full(mesh.values.shape, 0.025) # set simulation dates spinup_time = timedelta(days=2) start_date = datetime(2015, 12, 14) + spinup_time end_date = start_date + timedelta(days=3) wind_forcing = AtmosphericMeshForcing(17, 3600) wave_forcing = WaveWatch3DataForcing(5, 3600) mesh.add_forcing(wind_forcing) mesh.add_forcing(wave_forcing) # instantiate AdcircRun object. driver = AdcircRun( mesh, start_date, end_date, spinup_time, ) driver.write(output_directory, overwrite=True) for reference_filename in reference_directory.iterdir(): generated_filename = output_directory / reference_filename.name with open(generated_filename) as generated_file, \ open(reference_filename) as reference_file: assert generated_file.readlines()[1:] == \ reference_file.readlines()[1:]
def main(): # fetch shinnecock inlet test data if not FORT14.is_file(): url = "https://www.dropbox.com/s/1wk91r67cacf132/" url += "NetCDF_shinnecock_inlet.tar.bz2?dl=1" g = urllib.request.urlopen(url) tmpfile = tempfile.NamedTemporaryFile() with open(tmpfile.name, 'b+w') as f: f.write(g.read()) with tarfile.open(tmpfile.name, "r:bz2") as tar: tar.extractall(PARENT / "data/NetCDF_Shinnecock_Inlet/") # open mesh file mesh = AdcircMesh.open(FORT14, crs=4326) # init tidal forcing and setup requests tidal_forcing = Tides() tidal_forcing.use_constituent('M2') tidal_forcing.use_constituent('N2') tidal_forcing.use_constituent('S2') tidal_forcing.use_constituent('K1') tidal_forcing.use_constituent('O1') mesh.add_forcing(tidal_forcing) # set simulation dates start_date = datetime(2015, 12, 14) end_date = start_date + timedelta(days=5) # instantiate AdcircRun object. driver = AdcircRun(mesh, start_date, end_date) # request outputs driver.set_elevation_surface_output(sampling_rate=timedelta(minutes=30)) driver.set_velocity_surface_output(sampling_rate=timedelta(minutes=30)) # override the AdcircPy defaults so that the fort.15 # matches the original Shinnecock test case options driver.timestep = 6. driver.DRAMP = 2. driver.smagorinsky = False driver.horizontal_mixing_coefficient = 5. driver.TOUTGE = 3.8 driver.TOUTGV = 3.8 # run parallel ADCIRC if binary is installed if shutil.which('padcirc') is not None: driver.run(PARENT / "outputs/example_1", overwrite=True) # run serial ADCIRC if binary is installed elif shutil.which('adcirc') is not None: driver.run(PARENT / "outputs/example_1", overwrite=True, nproc=1) # binaries are not installed, write to disk and exit else: msg = 'ADCIRC binaries were not found in PATH. ADCIRC will not run. ' msg += "Writing files to disk..." warnings.warn(msg) driver.write(PARENT / "outputs/example_1", overwrite=True)
# initialize tidal forcing and constituents tidal_forcing = Tides() tidal_forcing.use_constituent('M2') tidal_forcing.use_constituent('N2') tidal_forcing.use_constituent('S2') tidal_forcing.use_constituent('K1') tidal_forcing.use_constituent('O1') mesh.add_forcing(tidal_forcing) # set simulation dates duration = timedelta(days=5) start_date = datetime(2015, 12, 14) end_date = start_date + duration # instantiate driver object driver = AdcircRun(mesh, start_date, end_date) # request outputs driver.set_elevation_surface_output(sampling_rate=timedelta(minutes=30)) driver.set_velocity_surface_output(sampling_rate=timedelta(minutes=30)) # override default options so the resulting `fort.15` matches the original Shinnecock test case options driver.timestep = 6.0 driver.DRAMP = 2.0 driver.TOUTGE = 3.8 driver.TOUTGV = 3.8 driver.smagorinsky = False driver.horizontal_mixing_coefficient = 5.0 driver.gwce_solution_scheme = 'semi-implicit-legacy' if shutil.which('padcirc') is not None:
def test_import_stations(shinnecock_mesh_directory): input_directory = INPUT_DIRECTORY / 'test_import_stations' mesh = AdcircMesh.open(shinnecock_mesh_directory / 'fort.14', crs=4326) spinup_time = timedelta(days=2) start_date = datetime(2015, 12, 14) + spinup_time end_date = start_date + timedelta(days=3) driver_1 = AdcircRun(copy(mesh), start_date, end_date, spinup_time) driver_1.import_stations(input_directory / 'stations_1.txt') driver_2 = AdcircRun(copy(mesh), start_date, end_date, spinup_time) driver_2.import_stations(input_directory / 'stations_2.txt') driver_3 = AdcircRun(copy(mesh), start_date, end_date, spinup_time) driver_3.import_stations(input_directory / 'stations_3.txt') driver_4 = AdcircRun(copy(mesh), start_date, end_date, spinup_time) driver_4.import_stations( input_directory / 'stations_3.txt', station_types=['elevation', 'NSTAC', StationType.METEOROLOGICAL], ) assert driver_1.elevation_stations == {'8512769': (-72.5772, 40.823)} assert driver_1.velocity_stations == {} assert driver_1.concentration_stations == {} assert driver_1.meteorological_stations == {} assert driver_2.elevation_stations == {'8512769': (-72.5772, 40.823)} assert driver_2.velocity_stations == {'8512769': (-72.5772, 40.823)} assert driver_2.concentration_stations == {} assert driver_2.meteorological_stations == {} assert driver_3.elevation_stations == {'8512769': (-72.5772, 40.823)} assert driver_3.velocity_stations == {'8512769': (-72.5772, 40.823)} assert driver_3.concentration_stations == {} assert driver_3.meteorological_stations == {} assert driver_4.elevation_stations == {'8512769': (-72.5772, 40.823)} assert driver_4.velocity_stations == {} assert driver_4.concentration_stations == {'8512769': (-72.5772, 40.823)} assert driver_4.meteorological_stations == {}
# initialize Slurm configuration slurm = SlurmConfig( account='account', ntasks=1000, run_name='adcircpy/examples/example_3.py', partition='partition', walltime=timedelta(hours=8), mail_type='all', mail_user='******', log_filename='example_3.log', modules=['intel/2020', 'impi/2020', 'netcdf/4.7.2-parallel'], path_prefix='$HOME/adcirc/build', ) # set simulation dates spinup_time = timedelta(days=15) duration = timedelta(days=3) start_date = datetime(2012, 10, 21, 18) end_date = start_date + duration # instantiate driver object driver = AdcircRun(mesh, start_date, end_date, spinup_time, server_config=slurm) # write driver state to disk driver.write(OUTPUT_DIRECTORY, overwrite=True)
def main(): # fetch shinnecock inlet test data if not FORT14.is_file(): url = "https://www.dropbox.com/s/1wk91r67cacf132/" url += "NetCDF_shinnecock_inlet.tar.bz2?dl=1" g = urllib.request.urlopen(url) tmpfile = tempfile.NamedTemporaryFile() with open(tmpfile.name, 'b+w') as f: f.write(g.read()) with tarfile.open(tmpfile.name, "r:bz2") as tar: tar.extractall(PARENT / "data/NetCDF_Shinnecock_Inlet/") # open mesh file mesh = AdcircMesh.open(FORT14, crs=4326) # let's generate the tau0 factor mesh.generate_tau0() # let's also add a mannings to the domain (constant for this example) mesh.mannings_n_at_sea_floor = np.full(mesh.values.shape, 0.025) # init tidal forcing and setup requests tidal_forcing = Tides() tidal_forcing.use_constituent('M2') tidal_forcing.use_constituent('N2') tidal_forcing.use_constituent('S2') tidal_forcing.use_constituent('K1') tidal_forcing.use_constituent('O1') mesh.add_forcing(tidal_forcing) # set simulation dates spinup_time = timedelta(days=2) start_date = datetime(2015, 12, 14) + spinup_time end_date = start_date + timedelta(days=3) # instantiate AdcircRun object. driver = AdcircRun( mesh, start_date, end_date, spinup_time, ) # request outputs driver.set_elevation_surface_output(sampling_rate=timedelta(minutes=30)) driver.set_velocity_surface_output(sampling_rate=timedelta(minutes=30)) # override defaults options driver.timestep = 4.0 # run parallel ADCIRC if binary is installed if shutil.which('padcirc') is not None: driver.run(PARENT / "outputs/example_2", overwrite=True) # run serial ADCIRC if binary is installed elif shutil.which('adcirc') is not None: driver.run(PARENT / "outputs/example_2", overwrite=True, nproc=1) # binaries are not installed, write to disk and exit else: msg = 'ADCIRC binaries were not found in PATH. ADCIRC will not run. ' msg += "Writing files to disk..." warnings.warn(msg) driver.write(PARENT / "outputs/example_2", overwrite=True)
nrs=5, interval_seconds=3600, ) mesh.add_forcing(wave_forcing) # initialize Slurm configuration slurm = SlurmConfig( account='account', ntasks=1000, run_name='adcircpy/examples/example_4.py', partition='partition', walltime=timedelta(hours=8), mail_type='all', mail_user='******', log_filename='example_4.log', modules=['intel/2020', 'impi/2020', 'netcdf/4.7.2-parallel'], path_prefix='$HOME/adcirc/build', ) # instantiate driver object driver = AdcircRun( mesh=mesh, start_date=datetime.now(), end_date=timedelta(days=7), spinup_time=timedelta(days=5), server_config=slurm, ) # write driver state to disk driver.write(OUTPUT_DIRECTORY, overwrite=True)
tidal_forcing = Tides() tidal_forcing.use_constituent('M2') tidal_forcing.use_constituent('N2') tidal_forcing.use_constituent('S2') tidal_forcing.use_constituent('K1') tidal_forcing.use_constituent('O1') mesh.add_forcing(tidal_forcing) # set simulation dates spinup_time = timedelta(days=2) duration = timedelta(days=3) start_date = datetime(2015, 12, 14) + spinup_time end_date = start_date + duration # instantiate driver object driver = AdcircRun(mesh, start_date, end_date, spinup_time) # request outputs driver.set_elevation_surface_output(sampling_rate=timedelta(minutes=30)) driver.set_velocity_surface_output(sampling_rate=timedelta(minutes=30)) # override default options driver.timestep = 4.0 if shutil.which('padcirc') is not None: driver.run(OUTPUT_DIRECTORY, overwrite=True) elif shutil.which('adcirc') is not None: driver.run(OUTPUT_DIRECTORY, overwrite=True, nproc=1) else: logging.warning('ADCIRC binaries were not found in PATH. ' 'ADCIRC will not run. Writing files to disk...')
tidal_forcing.use_all() mesh.add_forcing(tidal_forcing) # initialize wind forcing wind_forcing = BestTrackForcing('Sandy2012') mesh.add_forcing(wind_forcing) # initialize Slurm configuration slurm = SlurmConfig( account='account', ntasks=1000, run_name='adcircpy/examples/example_3.py', partition='partition', walltime=timedelta(hours=8), mail_type='all', mail_user='******', log_filename='example_3.log', modules=['intel/2020', 'impi/2020', 'netcdf/4.7.2-parallel'], path_prefix='$HOME/adcirc/build', ) # instantiate driver object driver = AdcircRun( mesh, spinup_time=timedelta(days=15), server_config=slurm, ) # write driver state to disk driver.write(OUTPUT_DIRECTORY, overwrite=True)