Skip to content

Commit

Permalink
Merge pull request #221 from stoiver/anuga_py3
Browse files Browse the repository at this point in the history
Anuga py3
  • Loading branch information
stoiver committed Dec 27, 2019
2 parents d179c1f + da64419 commit 7f57f87
Show file tree
Hide file tree
Showing 152 changed files with 2,968 additions and 5,995 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ matrix:
language: generic
sudo: false
python: "2.7"
env: PYTHON_VERSION="2.7" ANUGA_PARALLEL="false" DISTRIB="conda_macos"
env: PYTHON_VERSION="2.7" ANUGA_PARALLEL="conda" PYPAR_AVAILABLE="mpi4py" DISTRIB="conda_macos"

- os: linux
language: generic
sudo: required
python: "2.7"
env: PYTHON_VERSION="2.7" ANUGA_PARALLEL="openmpi" DISTRIB="conda"
env: PYTHON_VERSION="2.7" ANUGA_PARALLEL="conda" PYPAR_AVAILABLE="mpi4py" DISTRIB="conda"

- os: linux
dist: trusty
sudo: required
python: "2.7_with_system_site_packages"
env: PYTHON_VERSION="2.7" ANUGA_PARALLEL="mpich" DISTRIB="ubuntu"
env: PYTHON_VERSION="2.7" ANUGA_PARALLEL="mpich" PYPAR_AVAILABLE="mpi4py" DISTRIB="ubuntu"

- os: linux
dist: trusty
Expand All @@ -31,7 +31,7 @@ matrix:
dist: trusty
sudo: required
python: "2.7_with_system_site_packages"
env: PYTHON_VERSION="2.7" ANUGA_PARALLEL="openmpi" DISTRIB="ubuntu" COVERAGE="--coverage"
env: PYTHON_VERSION="2.7" ANUGA_PARALLEL="openmpi" PYPAR_AVAILABLE="mpi4py" DISTRIB="ubuntu" COVERAGE="--coverage"


install:
Expand Down
34 changes: 17 additions & 17 deletions anuga/abstract_2d_finite_volumes/ermapper_grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,39 +207,39 @@ def create_default_header(header = {}):
# to be filled with default values


if not header.has_key('datum'):
if 'datum' not in header:
header['datum'] = '"GDA94"'
if not header.has_key('projection'):
if 'projection' not in header:
header['projection'] = '"GEOGRAPHIC"'
if not header.has_key('coordinatetype'):
if 'coordinatetype' not in header:
header['coordinatetype'] = 'LL'
if not header.has_key('rotation'):
if 'rotation' not in header:
header['rotation'] = '0:0:0.0'
if not header.has_key('units'):
if 'units' not in header:
header['units'] = '"METERS"'
if not header.has_key('celltype'):
if 'celltype' not in header:
header['celltype'] = 'IEEE4ByteReal'
if not header.has_key('nullcellvalue'):
if 'nullcellvalue' not in header:
header['nullcellvalue'] = '-99999'
if not header.has_key('xdimension'):
if 'xdimension' not in header:
header['xdimension'] = '100'
if not header.has_key('latitude'):
if 'latitude' not in header:
header['latitude'] = '0:0:0'
if not header.has_key('longitude'):
if 'longitude' not in header:
header['longitude'] = '0:0:0'
if not header.has_key('ydimension'):
if 'ydimension' not in header:
header['ydimension'] = '100'
if not header.has_key('nroflines'):
if 'nroflines' not in header:
header['nroflines'] = '3'
if not header.has_key('nrofcellsperline'):
if 'nrofcellsperline' not in header:
header['nrofcellsperline'] = '4'
if not header.has_key('registrationcellx'):
if 'registrationcellx' not in header:
header['registrationcellx'] = '0'
if not header.has_key('registrationcelly'):
if 'registrationcelly' not in header:
header['registrationcelly'] = str(int(header['nroflines'])-1)
if not header.has_key('nrofbands'):
if 'nrofbands' not in header:
header['nrofbands'] = '1'
if not header.has_key('value'):
if 'value' not in header:
header['value'] = '"Default_Band"'


Expand Down
7 changes: 3 additions & 4 deletions anuga/abstract_2d_finite_volumes/file_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ def file_function(filename,
compression=False,
verbose=verbose)
else:
f, starttime = apply(_file_function,
args, kwargs)
f, starttime = _file_function(*args, **kwargs)

