Skip to content

Commit

Permalink
Merge pull request clawpack#233 from clawpack/python3
Browse files Browse the repository at this point in the history
Support Python 3
  • Loading branch information
ketch authored Dec 20, 2016
2 parents 68676b9 + 5792610 commit 672f071
Show file tree
Hide file tree
Showing 66 changed files with 493 additions and 356 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
language: python
python:
- 2.7
- 3.5
env:
- BUILD_TYPE="Release"

before_install:
- sudo apt-get update
- sudo apt-get install gfortran liblapack-dev
# Print NumPy version that is already installed by Travis CI:
- python -c "import numpy; print numpy.__version__"
- python -c "import numpy; print(numpy.__version__)"
# - pip install matplotlib
# - python -c "import matplotlib; print matplotlib.__version__"
# - python -c "import matplotlib; print(matplotlib.__version__)"
- git clone --branch=master --depth=100 --quiet git://github.com/clawpack/clawpack
- cd clawpack
- python setup.py symlink-only
Expand Down
6 changes: 4 additions & 2 deletions examples/multi-layer/plane_wave/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# http://www.opensource.org/licenses/
# ============================================================================

from __future__ import absolute_import
from __future__ import print_function
import sys
import numpy

Expand Down Expand Up @@ -174,11 +176,11 @@ def __str__(self):
tests_to_run.append(tests[int(test)])

controller = batch.BatchController(tests_to_run)
print controller
print(controller)
controller.run()

else:
controller = batch.BatchController(tests)
print controller
print(controller)


1 change: 1 addition & 0 deletions examples/multi-layer/plane_wave/setplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

from __future__ import absolute_import
def setplot(plotdata, bathy_location=0.15, bathy_angle=0.0,
bathy_left=-1.0, bathy_right=-0.2):
"""Setup the plotting data objects.
Expand Down
8 changes: 5 additions & 3 deletions examples/multi-layer/plane_wave/setrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"""

from __future__ import absolute_import
from __future__ import print_function
import numpy as numpy

import clawpack.geoclaw.data
Expand Down Expand Up @@ -421,7 +423,7 @@ def setgeo(rundata):
try:
geo_data = rundata.geo_data
except:
print "*** Error, this rundata has no geo_data attribute"
print("*** Error, this rundata has no geo_data attribute")
raise AttributeError("Missing geo_data attribute")

# == Physics ==
Expand Down Expand Up @@ -511,11 +513,11 @@ def write_topo_file(run_data, out_file, **kwargs):

