From 8bd73faf4986f1e60b7c226d9c588e3a03414283 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Thu, 9 May 2024 17:18:53 -0400 Subject: [PATCH 01/39] Add support for PyTest This is an initial go at converting from nose to pytest. There are a few issues that were also fixed so that the tests could run to completion that were from some older files that were not being run. Note that the regression tests are not passing barely right now probably due to a slight change to the code in the intervening time since the tests were working. --- src/python/geoclaw/surge/storm.py | 22 ++++--- src/python/geoclaw/test.py | 3 + src/python/geoclaw/util.py | 2 +- tests/bowl_slosh/__init__.py | 0 tests/bowl_slosh/setrun.py | 2 - ...regression_tests.py => test_bowl_slosh.py} | 0 tests/chile2010_adjoint/__init__.py | 0 tests/chile2010_adjoint/adjoint/setrun.py | 9 --- tests/chile2010_adjoint/setrun.py | 8 --- ...ion_tests.py => test_chile2010_adjoint.py} | 9 --- tests/dtopo1/__init__.py | 0 tests/dtopo1/setrun.py | 8 --- .../{regression_tests.py => test_dtopo.py} | 0 tests/multilayer/__init__.py | 0 tests/multilayer/setrun.py | 4 +- ...regression_tests.py => test_multilayer.py} | 0 tests/netcdf_topo/Makefile | 6 +- tests/netcdf_topo/__init__.py | 0 tests/netcdf_topo/setrun.py | 10 +-- .../{regression_tests.py => test_netcdf.py} | 24 +++---- tests/old_topotools.py | 2 - tests/particles/setrun.py | 5 -- ...{regression_tests.py => test_particles.py} | 0 tests/storm_surge/__init__.py | 0 tests/storm_surge/setrun.py | 12 +--- .../{regression_tests.py => test_ike.py} | 61 ++++------------- tests/test_dtopotools.py | 28 ++++---- tests/test_etopo1.py | 23 +++---- tests/test_storm.py | 19 ++---- tests/test_topotools.py | 65 ++++++++----------- tests/test_util.py | 62 +++++++++--------- 31 files changed, 132 insertions(+), 252 deletions(-) delete mode 100644 tests/bowl_slosh/__init__.py rename tests/bowl_slosh/{regression_tests.py => test_bowl_slosh.py} (100%) delete mode 100644 tests/chile2010_adjoint/__init__.py rename tests/chile2010_adjoint/{regression_tests.py => test_chile2010_adjoint.py} (84%) delete mode 100644 tests/dtopo1/__init__.py rename tests/dtopo1/{regression_tests.py => test_dtopo.py} (100%) delete mode 100644 tests/multilayer/__init__.py rename tests/multilayer/{regression_tests.py => test_multilayer.py} (100%) delete mode 100644 tests/netcdf_topo/__init__.py rename tests/netcdf_topo/{regression_tests.py => test_netcdf.py} (92%) rename tests/particles/{regression_tests.py => test_particles.py} (100%) delete mode 100644 tests/storm_surge/__init__.py rename tests/storm_surge/{regression_tests.py => test_ike.py} (56%) diff --git a/src/python/geoclaw/surge/storm.py b/src/python/geoclaw/surge/storm.py index 6e48eacc8..077cc8a65 100644 --- a/src/python/geoclaw/surge/storm.py +++ b/src/python/geoclaw/surge/storm.py @@ -101,17 +101,17 @@ # Warning for formats that have yet to have a default way to determine crticial # radii from the input data -missing_data_warning_str = """*** Cannot yet automatically determine the - maximum wind radius. Will write out GeoClaw - formats but note that these will not work - when running GeoClaw currently without a custom - `max_wind_radius_fill` function passed as argument - to the `write` function.""" +missing_data_warning_str = ("Cannot yet automatically determine the" + + "maximum wind radius. Will write out GeoClaw" + + "formats but note that these will not work" + + "when running GeoClaw currently without a custom" + + "`max_wind_radius_fill` function passed as " + + "argument to the `write` function.") # Warning for not having any time points with both a max wind speed and central # pressure observation -missing_necessary_data_warning_str = """No storm points in the input file - had both a max wind speed and a central pressure observation.""" +missing_necessary_data_warning_str = ("No storm points in the input file" + + "had both a max wind speed and a central pressure observation.") class NoDataError(ValueError): """Exception to raise when no valid data in input file""" @@ -400,6 +400,9 @@ def read_atcf(self, path, verbose=False): warnings.warn('Some timesteps have missing central pressure. These will not be written' ' out to geoclaw format.') + # Set time offset to first time as a default + self.time_offset = self.t[0] + def read_hurdat(self, path, verbose=False): r"""Read in HURDAT formatted storm file @@ -663,6 +666,7 @@ def map_val_to_ix(a): # convert datetime64 to datetime.datetime self.t = [] for d in ds.time: + print(d) t = d.dt self.t.append(datetime.datetime(t.year,t.month,t.day,t.hour,t.minute,t.second)) @@ -901,7 +905,7 @@ def write_geoclaw(self, path, verbose=False, max_wind_radius_fill=None, num_casts = 0 data_string = [""] if self.time_offset is None: - data_string.append("None") + data_string.append("None\n\n") self.time_offset = self.t[0] else: data_string.append("%s\n\n" % self.time_offset.isoformat()) diff --git a/src/python/geoclaw/test.py b/src/python/geoclaw/test.py index c3685e973..c6700deda 100644 --- a/src/python/geoclaw/test.py +++ b/src/python/geoclaw/test.py @@ -30,6 +30,9 @@ for path in glob.glob(os.path.join(lib_path,"*.mod")): os.remove(path) +# Scratch directory for GeoClaw +scratch_path = os.path.abspath(os.path.join(CLAW, 'scratch')) + class GeoClawRegressionTest(clawpack.clawutil.test.ClawpackRegressionTest): diff --git a/src/python/geoclaw/util.py b/src/python/geoclaw/util.py index 816043f05..c9be0c0de 100644 --- a/src/python/geoclaw/util.py +++ b/src/python/geoclaw/util.py @@ -197,7 +197,7 @@ def bearing(x0, y0, x1, y1, units='degrees', bearing_units='degrees'): return beta def gctransect(x1,y1,x2,y2,npts,coords='W',units='degrees',Rearth=Rearth): - """ + r""" Given (longitude,latitude) pairs (x1,y1), (x2,y2) and npts Compute (x,y) for npts equally spaced points on the great circle connecting them. diff --git a/tests/bowl_slosh/__init__.py b/tests/bowl_slosh/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/bowl_slosh/setrun.py b/tests/bowl_slosh/setrun.py index 1d2120913..1f9288b33 100644 --- a/tests/bowl_slosh/setrun.py +++ b/tests/bowl_slosh/setrun.py @@ -360,8 +360,6 @@ def setgeo(rundata): # Refinement data refinement_data = rundata.refinement_data refinement_data.wave_tolerance = 1.e-2 - refinement_data.deep_depth = 1e2 - refinement_data.max_level_deep = 3 refinement_data.variable_dt_refinement_ratios = True # == settopo.data values == diff --git a/tests/bowl_slosh/regression_tests.py b/tests/bowl_slosh/test_bowl_slosh.py similarity index 100% rename from tests/bowl_slosh/regression_tests.py rename to tests/bowl_slosh/test_bowl_slosh.py diff --git a/tests/chile2010_adjoint/__init__.py b/tests/chile2010_adjoint/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/chile2010_adjoint/adjoint/setrun.py b/tests/chile2010_adjoint/adjoint/setrun.py index 950182709..05286d667 100644 --- a/tests/chile2010_adjoint/adjoint/setrun.py +++ b/tests/chile2010_adjoint/adjoint/setrun.py @@ -382,8 +382,6 @@ def setgeo(rundata): refinement_data = rundata.refinement_data refinement_data.variable_dt_refinement_ratios = True refinement_data.wave_tolerance = 1.e-1 - refinement_data.deep_depth = 1e2 - refinement_data.max_level_deep = 3 # == settopo.data values == topo_data = rundata.topo_data @@ -405,13 +403,6 @@ def setgeo(rundata): # [fname] rundata.qinit_data.qinitfiles.append(['hump.xyz']) - - # == setfixedgrids.data values == - fixed_grids = rundata.fixed_grid_data - # for fixed grids append lines of the form - # [t1,t2,noutput,x1,x2,y1,y2,xpoints,ypoints,\ - # ioutarrivaltimes,ioutsurfacemax] - return rundata # end of function setgeo # ---------------------- diff --git a/tests/chile2010_adjoint/setrun.py b/tests/chile2010_adjoint/setrun.py index e4d246c90..c63bcdda6 100644 --- a/tests/chile2010_adjoint/setrun.py +++ b/tests/chile2010_adjoint/setrun.py @@ -430,8 +430,6 @@ def setgeo(rundata): refinement_data = rundata.refinement_data refinement_data.variable_dt_refinement_ratios = True refinement_data.wave_tolerance = 1.e-1 # not used for adjoint flagging - refinement_data.deep_depth = 1e2 - refinement_data.max_level_deep = 3 # == settopo.data values == topo_data = rundata.topo_data @@ -455,12 +453,6 @@ def setgeo(rundata): # for qinit perturbations, append lines of the form: (<= 1 allowed for now!) # [minlev, maxlev, fname] - # == setfixedgrids.data values == - fixed_grids = rundata.fixed_grid_data - # for fixed grids append lines of the form - # [t1,t2,noutput,x1,x2,y1,y2,xpoints,ypoints,\ - # ioutarrivaltimes,ioutsurfacemax] - return rundata # end of function setgeo # ---------------------- diff --git a/tests/chile2010_adjoint/regression_tests.py b/tests/chile2010_adjoint/test_chile2010_adjoint.py similarity index 84% rename from tests/chile2010_adjoint/regression_tests.py rename to tests/chile2010_adjoint/test_chile2010_adjoint.py index 934c03466..3b6a980d7 100644 --- a/tests/chile2010_adjoint/regression_tests.py +++ b/tests/chile2010_adjoint/test_chile2010_adjoint.py @@ -16,8 +16,6 @@ import clawpack.geoclaw.test as test import clawpack.geoclaw.topotools as topotools -from clawpack.clawutil.test import wip - try: CLAW = os.environ['CLAW'] @@ -49,23 +47,16 @@ def setUp(self): # run adjoint code os.chdir(temp_adjoint_path) - #print('+++ Running adjoint in directory ',os.getcwd()) - #print('+++ contents: ', os.listdir('.')) os.system('make -s topo') os.system('make -s data') os.system('make -s new') os.system('make .output > output.txt') - #print('+++ contents of _output: ', os.listdir('_output')) # set up forward code shutil.copy(os.path.join(self.test_path, "maketopo.py"), self.temp_path) os.chdir(self.temp_path) - #print('+++ Running forward in directory ',os.getcwd()) - #print('+++ contents: ', os.listdir()) os.system('python maketopo.py') - #print('+++ scratch directory: ', scratch_dir) - #print('+++ contents of scratch: ', os.listdir(scratch_dir)) os.chdir(start_dir) diff --git a/tests/dtopo1/__init__.py b/tests/dtopo1/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/dtopo1/setrun.py b/tests/dtopo1/setrun.py index 906af6574..0cbc8491c 100644 --- a/tests/dtopo1/setrun.py +++ b/tests/dtopo1/setrun.py @@ -375,8 +375,6 @@ def setgeo(rundata): # Refinement data refinement_data = rundata.refinement_data refinement_data.wave_tolerance = 1.e-2 - refinement_data.deep_depth = 1e2 - refinement_data.max_level_deep = 3 refinement_data.variable_dt_refinement_ratios = True # == settopo.data values == @@ -401,12 +399,6 @@ def setgeo(rundata): # for qinit perturbations, append lines of the form: (<= 1 allowed for now!) # [fname] - # == setfixedgrids.data values == - fixedgrids = rundata.fixed_grid_data - # for fixed grids append lines of the form - # [t1,t2,noutput,x1,x2,y1,y2,xpoints,ypoints,\ - # ioutarrivaltimes,ioutsurfacemax] - return rundata # end of function setgeo # ---------------------- diff --git a/tests/dtopo1/regression_tests.py b/tests/dtopo1/test_dtopo.py similarity index 100% rename from tests/dtopo1/regression_tests.py rename to tests/dtopo1/test_dtopo.py diff --git a/tests/multilayer/__init__.py b/tests/multilayer/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/multilayer/setrun.py b/tests/multilayer/setrun.py index 472cf02d8..226a506d8 100644 --- a/tests/multilayer/setrun.py +++ b/tests/multilayer/setrun.py @@ -448,14 +448,12 @@ def setgeo(rundata): refinement_data = rundata.refinement_data refinement_data.variable_dt_refinement_ratios = True refinement_data.wave_tolerance = 1.e-1 - refinement_data.deep_depth = 1e2 - refinement_data.max_level_deep = 3 # == settopo.data values == topo_data = rundata.topo_data # for topography, append lines of the form # [topotype, minlevel, maxlevel, t1, t2, fname] - topo_data.topofiles.append([2, 1, 5, 0.0, 1e10, 'jump_topo.topotype2']) + topo_data.topofiles.append([2, 'jump_topo.topotype2']) # == setdtopo.data values == dtopo_data = rundata.dtopo_data diff --git a/tests/multilayer/regression_tests.py b/tests/multilayer/test_multilayer.py similarity index 100% rename from tests/multilayer/regression_tests.py rename to tests/multilayer/test_multilayer.py diff --git a/tests/netcdf_topo/Makefile b/tests/netcdf_topo/Makefile index 11cccb22f..c06dfd918 100644 --- a/tests/netcdf_topo/Makefile +++ b/tests/netcdf_topo/Makefile @@ -23,8 +23,8 @@ RESTART = False # Environment variable FC should be set to fortran compiler, e.g. gfortran # Compiler flags can be specified here or set as an environment variable -FFLAGS += -DNETCDF -lnetcdf -I$(NETCDF4_DIR)/include -L$(NETCDF4_DIR)/lib -LFLAGS += $(FFLAGS) -lnetcdff +FFLAGS += -DNETCDF $(shell nf-config --fflags) +LFLAGS += $(FFLAGS) -L$(shell nc-config --libdir) $(shell nf-config --flibs) # --------------------------------- @@ -66,4 +66,4 @@ include $(CLAWMAKE) .PHONY: netcdf_test netcdf_test: netcdf_test.f90 - $(FC) netcdf_test.f90 $(FFLAGS) $(LFLAGS) -o netcdf_test \ No newline at end of file + $(shell nf-config --fc) netcdf_test.f90 $(FFLAGS) $(LFLAGS) -o netcdf_test \ No newline at end of file diff --git a/tests/netcdf_topo/__init__.py b/tests/netcdf_topo/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/netcdf_topo/setrun.py b/tests/netcdf_topo/setrun.py index 88a1d8b93..adb08e904 100644 --- a/tests/netcdf_topo/setrun.py +++ b/tests/netcdf_topo/setrun.py @@ -357,15 +357,13 @@ def setgeo(rundata): # Refinement data refinement_data = rundata.refinement_data refinement_data.wave_tolerance = 1.e-2 - refinement_data.deep_depth = 1e2 - refinement_data.max_level_deep = 3 refinement_data.variable_dt_refinement_ratios = True # == settopo.data values == topo_data = rundata.topo_data # for topography, append lines of the form # [topotype, minlevel, maxlevel, t1, t2, fname] - topo_data.topofiles.append([4, 1, 10, 0., 1.e10, 'bowl.nc']) + topo_data.topofiles.append([4, 'bowl.nc']) # topo_data.topofiles.append([2, 1, 10, 0., 1.e10, 'bowl.tt2']) # == setdtopo.data values == @@ -378,12 +376,6 @@ def setgeo(rundata): rundata.qinit_data.qinitfiles = [] # for qinit perturbations, append lines of the form: (<= 1 allowed for now!) # [minlev, maxlev, fname] - - # == setfixedgrids.data values == - fixedgrids = rundata.fixed_grid_data - # for fixed grids append lines of the form - # [t1,t2,noutput,x1,x2,y1,y2,xpoints,ypoints,\ - # ioutarrivaltimes,ioutsurfacemax] # == fgmax.data values == fgmax_files = rundata.fgmax_data.fgmax_files diff --git a/tests/netcdf_topo/regression_tests.py b/tests/netcdf_topo/test_netcdf.py similarity index 92% rename from tests/netcdf_topo/regression_tests.py rename to tests/netcdf_topo/test_netcdf.py index e8c54ca24..e673003b4 100644 --- a/tests/netcdf_topo/regression_tests.py +++ b/tests/netcdf_topo/test_netcdf.py @@ -17,7 +17,7 @@ import numpy import xarray as xr -import nose +import pytest import clawpack.geoclaw.test as test import clawpack.geoclaw.topotools as topotools @@ -35,6 +35,8 @@ def __init__(self, methodName="runTest"): def setUp(self): + netCDF4 = pytest.importorskip("netCDF4", reason=build_failure_str) + self.temp_path = tempfile.mkdtemp() self.stdout = open(os.path.join(self.temp_path, "run_output.txt"), "w") @@ -74,10 +76,9 @@ def setUp(self): topo.x = numpy.linspace(-3.1, 3.1, 310) topo.y = numpy.linspace(-3.5,2.5, 300) - try: - import netCDF4 - this_path = os.path.join(self.temp_path, 'bowl.nc') + this_path = os.path.join(self.temp_path, 'bowl.nc') + try: # now mess with the order of the dimension IDs (lat, then lon) with netCDF4.Dataset(this_path,'w') as out: lat = out.createDimension('lat',len(topo.y)) @@ -91,18 +92,13 @@ def setUp(self): longitudes[:] = topo.x elevations[:] = topo.Z - - except ImportError: - # Assume that NetCDF is not installed and move on - raise nose.SkipTest(build_failure_str) - except RuntimeError as e: - print(e.message) - raise nose.SkipTest("NetCDF topography test skipped due to " + - "runtime failure.") + pytest.skip(("NetCDF topography test skipped due to runtime failure.")) + raise e else: self.build_executable() + def build_executable(self): try: self.stdout.write("Teting NetCDF output:\n") @@ -111,9 +107,9 @@ def build_executable(self): stderr=self.stderr, shell=True) except subprocess.CalledProcessError: - self.stdout.write(build_failure_str) - raise nose.SkipTest(build_failure_str) + pytest.skip(build_failure_str) + raise e else: # Force recompilation of topo_module to add NetCDF flags diff --git a/tests/old_topotools.py b/tests/old_topotools.py index fd3dbad42..5ff4cd035 100644 --- a/tests/old_topotools.py +++ b/tests/old_topotools.py @@ -3,8 +3,6 @@ import numpy import re -import nose - def topo1writer(outfile, topo, xlower, xupper, ylower, yupper, nxpoints, nypoints): fout=open(outfile, 'w') diff --git a/tests/particles/setrun.py b/tests/particles/setrun.py index 9f5852dfd..8b51c56f7 100644 --- a/tests/particles/setrun.py +++ b/tests/particles/setrun.py @@ -392,11 +392,6 @@ def setgeo(rundata): # [fname] rundata.qinit_data.qinitfiles.append(['qinit.xyz']) - # == setfixedgrids.data values == - fixedgrids = rundata.fixed_grid_data.fixedgrids - # for fixed grids append lines of the form - # [t1,t2,noutput,x1,x2,y1,y2,xpoints,ypoints,\ - # ioutarrivaltimes,ioutsurfacemax] return rundata # end of function setgeo diff --git a/tests/particles/regression_tests.py b/tests/particles/test_particles.py similarity index 100% rename from tests/particles/regression_tests.py rename to tests/particles/test_particles.py diff --git a/tests/storm_surge/__init__.py b/tests/storm_surge/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/storm_surge/setrun.py b/tests/storm_surge/setrun.py index 24fb6dd9f..c148c4ac9 100644 --- a/tests/storm_surge/setrun.py +++ b/tests/storm_surge/setrun.py @@ -384,8 +384,6 @@ def setgeo(rundata): refine_data = rundata.refinement_data refine_data.wave_tolerance = 1.0 refine_data.speed_tolerance = [1.0,2.0,3.0,4.0] - refine_data.deep_depth = 300.0 - refine_data.max_level_deep = 4 refine_data.variable_dt_refinement_ratios = True # == settopo.data values == @@ -395,8 +393,8 @@ def setgeo(rundata): # [topotype, minlevel, maxlevel, t1, t2, fname] # See regions for control over these regions, need better bathy data for the # smaller domains - topo_data.topofiles.append([3, 1, 5, rundata.clawdata.t0, rundata.clawdata.tfinal, - 'gulf_caribbean.tt3']) + topo_data.topofiles.append([3, 'gulf_caribbean.tt3']) + # == setdtopo.data values == dtopo_data = rundata.dtopo_data dtopo_data.dtopofiles = [] @@ -409,12 +407,6 @@ def setgeo(rundata): # for qinit perturbations, append lines of the form: (<= 1 allowed for now!) # [minlev, maxlev, fname] - # == setfixedgrids.data values == - rundata.fixed_grid_data.fixedgrids = [] - # for fixed grids append lines of the form - # [t1,t2,noutput,x1,x2,y1,y2,xpoints,ypoints,\ - # ioutarrivaltimes,ioutsurfacemax] - return rundata # end of function setgeo # ---------------------- diff --git a/tests/storm_surge/regression_tests.py b/tests/storm_surge/test_ike.py similarity index 56% rename from tests/storm_surge/regression_tests.py rename to tests/storm_surge/test_ike.py index ac7ae66a9..52a9edff7 100644 --- a/tests/storm_surge/regression_tests.py +++ b/tests/storm_surge/test_ike.py @@ -2,27 +2,22 @@ """Regression test for GeoClaw's storm surge functionality""" -from __future__ import absolute_import import sys import os import unittest +import pytest import gzip -import nose - -try: - # For Python 3.0 and later - from urllib.error import URLError -except ImportError: - # Fall back to Python 2's urllib2 - from urllib2 import URLError +import urllib.error +import pytest import numpy -import clawpack.geoclaw.test as test +import clawpack.geoclaw.test import clawpack.geoclaw.topotools +import clawpack.clawutil from clawpack.geoclaw.surge import storm -class IkeTest(test.GeoClawRegressionTest): +class IkeTest(clawpack.geoclaw.test.GeoClawRegressionTest): r"""Hurricane Ike regression test""" @@ -34,8 +29,9 @@ def setUp(self): remote_url = "http://ftp.nhc.noaa.gov/atcf/archive/2008/bal092008.dat.gz" try: path = self.get_remote_file(remote_url, unpack=False) - except URLError: - raise nose.SkipTest("Could not fetch remote file, skipping test.") + except urllib.error.URLError as e: + pytest.skip("Could not fetch remote file, skipping test.") + raise e storm_path = os.path.join(os.path.dirname(path), 'ike.storm') @@ -51,8 +47,8 @@ def setUp(self): ike_storm.write(storm_path) # Download file - #self.get_remote_file( - # "http://www.columbia.edu/~ktm2132/bathy/gulf_caribbean.tt3.tar.bz2") + # clawpack.clawutil.data.get_remote_file( + # "https://depts.washington.edu/clawpack/geoclaw/topo/gulf_caribbean.tt3.tar.bz2") # Create synthetic bathymetry - needs more work topo = clawpack.geoclaw.topotools.Topography() @@ -63,7 +59,7 @@ def setUp(self): topo_type=2, Z_format="%22.15e") - def runTest(self, save=False, indices=(2, 3)): + def runTest(self, save=False, indices=range(4)): r"""Storm Surge Regression Test :Input: @@ -89,39 +85,6 @@ def runTest(self, save=False, indices=(2, 3)): self.success = True - # def check_gauges(self, save=False, indices=(2, 3)): - # r"""Basic test to assert gauge equality - - # :Input: - # - *save* (bool) - If *True* will save the output from this test to - # the file *regresion_data.txt*. Default is *False*. - # - *indices* (tuple) - Contains indices to compare in the gague - # comparison. Defaults to *(2, 3)*. - # """ - - # # Get gauge data - # data = numpy.loadtxt(os.path.join(self.temp_path, 'fort.gauge')) - # data_sum = [] - # for index in indices: - # data_sum.append(data[:, index].sum()) - - # # Get (and save) regression comparison data - # regression_data_file = os.path.join(self.test_path, "regression_data.txt") - # if save: - # numpy.savetxt(regression_data_file, data) - # regression_data = numpy.loadtxt(regression_data_file) - # regression_sum = [] - # for index in indices: - # regression_sum.append(regression_data[:, index].sum()) - # # regression_sum = regression_data - - # # Compare data - # tolerance = 1e-14 - # assert numpy.allclose(data_sum, regression_sum, tolerance), \ - # "\n data: %s, \n expected: %s" % (data_sum, regression_sum) - # # assert numpy.allclose(data, regression_data, tolerance), \ - # # "Full gauge match failed." - if __name__=="__main__": if len(sys.argv) > 1: if bool(sys.argv[1]): diff --git a/tests/test_dtopotools.py b/tests/test_dtopotools.py index cef88420b..c565e6d7e 100644 --- a/tests/test_dtopotools.py +++ b/tests/test_dtopotools.py @@ -8,7 +8,7 @@ import time import numpy -import nose +import pytest import clawpack.geoclaw.dtopotools as dtopotools @@ -220,8 +220,9 @@ def test_dtopo_io(): except AssertionError as e: test_dump_path = os.path.join(os.getcwd(), "test_dtopo_io") - shutil.mkdir(test_dump_path) - shutil.copy(temp_path, test_dump_path) + if os.path.exists(test_dump_path): + shutil.rmtree(test_dump_path) + shutil.copytree(temp_path, test_dump_path) raise e finally: shutil.rmtree(temp_path) @@ -284,7 +285,7 @@ def test_geometry(): def test_vs_old_dtopo(): r"""Test new dtopotools with old version from 5.2""" - raise nose.SkipTest("Skipping comparison with old tools.") + pytest.skip("Skipping comparison with old tools.") from . import old_dtopotools @@ -469,13 +470,12 @@ def test_subdivided_plane_fault(verbose=False, plot=False): pass elif bool(sys.argv[1]): save = True - try: - test_read_csv_make_dtopo(save=save) - test_read_ucsb_make_dtopo(save=save) - test_read_sift_make_dtopo(save=save) - test_SubdividedPlaneFault_make_dtopo(save=save) - test_dtopo_io() - test_geometry() - test_vs_old_dtopo() - except nose.SkipTest as e: - print(e.message) + + test_read_csv_make_dtopo(save=save) + test_read_ucsb_make_dtopo(save=save) + test_read_sift_make_dtopo(save=save) + test_SubdividedPlaneFault_make_dtopo(save=save) + test_dtopo_io() + test_geometry() + test_vs_old_dtopo() + \ No newline at end of file diff --git a/tests/test_etopo1.py b/tests/test_etopo1.py index c8e588919..bbe0e8212 100644 --- a/tests/test_etopo1.py +++ b/tests/test_etopo1.py @@ -1,11 +1,10 @@ #!/usr/bin/env python -from __future__ import print_function import os import numpy -import nose -import os +import pytest import warnings + from clawpack.geoclaw import topotools @@ -18,10 +17,7 @@ def test_etopo1_topo(make_plot=False, save=False): - try: - import netCDF4 - except ImportError: - raise nose.SkipTest("netCDF4 not installed, skipping test") + netCDF4 = pytest.importorskip('netCDF4', reason="netCDF4 not installed, skipping test") try: topo1 = topotools.read_netcdf('etopo1', extent=extent, verbose=True) @@ -29,7 +25,8 @@ def test_etopo1_topo(make_plot=False, save=False): coarsen=10, verbose=True) except (OSError, RuntimeError): warnings.warn('Could not read etopo1 data, check if thredds server up') - raise nose.SkipTest("Reading etopo1 failed, skipping test") + pytest.skip("Reading etopo1 failed, skipping test") + # raise nose.SkipTest("Reading etopo1 failed, skipping test") testdata_path = os.path.join(os.path.dirname(__file__), 'data', 'etopo1_10min.asc') if save: @@ -57,10 +54,8 @@ def test_etopo1_topo(make_plot=False, save=False): def test_etopo1_xarray(): - try: - import xarray - except ImportError: - raise nose.SkipTest("xarray not installed, skipping test") + xarray = pytest.importorskip("xarray", + reason="xarray not installed, skipping test") try: topo10,topo10_xarray = topotools.read_netcdf('etopo1', extent=extent, @@ -68,7 +63,7 @@ def test_etopo1_xarray(): coarsen=10, verbose=True) except (OSError, RuntimeError): warnings.warn('Could not read etopo1 data, check if thredds server up') - raise nose.SkipTest("Reading etopo1 failed, skipping test") + pytest.skip("Reading etopo1 failed, skipping test") testdata_path = os.path.join(testdir, 'data', 'etopo1_10min.asc') topo10input = topotools.Topography() @@ -86,8 +81,6 @@ def test_etopo1_xarray(): elif bool(sys.argv[1]): test_etopo1_topo(save=True) else: - # Run tests test_etopo1_topo() test_etopo1_xarray() - print("All tests passed.") diff --git a/tests/test_storm.py b/tests/test_storm.py index 1099bbc61..6e948f815 100644 --- a/tests/test_storm.py +++ b/tests/test_storm.py @@ -11,6 +11,7 @@ import os import sys import datetime +import pytest import numpy @@ -93,22 +94,16 @@ def test_storm_IO(save=False): for file_format in file_format_tests: if file_format=='ibtracs': file_suffix = 'nc' - # Check here to see if we have xarray - try: - import xarray - except ImportError as e: - print("Skipping IBTrACS IO test, missing xarray.") - continue + xarray = pytest.importorskip("xarray", + reason="Skipping IBTrACS IO test, missing xarray.") + pytest.skip("IBTrACS test skipped.") elif file_format == 'atcf': file_suffix = 'txt' - # Check here to see if we have pandas - try: - import pandas - except ImportError as e: - print("Skipping ATCF IO test, missing pandas.") - continue + pandas = pytest.importorskip("pandas", + reason="Skipping ATCF IO test, missing pandas.") else: file_suffix = 'txt' + input_path = os.path.join(testdir, "data", "storm", "%s.%s" % (file_format,file_suffix)) out_path = os.path.join(temp_path, '%s_geoclaw.txt' % file_format) check_path = os.path.join(testdir, "data", "storm", diff --git a/tests/test_topotools.py b/tests/test_topotools.py index b7b89aa9f..d050bc5df 100644 --- a/tests/test_topotools.py +++ b/tests/test_topotools.py @@ -4,18 +4,11 @@ import sys import tempfile import shutil - -try: - # For Python 3.0 and later - from urllib.error import URLError -except ImportError: - # Fall back to Python 2's urllib2 - from urllib2 import URLError +import pytest +import urllib.error import numpy -import nose - import clawpack.geoclaw.topotools as topotools import clawpack.clawutil.data @@ -200,9 +193,9 @@ def test_netcdf(): try: # Fetch comparison data - url = "".join(('https://raw.githubusercontent.com/rjleveque/geoclaw/', - '5f675256c043e59e5065f9f3b5bdd41c2901702c/src/python/', - 'geoclaw/tests/kahului_sample_1s.tt2')) + url = ('https://raw.githubusercontent.com/rjleveque/geoclaw/' + + '5f675256c043e59e5065f9f3b5bdd41c2901702c/src/python/' + + 'geoclaw/tests/kahului_sample_1s.tt2') clawpack.clawutil.data.get_remote_file(url, output_dir=temp_path, force=True) @@ -233,13 +226,14 @@ def test_netcdf(): raise e except ImportError as e: - raise nose.SkipTest("Skipping test since NetCDF support not found.") + pytest.skip("Skipping test since NetCDF support not found.") except RuntimeError as e: - raise nose.SkipTest("NetCDF topography test skipped due to " + - "runtime failure.") - except URLError: - raise nose.SkipTest("Could not fetch remote file, skipping test.") + pytest.skip("NetCDF topography test skipped due to " + + "runtime failure.") + + except urllib.error.URLError: + pytest.skip("Could not fetch remote file, skipping test.") finally: shutil.rmtree(temp_path) @@ -251,8 +245,8 @@ def test_get_remote_file(): temp_path = tempfile.mkdtemp() try: - url = "".join(('https://raw.githubusercontent.com/rjleveque/geoclaw/', - '5f675256c043e59e5065f9f3b5bdd41c2901702c/src/python/', + url = "".join(('https://raw.githubusercontent.com/rjleveque/geoclaw/' + + '5f675256c043e59e5065f9f3b5bdd41c2901702c/src/python/' + 'geoclaw/tests/kahului_sample_1s.tt2')) clawpack.clawutil.data.get_remote_file(url, output_dir=temp_path, force=True) @@ -269,8 +263,8 @@ def test_get_remote_file(): shutil.copy(local_path, os.path.join(os.getcwd(), "remote_file.tt2")) raise e - except URLError: - raise nose.SkipTest("Could not fetch remote file, skipping test.") + except urllib.error.URLError: + pytest.skip("Could not fetch remote file, skipping test.") finally: shutil.rmtree(temp_path) @@ -278,10 +272,8 @@ def test_get_remote_file(): def test_unstructured_topo(save=False, plot=False): - try: - import scipy - except: - raise nose.SkipTest("Skipping test since scipy not found") + scipy = pytest.importorskip('scipy', + reason="Skipping test since scipy not found") # Create random test data def func(x, y): @@ -340,10 +332,13 @@ def plot_topo_bowl_hill(): Note that center of bowl should be at (0,0). """ - try: - import matplotlib - except ImportError: - raise nose.SkipTest("Skipping test since matplotlib not found.") + matplotlib = pytest.importorskip('matplotlib', + reason="Skipping test since matplotlib not found.") + + # try: + # import matplotlib + # except ImportError: + # raise nose.SkipTest("Skipping test since matplotlib not found.") matplotlib.use("Agg") # use image backend -- needed for Travis tests import matplotlib.pyplot as plt @@ -357,14 +352,12 @@ def plot_topo_bowl_hill(): topo.plot() fname = "bowl_hill.png" plt.savefig(fname) - print("Created ",fname) topo2 = topo.crop([0.5, 1.5, 0., 2.]) topo2.plot() plt.title("Cropped topography") fname = "bowl_hill_crop.png" plt.savefig(fname) - print("Created ",fname) def plot_kahului(): @@ -377,10 +370,8 @@ def plot_kahului(): illustrate how to do a contour data of the data directly. """ - try: - import matplotlib - except ImportError: - raise nose.SkipTest("Skipping test since matplotlib not found.") + matplotlib = pytest.importorskip('matplotlib', + reason="Skipping test since matplotlib not found.") matplotlib.use("Agg") # use image backend -- needed for Travis tests import matplotlib.pyplot as plt @@ -393,7 +384,6 @@ def plot_kahului(): plt.title("Kahului Harbor at 1 second resolution") fname = "kahului_imshow.png" plt.savefig(fname) - print("Created ",fname) assert K.Z.shape == (46, 65), "*** K.Z is wrong shape" assert numpy.allclose(K.Z[:3,:3], \ @@ -422,7 +412,6 @@ def plot_kahului(): fontsize=12) fname = "kahului_contour.png" plt.savefig(fname) - print("Created ",fname) if __name__ == "__main__": @@ -442,5 +431,3 @@ def plot_kahului(): test_get_remote_file() test_unstructured_topo() test_netcdf() - - print("All tests passed.") diff --git a/tests/test_util.py b/tests/test_util.py index 6e72e69df..4c07cd7f0 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -5,7 +5,7 @@ import shutil import tempfile -from nose.tools import raises +import pytest import numpy as np import clawpack.geoclaw.util as util @@ -89,37 +89,37 @@ def test_api_error(self): d,w,p = fetch_noaa_tide_data(self.station, self.begin_date, self.end_date, cache_dir=cache_dir) assert d == None, '*** expected d == None' - - @raises(ValueError) + def test_date_time_range_mismatch(self): - cache_dir = os.path.join(self.temp_dir, - self.test_date_time_range_mismatch.__name__) - - # missing first two entries - water_level_response = \ - ('Date Time, Water Level, Sigma, O or I (for verified), F, R, L, Quality\n' - '2000-10-30 12:12,1.003,0.003,0,0,0,0,v\n' - '2000-10-30 12:18,1.004,0.004,0,0,0,0,v\n' - '2000-10-30 12:24,1.005,0.005,0,0,0,0,v\n') - - # missing last two entries - predictions_response = ('Date Time, Prediction\n' - '2000-10-30 12:00,1.101\n' - '2000-10-30 12:06,1.102\n' - '2000-10-30 12:12,1.103\n') - - # monkey patch urllib to return mock data - def mock_read_response(url): - if 'product=water_level' in url: - return water_level_response - if 'product=predictions' in url: - return predictions_response - raise AssertionError - self._monkey_patch_urlopen(mock_read_response) - - # should raise ValueError - fetch_noaa_tide_data(self.station, self.begin_date, self.end_date, - cache_dir=cache_dir) + with pytest.raises(ValueError): + cache_dir = os.path.join(self.temp_dir, + self.test_date_time_range_mismatch.__name__) + + # missing first two entries + water_level_response = \ + ('Date Time, Water Level, Sigma, O or I (for verified), F, R, L, Quality\n' + '2000-10-30 12:12,1.003,0.003,0,0,0,0,v\n' + '2000-10-30 12:18,1.004,0.004,0,0,0,0,v\n' + '2000-10-30 12:24,1.005,0.005,0,0,0,0,v\n') + + # missing last two entries + predictions_response = ('Date Time, Prediction\n' + '2000-10-30 12:00,1.101\n' + '2000-10-30 12:06,1.102\n' + '2000-10-30 12:12,1.103\n') + + # monkey patch urllib to return mock data + def mock_read_response(url): + if 'product=water_level' in url: + return water_level_response + if 'product=predictions' in url: + return predictions_response + raise AssertionError + self._monkey_patch_urlopen(mock_read_response) + + # should raise ValueError + fetch_noaa_tide_data(self.station, self.begin_date, self.end_date, + cache_dir=cache_dir) def test_missing_values(self): cache_dir = os.path.join(self.temp_dir, From 9aa205366cafdbce04a18f4e4d0392c2598c6072 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 10:35:56 -0400 Subject: [PATCH 02/39] Add testing github action --- .github/workflows/testing.yml | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/testing.yml diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 000000000..7b0cf8db0 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,49 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Checkout clawpack + uses: actions/checkout@v4.1.5 + with: + repository: https://github.com/clawpack/clawpack.git + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev + python -m pip install --upgrade pip + pip install flake8 pytest + - name: Setup clawpack + run: | + git submodule init + git submodule update + cd geoclaw + echo ${{ github.GITHUB_REF_NAME }} + # - name: Lint with flake8 + # run: | + # # stop the build if there are Python syntax errors or undefined names + # flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + # - name: Test with pytest + # run: | + # pytest From 27f09a60ad787172b295867374b0d4e0999a099a Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 13:47:18 -0400 Subject: [PATCH 03/39] Add github CI script --- .github/workflows/testing.yml | 35 ++++++++++++++++++---------------- src/2d/bouss/setrun_changes.py | 33 -------------------------------- 2 files changed, 19 insertions(+), 49 deletions(-) delete mode 100644 src/2d/bouss/setrun_changes.py diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 7b0cf8db0..7cca665c0 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -1,7 +1,5 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python -name: Python application +name: Test GeoClaw on: push: @@ -19,31 +17,36 @@ jobs: steps: - name: Set up Python 3.10 - uses: actions/setup-python@v3 + uses: actions/setup-python@v5 with: python-version: "3.10" - name: Checkout clawpack uses: actions/checkout@v4.1.5 with: - repository: https://github.com/clawpack/clawpack.git + repository: clawpack/clawpack - name: Install dependencies run: | sudo apt-get update sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev python -m pip install --upgrade pip pip install flake8 pytest - - name: Setup clawpack + - name: Setup clawpack super repository run: | git submodule init git submodule update + pip install --user -e . + - name: Setup geoclaw + run: | + cd geoclaw + git checkout ${{ github.ref }} + - name: Lint with flake8 + run: | + cd geoclaw + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude old_dtopotools.py + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | cd geoclaw - echo ${{ github.GITHUB_REF_NAME }} - # - name: Lint with flake8 - # run: | - # # stop the build if there are Python syntax errors or undefined names - # flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - # - name: Test with pytest - # run: | - # pytest + pytest \ No newline at end of file diff --git a/src/2d/bouss/setrun_changes.py b/src/2d/bouss/setrun_changes.py deleted file mode 100644 index 95e7fdfc9..000000000 --- a/src/2d/bouss/setrun_changes.py +++ /dev/null @@ -1,33 +0,0 @@ - -# OLD: - - #------------------------------------------------------------------ - # Problem-specific parameters to be written to setprob.data: - #------------------------------------------------------------------ - - probdata = rundata.new_UserData(name='probdata',fname='setprob.data') - probdata.add_param('minLevelBouss', 1,' minlevel for Bouss terms') - probdata.add_param('maxLevelBouss', 10,' maxlevel for Bouss terms') - probdata.add_param('deepBouss', 5,' min water depth for Bouss terms') - probdata.add_param('solver', 3, ' 1=GMRES, 2=Pardiso, 3=PETSc') - probdata.add_param('equations', 2, ' 1=MadsenSchaffer, 2=SGN') - probdata.add_param('alpha', 1.153, ' If using SGN, else ignore') - probdata.add_param('startWithBouss', True, 'Take numSWEsteps of SWE first') - probdata.add_param('numSWEsteps', 0, ' Take this many SWE steps first') - - -# NEW: - - # To use Boussinesq solver, add bouss_data parameters here - # Also make sure to use the correct Makefile pointing to bouss version - from clawpack.geoclaw.data import BoussData - rundata.add_data(BoussData(),'bouss_data') - - # CHECK ORDER! - - rundata.bouss_data.bouss_equations = 2 # 0=SWE, 1=MS, 2=SGN - rundata.bouss_data.bouss_min_level = 1 # coarsest level to apply bouss - rundata.bouss_data.bouss_max_level = 10 # finest level to apply bouss - rundata.bouss_data.bouss_min_depth = 10. # depth to switch to SWE - rundata.bouss_data.bouss_solver = 3 # 1=GMRES, 2=Pardiso, 3=PETSc - rundata.bouss_data.bouss_tstart = 0. # time to switch from SWE From ac53c2c3e8496f2e71a559aea9fe20958a47911c Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 13:49:39 -0400 Subject: [PATCH 04/39] Correct multiple python errors so that linting passes --- examples/multi-layer/bowl-radial/setplot.py | 35 +- examples/multi-layer/plane_wave/setplot.py | 36 +- examples/multi-layer/plane_wave/setrun.py | 28 +- src/python/geoclaw/dtopotools.py | 4 +- src/python/geoclaw/fgmax_tools.py | 4 +- src/python/geoclaw/multilayer/plot.py | 352 ++++++++++---------- src/python/geoclaw/surge/plot.py | 28 +- src/python/geoclaw/surge/storm.py | 199 +++++------ src/python/geoclaw/topotools.py | 6 +- tests/multilayer/setplot.py | 303 ----------------- tests/netcdf_topo/test_netcdf.py | 2 +- tests/test_storm.py | 1 + 12 files changed, 336 insertions(+), 662 deletions(-) diff --git a/examples/multi-layer/bowl-radial/setplot.py b/examples/multi-layer/bowl-radial/setplot.py index da62ac9e4..995405ced 100644 --- a/examples/multi-layer/bowl-radial/setplot.py +++ b/examples/multi-layer/bowl-radial/setplot.py @@ -74,15 +74,15 @@ def pcolor_afteraxes(current_data): # bathy_ref_lines(current_data) gauge_locations(current_data) - def contour_afteraxes(current_data): - # gauge_locations(current_data) - # m_to_km_labels() - plt.hold(True) - pos = -80.0 * (23e3 / 180) + 500e3 - 5e3 - plt.plot([pos,pos],[-300e3,300e3],'b',[pos-5e3,pos-5e3],[-300e3,300e3],'y') - plt.hold(False) - wind_contours(current_data) - bathy_ref_lines(current_data) + # def contour_afteraxes(current_data): + # # gauge_locations(current_data) + # # m_to_km_labels() + # plt.hold(True) + # pos = -80.0 * (23e3 / 180) + 500e3 - 5e3 + # plt.plot([pos,pos],[-300e3,300e3],'b',[pos-5e3,pos-5e3],[-300e3,300e3],'y') + # plt.hold(False) + # wind_contours(current_data) + # bathy_ref_lines(current_data) def profile_afteraxes(current_data): pass @@ -259,23 +259,6 @@ def gaugetopo(current_data): plotitem.plot_var = gaugetopo plotitem.plotstyle = 'g-' - def add_zeroline(current_data): - from pylab import plot, legend, xticks, floor, axis, xlabel - t = current_data.t - gaugeno = current_data.gaugeno - - if gaugeno == 32412: - try: - plot(TG32412[:,0], TG32412[:,1], 'r') - legend(['GeoClaw','Obs'],loc='lower right') - except: pass - axis((0,t.max(),-0.3,0.3)) - - plot(t, 0*t, 'k') - n = int(floor(t.max()/3600.) + 2) - xticks([3600*i for i in range(n)], ['%i' % i for i in range(n)]) - xlabel('time (hours)') - #----------------------------------------- diff --git a/examples/multi-layer/plane_wave/setplot.py b/examples/multi-layer/plane_wave/setplot.py index f338e70c4..4056aff06 100644 --- a/examples/multi-layer/plane_wave/setplot.py +++ b/examples/multi-layer/plane_wave/setplot.py @@ -76,7 +76,7 @@ def transform_p2c(x, y, x0, y0, theta): plotdata.clearfigures() plotdata.save_frames = False - plotdata.format = 'ascii' + # plotdata.format = 'ascii' # ======================================================================== # Generic helper functions @@ -88,7 +88,6 @@ def contour_afteraxes(current_data): pos = -80.0 * (23e3 / 180) + 500e3 - 5e3 axes.plot([pos, pos], [-300e3, 300e3], 'b', [pos-5e3, pos-5e3], [-300e3, 300e3], 'y') - wind_contours(current_data) bathy_ref_lines(current_data) def profile_afteraxes(current_data): @@ -105,7 +104,6 @@ def bathy_ref_lines(current_data): # ======================================================================== # Axis limits - xlimits = [-0.5, 0.5] ylimits = [-0.5, 0.5] eta = [multilayer_data.eta[0], multilayer_data.eta[1]] @@ -129,8 +127,6 @@ def bathy_ref_lines(current_data): plotaxes.ylimits = ylimits plotaxes.afteraxes = pcolor_afteraxes ml_plot.add_surface_elevation(plotaxes,1,bounds=top_surface_limits) - # ml_plot.add_surface_elevation(plotaxes,1,bounds=[-0.06,0.06]) - # ml_plot.add_surface_elevation(plotaxes,1) ml_plot.add_land(plotaxes, 1) # Bottom surface @@ -141,9 +137,7 @@ def bathy_ref_lines(current_data): plotaxes.xlimits = xlimits plotaxes.ylimits = ylimits plotaxes.afteraxes = pcolor_afteraxes - # ml_plot.add_surface_elevation(plotaxes,2,bounds=[-300-0.5,-300+0.5]) ml_plot.add_surface_elevation(plotaxes,2,bounds=internal_surface_limits) - # ml_plot.add_surface_elevation(plotaxes,2) ml_plot.add_land(plotaxes, 2) # ======================================================================== @@ -177,6 +171,7 @@ def bathy_ref_lines(current_data): # ======================================================================== # Water Speed + # ======================================================================== plotfigure = plotdata.new_plotfigure(name='speed') plotfigure.show = True plotfigure.kwargs = {'figsize': (14, 4)} @@ -200,9 +195,7 @@ def bathy_ref_lines(current_data): plotaxes.ylimits = ylimits plotaxes.axescmd = 'subplot(1,2,2)' plotaxes.afteraxes = pcolor_afteraxes - # add_speed(plotaxes,2,bounds=[0.0,1e-10]) ml_plot.add_speed(plotaxes,2,bounds=internal_speed_limits) - # add_speed(plotaxes,2) ml_plot.add_land(plotaxes, 2) # Individual components @@ -218,7 +211,6 @@ def bathy_ref_lines(current_data): plotaxes.ylimits = ylimits plotaxes.axescmd = 'subplot(2,2,1)' plotaxes.afteraxes = pcolor_afteraxes - # add_x_velocity(plotaxes,1,bounds=[-1e-10,1e-10]) ml_plot.add_x_velocity(plotaxes,1) ml_plot.add_land(plotaxes, 1) @@ -229,7 +221,6 @@ def bathy_ref_lines(current_data): plotaxes.ylimits = ylimits plotaxes.axescmd = 'subplot(2,2,2)' plotaxes.afteraxes = pcolor_afteraxes - # add_y_velocity(plotaxes,1,bounds=[-0.000125,0.000125]) ml_plot.add_y_velocity(plotaxes,1) ml_plot.add_land(plotaxes, 1) @@ -241,7 +232,6 @@ def bathy_ref_lines(current_data): plotaxes.ylimits = ylimits plotaxes.axescmd = 'subplot(2,2,3)' plotaxes.afteraxes = pcolor_afteraxes - # add_x_velocity(plotaxes,2,bounds=[-1e-10,1e-10]) ml_plot.add_x_velocity(plotaxes,2) ml_plot.add_land(plotaxes, 2) @@ -252,10 +242,9 @@ def bathy_ref_lines(current_data): plotaxes.ylimits = ylimits plotaxes.axescmd = 'subplot(2,2,4)' plotaxes.afteraxes = pcolor_afteraxes - # add_y_velocity(plotaxes,2,bounds=[-0.8e-6,.8e-6]) ml_plot.add_y_velocity(plotaxes,2) - ml_plot.add_land(plotaxes, 2) + # ======================================================================== # Profile Plots # Note that these are not currently plotted by default - set @@ -274,39 +263,40 @@ def bathy_ref_lines(current_data): # Internal surface def bathy_profile(current_data): - return current_data.x[:, slice_index], b(current_data)[:, slice_index] + return current_data.x[:, slice_index], \ + ml_plot.b(current_data)[:, slice_index] def lower_surface(current_data): if multilayer_data.init_type == 2: return current_data.x[:, slice_index], \ - eta2(current_data)[:, slice_index] + ml_plot.eta2(current_data)[:, slice_index] elif multilayer_data.init_type == 6: return current_data.y[slice_index, :], \ - eta2(current_data)[slice_index, :] + ml_plot.eta2(current_data)[slice_index, :] def upper_surface(current_data): if multilayer_data.init_type == 2: return current_data.x[:, slice_index], \ - eta1(current_data)[:, slice_index] + ml_plot.eta1(current_data)[:, slice_index] elif multilayer_data.init_type == 6: return current_data.y[slice_index, :], \ - eta1(current_data)[slice_index, :] + ml_plot.eta1(current_data)[slice_index, :] def top_speed(current_data): if multilayer_data.init_type == 2: return current_data.x[:, slice_index], \ - water_u1(current_data)[:, slice_index] + ml_plot.water_u1(current_data)[:, slice_index] elif multilayer_data.init_type == 6: return current_data.y[slice_index, :], \ - water_u1(current_data)[slice_index, :] + ml_plot.water_u1(current_data)[slice_index, :] def bottom_speed(current_data): if multilayer_data.init_type == 2: return current_data.x[:, slice_index], \ - water_u2(current_data)[:, slice_index] + ml_plot.water_u2(current_data)[:, slice_index] elif multilayer_data.init_type == 6: return current_data.y[slice_index, :], \ - water_u2(current_data)[slice_index, :] + ml_plot.water_u2(current_data)[slice_index, :] # Bathy plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data') diff --git a/examples/multi-layer/plane_wave/setrun.py b/examples/multi-layer/plane_wave/setrun.py index 7fd9a7514..021bbc1c6 100644 --- a/examples/multi-layer/plane_wave/setrun.py +++ b/examples/multi-layer/plane_wave/setrun.py @@ -4,9 +4,9 @@ that will be read in by the Fortran code. """ -from __future__ import absolute_import -from __future__ import print_function -import numpy +import os + +import numpy as np import clawpack.geoclaw.data import clawpack.geoclaw.topotools as tt @@ -14,12 +14,12 @@ # Rotation transformations def transform_c2p(x,y,x0,y0,theta): - return ((x+x0)*numpy.cos(theta) - (y+y0)*numpy.sin(theta), - (x+x0)*numpy.sin(theta) + (y+y0)*numpy.cos(theta)) + return ((x+x0)*np.cos(theta) - (y+y0)*np.sin(theta), + (x+x0)*np.sin(theta) + (y+y0)*np.cos(theta)) def transform_p2c(x,y,x0,y0,theta): - return ( x*numpy.cos(theta) + y*numpy.sin(theta) - x0, - -x*numpy.sin(theta) + y*numpy.cos(theta) - y0) + return ( x*np.cos(theta) + y*np.sin(theta) - x0, + -x*np.sin(theta) + y*np.cos(theta) - y0) # Class containing some setup for the qinit especially for multilayer tests @@ -300,15 +300,15 @@ def setrun(claw_pkg='geoclaw'): # Do not checkpoint at all pass - elif numpy.abs(clawdata.checkpt_style) == 1: + elif np.abs(clawdata.checkpt_style) == 1: # Checkpoint only at tfinal. pass - elif numpy.abs(clawdata.checkpt_style) == 2: + elif np.abs(clawdata.checkpt_style) == 2: # Specify a list of checkpoint times. clawdata.checkpt_times = [0.1,0.15] - elif numpy.abs(clawdata.checkpt_style) == 3: + elif np.abs(clawdata.checkpt_style) == 3: # Checkpoint every checkpt_interval timesteps (on Level 1) # and at the final time. clawdata.checkpt_interval = 5 @@ -384,8 +384,8 @@ def setrun(claw_pkg='geoclaw'): for (i,x_c) in enumerate(gauge_locations): # y0 = (self.run_data.clawdata.yupper - self.run_data.clawdata.ylower) / 2.0 # x_p,y_p = transform_c2p(x_c,0.0,location[0],location[1],angle) - x_p = x_c * numpy.cos(0.0) - y_p = x_c * numpy.sin(0.0) + x_p = x_c * np.cos(0.0) + y_p = x_c * np.sin(0.0) # print "+=====+" # print x_c,0.0 # print x_p,y_p @@ -487,10 +487,10 @@ def write_topo_file(run_data, out_file, **kwargs): # Make topography topo_func = lambda x, y: bathy_step(x, y, **kwargs) topo = tt.Topography(topo_func=topo_func) - topo.x = numpy.linspace(run_data.clawdata.lower[0], + topo.x = np.linspace(run_data.clawdata.lower[0], run_data.clawdata.upper[0], run_data.clawdata.num_cells[0] + 8) - topo.y = numpy.linspace(run_data.clawdata.lower[1], + topo.y = np.linspace(run_data.clawdata.lower[1], run_data.clawdata.upper[1], run_data.clawdata.num_cells[1] + 8) topo.write(out_file) diff --git a/src/python/geoclaw/dtopotools.py b/src/python/geoclaw/dtopotools.py index 37abc634f..82b89c7fe 100644 --- a/src/python/geoclaw/dtopotools.py +++ b/src/python/geoclaw/dtopotools.py @@ -3151,7 +3151,7 @@ def __init__(self, strike=0, length=1000e3): if strike not in [0, 180]: msg = "strike should be 0 for top at right or 180 for top at left\n" msg = msg + " strike = %s not allowed in 1d" % strike - raise InputError(msg) + raise ValueError(msg) self.strike = strike r"""rake=90, so top at right if strike=0, at left if strike=180""" @@ -3218,7 +3218,7 @@ def read(self, path=None, dtopo_type=None, verbose=False): dZvals = numpy.array(numpy.loadtxt(path, skiprows=6), ndmin=2) if dtopo_type==2: - dZ = reshape(dZvals,(mt,mx)) + dZ = numpy.reshape(dZvals,(mt,mx)) elif dtopo_type==3: dZ = dZvals diff --git a/src/python/geoclaw/fgmax_tools.py b/src/python/geoclaw/fgmax_tools.py index 224d7878b..baca3c5c4 100644 --- a/src/python/geoclaw/fgmax_tools.py +++ b/src/python/geoclaw/fgmax_tools.py @@ -375,10 +375,10 @@ def read_output(self, fgno=None, outdir=None, verbose=True, elif indexing == 'ij': reshape_order = 'F' else: - raise InputError("*** indexing must by 'xy' or 'ij'") + raise ValueError("*** indexing must by 'xy' or 'ij'") if self.point_style is None: - raise InputError("*** point_style is not set, need to read input?") + raise ValueError("*** point_style is not set, need to read input?") point_style = self.point_style if fgno is not None: diff --git a/src/python/geoclaw/multilayer/plot.py b/src/python/geoclaw/multilayer/plot.py index a37963d51..748f11fef 100644 --- a/src/python/geoclaw/multilayer/plot.py +++ b/src/python/geoclaw/multilayer/plot.py @@ -346,182 +346,182 @@ def add_land(plotaxes, surface, plot_type='pcolor', bounds=[-10, 10]): raise NotImplementedError("Plot type %s not implemented" % plot_type) -def add_combined_profile_plot(plot_data, slice_value, direction='x', - figno=120): - def slice_index(cd): - if direction == 'x': - if cd.grid.y.lower < slice_value < cd.grid.y.upper: - return int((slice_value - cd.grid.y.lower) / cd.dy - 0.5) - else: - return None - elif direction == 'y': - if cd.grid.x.lower < slice_value < cd.grid.x.upper: - return int((slice_value - cd.grid.x.lower) / cd.dx - 0.5) - else: - return None - - def bathy_profile(current_data): - index = slice_index(current_data) - if direction == 'x': - if index: - return current_data.x[:, index], b(current_data)[:, index] - else: - return None - elif direction == 'y': - if index: - return current_data.y[index, :], b(current_data)[index, :] - else: - return None - - def lower_surface(current_data): - index = slice_index(current_data) - if direction == 'x': - if index: - return current_data.x[:, index], eta2(current_data)[:, index] - else: - return None - elif direction == 'y': - if index: - return current_data.y[index, :], eta2(current_data)[index, :] - else: - return None - - def upper_surface(current_data): - index = slice_index(current_data) - if direction == 'x': - if index: - return current_data.x[:, index], eta1(current_data)[:, index] - else: - return None - elif direction == 'y': - if index: - return current_data.y[index, :], eta1(current_data)[index, :] - else: - return None - - # Surfaces - plotfigure = plotdata.new_plotfigure(name='combined_surface_%s' % figno, - figno=figno) - plotfigure.show = True - plotfigure.kwargs = {'figsize': (6, 6)} - - # Top surface - plotaxes = plotfigure.new_plotaxes() - plotaxes.axescmd = 'subplot(2,1,1)' - plotaxes.title = 'Surfaces Profile %s at %s' % (direction, slice_value) - if multilayer_data.init_type == 2: - plotaxes.xlimits = xlimits - elif multilayer_data.init_type == 6: - plotaxes.xlimits = ylimits - - plotaxes.ylimits = top_surf_zoomed - - def top_surf_afteraxes(cd): - axes = plt.gca() - axes.set_xlabel('') - locs, labels = plt.xticks() - labels = ['' for i in range(len(locs))] - plt.xticks(locs, labels) - axes.plot([multilayer_data.bathy_location, - multilayer_data.bathy_location], top_surf_zoomed, '--k') - axes.set_ylabel('m') - - plotaxes.afteraxes = top_surf_afteraxes - plotitem = plotaxes.new_plotitem(plot_type="1d_from_2d_data") - plotitem.map_2d_to_1d = upper_surface - plotitem.amr_plotstyle = ['-', '+', 'x'] - plotitem.show = True - - # Internal surface - plotaxes = plotfigure.new_plotaxes() - plotaxes.axescmd = 'subplot(2,1,2)' - plotaxes.title = '' - if multilayer_data.init_type == 2: - plotaxes.xlimits = xlimits - elif multilayer_data.init_type == 6: - plotaxes.xlimits = ylimits - plotaxes.ylimits = bottom_surf_zoomed - - def internal_surf_afteraxes(cd): - axes = plt.gca() - axes.set_title('') - axes.set_ylabel('m') - axes.subplots_adjust(hspace=0.05) - axes.plot([multilayer_data.bathy_location, - multilayer_data.bathy_location], bottom_surf_zoomed, '--k') - plotaxes.afteraxes = internal_surf_afteraxes - plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data') - plotitem.map_2d_to_1d = lower_surface - plotitem.amr_plotstyle = ['-', '+', 'x'] - plotitem.color = 'k' - plotitem.show = True - - -def add_velocities_profile_plot(plot_data, slice_value, direction='x', - figno=130): - - def slice_index(cd): - if cd.grid.y.lower < slice_value < cd.grid.y.upper: - return int((slice_value - cd.grid.y.lower) / cd.dy - 0.5) - else: - return None - - def upper_surface(current_data): - index = slice_index(current_data) - if index: - return current_data.x[:, index], eta1(current_data)[:, index] - else: - return None - - def top_speed(current_data): - index = slice_index(current_data) - if index: - return current_data.x[:, index], water_u1(current_data)[:, index] - else: - return None, None - - def bottom_speed(current_data): - index = slice_index(current_data) - if index: - return current_data.x[:, index], water_u2(current_data)[:, index] - else: - return None, None - - # Velocities - plotfigure = plotdata.new_plotfigure(name='combined_velocities_%s' - % figno, figno=figno) - plotfigure.show = True - - # Top surface - plotaxes = plotfigure.new_plotaxes() - plotaxes.title = 'Velocities Profile %s at %s' % (direction, slice_value) - if multilayer_data.init_type == 2: - plotaxes.xlimits = xlimits - elif multilayer_data.init_type == 6: - plotaxes.xlimits = ylimits - plotaxes.ylimits = velocities_zoomed - - def velocity_afteraxes(cd): - axes = plt.gca() - axes.set_xlabel('') - locs, labels = plt.xticks() - labels = ['' for i in range(len(locs))] - plt.xticks(locs, labels) - axes.plot([multilayer_data.bathy_location, - multilayer_data.bathy_location], velocities_zoomed, '--k') - axes.set_ylabel('m/s') - plotaxes.afteraxes = velocity_afteraxes - - plotitem = plotaxes.new_plotitem(plot_type="1d_from_2d_data") - plotitem.map_2d_to_1d = top_speed - plotitem.amr_plotstyle = ['-', '+', 'x'] - plotitem.show = True - - plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data') - plotitem.map_2d_to_1d = bottom_speed - plotitem.amr_plotstyle = ['-', '+', 'x'] - plotitem.color = 'k' - plotitem.show = True +# def add_combined_profile_plot(plot_data, slice_value, direction='x', +# figno=120): +# def slice_index(cd): +# if direction == 'x': +# if cd.grid.y.lower < slice_value < cd.grid.y.upper: +# return int((slice_value - cd.grid.y.lower) / cd.dy - 0.5) +# else: +# return None +# elif direction == 'y': +# if cd.grid.x.lower < slice_value < cd.grid.x.upper: +# return int((slice_value - cd.grid.x.lower) / cd.dx - 0.5) +# else: +# return None + +# def bathy_profile(current_data): +# index = slice_index(current_data) +# if direction == 'x': +# if index: +# return current_data.x[:, index], b(current_data)[:, index] +# else: +# return None +# elif direction == 'y': +# if index: +# return current_data.y[index, :], b(current_data)[index, :] +# else: +# return None + +# def lower_surface(current_data): +# index = slice_index(current_data) +# if direction == 'x': +# if index: +# return current_data.x[:, index], eta2(current_data)[:, index] +# else: +# return None +# elif direction == 'y': +# if index: +# return current_data.y[index, :], eta2(current_data)[index, :] +# else: +# return None + +# def upper_surface(current_data): +# index = slice_index(current_data) +# if direction == 'x': +# if index: +# return current_data.x[:, index], eta1(current_data)[:, index] +# else: +# return None +# elif direction == 'y': +# if index: +# return current_data.y[index, :], eta1(current_data)[index, :] +# else: +# return None + +# # Surfaces +# plotfigure = plotdata.new_plotfigure(name='combined_surface_%s' % figno, +# figno=figno) +# plotfigure.show = True +# plotfigure.kwargs = {'figsize': (6, 6)} + +# # Top surface +# plotaxes = plotfigure.new_plotaxes() +# plotaxes.axescmd = 'subplot(2,1,1)' +# plotaxes.title = 'Surfaces Profile %s at %s' % (direction, slice_value) +# if multilayer_data.init_type == 2: +# plotaxes.xlimits = xlimits +# elif multilayer_data.init_type == 6: +# plotaxes.xlimits = ylimits + +# plotaxes.ylimits = top_surf_zoomed + +# def top_surf_afteraxes(cd): +# axes = plt.gca() +# axes.set_xlabel('') +# locs, labels = plt.xticks() +# labels = ['' for i in range(len(locs))] +# plt.xticks(locs, labels) +# axes.plot([multilayer_data.bathy_location, +# multilayer_data.bathy_location], top_surf_zoomed, '--k') +# axes.set_ylabel('m') + +# plotaxes.afteraxes = top_surf_afteraxes +# plotitem = plotaxes.new_plotitem(plot_type="1d_from_2d_data") +# plotitem.map_2d_to_1d = upper_surface +# plotitem.amr_plotstyle = ['-', '+', 'x'] +# plotitem.show = True + +# # Internal surface +# plotaxes = plotfigure.new_plotaxes() +# plotaxes.axescmd = 'subplot(2,1,2)' +# plotaxes.title = '' +# if multilayer_data.init_type == 2: +# plotaxes.xlimits = xlimits +# elif multilayer_data.init_type == 6: +# plotaxes.xlimits = ylimits +# plotaxes.ylimits = bottom_surf_zoomed + +# def internal_surf_afteraxes(cd): +# axes = plt.gca() +# axes.set_title('') +# axes.set_ylabel('m') +# axes.subplots_adjust(hspace=0.05) +# axes.plot([multilayer_data.bathy_location, +# multilayer_data.bathy_location], bottom_surf_zoomed, '--k') +# plotaxes.afteraxes = internal_surf_afteraxes +# plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data') +# plotitem.map_2d_to_1d = lower_surface +# plotitem.amr_plotstyle = ['-', '+', 'x'] +# plotitem.color = 'k' +# plotitem.show = True + + +# def add_velocities_profile_plot(plot_data, slice_value, direction='x', +# figno=130): + +# def slice_index(cd): +# if cd.grid.y.lower < slice_value < cd.grid.y.upper: +# return int((slice_value - cd.grid.y.lower) / cd.dy - 0.5) +# else: +# return None + +# def upper_surface(current_data): +# index = slice_index(current_data) +# if index: +# return current_data.x[:, index], eta1(current_data)[:, index] +# else: +# return None + +# def top_speed(current_data): +# index = slice_index(current_data) +# if index: +# return current_data.x[:, index], water_u1(current_data)[:, index] +# else: +# return None, None + +# def bottom_speed(current_data): +# index = slice_index(current_data) +# if index: +# return current_data.x[:, index], water_u2(current_data)[:, index] +# else: +# return None, None + +# # Velocities +# plotfigure = plotdata.new_plotfigure(name='combined_velocities_%s' +# % figno, figno=figno) +# plotfigure.show = True + +# # Top surface +# plotaxes = plotfigure.new_plotaxes() +# plotaxes.title = 'Velocities Profile %s at %s' % (direction, slice_value) +# if multilayer_data.init_type == 2: +# plotaxes.xlimits = xlimits +# elif multilayer_data.init_type == 6: +# plotaxes.xlimits = ylimits +# plotaxes.ylimits = velocities_zoomed + +# def velocity_afteraxes(cd): +# axes = plt.gca() +# axes.set_xlabel('') +# locs, labels = plt.xticks() +# labels = ['' for i in range(len(locs))] +# plt.xticks(locs, labels) +# axes.plot([multilayer_data.bathy_location, +# multilayer_data.bathy_location], velocities_zoomed, '--k') +# axes.set_ylabel('m/s') +# plotaxes.afteraxes = lambda cd: velocity_afteraxes(cd, velocities_zoomed) + +# plotitem = plotaxes.new_plotitem(plot_type="1d_from_2d_data") +# plotitem.map_2d_to_1d = top_speed +# plotitem.amr_plotstyle = ['-', '+', 'x'] +# plotitem.show = True + +# plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data') +# plotitem.map_2d_to_1d = bottom_speed +# plotitem.amr_plotstyle = ['-', '+', 'x'] +# plotitem.color = 'k' +# plotitem.show = True diff --git a/src/python/geoclaw/surge/plot.py b/src/python/geoclaw/surge/plot.py index 254d74f7b..b8616a9d3 100644 --- a/src/python/geoclaw/surge/plot.py +++ b/src/python/geoclaw/surge/plot.py @@ -13,7 +13,7 @@ from __future__ import absolute_import from __future__ import print_function -import numpy as np +import numpy import matplotlib.pyplot as plt import matplotlib.colors as colors import matplotlib.lines as mlines @@ -50,7 +50,7 @@ def __init__(self, path=None): try: self._path = path - self._data = np.loadtxt(self._path) + self._data = numpy.loadtxt(self._path) except: self._data = None @@ -63,7 +63,7 @@ def get_track(self, frame): # If it appears that our data is not long enough, try reloading file if self._data.shape[0] < frame + 1: - self._data = np.loadtxt(self._path) + self._data = numpy.loadtxt(self._path) # Check to make sure that this fixed the problem if self._data.shape[0] < frame + 1: @@ -131,7 +131,7 @@ def surge_afteraxes(current_data, track, land_fall=0.0, plot_direction=False, axes.plot(track_data[0], track_data[1], style, **kwargs) if plot_direction: axes.quiver(track_data[0], track_data[1], - np.cos(track_data[2]), np.sin(track_data[2])) + numpy.cos(track_data[2]), numpy.sin(track_data[2])) days_figure_title(current_data, land_fall) @@ -150,7 +150,7 @@ def wind_y(cd): def wind_speed(cd): - return np.sqrt(wind_x(cd)**2 + wind_y(cd)**2) + return numpy.sqrt(wind_x(cd)**2 + wind_y(cd)**2) def pressure(cd): @@ -169,14 +169,14 @@ def b(cd): def extract_eta(h, eta, DRY_TOL=1e-3): - index = np.nonzero((np.abs(h) < DRY_TOL) + (h == np.nan)) - eta[index[0], index[1]] = np.nan + index = numpy.nonzero((numpy.abs(h) < DRY_TOL) + (h == numpy.nan)) + eta[index[0], index[1]] = numpy.nan return eta def extract_velocity(h, hu, DRY_TOL=1e-8): - u = np.zeros(hu.shape) - index = np.nonzero((np.abs(h) > DRY_TOL) * (h != np.nan)) + u = numpy.zeros(hu.shape) + index = numpy.nonzero((numpy.abs(h) > DRY_TOL) * (h != numpy.nan)) u[index[0], index[1]] = hu[index[0], index[1]] / h[index[0], index[1]] return u @@ -197,7 +197,7 @@ def water_speed(current_data): u = water_u(current_data) v = water_v(current_data) - return np.sqrt(u**2+v**2) + return numpy.sqrt(u**2+v**2) # ======================================================================== @@ -442,7 +442,7 @@ def plot_track(t, x, y, wind_radius, wind_speed, Pc, name=None): name = " - %s" % name colors = ['r', 'b'] - divide = (np.max(Pc) + np.min(Pc)) / 2.0 + divide = (numpy.max(Pc) + numpy.min(Pc)) / 2.0 fig = plt.figure(1) axes = fig.add_subplot(111) @@ -463,7 +463,7 @@ def plot_track(t, x, y, wind_radius, wind_speed, Pc, name=None): axes = fig.add_subplot(133) axes.plot(sec2days(t), Pc) - axes.plot(sec2days(t), np.ones(t.shape) * divide, 'k--') + axes.plot(sec2days(t), numpy.ones(t.shape) * divide, 'k--') axes.set_title("Central Pressure%s" % name) @@ -471,7 +471,7 @@ def plot_track(t, x, y, wind_radius, wind_speed, Pc, name=None): Easily plot the track and intensity of a storm using a mapping package. -:Input: +:Inumpyut: - *axes* (matplotlib.pyplot.axes) Axes to plot into. Default is *None* - *intensity* (bool) Plot the intensity of storm along the track. Defaults to *False*. @@ -524,7 +524,7 @@ def add_track(Storm, axes, plot_package=None, category_color=None, legend_loc='b categories_legend = [] - if intensity and categorization is "NHC": + if intensity and categorization == "NHC": categories_legend = [] # plotitem = plotaxes.new_plotitem(name='category', plot_type='1d_plot') diff --git a/src/python/geoclaw/surge/storm.py b/src/python/geoclaw/surge/storm.py index 077cc8a65..64f8e868d 100644 --- a/src/python/geoclaw/surge/storm.py +++ b/src/python/geoclaw/surge/storm.py @@ -981,33 +981,33 @@ def write_atcf(self, path, verbose=False): """ raise NotImplementedError(("Writing out ATCF files is not implemented ", "yet but is planned for a future release.")) - try: - with open(path, 'w') as data_file: - for n in range(len(self.t)): - data_file.write("".join((", " * 2, - "%s" % seconds2date(self.t[n]), - ", " * 4, - "%s" % (int(self.eye_location[n, 0] * - 10.0)), - ", ", - "%s" % (int(self.eye_location[n, 1] * - 10.0)), - ", ", - "%s" % self.max_wind_speed[n], - ", ", - "%s" % self.central_pressure[n], - ", ", - ", " * 8, - "%s" % self.storm_radius[n], - ", ", - "%s" % self.max_wind_radius[n], - ", " * 10, - "\n"))) - except Exception as e: - # Remove possiblly partially generated file if not successful - if os.path.exists(path): - os.remove(path) - raise e + # try: + # with open(path, 'w') as data_file: + # for n in range(len(self.t)): + # data_file.write("".join((", " * 2, + # "%s" % seconds2date(self.t[n]), + # ", " * 4, + # "%s" % (int(self.eye_location[n, 0] * + # 10.0)), + # ", ", + # "%s" % (int(self.eye_location[n, 1] * + # 10.0)), + # ", ", + # "%s" % self.max_wind_speed[n], + # ", ", + # "%s" % self.central_pressure[n], + # ", ", + # ", " * 8, + # "%s" % self.storm_radius[n], + # ", ", + # "%s" % self.max_wind_radius[n], + # ", " * 10, + # "\n"))) + # except Exception as e: + # # Remove possiblly partially generated file if not successful + # if os.path.exists(path): + # os.remove(path) + # raise e def write_hurdat(self, path, verbose=False): r"""Write out a HURDAT formatted storm file @@ -1019,50 +1019,50 @@ def write_hurdat(self, path, verbose=False): raise NotImplementedError(("Writing out hurdat files is not ", "implemented yet but is planned for a ", "future release.")) - try: - with open(path, 'w') as data_file: - data_file.write('%s %s %s' % ("Date", "Hurricane Name", - "Indicator")) - for n in range(self.t.shape[0]): - - latitude = float(self.eye_location[n, 0]) - longitude = float(self.eye_location[n, 1]) - - # Convert latitude to proper Hurdat format e.g 12.0N - if latitude > 0: - latitude = str(numpy.abs(latitude)) + 'N' - else: - latitude = str(numpy.abs(latitude)) + 'S' - - # Convert longitude to proper Hurdat format e.g 12.0W - if longitude > 0: - longitude = str(numpy.abs(longitude)) + 'E' - else: - longitude = str(numpy.abs(longitude)) + 'W' - - data_file.write("".join(("%s" % self.seconds2date( - self.t[n])[0:-2], - "%s00" % self.seconds2date( - self.t[n])[-2:], - ", " * 3, - "%s" % (latitude), - ", ", - "%s" % (longitude), - ", ", - "%s" % self.max_wind_speed[n], - ", ", - "%s" % self.central_pressure[n], - ", ", - "%s" % self.storm_radius[n], - ", ", - "%s" % self.max_wind_radius[n], - ", " * 10, - "\n"))) - except Exception as e: - # Remove possiblly partially generated file if not successful - if os.path.exists(path): - os.remove(path) - raise e + # try: + # with open(path, 'w') as data_file: + # data_file.write('%s %s %s' % ("Date", "Hurricane Name", + # "Indicator")) + # for n in range(self.t.shape[0]): + + # latitude = float(self.eye_location[n, 0]) + # longitude = float(self.eye_location[n, 1]) + + # # Convert latitude to proper Hurdat format e.g 12.0N + # if latitude > 0: + # latitude = str(numpy.abs(latitude)) + 'N' + # else: + # latitude = str(numpy.abs(latitude)) + 'S' + + # # Convert longitude to proper Hurdat format e.g 12.0W + # if longitude > 0: + # longitude = str(numpy.abs(longitude)) + 'E' + # else: + # longitude = str(numpy.abs(longitude)) + 'W' + + # data_file.write("".join(("%s" % self.seconds2date( + # self.t[n])[0:-2], + # "%s00" % self.seconds2date( + # self.t[n])[-2:], + # ", " * 3, + # "%s" % (latitude), + # ", ", + # "%s" % (longitude), + # ", ", + # "%s" % self.max_wind_speed[n], + # ", ", + # "%s" % self.central_pressure[n], + # ", ", + # "%s" % self.storm_radius[n], + # ", ", + # "%s" % self.max_wind_radius[n], + # ", " * 10, + # "\n"))) + # except Exception as e: + # # Remove possiblly partially generated file if not successful + # if os.path.exists(path): + # os.remove(path) + # raise e def write_jma(self, path, verbose=False): r"""Write out a JMA formatted storm file @@ -1073,32 +1073,32 @@ def write_jma(self, path, verbose=False): """ raise NotImplementedError(("Writing out JMA files is not implemented ", "yet but is planned for a future release.")) - try: - with open(path, 'w') as data_file: - for n in range(self.t.shape[0]): - data_file.write("".join(("%s" % self.seconds2date(self.t[n]), - " " * 4, - "%s" % (int(self.eye_location[n, 0] * - 10.0)), - ", ", - "%s" % (int(self.eye_location[n, 1] * - 10.0)), - ", ", - "%s" % self.max_wind_speed[n], - ", ", - "%s" % self.central_pressure[n], - ", ", - ", " * 8, - "%s" % self.storm_radius[n], - ", ", - "%s" % self.max_wind_radius[n], - ", " * 10, - "\n"))) - except Exception as e: - # Remove possiblly partially generated file if not successful - if os.path.exists(path): - os.remove(path) - raise e + # try: + # with open(path, 'w') as data_file: + # for n in range(self.t.shape[0]): + # data_file.write("".join(("%s" % self.seconds2date(self.t[n]), + # " " * 4, + # "%s" % (int(self.eye_location[n, 0] * + # 10.0)), + # ", ", + # "%s" % (int(self.eye_location[n, 1] * + # 10.0)), + # ", ", + # "%s" % self.max_wind_speed[n], + # ", ", + # "%s" % self.central_pressure[n], + # ", ", + # ", " * 8, + # "%s" % self.storm_radius[n], + # ", ", + # "%s" % self.max_wind_radius[n], + # ", " * 10, + # "\n"))) + # except Exception as e: + # # Remove possiblly partially generated file if not successful + # if os.path.exists(path): + # os.remove(path) + # raise e def write_imd(self, path, verbose=False): r"""Write out an IMD formatted storm file @@ -1242,7 +1242,7 @@ def construct_fields(storm, r, t, model="holland_1980"): if model.lower() not in _supported_models.keys(): raise ValueError("Model %s not available." % model) - return getattr(sys.modules[__name__], model.lower())(storm, x, t) + return getattr(sys.modules[__name__], model.lower())(storm, r, t) # Specific implementations @@ -1383,12 +1383,15 @@ def available_models(): def make_multi_structure(path): r"""Create a dictionary of Storm objects for ATCF files with multiple storm tracks in them """ + raise NotImplementedError("Extracing multiple tracks from ATCF files is " + + "not supported yet.") with open(path, 'r') as f: lines = f.readlines() curTime = "test" curTrack = "test" os.mkdir("Clipped_ATCFs") stormDict = {} + fileWrite = None for line in lines: lineArr = line.split(", ") if curTime in lineArr[2]: diff --git a/src/python/geoclaw/topotools.py b/src/python/geoclaw/topotools.py index 1743e1ae6..ad3a8911a 100644 --- a/src/python/geoclaw/topotools.py +++ b/src/python/geoclaw/topotools.py @@ -931,7 +931,7 @@ def read_header(self): raise e data = gdal.Open(self.path) - # z = data.GetRasterBand(1).ReadAsArray() + z = data.GetRasterBand(1).ReadAsArray() transform = data.GetGeoTransform() x_origin = transform[0] y_origin = transform[3] @@ -940,9 +940,9 @@ def read_header(self): # self._Z = numpy.flipud(z) self._x = numpy.linspace(x_origin, - x_origin + (z.shape[0] - 1) * dx, z.shape[0]) + x_origin + (z.shape[0] - 1) * dx, z.shape[0]) self._y = numpy.linspace(y_origin - (z.shape[0] - 1) * dy, - y_origin, z.shape[1]) + y_origin, z.shape[1]) else: raise IOError("Cannot read header for topo_type %s" % self.topo_type) diff --git a/tests/multilayer/setplot.py b/tests/multilayer/setplot.py index eee13adeb..2f45e2966 100644 --- a/tests/multilayer/setplot.py +++ b/tests/multilayer/setplot.py @@ -82,17 +82,6 @@ def transform_p2c(x, y, x0, y0, theta): def pcolor_afteraxes(current_data): bathy_ref_lines(current_data) - def contour_afteraxes(current_data): - axes = plt.gca() - pos = -80.0 * (23e3 / 180) + 500e3 - 5e3 - axes.plot([pos, pos], [-300e3, 300e3], 'b', - [pos-5e3, pos-5e3], [-300e3, 300e3], 'y') - wind_contours(current_data) - bathy_ref_lines(current_data) - - def profile_afteraxes(current_data): - pass - def bathy_ref_lines(current_data): axes = plt.gca() for ref_line in ref_lines: @@ -128,8 +117,6 @@ def bathy_ref_lines(current_data): plotaxes.ylimits = ylimits plotaxes.afteraxes = pcolor_afteraxes ml_plot.add_surface_elevation(plotaxes,1,bounds=top_surface_limits) - # ml_plot.add_surface_elevation(plotaxes,1,bounds=[-0.06,0.06]) - # ml_plot.add_surface_elevation(plotaxes,1) ml_plot.add_land(plotaxes, 1) # Bottom surface @@ -140,38 +127,7 @@ def bathy_ref_lines(current_data): plotaxes.xlimits = xlimits plotaxes.ylimits = ylimits plotaxes.afteraxes = pcolor_afteraxes - # ml_plot.add_surface_elevation(plotaxes,2,bounds=[-300-0.5,-300+0.5]) ml_plot.add_surface_elevation(plotaxes,2,bounds=internal_surface_limits) - # ml_plot.add_surface_elevation(plotaxes,2) - ml_plot.add_land(plotaxes, 2) - - # ======================================================================== - # Depths - # ======================================================================== - plotfigure = plotdata.new_plotfigure(name='Depths', figno=42) - plotfigure.show = False - plotfigure.kwargs = {'figsize':(14,4)} - - # Top surface - plotaxes = plotfigure.new_plotaxes() - plotaxes.title = 'Top Layer Depth' - plotaxes.axescmd = 'subplot(1,2,1)' - plotaxes.scaled = True - plotaxes.xlimits = xlimits - plotaxes.ylimits = ylimits - plotaxes.afteraxes = pcolor_afteraxes - ml_plot.add_layer_depth(plotaxes,1,bounds=[-0.1,1.1]) - ml_plot.add_land(plotaxes, 1) - - # Bottom surface - plotaxes = plotfigure.new_plotaxes() - plotaxes.title = 'Bottom Layer Depth' - plotaxes.axescmd = 'subplot(1,2,2)' - plotaxes.scaled = True - plotaxes.xlimits = xlimits - plotaxes.ylimits = ylimits - plotaxes.afteraxes = pcolor_afteraxes - ml_plot.add_layer_depth(plotaxes,2,bounds=[-0.1,0.7]) ml_plot.add_land(plotaxes, 2) # ======================================================================== @@ -199,233 +155,8 @@ def bathy_ref_lines(current_data): plotaxes.ylimits = ylimits plotaxes.axescmd = 'subplot(1,2,2)' plotaxes.afteraxes = pcolor_afteraxes - # add_speed(plotaxes,2,bounds=[0.0,1e-10]) ml_plot.add_speed(plotaxes,2,bounds=internal_speed_limits) - # add_speed(plotaxes,2) - ml_plot.add_land(plotaxes, 2) - - # Individual components - plotfigure = plotdata.new_plotfigure(name='speed_components',figno=401) - plotfigure.show = False - plotfigure.kwargs = {'figsize':(14,14)} - - # Top layer - plotaxes = plotfigure.new_plotaxes() - plotaxes.title = "X-Velocity - Top Layer" - plotaxes.scaled = True - plotaxes.xlimits = xlimits - plotaxes.ylimits = ylimits - plotaxes.axescmd = 'subplot(2,2,1)' - plotaxes.afteraxes = pcolor_afteraxes - # add_x_velocity(plotaxes,1,bounds=[-1e-10,1e-10]) - ml_plot.add_x_velocity(plotaxes,1) - ml_plot.add_land(plotaxes, 1) - - plotaxes = plotfigure.new_plotaxes() - plotaxes.title = "Y-Velocity - Top Layer" - plotaxes.scaled = True - plotaxes.xlimits = xlimits - plotaxes.ylimits = ylimits - plotaxes.axescmd = 'subplot(2,2,2)' - plotaxes.afteraxes = pcolor_afteraxes - # add_y_velocity(plotaxes,1,bounds=[-0.000125,0.000125]) - ml_plot.add_y_velocity(plotaxes,1) - ml_plot.add_land(plotaxes, 1) - - # Bottom layer - plotaxes = plotfigure.new_plotaxes() - plotaxes.title = "X-Velocity - Bottom Layer" - plotaxes.scaled = True - plotaxes.xlimits = xlimits - plotaxes.ylimits = ylimits - plotaxes.axescmd = 'subplot(2,2,3)' - plotaxes.afteraxes = pcolor_afteraxes - # add_x_velocity(plotaxes,2,bounds=[-1e-10,1e-10]) - ml_plot.add_x_velocity(plotaxes,2) - ml_plot.add_land(plotaxes, 2) - - plotaxes = plotfigure.new_plotaxes() - plotaxes.title = "Y-Velocity - Bottom Layer" - plotaxes.scaled = True - plotaxes.xlimits = xlimits - plotaxes.ylimits = ylimits - plotaxes.axescmd = 'subplot(2,2,4)' - plotaxes.afteraxes = pcolor_afteraxes - # add_y_velocity(plotaxes,2,bounds=[-0.8e-6,.8e-6]) - ml_plot.add_y_velocity(plotaxes,2) - ml_plot.add_land(plotaxes, 2) - # ======================================================================== - # Profile Plots - # Note that these are not currently plotted by default - set - # `plotfigure.show = True` is you want this to be plotted - plotfigure = plotdata.new_plotfigure(name='profile') - plotfigure.show = False - - # Top surface - plotaxes = plotfigure.new_plotaxes() - plotaxes.xlimits = xlimits - plotaxes.ylimits = [-1.1, 0.1] - plotaxes.title = "Profile of depth" - plotaxes.afteraxes = profile_afteraxes - - slice_index = 30 - - # Internal surface - def bathy_profile(current_data): - return current_data.x[:, slice_index], b(current_data)[:, slice_index] - - def lower_surface(current_data): - if multilayer_data.init_type == 2: - return current_data.x[:, slice_index], \ - eta2(current_data)[:, slice_index] - elif multilayer_data.init_type == 6: - return current_data.y[slice_index, :], \ - eta2(current_data)[slice_index, :] - - def upper_surface(current_data): - if multilayer_data.init_type == 2: - return current_data.x[:, slice_index], \ - eta1(current_data)[:, slice_index] - elif multilayer_data.init_type == 6: - return current_data.y[slice_index, :], \ - eta1(current_data)[slice_index, :] - - def top_speed(current_data): - if multilayer_data.init_type == 2: - return current_data.x[:, slice_index], \ - water_u1(current_data)[:, slice_index] - elif multilayer_data.init_type == 6: - return current_data.y[slice_index, :], \ - water_u1(current_data)[slice_index, :] - - def bottom_speed(current_data): - if multilayer_data.init_type == 2: - return current_data.x[:, slice_index], \ - water_u2(current_data)[:, slice_index] - elif multilayer_data.init_type == 6: - return current_data.y[slice_index, :], \ - water_u2(current_data)[slice_index, :] - - # Bathy - plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data') - plotitem.map_2d_to_1d = bathy_profile - plotitem.plot_var = 0 - plotitem.amr_plotstyle = ['-', '+', 'x'] - plotitem.color = 'k' - plotitem.show = True - - # Internal Interface - plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data') - plotitem.map_2d_to_1d = lower_surface - plotitem.plot_var = 7 - plotitem.amr_plotstyle = ['-', '+', 'x'] - plotitem.color = 'b' - plotitem.show = True - - # Upper Interface - plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data') - plotitem.map_2d_to_1d = upper_surface - plotitem.plot_var = 6 - plotitem.amr_plotstyle = ['-', '+', 'x'] - plotitem.color = (0.2, 0.8, 1.0) - plotitem.show = True - - # Set up for axes in this figure: - plotaxes = plotfigure.new_plotaxes() - plotaxes.title = 'Y-Velocity' - plotaxes.scaled = True - plotaxes.xlimits = xlimits - plotaxes.ylimits = ylimits - plotaxes.afteraxes = pcolor_afteraxes - - # Water - # plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor') - # # plotitem.plot_var = geoplot.surface - # plotitem.plot_var = water_v - # plotitem.pcolor_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'}) - # # plotitem.pcolor_cmin = -1.e-10 - # # plotitem.pcolor_cmax = 1.e-10 - # # plotitem.pcolor_cmin = -2.5 # -3.0 - # # plotitem.pcolor_cmax = 2.5 # 3.0 - # plotitem.add_colorbar = True - # plotitem.amr_celledges_show = [0,0,0] - # plotitem.amr_patchedges_show = [1,1,1] - - # Land - ml_plot.add_land(plotaxes, 1) - - # ======================================================================== - # Contour plot for surface - # ======================================================================== - plotfigure = plotdata.new_plotfigure(name='contour_surface',figno=15) - plotfigure.show = False - plotfigure.kwargs = {'figsize':(14,4)} - - # Set up for axes in this figure: - - # Top Surface - plotaxes = plotfigure.new_plotaxes() - plotaxes.title = 'Top Surface' - plotaxes.axescmd = 'subplot(1,2,1)' - plotaxes.scaled = True - plotaxes.xlimits = xlimits - plotaxes.ylimits = ylimits - plotaxes.afteraxes = contour_afteraxes - ml_plot.add_surface_elevation(plotaxes,plot_type='contour',surface=1,bounds=[-2.5,-1.5,-0.5,0.5,1.5,2.5]) - ml_plot.add_land(plotaxes, 1, plot_type='contour') - - # Internal Surface - plotaxes = plotfigure.new_plotaxes() - plotaxes.title = 'Internal Surface' - plotaxes.axescmd = 'subplot(1,2,2)' - plotaxes.scaled = True - plotaxes.xlimits = xlimits - plotaxes.ylimits = ylimits - plotaxes.afteraxes = contour_afteraxes - ml_plot.add_surface_elevation(plotaxes,plot_type='contour',surface=2,bounds=[-2.5,-1.5,-0.5,0.5,1.5,2.5]) - ml_plot.add_land(plotaxes, 2, plot_type='contour') - - # ======================================================================== - # Contour plot for speed - # ======================================================================== - plotfigure = plotdata.new_plotfigure(name='contour_speed',figno=16) - plotfigure.show = False - plotfigure.kwargs = {'figsize':(14,4)} - - # Set up for axes in this figure: - plotaxes = plotfigure.new_plotaxes() - plotaxes.title = 'Current' - plotaxes.scaled = True - plotaxes.xlimits = xlimits - plotaxes.ylimits = ylimits - plotaxes.afteraxes = contour_afteraxes - - # Surface - plotitem = plotaxes.new_plotitem(plot_type='2d_contour') - plotitem.plot_var = ml_plot.water_speed_depth_ave - plotitem.kwargs = {'linewidths':1} - # plotitem.contour_levels = [1.0,2.0,3.0,4.0,5.0,6.0] - plotitem.contour_levels = [0.5,1.5,3,4.5,6.0] - plotitem.amr_contour_show = [1,1,1] - plotitem.amr_celledges_show = [0,0,0] - plotitem.amr_patchedges_show = [1,1,1] - plotitem.amr_contour_colors = 'k' - # plotitem.amr_contour_colors = ['r','k','b'] # color on each level - # plotitem.amr_grid_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee'] - plotitem.show = True - - # Land - plotitem = plotaxes.new_plotitem(plot_type='2d_contour') - plotitem.plot_var = geoplot.land - plotitem.contour_nlevels = 40 - plotitem.contour_min = 0.0 - plotitem.contour_max = 100.0 - plotitem.amr_contour_colors = ['g'] # color on each level - plotitem.amr_patch_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee'] - plotitem.amr_celledges_show = 0 - plotitem.amr_patchedges_show = 0 - plotitem.show = True # ======================================================================== # Grid Cells @@ -446,40 +177,6 @@ def bottom_speed(current_data): plotitem.amr_patch_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee'] plotitem.amr_celledges_show = [1,1,1] plotitem.amr_patchedges_show = [1,1,1] - - # ======================================================================== - # Vorticity Plot - # ======================================================================== - # plotfigure = plotdata.new_plotfigure(name='vorticity',figno=17) - # plotfigure.show = False - # plotaxes = plotfigure.new_plotaxes() - # plotaxes.title = "Vorticity" - # plotaxes.scaled = True - # plotaxes.xlimits = xlimits - # plotaxes.ylimits = ylimits - # plotaxes.afteraxes = pcolor_afteraxes - # - # # Vorticity - # plotitem = plotaxes.new_plotitem(plot_type='2d_imshow') - # plotitem.plot_var = 9 - # plotitem.imshow_cmap = plt.get_cmap('PRGn') - # # plotitem.pcolor_cmap = plt.get_cmap('PuBu') - # # plotitem.pcolor_cmin = 0.0 - # # plotitem.pcolor_cmax = 6.0 - # plotitem.imshow_cmin = -1.e-2 - # plotitem.imshow_cmax = 1.e-2 - # plotitem.add_colorbar = True - # plotitem.amr_celledges_show = [0,0,0] - # plotitem.amr_patchedges_show = [1] - # - # # Land - # plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor') - # plotitem.plot_var = geoplot.land - # plotitem.pcolor_cmap = geoplot.land_colors - # plotitem.pcolor_cmin = 0.0 - # plotitem.pcolor_cmax = 80.0 - # plotitem.add_colorbar = False - # plotitem.amr_celledges_show = [0,0,0] # ======================================================================== # Figures for gauges diff --git a/tests/netcdf_topo/test_netcdf.py b/tests/netcdf_topo/test_netcdf.py index e673003b4..f26eda5a4 100644 --- a/tests/netcdf_topo/test_netcdf.py +++ b/tests/netcdf_topo/test_netcdf.py @@ -106,7 +106,7 @@ def build_executable(self): stdout=self.stdout, stderr=self.stderr, shell=True) - except subprocess.CalledProcessError: + except subprocess.CalledProcessError as e: self.stdout.write(build_failure_str) pytest.skip(build_failure_str) raise e diff --git a/tests/test_storm.py b/tests/test_storm.py index 6e948f815..2ee368513 100644 --- a/tests/test_storm.py +++ b/tests/test_storm.py @@ -44,6 +44,7 @@ def check_geoclaw(paths, check_header=False): """ if check_header: + data_file = [None, None] with open(paths[0], 'r') as data_file[0], open(paths[1], 'r') as data_file[1]: # Check for number of lines assert(int(data_file[0].readline()) == int(data_file[1].readline())) From ecc66c5caf1a16bf462a55105f0cf32e58c019a5 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 13:55:05 -0400 Subject: [PATCH 05/39] Fix git branch checkout reference --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index bcecab2f2..44ef02cf2 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -37,7 +37,7 @@ jobs: - name: Setup geoclaw run: | cd geoclaw - git checkout ${{ github.ref }} + git checkout ${GITHUB_HEAD_REF} - name: Lint with flake8 run: | cd geoclaw From a909c0b30d01173df3111d8c578f3ddf2948d19d Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 13:58:14 -0400 Subject: [PATCH 06/39] Add tests badge to readme --- README.md | 6 ++++++ README.txt | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 README.md delete mode 100644 README.txt diff --git a/README.md b/README.md new file mode 100644 index 000000000..0112a6a32 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# GeoClaw - Geophysical Shallow Flow Package + +[![Test GeoClaw](https://github.com/clawpack/geoclaw/actions/workflows/testing.yml/badge.svg)](https://github.com/clawpack/geoclaw/actions/workflows/testing.yml) + +This repository hosts the source code for GeoClaw. + diff --git a/README.txt b/README.txt deleted file mode 100644 index cbfb9ef1a..000000000 --- a/README.txt +++ /dev/null @@ -1 +0,0 @@ -This repository will host the GeoClaw code. From 1ad18dbddfa55d8818316fb792e0af19f2a62421 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 14:00:36 -0400 Subject: [PATCH 07/39] Try another variable for checkout --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 44ef02cf2..0fbe854ce 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -37,7 +37,7 @@ jobs: - name: Setup geoclaw run: | cd geoclaw - git checkout ${GITHUB_HEAD_REF} + git checkout ${GITHUB_REF} - name: Lint with flake8 run: | cd geoclaw From d0bb3a666fe78d70c02f0a4d1b54e47fafabbe34 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 14:17:06 -0400 Subject: [PATCH 08/39] Try to use checkout default action --- .github/workflows/testing.yml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 0fbe854ce..dd12be14b 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -19,25 +19,28 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.10" - - name: Checkout clawpack - uses: actions/checkout@v4.1.5 - with: - repository: clawpack/clawpack + cache: 'pip' - name: Install dependencies run: | sudo apt-get update sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev python -m pip install --upgrade pip pip install flake8 pytest - - name: Setup clawpack super repository + - name: Checkout clawpack + uses: actions/checkout@v4.1.5 + with: + repository: clawpack/clawpack + - name: Setup clawpack repository run: | git submodule init git submodule update - pip install --user -e . - - name: Setup geoclaw + - name: Checkout geoclaw branch + uses: actions/checkout@v4.1.5 + with: + repository: clawpack/geoclaw + - name: Install clawpack run: | - cd geoclaw - git checkout ${GITHUB_REF} + pip install --user -e . - name: Lint with flake8 run: | cd geoclaw @@ -47,5 +50,5 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | - cd geoclaw + export CLAW=${GITHUB_WORKSPACE}/clawpack pytest From 28a9924faa11c9500d2c4633c02cdfeaecbbe29a Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 15:26:02 -0400 Subject: [PATCH 09/39] Remove caching --- .github/workflows/testing.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index dd12be14b..3a35f158c 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -19,7 +19,6 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.10" - cache: 'pip' - name: Install dependencies run: | sudo apt-get update From 929c2e01ddfd469d90742067eb3d16687784c425 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 15:29:13 -0400 Subject: [PATCH 10/39] Add explicit pathing --- .github/workflows/testing.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 3a35f158c..8e641d420 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -25,12 +25,14 @@ jobs: sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev python -m pip install --upgrade pip pip install flake8 pytest + - name: Checkout clawpack uses: actions/checkout@v4.1.5 with: repository: clawpack/clawpack - name: Setup clawpack repository run: | + export CLAW=${GITHUB_WORKSPACE}/clawpack git submodule init git submodule update - name: Checkout geoclaw branch @@ -39,15 +41,17 @@ jobs: repository: clawpack/geoclaw - name: Install clawpack run: | + git log + cd ${CLAW} pip install --user -e . - name: Lint with flake8 run: | - cd geoclaw + cd ${CLAW}/geoclaw # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude old_dtopotools.py # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | - export CLAW=${GITHUB_WORKSPACE}/clawpack + cd ${CLAW}/geoclaw pytest From 55db9eed900c71c88b27cbee27e55d5dd7dab0eb Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 15:32:29 -0400 Subject: [PATCH 11/39] Add more explicit pathing --- .github/workflows/testing.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 8e641d420..8707d40ea 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -30,11 +30,14 @@ jobs: uses: actions/checkout@v4.1.5 with: repository: clawpack/clawpack + - name: Setup clawpack repository run: | export CLAW=${GITHUB_WORKSPACE}/clawpack + printenv ${CLAW} git submodule init git submodule update + - name: Checkout geoclaw branch uses: actions/checkout@v4.1.5 with: @@ -43,7 +46,8 @@ jobs: run: | git log cd ${CLAW} - pip install --user -e . + pip install --user -e ${CLAW} + - name: Lint with flake8 run: | cd ${CLAW}/geoclaw From b2c2a9e7f011c8b30de91bf557e2c86804dbab38 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 15:34:36 -0400 Subject: [PATCH 12/39] Add more explicit pathing --- .github/workflows/testing.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 8707d40ea..3e5d41c32 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -34,7 +34,7 @@ jobs: - name: Setup clawpack repository run: | export CLAW=${GITHUB_WORKSPACE}/clawpack - printenv ${CLAW} + printenv $CLAW git submodule init git submodule update @@ -45,9 +45,9 @@ jobs: - name: Install clawpack run: | git log - cd ${CLAW} - pip install --user -e ${CLAW} - + cd $CLAW + pip install --user -e $CLAW + - name: Lint with flake8 run: | cd ${CLAW}/geoclaw From 15da52a8c4657e6f34d0e45eadcb965aa686bf2c Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 15:37:11 -0400 Subject: [PATCH 13/39] Add more explicit pathing --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 3e5d41c32..210df4183 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -33,7 +33,7 @@ jobs: - name: Setup clawpack repository run: | - export CLAW=${GITHUB_WORKSPACE}/clawpack + export CLAW="${GITHUB_WORKSPACE}/clawpack" printenv $CLAW git submodule init git submodule update From 3c870bfea6883a1e8e681460aeec03e9562cdab0 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 16:12:59 -0400 Subject: [PATCH 14/39] Modify testing action --- .github/workflows/testing.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 210df4183..f6e6b30df 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -19,6 +19,7 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.10" + - name: Install dependencies run: | sudo apt-get update @@ -33,8 +34,6 @@ jobs: - name: Setup clawpack repository run: | - export CLAW="${GITHUB_WORKSPACE}/clawpack" - printenv $CLAW git submodule init git submodule update @@ -59,3 +58,6 @@ jobs: run: | cd ${CLAW}/geoclaw pytest + +# export CLAW="${GITHUB_WORKSPACE}/clawpack" + # printenv $CLAW \ No newline at end of file From 67e15cc4e067577de92a5f8f1ca95321e4d96a05 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 16:16:44 -0400 Subject: [PATCH 15/39] Modify testing action --- .github/workflows/testing.yml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index f6e6b30df..d0b279d4c 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -9,6 +9,9 @@ on: permissions: contents: read +env: + CLAW: ${GITHUB_WORKSPACE}/clawpack + jobs: build: @@ -19,7 +22,6 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.10" - - name: Install dependencies run: | sudo apt-get update @@ -31,19 +33,17 @@ jobs: uses: actions/checkout@v4.1.5 with: repository: clawpack/clawpack - - - name: Setup clawpack repository + - name: Setup clawpack subrepositories run: | git submodule init git submodule update - - name: Checkout geoclaw branch uses: actions/checkout@v4.1.5 with: repository: clawpack/geoclaw + - name: Install clawpack run: | - git log cd $CLAW pip install --user -e $CLAW @@ -58,6 +58,3 @@ jobs: run: | cd ${CLAW}/geoclaw pytest - -# export CLAW="${GITHUB_WORKSPACE}/clawpack" - # printenv $CLAW \ No newline at end of file From e3e83780e1a6120a2bec68fe36fe54ff0417fcc7 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 16:18:45 -0400 Subject: [PATCH 16/39] Modify testing action --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index d0b279d4c..a781f1efb 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -43,7 +43,7 @@ jobs: repository: clawpack/geoclaw - name: Install clawpack - run: | + run: env cd $CLAW pip install --user -e $CLAW From 6abcaa86c082b3a256c7d90b0962a2a3e3839f72 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 16:24:34 -0400 Subject: [PATCH 17/39] Modify testing action --- .github/workflows/testing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index a781f1efb..b9ea1f838 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -10,7 +10,7 @@ permissions: contents: read env: - CLAW: ${GITHUB_WORKSPACE}/clawpack + CLAW: ${{ github.GITHUB_WORKSPACE }}/clawpack jobs: build: @@ -43,7 +43,7 @@ jobs: repository: clawpack/geoclaw - name: Install clawpack - run: env + run: | cd $CLAW pip install --user -e $CLAW From 5f226530fdf98b7f06869a9e8a19cf79f07bc232 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 16:30:26 -0400 Subject: [PATCH 18/39] Modify testing action --- .github/workflows/testing.yml | 52 +++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index b9ea1f838..af182e21f 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -11,24 +11,30 @@ permissions: env: CLAW: ${{ github.GITHUB_WORKSPACE }}/clawpack + TEST: $GITHUB_WORKSPACE/clawpack jobs: build: runs-on: ubuntu-latest - steps: - - name: Set up Python 3.10 - uses: actions/setup-python@v5 - with: - python-version: "3.10" - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev - python -m pip install --upgrade pip - pip install flake8 pytest + # steps: + # - name: Set up Python 3.10 + # uses: actions/setup-python@v5 + # with: + # python-version: "3.10" + # - name: Install dependencies + # run: | + # sudo apt-get update + # sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev + # python -m pip install --upgrade pip + # pip install flake8 pytest + - name: Testing + run: env | + echo $GITHUB_WORKSPACE + echo $CLAW + echo $TEST - name: Checkout clawpack uses: actions/checkout@v4.1.5 with: @@ -45,16 +51,16 @@ jobs: - name: Install clawpack run: | cd $CLAW - pip install --user -e $CLAW + # pip install --user -e $CLAW - - name: Lint with flake8 - run: | - cd ${CLAW}/geoclaw - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude old_dtopotools.py - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest - run: | - cd ${CLAW}/geoclaw - pytest + # - name: Lint with flake8 + # run: | + # cd ${CLAW}/geoclaw + # # stop the build if there are Python syntax errors or undefined names + # flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude old_dtopotools.py + # # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + # - name: Test with pytest + # run: | + # cd ${CLAW}/geoclaw + # pytest From b8990da3c4b05e7ffcdc412536a554ee6a86657d Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 16:38:33 -0400 Subject: [PATCH 19/39] Modify testing action --- .github/workflows/testing.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index af182e21f..73b63203a 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -15,10 +15,8 @@ env: jobs: build: - runs-on: ubuntu-latest - - # steps: + steps: # - name: Set up Python 3.10 # uses: actions/setup-python@v5 # with: @@ -35,6 +33,7 @@ jobs: echo $GITHUB_WORKSPACE echo $CLAW echo $TEST + - name: Checkout clawpack uses: actions/checkout@v4.1.5 with: @@ -53,6 +52,8 @@ jobs: cd $CLAW # pip install --user -e $CLAW + + # - name: Lint with flake8 # run: | # cd ${CLAW}/geoclaw From 803a00b4eb98913f926b3fb2583d74817c01cd92 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 16:41:25 -0400 Subject: [PATCH 20/39] Modify testing action --- .github/workflows/testing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 73b63203a..8a27563d8 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -29,11 +29,11 @@ jobs: # pip install flake8 pytest - name: Testing - run: env | + run: | echo $GITHUB_WORKSPACE echo $CLAW echo $TEST - + - name: Checkout clawpack uses: actions/checkout@v4.1.5 with: From 84c0b3787bbe5a2a4aa90a949e345c90d9b535ee Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 16:46:03 -0400 Subject: [PATCH 21/39] Modify testing action --- .github/workflows/testing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 8a27563d8..cc2f16ce0 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -10,8 +10,7 @@ permissions: contents: read env: - CLAW: ${{ github.GITHUB_WORKSPACE }}/clawpack - TEST: $GITHUB_WORKSPACE/clawpack + TEST: ${{ github.workspace }} jobs: build: @@ -31,6 +30,7 @@ jobs: - name: Testing run: | echo $GITHUB_WORKSPACE + export CLAW="$GITHUB_WORKSPACE/clawpack" echo $CLAW echo $TEST From aea30729b535d0677db3b7477d9f700be0bfce28 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 16:47:58 -0400 Subject: [PATCH 22/39] Modify testing action --- .github/workflows/testing.yml | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index cc2f16ce0..536dd4b8e 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -10,29 +10,28 @@ permissions: contents: read env: - TEST: ${{ github.workspace }} + CLAW: ${{ github.workspace }}/clawpack jobs: build: runs-on: ubuntu-latest steps: - # - name: Set up Python 3.10 - # uses: actions/setup-python@v5 - # with: - # python-version: "3.10" - # - name: Install dependencies - # run: | - # sudo apt-get update - # sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev - # python -m pip install --upgrade pip - # pip install flake8 pytest - - name: Testing + - name: Set up Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: Install dependencies run: | - echo $GITHUB_WORKSPACE - export CLAW="$GITHUB_WORKSPACE/clawpack" + sudo apt-get update + sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev + python -m pip install --upgrade pip + pip install flake8 pytest + + # - name: Testing + # run: | + # echo $GITHUB_WORKSPACE echo $CLAW - echo $TEST - name: Checkout clawpack uses: actions/checkout@v4.1.5 @@ -50,9 +49,7 @@ jobs: - name: Install clawpack run: | cd $CLAW - # pip install --user -e $CLAW - - + pip install --user -e $CLAW # - name: Lint with flake8 # run: | From 9ce11ad1703e98a1b33461139f8871da19eaf687 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 16:49:01 -0400 Subject: [PATCH 23/39] Modify testing action --- .github/workflows/testing.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 536dd4b8e..296146e69 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -16,7 +16,6 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Set up Python 3.10 uses: actions/setup-python@v5 with: @@ -28,9 +27,9 @@ jobs: python -m pip install --upgrade pip pip install flake8 pytest - # - name: Testing - # run: | - # echo $GITHUB_WORKSPACE + - name: Testing + run: | + echo $GITHUB_WORKSPACE echo $CLAW - name: Checkout clawpack From 82cb14708f68a4cf432024829212a119cd4e6d83 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 16:51:31 -0400 Subject: [PATCH 24/39] Modify testing action --- .github/workflows/testing.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 296146e69..58c2e820f 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -47,7 +47,9 @@ jobs: - name: Install clawpack run: | + ls -l cd $CLAW + ls -l pip install --user -e $CLAW # - name: Lint with flake8 From fd67ed59b01cee62ae7213b9a97e966882426626 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 16:54:01 -0400 Subject: [PATCH 25/39] Modify testing action --- .github/workflows/testing.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 58c2e820f..ab58dfb14 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -48,9 +48,11 @@ jobs: - name: Install clawpack run: | ls -l - cd $CLAW - ls -l - pip install --user -e $CLAW + + # cd $CLAW + # ls -l + + # pip install --user -e $CLAW # - name: Lint with flake8 # run: | From 56643804ba407b93191c328440ada89beb2ba56c Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 16:56:05 -0400 Subject: [PATCH 26/39] Modify testing action --- .github/workflows/testing.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index ab58dfb14..cfb5421b2 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -10,7 +10,7 @@ permissions: contents: read env: - CLAW: ${{ github.workspace }}/clawpack + CLAW: ${{ github.workspace }} jobs: build: @@ -48,7 +48,9 @@ jobs: - name: Install clawpack run: | ls -l - + cd $CLAW + ls -l + # cd $CLAW # ls -l From b80dc774437084a6c3d7950cb3540a8d57520d5b Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 16:57:07 -0400 Subject: [PATCH 27/39] Modify testing action --- .github/workflows/testing.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index cfb5421b2..9dec36a7f 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -40,10 +40,10 @@ jobs: run: | git submodule init git submodule update - - name: Checkout geoclaw branch - uses: actions/checkout@v4.1.5 - with: - repository: clawpack/geoclaw + # - name: Checkout geoclaw branch + # uses: actions/checkout@v4.1.5 + # with: + # repository: clawpack/geoclaw - name: Install clawpack run: | From 7f4223f917f8465ee01fdea46aeff6bf1549b171 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 17:01:10 -0400 Subject: [PATCH 28/39] Modify testing action --- .github/workflows/testing.yml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 9dec36a7f..ec96a3646 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -36,19 +36,21 @@ jobs: uses: actions/checkout@v4.1.5 with: repository: clawpack/clawpack - - name: Setup clawpack subrepositories - run: | - git submodule init - git submodule update - # - name: Checkout geoclaw branch - # uses: actions/checkout@v4.1.5 - # with: - # repository: clawpack/geoclaw + submodules: true + # - name: Setup clawpack subrepositories + # run: | + # git submodule init + # git submodule update + - name: Checkout geoclaw branch + uses: actions/checkout@v4.1.5 + with: + repository: clawpack/geoclaw + path: geoclaw - name: Install clawpack run: | ls -l - cd $CLAW + cd $CLAW/geoclaw ls -l # cd $CLAW From 3f08d405d9fe63cfea8c866fd4b8e5b65c5d0276 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 17:03:21 -0400 Subject: [PATCH 29/39] Modify testing action --- .github/workflows/testing.yml | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index ec96a3646..e000a5964 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -37,10 +37,6 @@ jobs: with: repository: clawpack/clawpack submodules: true - # - name: Setup clawpack subrepositories - # run: | - # git submodule init - # git submodule update - name: Checkout geoclaw branch uses: actions/checkout@v4.1.5 with: @@ -49,15 +45,14 @@ jobs: - name: Install clawpack run: | - ls -l + pip install --user -e $CLAW + + - name: Testing + run: | + echo $CLAW cd $CLAW/geoclaw ls -l - # cd $CLAW - # ls -l - - # pip install --user -e $CLAW - # - name: Lint with flake8 # run: | # cd ${CLAW}/geoclaw From 07fa18b53ea53e2bd289f264d923904505e1fc95 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 17:05:43 -0400 Subject: [PATCH 30/39] Modify testing action --- .github/workflows/testing.yml | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index e000a5964..2aa681b13 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -27,11 +27,6 @@ jobs: python -m pip install --upgrade pip pip install flake8 pytest - - name: Testing - run: | - echo $GITHUB_WORKSPACE - echo $CLAW - - name: Checkout clawpack uses: actions/checkout@v4.1.5 with: @@ -41,26 +36,19 @@ jobs: uses: actions/checkout@v4.1.5 with: repository: clawpack/geoclaw - path: geoclaw - + path: geoclaw - name: Install clawpack run: | pip install --user -e $CLAW - - name: Testing + - name: Lint with flake8 run: | - echo $CLAW - cd $CLAW/geoclaw - ls -l - - # - name: Lint with flake8 - # run: | - # cd ${CLAW}/geoclaw - # # stop the build if there are Python syntax errors or undefined names - # flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude old_dtopotools.py - # # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - # - name: Test with pytest - # run: | - # cd ${CLAW}/geoclaw - # pytest + cd ${CLAW}/geoclaw + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude old_dtopotools.py + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + cd ${CLAW}/geoclaw + pytest From 6e16d76f8ca63d5cb00517829b92074d362133d6 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 17:08:28 -0400 Subject: [PATCH 31/39] Modify testing action --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 2aa681b13..60236d9fb 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -25,7 +25,7 @@ jobs: sudo apt-get update sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev python -m pip install --upgrade pip - pip install flake8 pytest + pip install flake8 pytest numpy pandas - name: Checkout clawpack uses: actions/checkout@v4.1.5 From 98a9d70af684909db58ae88dcf7fa6f834c97455 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 10 May 2024 17:18:36 -0400 Subject: [PATCH 32/39] Modify testing action --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 60236d9fb..40472ea73 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -25,7 +25,7 @@ jobs: sudo apt-get update sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev python -m pip install --upgrade pip - pip install flake8 pytest numpy pandas + pip install flake8 meson-python ninja pytest numpy pandas - name: Checkout clawpack uses: actions/checkout@v4.1.5 From f7a1620f2b928ac4715950a2cf6babc7e301a7ce Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Mon, 13 May 2024 14:31:02 -0400 Subject: [PATCH 33/39] Try installing clawpack not in user --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 40472ea73..8bf7bcc7b 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -39,7 +39,7 @@ jobs: path: geoclaw - name: Install clawpack run: | - pip install --user -e $CLAW + pip install -e $CLAW - name: Lint with flake8 run: | From 76134f256cebeb2c5b29e518996cf4815c08958e Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Mon, 13 May 2024 14:42:00 -0400 Subject: [PATCH 34/39] Futzing with ninja --- .github/workflows/testing.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 8bf7bcc7b..29638f154 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -23,9 +23,11 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev + sudo apt-get install ninja-build gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev + which ninja python -m pip install --upgrade pip pip install flake8 meson-python ninja pytest numpy pandas + which ninja - name: Checkout clawpack uses: actions/checkout@v4.1.5 From 7b28937e709e663f1086934d98c0abb981cb7651 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Mon, 13 May 2024 14:58:15 -0400 Subject: [PATCH 35/39] Restore ninja and try debugging line --- .github/workflows/testing.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 29638f154..afa683575 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -23,11 +23,9 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install ninja-build gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev - which ninja + sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev python -m pip install --upgrade pip pip install flake8 meson-python ninja pytest numpy pandas - which ninja - name: Checkout clawpack uses: actions/checkout@v4.1.5 @@ -42,6 +40,7 @@ jobs: - name: Install clawpack run: | pip install -e $CLAW + python -m clawpack.geoclaw.data - name: Lint with flake8 run: | From 2fdf54a5da710e86b425f17391b87f5e2ba24284 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 31 May 2024 13:40:09 -0400 Subject: [PATCH 36/39] Think worked out kinks in CI action --- .github/workflows/testing.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index afa683575..8bd8c65da 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -26,21 +26,21 @@ jobs: sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev python -m pip install --upgrade pip pip install flake8 meson-python ninja pytest numpy pandas + # if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Checkout clawpack + - name: Checkout Clawpack uses: actions/checkout@v4.1.5 with: repository: clawpack/clawpack submodules: true - - name: Checkout geoclaw branch + - name: Checkout GeoClaw branch uses: actions/checkout@v4.1.5 with: - repository: clawpack/geoclaw path: geoclaw + - name: Install clawpack run: | - pip install -e $CLAW - python -m clawpack.geoclaw.data + pip install --no-build-isolation --editable . - name: Lint with flake8 run: | From 9e85d95b2b2262e5e409461075780a94dfab04f6 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 31 May 2024 13:45:27 -0400 Subject: [PATCH 37/39] Fix numpy reference --- src/python/geoclaw/surge/plot.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/python/geoclaw/surge/plot.py b/src/python/geoclaw/surge/plot.py index b8616a9d3..e57d577e6 100644 --- a/src/python/geoclaw/surge/plot.py +++ b/src/python/geoclaw/surge/plot.py @@ -13,7 +13,7 @@ from __future__ import absolute_import from __future__ import print_function -import numpy +import numpy as np import matplotlib.pyplot as plt import matplotlib.colors as colors import matplotlib.lines as mlines @@ -50,7 +50,7 @@ def __init__(self, path=None): try: self._path = path - self._data = numpy.loadtxt(self._path) + self._data = np.loadtxt(self._path) except: self._data = None @@ -63,7 +63,7 @@ def get_track(self, frame): # If it appears that our data is not long enough, try reloading file if self._data.shape[0] < frame + 1: - self._data = numpy.loadtxt(self._path) + self._data = np.loadtxt(self._path) # Check to make sure that this fixed the problem if self._data.shape[0] < frame + 1: @@ -131,7 +131,7 @@ def surge_afteraxes(current_data, track, land_fall=0.0, plot_direction=False, axes.plot(track_data[0], track_data[1], style, **kwargs) if plot_direction: axes.quiver(track_data[0], track_data[1], - numpy.cos(track_data[2]), numpy.sin(track_data[2])) + np.cos(track_data[2]), np.sin(track_data[2])) days_figure_title(current_data, land_fall) @@ -150,7 +150,7 @@ def wind_y(cd): def wind_speed(cd): - return numpy.sqrt(wind_x(cd)**2 + wind_y(cd)**2) + return np.sqrt(wind_x(cd)**2 + wind_y(cd)**2) def pressure(cd): @@ -169,14 +169,14 @@ def b(cd): def extract_eta(h, eta, DRY_TOL=1e-3): - index = numpy.nonzero((numpy.abs(h) < DRY_TOL) + (h == numpy.nan)) - eta[index[0], index[1]] = numpy.nan + index = np.nonzero((np.abs(h) < DRY_TOL) + (h == np.nan)) + eta[index[0], index[1]] = np.nan return eta def extract_velocity(h, hu, DRY_TOL=1e-8): - u = numpy.zeros(hu.shape) - index = numpy.nonzero((numpy.abs(h) > DRY_TOL) * (h != numpy.nan)) + u = np.zeros(hu.shape) + index = np.nonzero((np.abs(h) > DRY_TOL) * (h != np.nan)) u[index[0], index[1]] = hu[index[0], index[1]] / h[index[0], index[1]] return u @@ -197,7 +197,7 @@ def water_speed(current_data): u = water_u(current_data) v = water_v(current_data) - return numpy.sqrt(u**2+v**2) + return np.sqrt(u**2+v**2) # ======================================================================== @@ -241,7 +241,7 @@ def add_surface_elevation(plotaxes, plot_type='pcolor', bounds=None, plot_type='2d_contourf') plotitem.plot_var = geoplot.surface_or_depth if bounds is not None: - contours = numpy.linspace(bounds[0], bounds[1], 11) + contours = np.linspace(bounds[0], bounds[1], 11) plotitem.contour_levels = contours plotitem.fill_cmin = bounds[0] plotitem.fill_cmax = bounds[1] @@ -302,7 +302,7 @@ def add_speed(plotaxes, plot_type='pcolor', bounds=None, contours=None, plotitem.colorbar_shrink = shrink plotitem.fill_cmap = plt.get_cmap('PuBu') if bounds is not None: - plotitem.contour_levels = numpy.linspace(bounds[0], bounds[1], 11) + plotitem.contour_levels = np.linspace(bounds[0], bounds[1], 11) plotitem.fill_cmin = bounds[0] plotitem.fill_cmap = bounds[1] elif contours is not None: @@ -442,7 +442,7 @@ def plot_track(t, x, y, wind_radius, wind_speed, Pc, name=None): name = " - %s" % name colors = ['r', 'b'] - divide = (numpy.max(Pc) + numpy.min(Pc)) / 2.0 + divide = (np.max(Pc) + np.min(Pc)) / 2.0 fig = plt.figure(1) axes = fig.add_subplot(111) @@ -463,7 +463,7 @@ def plot_track(t, x, y, wind_radius, wind_speed, Pc, name=None): axes = fig.add_subplot(133) axes.plot(sec2days(t), Pc) - axes.plot(sec2days(t), numpy.ones(t.shape) * divide, 'k--') + axes.plot(sec2days(t), np.ones(t.shape) * divide, 'k--') axes.set_title("Central Pressure%s" % name) @@ -471,7 +471,7 @@ def plot_track(t, x, y, wind_radius, wind_speed, Pc, name=None): Easily plot the track and intensity of a storm using a mapping package. -:Inumpyut: +:Input: - *axes* (matplotlib.pyplot.axes) Axes to plot into. Default is *None* - *intensity* (bool) Plot the intensity of storm along the track. Defaults to *False*. From e9014399ec44b3f5548c43265e4191357308bf7f Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 31 May 2024 14:06:40 -0400 Subject: [PATCH 38/39] Add xarray to test environment --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 8bd8c65da..2d91032f3 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -25,7 +25,7 @@ jobs: sudo apt-get update sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev python -m pip install --upgrade pip - pip install flake8 meson-python ninja pytest numpy pandas + pip install flake8 meson-python ninja pytest numpy pandas xarray # if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Checkout Clawpack From fb8e638ef2eee8d3d18253d6bb60ff50f141e498 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Fri, 31 May 2024 14:17:02 -0400 Subject: [PATCH 39/39] Add netCDF4 module --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 2d91032f3..72da8f3e4 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -25,7 +25,7 @@ jobs: sudo apt-get update sudo apt-get install gfortran liblapack-pic liblapack-dev libnetcdf-dev libnetcdff-dev python -m pip install --upgrade pip - pip install flake8 meson-python ninja pytest numpy pandas xarray + pip install flake8 meson-python ninja pytest numpy pandas xarray netCDF4 # if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Checkout Clawpack