#FIXME (Ole): Pass cache arguments, such as compression, in some sort of
#structure
Expand Down Expand Up @@ -268,7 +267,7 @@ def get_netcdf_file_function(filename,
# are present in file
missing = []
for quantity in ['time'] + quantity_names:
if not fid.variables.has_key(quantity):
if quantity not in fid.variables:
missing.append(quantity)

if len(missing) > 0:
Expand All @@ -280,7 +279,7 @@ def get_netcdf_file_function(filename,
# Decide whether this data has a spatial dimension
spatial = True
for quantity in ['x', 'y']:
if not fid.variables.has_key(quantity):
if quantity not in fid.variables:
spatial = False

if filename[-3:] == 'tms' and spatial is True:
Expand Down
13 changes: 7 additions & 6 deletions anuga/abstract_2d_finite_volumes/gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
Ole Nielsen, Stephen Roberts, Duncan Gray, Christopher Zoppou, James Hudson
Geoscience Australia
"""
from __future__ import absolute_import

import numpy as num

from anuga.geospatial_data.geospatial_data import ensure_absolute
from util import check_list, calc_bearing
from file_function import file_function
from .util import check_list, calc_bearing
from .file_function import file_function

import os

Expand Down Expand Up @@ -142,7 +143,7 @@ def sww2csv_gauges(sww_file,

try:
point_reader = reader(file(gauge_file))
except Exception, e:
except Exception as e:
msg = 'File "%s" could not be opened: Error="%s"' % (gauge_file, e)
raise Exception(msg)

Expand Down Expand Up @@ -411,7 +412,7 @@ def _sww2timeseries(swwfiles,

try:
fid = open(gauge_filename)
except Exception, e:
except Exception as e:
msg = 'File "%s" could not be opened: Error="%s"' % (gauge_filename, e)
raise Exception(msg)

Expand Down Expand Up @@ -449,7 +450,7 @@ def _sww2timeseries(swwfiles,
for swwfile in swwfiles.keys():
try:
fid = open(swwfile)
except Exception, e:
except Exception as e:
msg = 'File "%s" could not be opened: Error="%s"' % (swwfile, e)
raise Exception(msg)

Expand Down Expand Up @@ -515,7 +516,7 @@ def _sww2timeseries(swwfiles,
if verbose and len(gauge_index) > 0:
log.critical('Inputs OK - going to generate figures')

if len(gauge_index) <> 0:
if len(gauge_index) != 0:
texfile, elev_output = \
_generate_figures(plot_quantity, file_loc, report, reportname,
surface, leg_label, f_list, gauges, locations,
Expand Down
3 changes: 2 additions & 1 deletion anuga/abstract_2d_finite_volumes/general_mesh.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import copy
import numpy as num

Expand Down Expand Up @@ -799,7 +800,7 @@ def build_inverted_triangle_structure(self):

if number_of_orphan_nodes > 0 and self.verbose:
msg = 'Node(s) %d not associated to a triangle.' % orphan_nodes[0]
print msg
print(msg)

if number_of_lone_nodes > 0:
number_of_triangles_per_node = \
Expand Down
16 changes: 8 additions & 8 deletions anuga/abstract_2d_finite_volumes/generic_boundary_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ def get_boundary_values(self, t=None):

try:
res = self.function(t)
except Modeltime_too_early, e:
except Modeltime_too_early as e:
raise Modeltime_too_early(e)
except Modeltime_too_late, e:
except Modeltime_too_late as e:
if self.default_boundary is None:
raise Modeltime_too_late(e) # Reraise exception
else:
Expand Down Expand Up @@ -328,7 +328,7 @@ def __init__(self, domain=None,

try:
q = function(0.0)
except Exception, e:
except Exception as e:
msg = 'Function for time boundary could not be executed:\n%s' %e
raise Exception(msg)

Expand Down Expand Up @@ -447,7 +447,7 @@ def __init__(self, domain=None,

try:
q = function(0.0, 0.0, 0.0)
except Exception, e:
except Exception as e:
msg = 'Function for time_space_boundary could not be executed:\n%s' %e
raise Exception(msg)

Expand Down Expand Up @@ -481,9 +481,9 @@ def evaluate(self, vol_id=None, edge_id=None):

try:
res = self.function(self.domain.get_time(), x, y)
except Modeltime_too_early, e:
except Modeltime_too_early as e:
raise Modeltime_too_early(e)
except Modeltime_too_late, e:
except Modeltime_too_late as e:
if self.default_boundary is None:
raise Exception(e) # Reraise exception
else:
Expand Down Expand Up @@ -656,9 +656,9 @@ def evaluate(self, vol_id=None, edge_id=None):

try:
res = self.F(t, point_id=i)
except Modeltime_too_early, e:
except Modeltime_too_early as e:
raise Modeltime_too_early(e)
except Modeltime_too_late, e:
except Modeltime_too_late as e:
if self.default_boundary is None:
raise Exception(e) # Reraise exception
else:
Expand Down
30 changes: 16 additions & 14 deletions anuga/abstract_2d_finite_volumes/generic_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
Ole Nielsen, Stephen Roberts, Duncan Gray
Geoscience Australia
"""
from __future__ import print_function
from __future__ import absolute_import

from time import time as walltime

from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh
from pmesh2domain import pmesh_to_domain
from tag_region import Set_tag_region as region_set_tag_region
from .pmesh2domain import pmesh_to_domain
from .tag_region import Set_tag_region as region_set_tag_region
from anuga.geometry.polygon import inside_polygon
from anuga.abstract_2d_finite_volumes.util import get_textual_float
from quantity import Quantity
from .quantity import Quantity
import anuga.utilities.log as log

import numpy as num
Expand Down Expand Up @@ -457,7 +459,7 @@ def statistics(self, *args, **kwargs):
return self.mesh.statistics(*args, **kwargs)

def print_statistics(self, *args, **kwargs):
print self.statistics(*args, **kwargs)
print(self.statistics(*args, **kwargs))

def get_extent(self, *args, **kwargs):
return self.mesh.get_extent(*args, **kwargs)
Expand Down Expand Up @@ -707,7 +709,7 @@ def set_quantity(self, name,
"""

# Do the expression stuff
if kwargs.has_key('expression'):
if 'expression' in kwargs:
expression = kwargs['expression']
del kwargs['expression']

Expand All @@ -727,7 +729,7 @@ def add_quantity(self, name,
"""

# Do the expression stuff
if kwargs.has_key('expression'):
if 'expression' in kwargs:
expression = kwargs['expression']
Q2 = self.create_quantity_from_expression(expression)
else:
Expand All @@ -751,7 +753,7 @@ def minimum_quantity(self, name,
"""

# Do the expression stuff
if kwargs.has_key('expression'):
if 'expression' in kwargs:
expression = kwargs['expression']
Q2 = self.create_quantity_from_expression(expression)
else:
Expand All @@ -775,7 +777,7 @@ def maximum_quantity(self, name,
"""

# Do the expression stuff
if kwargs.has_key('expression'):
if 'expression' in kwargs:
expression = kwargs['expression']
Q2 = self.create_quantity_from_expression(expression)
else:
Expand Down Expand Up @@ -898,7 +900,7 @@ def set_boundary(self, boundary_map):
for k, (vol_id, edge_id) in enumerate(x):
tag = self.boundary[(vol_id, edge_id)]

if self.boundary_map.has_key(tag):
if tag in self.boundary_map:
B = self.boundary_map[tag] # Get callable boundary object

if B is not None:
Expand Down Expand Up @@ -1208,12 +1210,12 @@ def timestepping_statistics(self, track_speeds=False,
return msg

def print_timestepping_statistics(self, *args, **kwargs):
print self.timestepping_statistics(self, *args, **kwargs)
print(self.timestepping_statistics(self, *args, **kwargs))



def print_boundary_statistics(self, quantities=None, tags=None):
print self.boundary_statistics(quantities, tags)
print(self.boundary_statistics(quantities, tags))

def write_boundary_statistics(self, quantities=None, tags=None):
log.critical(self.boundary_statistics(quantities, tags))
Expand Down Expand Up @@ -1450,7 +1452,7 @@ def get_starttime(self):
def set_starttime(self, time):

if self.evolved_called:
raise "Can't change simulation start time once evolve has been called"
raise Exception("Can't change simulation start time once evolve has been called")

self.starttime = float(time)
self.set_time(0.0)
Expand All @@ -1476,7 +1478,7 @@ def dump_triangulation(self, filename="domain.png"):
import matplotlib.pyplot as plt
import matplotlib.tri as tri
except:
print "Couldn't import module from matplotlib, probably you need to update matplotlib"
print("Couldn't import module from matplotlib, probably you need to update matplotlib")
raise

vertices = self.get_vertex_coordinates()
Expand Down Expand Up @@ -2284,7 +2286,7 @@ def update_ghosts(self, quantities=None):

#Update of ghost cells
iproc = self.processor
if self.full_send_dict.has_key(iproc):
if iproc in self.full_send_dict:

# now store full as local id, global id, value
Idf = self.full_send_dict[iproc][0]
Expand Down
3 changes: 2 additions & 1 deletion anuga/abstract_2d_finite_volumes/mesh_factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Library of standard meshes and facilities for reading various
mesh file formats
"""
from __future__ import absolute_import

import anuga.utilities.log as log
import numpy as num
Expand Down Expand Up @@ -165,7 +166,7 @@ def rectangular_cross(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):
points = num.empty([(m+1)*(n+1)+m*n,2], dtype=num.float)
elements = num.empty([4*m*n,3], dtype=num.int)

from mesh_factory_ext import rectangular_cross_construct
from .mesh_factory_ext import rectangular_cross_construct
boundary = rectangular_cross_construct(arrParams, arrOrigin, points, elements)

#points = list(arrPoints)
Expand Down

0 comments on commit 7f57f87

Please sign in to comment.