# Write out simple bathy geometry file for communication to the plotting
with open("./bathy_geometry.data", 'w') as bathy_geometry_file:
if kwargs.has_key("location"):
if "location" in kwargs:
location = kwargs['location']
else:
location = 0.15
if kwargs.has_key("angle"):
if "angle" in kwargs:
angle = kwargs['angle']
else:
angle = 0.0
Expand Down
8 changes: 5 additions & 3 deletions examples/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Run all examples and then compare to gallery versions, if available.
"""

from __future__ import absolute_import
from __future__ import print_function
from clawpack.clawutil import regression_tests, make_all
import os

Expand All @@ -13,10 +15,10 @@
make_all.make_all(make_clean_first=True, env=env)


print "\n-----------------------------------------------------------\n"
print("\n-----------------------------------------------------------\n")

all_ok = regression_tests.test_subdirs()
if all_ok:
print "===> All tests pass"
print("===> All tests pass")
else:
print "===> Some test(s) failed"
print("===> Some test(s) failed")
1 change: 1 addition & 0 deletions examples/storm-surge/ike/get_bathy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

"""Simple implementation of a file fetcher"""

from __future__ import absolute_import
import sys
import os
import clawpack.clawutil.data
Expand Down
8 changes: 5 additions & 3 deletions examples/storm-surge/ike/plot_num_grids.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from __future__ import absolute_import
import os
import sys
import glob
Expand All @@ -9,6 +10,7 @@

# Plot customization
import matplotlib
from six.moves import range

# Markers and line widths
matplotlib.rcParams['lines.linewidth'] = 2.0
Expand Down Expand Up @@ -90,7 +92,7 @@ def set_cell_ticks():
colors = [ (value / 256.0, value / 256.0, value / 256.0)
for value in [247, 217, 189, 150, 115, 82, 37] ]
proxy_artists = [plt.Rectangle((0, 0), 1, 1, fc=colors[level],
label="Level %s" % (str(level+1))) for level in xrange(num_levels)]
label="Level %s" % (str(level+1))) for level in range(num_levels)]

# Number of grids
fig = plt.figure()
Expand All @@ -104,7 +106,7 @@ def set_cell_ticks():
set_day_ticks()
axes.set_ylabel('Number of Grids')
axes.set_title("Number of Grids per Level in Time")
axes.legend(proxy_artists, ["Level %s" % (str(level+1)) for level in xrange(num_levels)], loc=2)
axes.legend(proxy_artists, ["Level %s" % (str(level+1)) for level in range(num_levels)], loc=2)
fig.savefig("num_grids.png")

# Number of cells
Expand All @@ -119,7 +121,7 @@ def set_cell_ticks():
axes.set_xlabel('Days from landfall')
axes.set_ylabel('Number of Cells')
axes.set_title("Number of Cells per Level in Time")
axes.legend(proxy_artists, ["Level %s" % (str(level+1)) for level in xrange(num_levels)], loc=2)
axes.legend(proxy_artists, ["Level %s" % (str(level+1)) for level in range(num_levels)], loc=2)
fig.savefig("num_cells.png")


Expand Down
1 change: 1 addition & 0 deletions examples/storm-surge/ike/setplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

from __future__ import absolute_import
article = False

import os
Expand Down
1 change: 1 addition & 0 deletions examples/storm-surge/ike/setplot_kml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

from __future__ import absolute_import
article = False

import os
Expand Down
4 changes: 3 additions & 1 deletion examples/storm-surge/ike/setrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"""

from __future__ import absolute_import
from __future__ import print_function
import os
import datetime

Expand Down Expand Up @@ -360,7 +362,7 @@ def setgeo(rundata):
try:
geo_data = rundata.geo_data
except:
print "*** Error, this rundata has no geo_data attribute"
print("*** Error, this rundata has no geo_data attribute")
raise AttributeError("Missing geo_data attribute")

# == Physics ==
Expand Down
1 change: 1 addition & 0 deletions examples/tsunami/bowl-radial/maketopo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Module to create topo and qinit data files for this example.
"""

from __future__ import absolute_import
from clawpack.geoclaw.topotools import Topography
from numpy import *

Expand Down
4 changes: 3 additions & 1 deletion examples/tsunami/bowl-radial/setplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
"""


from __future__ import absolute_import
from __future__ import print_function
try:
from setplotfg import setplotfg
except:
print "Did not find setplotfg.py"
print("Did not find setplotfg.py")
setplotfg = None


Expand Down
4 changes: 3 additions & 1 deletion examples/tsunami/bowl-radial/setrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"""

from __future__ import absolute_import
from __future__ import print_function
import os
import numpy as np

Expand Down Expand Up @@ -355,7 +357,7 @@ def setgeo(rundata):
try:
geo_data = rundata.geo_data
except:
print "*** Error, this rundata has no geo_data attribute"
print("*** Error, this rundata has no geo_data attribute")
raise AttributeError("Missing geo_data attribute")


Expand Down
1 change: 1 addition & 0 deletions examples/tsunami/bowl-slosh/maketopo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Module to create topo and qinit data files for this example.
"""

from __future__ import absolute_import
from clawpack.geoclaw.topotools import Topography
from numpy import *

Expand Down
1 change: 1 addition & 0 deletions examples/tsunami/bowl-slosh/setplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

from __future__ import absolute_import
import numpy
a = 1.
sigma = 0.5
Expand Down
4 changes: 3 additions & 1 deletion examples/tsunami/bowl-slosh/setrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"""

from __future__ import absolute_import
from __future__ import print_function
import os
import numpy as np

Expand Down Expand Up @@ -333,7 +335,7 @@ def setgeo(rundata):
try:
geo_data = rundata.geo_data
except:
print "*** Error, this rundata has no geo_data attribute"
print("*** Error, this rundata has no geo_data attribute")
raise AttributeError("Missing geo_data attribute")


Expand Down
16 changes: 9 additions & 7 deletions examples/tsunami/chile2010/maketopo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
Call functions with makeplots==True to create plots of topo, slip, and dtopo.
"""

from __future__ import absolute_import
from __future__ import print_function
import os

import clawpack.clawutil.data
Expand Down Expand Up @@ -36,7 +38,7 @@ def get_topo(makeplots=False):
topo.plot()
fname = os.path.splitext(topo_fname)[0] + '.png'
plt.savefig(fname)
print "Created ",fname
print("Created ",fname)



Expand Down Expand Up @@ -68,13 +70,13 @@ def make_dtopo(makeplots=False):
fault = dtopotools.Fault()
fault.subfaults = [usgs_subfault]

print "Mw = ",fault.Mw()
print("Mw = ",fault.Mw())

if os.path.exists(dtopo_fname):
print "*** Not regenerating dtopo file (already exists): %s" \
% dtopo_fname
print("*** Not regenerating dtopo file (already exists): %s" \
% dtopo_fname)
else:
print "Using Okada model to create dtopo file"
print("Using Okada model to create dtopo file")

x = numpy.linspace(-77, -67, 100)
y = numpy.linspace(-40, -30, 100)
Expand All @@ -89,7 +91,7 @@ def make_dtopo(makeplots=False):
from matplotlib import pyplot as plt
if fault.dtopo is None:
# read in the pre-existing file:
print "Reading in dtopo file..."
print("Reading in dtopo file...")
dtopo = dtopotools.DTopography()
dtopo.read(dtopo_fname, dtopo_type=3)
x = dtopo.x
Expand All @@ -103,7 +105,7 @@ def make_dtopo(makeplots=False):
dtopo.plot_dZ_colors(1.,axes=ax2)
fname = os.path.splitext(os.path.split(dtopo_fname)[-1])[0] + '.png'
plt.savefig(fname)
print "Created ",fname
print("Created ",fname)


if __name__=='__main__':
Expand Down
1 change: 1 addition & 0 deletions examples/tsunami/chile2010/plot_dart.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Compare DART buoy results to NOAA results.
"""

from __future__ import absolute_import
import pylab
from pyclaw.plotters.data import ClawPlotData
from matplotlib import image
Expand Down
1 change: 1 addition & 0 deletions examples/tsunami/chile2010/plotfg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

from __future__ import absolute_import
from pylab import *

outdir = '_output'
Expand Down
5 changes: 4 additions & 1 deletion examples/tsunami/chile2010/setplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
"""

from __future__ import absolute_import
from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt

from clawpack.geoclaw import topotools
from six.moves import range

try:
TG32412 = np.loadtxt('32412_notide.txt')
except:
print "*** Could not load DART data file"
print("*** Could not load DART data file")

#--------------------------
def setplot(plotdata):
Expand Down
5 changes: 4 additions & 1 deletion examples/tsunami/chile2010/setplot_kml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
"""

from __future__ import absolute_import
from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt

from clawpack.geoclaw import topotools
from six.moves import range

try:
TG32412 = np.loadtxt('32412_notide.txt')
except:
print "*** Could not load DART data file"
print("*** Could not load DART data file")

#--------------------------
def setplot(plotdata):
Expand Down
5 changes: 4 additions & 1 deletion examples/tsunami/chile2010/setplot_speeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
"""

from __future__ import absolute_import
from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt

from clawpack.geoclaw import topotools
from six.moves import range

try:
TG32412 = np.loadtxt('32412_notide.txt')
except:
print "*** Could not load DART data file"
print("*** Could not load DART data file")


#--------------------------
Expand Down
Loading

0 comments on commit 672f071

Please sign in to comment.