Reference manual¶
An interface to the SWASHES software, a collection of analytic solutions to the shallow water equations.
-
class
pyswashes.pyswashes.
OneDimensional
(stype, domain, choice, num_cell_x, swashes_bin='')¶ Bases:
pyswashes.pyswashes.SWASHES
A one-dimensional analytic solution.
To select stype, domain and choice, please refer to the SWASHES manual.
Parameters: - stype (int) – The type of the solution.
- domain (int) – The domain of the solution.
- choice (int) – The choice of solution.
- num_cell_x (int) – The number of cells in the X dimension.
- swashes_bin (str, optional) – Path to the SWASHES executable. Only needed if swashes is not in your PATH. Default to an empty string, which triggers the setting of the path to ‘swashes’ or ‘swashes.exe’, according to the platform.
-
dom_params
¶ The paramters of the domain.
Type: dictionary
Examples
Get the solution of a MacDonald Long channel without rain, with a 5 cells discretization:
>>> import pyswashes >>> s = pyswashes.OneDimensional(2, 1, 2, 5)
Report the solution’s domain pramaters:
>>> print(s.dom_params) {'length': 1000.0, 'width': None, 'dx': 200.0, 'dy': None, 'ncellx': 5.0, 'ncelly': None}
Get a Pandas dataframe:
>>> print(s.dataframe()) depth u gd_elev q head Froude crit_head x 100 0.770195 2.59675 5.88374 2 6.65393 0.944702 6.62527 300 0.937035 2.13439 4.67542 2 5.61245 0.703982 5.41695 500 1.112300 1.79808 4.06441 2 5.17671 0.544331 4.80595 700 0.937035 2.13439 3.10854 2 4.04558 0.703982 3.85008 900 0.770195 2.59675 1.03618 2 1.80638 0.944702 1.77771
Raises: ValueError
– If the parameters are the wrong type.ValueError
– If num_cell_y is not given for a 2D solution.RuntimeError
– If the SWASHES executable is not foundRuntimeError
– When the SWASHES call returns an error
-
COLS
= {'(i-0.5)*dx': 'x', 'Fr[i]=Froude': 'Froude', 'h[i]': 'depth', 'q[i]': 'q', 'topo[i]': 'gd_elev', 'topo[i]+h[i]': 'head', 'topo[i]+hc[i]': 'crit_head', 'u[i]': 'u'}¶
-
DIMENSION_OK
= [1.0, 1.5, 2.0]¶
-
ascii_grid
(value, filename, nrows=3)¶ Write an ascii grid GIS file.
The lowest left corner is set to the coordinates 0,0.
Parameters: - value (str) – A value from cols().
- filename (str) – Path to the file to write.
- nrows (int, optional) – The minimum number of rows in the output file. Default to 3.
Examples
>>> import pyswashes >>> macdonald = pyswashes.OneDimensional(2,1,2,5) >>> macdonald.ascii_grid('depth', 'test.asc') >>> with open('test.asc', 'r') as test_file: ... for l in test_file: ... print(l.strip()) ... NCOLS 5 NROWS 3 XLLCORNER 0.0 YLLCORNER 0.0 CELLSIZE 200.0 NODATA_VALUE -99999 <BLANKLINE> 0.770195 0.937035 1.112300 0.937035 0.770195 0.770195 0.937035 1.112300 0.937035 0.770195 0.770195 0.937035 1.112300 0.937035 0.770195
-
cols
()¶ Return a list of the available values.
Returns: Return type: list of strings Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2,1,2,6) >>> print(unidim.cols()) ['x', 'depth', 'u', 'gd_elev', 'q', 'head', 'Froude', 'crit_head']
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1,1,1,5) >>> print(pseudo2d.cols()) ['x', 'depth', 'gd_elev', 'head']
-
csv
()¶ Return the solution results as a CSV string.
Returns: Values are separated by a comma. Lines are separated by an OS specific line separator. Return type: str Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2, 1, 2, 5) >>> print(unidim.csv()) x,depth,u,gd_elev,q,head,Froude,crit_head 100,0.770195,2.59675,5.88374,2,6.65393,0.944702,6.62527 300,0.937035,2.13439,4.67542,2,5.61245,0.703982,5.41695 500,1.1123,1.79808,4.06441,2,5.17671,0.544331,4.80595 700,0.937035,2.13439,3.10854,2,4.04558,0.703982,3.85008 900,0.770195,2.59675,1.03618,2,1.80638,0.944702,1.77771
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1, 1, 1, 5) >>> print(pseudo2d.csv()) x,depth,gd_elev,head 20,0.912229,1.64477,2.55699 60,1.0348,0.844012,1.87881 100,1.2,0.314957,1.51496 140,1.0348,0.281316,1.31611 180,0.912229,0.093772,1.006
>>> twod = pyswashes.TwoDimensional(1,1,1,50,50) >>> print(twod.csv()) x,y,depth,u,v,head,gd_elev,U,Froude,qx,qy,q ... 2.84,1.64,0.0,0.0,0.0,-0.01648,-0.01648,0.0,NaN,0.0,0.0,0.0 2.84,1.72,0.0025,-7.12758e-09,2.37586e-09,-0.0191,-0.0216,7.51313e-09,4.79751e-08,-1.78189e-11,5.93965e-12,1.87828e-11 2.84,1.8,0.0085,-7.12758e-09,1.69704e-09,-0.01694,-0.02544,7.32682e-09,2.5373e-08,-6.05844e-11,1.44249e-11,6.2278e-11 2.84,1.88,0.0125,-7.12758e-09,1.01823e-09,-0.0155,-0.028,7.19994e-09,2.05608e-08,-8.90947e-11,1.27278e-11,8.99993e-11 2.84,1.96,0.0145,-7.12758e-09,3.39408e-10,-0.01478,-0.02928,7.13565e-09,1.89197e-08,-1.0335e-10,4.92142e-12,1.03467e-10 2.84,2.04,0.0145,-7.12758e-09,-3.39408e-10,-0.01478,-0.02928,7.13565e-09,1.89197e-08,-1.0335e-10,-4.92142e-12,1.03467e-10 2.84,2.12,0.0125,-7.12758e-09,-1.01823e-09,-0.0155,-0.028,7.19994e-09,2.05608e-08,-8.90947e-11,-1.27278e-11,8.99993e-11 2.84,2.2,0.0085,-7.12758e-09,-1.69704e-09,-0.01694,-0.02544,7.32682e-09,2.5373e-08,-6.05844e-11,-1.44249e-11,6.2278e-11 2.84,2.28,0.0025,-7.12758e-09,-2.37586e-09,-0.0191,-0.0216,7.51313e-09,4.79751e-08,-1.78189e-11,-5.93965e-12,1.87828e-11 2.84,2.36,0.0,0.0,0.0,-0.01648,-0.01648,0.0,NaN,0.0,0.0,0.0 ...
-
dataframe
()¶ Return the solution results as a Pandas DataFrame.
Returns: The X in meters is the index. Return type: Pandas dataframe Examples
>>> import pyswashes
>>> unidim = pyswashes.OneDimensional(2, 1, 2, 5) >>> print(unidim.dataframe()) depth u gd_elev q head Froude crit_head x 100 0.770195 2.59675 5.88374 2 6.65393 0.944702 6.62527 300 0.937035 2.13439 4.67542 2 5.61245 0.703982 5.41695 500 1.112300 1.79808 4.06441 2 5.17671 0.544331 4.80595 700 0.937035 2.13439 3.10854 2 4.04558 0.703982 3.85008 900 0.770195 2.59675 1.03618 2 1.80638 0.944702 1.77771
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1, 1, 1, 5) >>> print(pseudo2d.dataframe()) depth gd_elev head x 20 0.912229 1.644770 2.55699 60 1.034800 0.844012 1.87881 100 1.200000 0.314957 1.51496 140 1.034800 0.281316 1.31611 180 0.912229 0.093772 1.00600
-
static
get_number_from_str
(string)¶ get a parameter string from the swashes comments return the float after ‘:’ and before trailing space
-
np_array
(value)¶ Return a NumPy ndarray of the given value.
Parameters: value (str) – A value from cols(). Returns: Return type: NumPy ndarray Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2,1,2,6) >>> print(unidim.np_array('depth')) [0.764586 0.87793 1.07331 1.07331 0.87793 0.764586]
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1,1,1,5) >>> print(pseudo2d.np_array('depth')) [0.912229 1.0348 1.2 1.0348 0.912229]
Raises: ValueError
– If value is not in cols()
-
np_depth
()¶ Return a numpy array of the water depth. It is a shortcut to np_array().
Returns: Return type: NumPy ndarray Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2,1,2,6) >>> print(unidim.np_depth()) [0.764586 0.87793 1.07331 1.07331 0.87793 0.764586]
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1,1,1,5) >>> print(pseudo2d.np_depth()) [0.912229 1.0348 1.2 1.0348 0.912229]
It is equivalent to calling np_array() with the adequate value parameter:
>>> unidim.np_depth().all() == unidim.np_array(value=pyswashes.pyswashes.DEPTH).all() True
-
np_topo
()¶ Return a NumPy array of the topography (i.e, ground elevation). It is a shortcut to np_array().
Returns: Return type: NumPy ndarray Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2,1,2,6) >>> print(unidim.np_topo()) [6.04563 4.85287 4.18056 3.70591 2.65771 0.885902]
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1,1,1,5) >>> print(pseudo2d.np_topo()) [1.64477 0.844012 0.314957 0.281316 0.093772]
It is equivalent to calling np_array() with the adequate value parameter:
>>> unidim.np_topo().all() == unidim.np_array(value=pyswashes.pyswashes.GD_ELEVATION).all() True
-
class
pyswashes.pyswashes.
PseudoTwoDimensional
(stype, domain, choice, num_cell_x, swashes_bin='')¶ Bases:
pyswashes.pyswashes.SWASHES
A pseudo two-dimensional analytic solution.
To select stype, domain and choice, please refer to the SWASHES manual.
Parameters: - stype (int) – The type of the solution.
- domain (int) – The domain of the solution.
- choice (int) – The choice of solution.
- num_cell_x (int) – The number of cells in the X dimension.
- swashes_bin (str, optional) – Path to the SWASHES executable. Only needed if swashes is not in your PATH. Default to an empty string, which triggers the setting of the path to ‘swashes’ or ‘swashes.exe’, according to the platform.
-
dom_params
¶ The paramters of the domain.
Type: dictionary
Examples
Get a MacDonald pseudo 2D with Rectangular short channel, subcritical flow, discretized with five cells:
>>> import pyswashes >>> s = pyswashes.PseudoTwoDimensional(1, 1, 1, 5)
Report the solution’s domain pramaters:
>>> print(s.dom_params) {'length': 200.0, 'width': None, 'dx': 40.0, 'dy': None, 'ncellx': 5.0, 'ncelly': None}
Get a Pandas dataframe:
>>> print(s.dataframe()) depth gd_elev head x 20 0.912229 1.644770 2.55699 60 1.034800 0.844012 1.87881 100 1.200000 0.314957 1.51496 140 1.034800 0.281316 1.31611 180 0.912229 0.093772 1.00600
Raises: ValueError
– If the parameters are the wrong type.ValueError
– If num_cell_y is not given for a 2D solution.RuntimeError
– If the SWASHES executable is not foundRuntimeError
– When the SWASHES call returns an error
-
COLS
= {'(i-0.5)*dx': 'x', 'Fr[i]=Froude': 'Froude', 'h[i]': 'depth', 'q[i]': 'q', 'topo[i]': 'gd_elev', 'topo[i]+h[i]': 'head', 'topo[i]+hc[i]': 'crit_head', 'u[i]': 'u'}¶
-
DIMENSION_OK
= [1.0, 1.5, 2.0]¶
-
cols
()¶ Return a list of the available values.
Returns: Return type: list of strings Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2,1,2,6) >>> print(unidim.cols()) ['x', 'depth', 'u', 'gd_elev', 'q', 'head', 'Froude', 'crit_head']
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1,1,1,5) >>> print(pseudo2d.cols()) ['x', 'depth', 'gd_elev', 'head']
-
csv
()¶ Return the solution results as a CSV string.
Returns: Values are separated by a comma. Lines are separated by an OS specific line separator. Return type: str Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2, 1, 2, 5) >>> print(unidim.csv()) x,depth,u,gd_elev,q,head,Froude,crit_head 100,0.770195,2.59675,5.88374,2,6.65393,0.944702,6.62527 300,0.937035,2.13439,4.67542,2,5.61245,0.703982,5.41695 500,1.1123,1.79808,4.06441,2,5.17671,0.544331,4.80595 700,0.937035,2.13439,3.10854,2,4.04558,0.703982,3.85008 900,0.770195,2.59675,1.03618,2,1.80638,0.944702,1.77771
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1, 1, 1, 5) >>> print(pseudo2d.csv()) x,depth,gd_elev,head 20,0.912229,1.64477,2.55699 60,1.0348,0.844012,1.87881 100,1.2,0.314957,1.51496 140,1.0348,0.281316,1.31611 180,0.912229,0.093772,1.006
>>> twod = pyswashes.TwoDimensional(1,1,1,50,50) >>> print(twod.csv()) x,y,depth,u,v,head,gd_elev,U,Froude,qx,qy,q ... 2.84,1.64,0.0,0.0,0.0,-0.01648,-0.01648,0.0,NaN,0.0,0.0,0.0 2.84,1.72,0.0025,-7.12758e-09,2.37586e-09,-0.0191,-0.0216,7.51313e-09,4.79751e-08,-1.78189e-11,5.93965e-12,1.87828e-11 2.84,1.8,0.0085,-7.12758e-09,1.69704e-09,-0.01694,-0.02544,7.32682e-09,2.5373e-08,-6.05844e-11,1.44249e-11,6.2278e-11 2.84,1.88,0.0125,-7.12758e-09,1.01823e-09,-0.0155,-0.028,7.19994e-09,2.05608e-08,-8.90947e-11,1.27278e-11,8.99993e-11 2.84,1.96,0.0145,-7.12758e-09,3.39408e-10,-0.01478,-0.02928,7.13565e-09,1.89197e-08,-1.0335e-10,4.92142e-12,1.03467e-10 2.84,2.04,0.0145,-7.12758e-09,-3.39408e-10,-0.01478,-0.02928,7.13565e-09,1.89197e-08,-1.0335e-10,-4.92142e-12,1.03467e-10 2.84,2.12,0.0125,-7.12758e-09,-1.01823e-09,-0.0155,-0.028,7.19994e-09,2.05608e-08,-8.90947e-11,-1.27278e-11,8.99993e-11 2.84,2.2,0.0085,-7.12758e-09,-1.69704e-09,-0.01694,-0.02544,7.32682e-09,2.5373e-08,-6.05844e-11,-1.44249e-11,6.2278e-11 2.84,2.28,0.0025,-7.12758e-09,-2.37586e-09,-0.0191,-0.0216,7.51313e-09,4.79751e-08,-1.78189e-11,-5.93965e-12,1.87828e-11 2.84,2.36,0.0,0.0,0.0,-0.01648,-0.01648,0.0,NaN,0.0,0.0,0.0 ...
-
dataframe
()¶ Return the solution results as a Pandas DataFrame.
Returns: The X in meters is the index. Return type: Pandas dataframe Examples
>>> import pyswashes
>>> unidim = pyswashes.OneDimensional(2, 1, 2, 5) >>> print(unidim.dataframe()) depth u gd_elev q head Froude crit_head x 100 0.770195 2.59675 5.88374 2 6.65393 0.944702 6.62527 300 0.937035 2.13439 4.67542 2 5.61245 0.703982 5.41695 500 1.112300 1.79808 4.06441 2 5.17671 0.544331 4.80595 700 0.937035 2.13439 3.10854 2 4.04558 0.703982 3.85008 900 0.770195 2.59675 1.03618 2 1.80638 0.944702 1.77771
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1, 1, 1, 5) >>> print(pseudo2d.dataframe()) depth gd_elev head x 20 0.912229 1.644770 2.55699 60 1.034800 0.844012 1.87881 100 1.200000 0.314957 1.51496 140 1.034800 0.281316 1.31611 180 0.912229 0.093772 1.00600
-
static
get_number_from_str
(string)¶ get a parameter string from the swashes comments return the float after ‘:’ and before trailing space
-
np_array
(value)¶ Return a NumPy ndarray of the given value.
Parameters: value (str) – A value from cols(). Returns: Return type: NumPy ndarray Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2,1,2,6) >>> print(unidim.np_array('depth')) [0.764586 0.87793 1.07331 1.07331 0.87793 0.764586]
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1,1,1,5) >>> print(pseudo2d.np_array('depth')) [0.912229 1.0348 1.2 1.0348 0.912229]
Raises: ValueError
– If value is not in cols()
-
np_depth
()¶ Return a numpy array of the water depth. It is a shortcut to np_array().
Returns: Return type: NumPy ndarray Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2,1,2,6) >>> print(unidim.np_depth()) [0.764586 0.87793 1.07331 1.07331 0.87793 0.764586]
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1,1,1,5) >>> print(pseudo2d.np_depth()) [0.912229 1.0348 1.2 1.0348 0.912229]
It is equivalent to calling np_array() with the adequate value parameter:
>>> unidim.np_depth().all() == unidim.np_array(value=pyswashes.pyswashes.DEPTH).all() True
-
np_topo
()¶ Return a NumPy array of the topography (i.e, ground elevation). It is a shortcut to np_array().
Returns: Return type: NumPy ndarray Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2,1,2,6) >>> print(unidim.np_topo()) [6.04563 4.85287 4.18056 3.70591 2.65771 0.885902]
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1,1,1,5) >>> print(pseudo2d.np_topo()) [1.64477 0.844012 0.314957 0.281316 0.093772]
It is equivalent to calling np_array() with the adequate value parameter:
>>> unidim.np_topo().all() == unidim.np_array(value=pyswashes.pyswashes.GD_ELEVATION).all() True
-
class
pyswashes.pyswashes.
SWASHES
(dimension, stype, domain, choice, num_cell_x, num_cell_y=None, swashes_bin='')¶ Bases:
object
A base class that interfaces with a SWASHES analytic solution.
Please use OneDimensional, PseudoTwoDimensional and TwoDimensional for normal use, as they overload some methods of the base class.
Parameters: - dimension (float) – Dimension of the solution. Either 1., 1.5 or 2.
- stype (int) – The type of the solution.
- domain (int) – The domain of the solution.
- choice (int) – The choice of solution.
- num_cell_x (int) – The number of cells in the X dimension.
- num_cell_y (int, optional) – The number of cells in the Y dimension.
- swashes_bin (str, optional) – Path to the SWASHES executable. Only needed if swashes is not in your PATH. Default to an empty string, which triggers the setting of the path to ‘swashes’ or ‘swashes.exe’, according to the platform.
-
dom_params
¶ The parameters of the domain.
Type: dictionary
Raises: ValueError
– If the parameters are the wrong type.ValueError
– If num_cell_y is not given for a 2D solution.RuntimeError
– If the SWASHES executable is not foundRuntimeError
– When SWASHES returns an error
-
COLS
= {'(i-0.5)*dx': 'x', 'Fr[i]=Froude': 'Froude', 'h[i]': 'depth', 'q[i]': 'q', 'topo[i]': 'gd_elev', 'topo[i]+h[i]': 'head', 'topo[i]+hc[i]': 'crit_head', 'u[i]': 'u'}¶
-
DIMENSION_OK
= [1.0, 1.5, 2.0]¶
-
cols
()¶ Return a list of the available values.
Returns: Return type: list of strings Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2,1,2,6) >>> print(unidim.cols()) ['x', 'depth', 'u', 'gd_elev', 'q', 'head', 'Froude', 'crit_head']
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1,1,1,5) >>> print(pseudo2d.cols()) ['x', 'depth', 'gd_elev', 'head']
-
csv
()¶ Return the solution results as a CSV string.
Returns: Values are separated by a comma. Lines are separated by an OS specific line separator. Return type: str Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2, 1, 2, 5) >>> print(unidim.csv()) x,depth,u,gd_elev,q,head,Froude,crit_head 100,0.770195,2.59675,5.88374,2,6.65393,0.944702,6.62527 300,0.937035,2.13439,4.67542,2,5.61245,0.703982,5.41695 500,1.1123,1.79808,4.06441,2,5.17671,0.544331,4.80595 700,0.937035,2.13439,3.10854,2,4.04558,0.703982,3.85008 900,0.770195,2.59675,1.03618,2,1.80638,0.944702,1.77771
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1, 1, 1, 5) >>> print(pseudo2d.csv()) x,depth,gd_elev,head 20,0.912229,1.64477,2.55699 60,1.0348,0.844012,1.87881 100,1.2,0.314957,1.51496 140,1.0348,0.281316,1.31611 180,0.912229,0.093772,1.006
>>> twod = pyswashes.TwoDimensional(1,1,1,50,50) >>> print(twod.csv()) x,y,depth,u,v,head,gd_elev,U,Froude,qx,qy,q ... 2.84,1.64,0.0,0.0,0.0,-0.01648,-0.01648,0.0,NaN,0.0,0.0,0.0 2.84,1.72,0.0025,-7.12758e-09,2.37586e-09,-0.0191,-0.0216,7.51313e-09,4.79751e-08,-1.78189e-11,5.93965e-12,1.87828e-11 2.84,1.8,0.0085,-7.12758e-09,1.69704e-09,-0.01694,-0.02544,7.32682e-09,2.5373e-08,-6.05844e-11,1.44249e-11,6.2278e-11 2.84,1.88,0.0125,-7.12758e-09,1.01823e-09,-0.0155,-0.028,7.19994e-09,2.05608e-08,-8.90947e-11,1.27278e-11,8.99993e-11 2.84,1.96,0.0145,-7.12758e-09,3.39408e-10,-0.01478,-0.02928,7.13565e-09,1.89197e-08,-1.0335e-10,4.92142e-12,1.03467e-10 2.84,2.04,0.0145,-7.12758e-09,-3.39408e-10,-0.01478,-0.02928,7.13565e-09,1.89197e-08,-1.0335e-10,-4.92142e-12,1.03467e-10 2.84,2.12,0.0125,-7.12758e-09,-1.01823e-09,-0.0155,-0.028,7.19994e-09,2.05608e-08,-8.90947e-11,-1.27278e-11,8.99993e-11 2.84,2.2,0.0085,-7.12758e-09,-1.69704e-09,-0.01694,-0.02544,7.32682e-09,2.5373e-08,-6.05844e-11,-1.44249e-11,6.2278e-11 2.84,2.28,0.0025,-7.12758e-09,-2.37586e-09,-0.0191,-0.0216,7.51313e-09,4.79751e-08,-1.78189e-11,-5.93965e-12,1.87828e-11 2.84,2.36,0.0,0.0,0.0,-0.01648,-0.01648,0.0,NaN,0.0,0.0,0.0 ...
-
dataframe
()¶ Return the solution results as a Pandas DataFrame.
Returns: The X in meters is the index. Return type: Pandas dataframe Examples
>>> import pyswashes
>>> unidim = pyswashes.OneDimensional(2, 1, 2, 5) >>> print(unidim.dataframe()) depth u gd_elev q head Froude crit_head x 100 0.770195 2.59675 5.88374 2 6.65393 0.944702 6.62527 300 0.937035 2.13439 4.67542 2 5.61245 0.703982 5.41695 500 1.112300 1.79808 4.06441 2 5.17671 0.544331 4.80595 700 0.937035 2.13439 3.10854 2 4.04558 0.703982 3.85008 900 0.770195 2.59675 1.03618 2 1.80638 0.944702 1.77771
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1, 1, 1, 5) >>> print(pseudo2d.dataframe()) depth gd_elev head x 20 0.912229 1.644770 2.55699 60 1.034800 0.844012 1.87881 100 1.200000 0.314957 1.51496 140 1.034800 0.281316 1.31611 180 0.912229 0.093772 1.00600
-
static
get_number_from_str
(string)¶ get a parameter string from the swashes comments return the float after ‘:’ and before trailing space
-
np_array
(value)¶ Return a NumPy ndarray of the given value.
Parameters: value (str) – A value from cols(). Returns: Return type: NumPy ndarray Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2,1,2,6) >>> print(unidim.np_array('depth')) [0.764586 0.87793 1.07331 1.07331 0.87793 0.764586]
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1,1,1,5) >>> print(pseudo2d.np_array('depth')) [0.912229 1.0348 1.2 1.0348 0.912229]
Raises: ValueError
– If value is not in cols()
-
np_depth
()¶ Return a numpy array of the water depth. It is a shortcut to np_array().
Returns: Return type: NumPy ndarray Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2,1,2,6) >>> print(unidim.np_depth()) [0.764586 0.87793 1.07331 1.07331 0.87793 0.764586]
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1,1,1,5) >>> print(pseudo2d.np_depth()) [0.912229 1.0348 1.2 1.0348 0.912229]
It is equivalent to calling np_array() with the adequate value parameter:
>>> unidim.np_depth().all() == unidim.np_array(value=pyswashes.pyswashes.DEPTH).all() True
-
np_topo
()¶ Return a NumPy array of the topography (i.e, ground elevation). It is a shortcut to np_array().
Returns: Return type: NumPy ndarray Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2,1,2,6) >>> print(unidim.np_topo()) [6.04563 4.85287 4.18056 3.70591 2.65771 0.885902]
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1,1,1,5) >>> print(pseudo2d.np_topo()) [1.64477 0.844012 0.314957 0.281316 0.093772]
It is equivalent to calling np_array() with the adequate value parameter:
>>> unidim.np_topo().all() == unidim.np_array(value=pyswashes.pyswashes.GD_ELEVATION).all() True
-
class
pyswashes.pyswashes.
TwoDimensional
(stype, domain, choice, num_cell_x, num_cell_y, swashes_bin='')¶ Bases:
pyswashes.pyswashes.SWASHES
A two-dimensional analytic solution.
To select stype, domain and choice, please refer to the SWASHES manual.
Parameters: - stype (int) – The type of the solution.
- domain (int) – The domain of the solution.
- choice (int) – The choice of solution.
- num_cell_x (int) – The number of cells in the X dimension.
- num_cell_y (int) – The number of cells in the X dimension.
- swashes_bin (str, optional) – Path to the SWASHES executable. Only needed if swashes is not in your PATH. Default to an empty string, which triggers the setting of the path to ‘swashes’ or ‘swashes.exe’, according to the platform.
-
dom_params
¶ The paramters of the domain.
Type: dictionary
Examples
Get a radially-symmetrical paraboloid (Thacker’s solution), discretized with 5x5 cells:
>>> import pyswashes >>> s = pyswashes.TwoDimensional(1, 1, 1, 5, 5)
Report the solution’s domain pramaters:
>>> print(s.dom_params) {'length': 4.0, 'width': 4.0, 'dx': 0.8, 'dy': 0.8, 'ncellx': 5.0, 'ncelly': 5.0}
Get a NumPy array of the ground elevation:
>>> print(s.np_topo()) [[ 0.412 0.22 0.156 0.22 0.412] [ 0.22 0.028 -0.036 0.028 0.22 ] [ 0.156 -0.036 -0.1 -0.036 0.156] [ 0.22 0.028 -0.036 0.028 0.22 ] [ 0.412 0.22 0.156 0.22 0.412]]
Raises: ValueError
– If the parameters are the wrong type.ValueError
– If num_cell_y is not given for a 2D solution.RuntimeError
– If the SWASHES executable is not foundRuntimeError
– When the SWASHES call returns an error
-
COLS
= {'(i-0.5)*dx': 'x', '(j-0.5)*dy': 'y', 'Fr[i][j]': 'Froude', 'h[i][j]': 'depth', 'q[i][j]': 'q', 'qx[i][j]': 'qx', 'qy[i][j]': 'qy', 'topo[i][j]': 'gd_elev', 'topo[i][j]+h[i][j]': 'head', 'u[i][j]': 'u', 'v[i][j]': 'v', '||U||[i][j]': 'U'}¶
-
DIMENSION_OK
= [1.0, 1.5, 2.0]¶
-
ascii_grid
(value, filename)¶ Write an ascii grid GIS file.
The lowest left corner is set to the coordinates 0,0.
Parameters: - value (str) – A value from cols().
- filename (str) – Path to the file to write.
Examples
>>> import pyswashes >>> thacker = pyswashes.TwoDimensional(1, 1, 1, 3, 3) >>> thacker.ascii_grid('depth', 'thacker.asc') >>> with open('thacker.asc', 'r') as test_file: ... for l in test_file: ... print(l.strip()) ... NCOLS 3 NROWS 3 XLLCORNER 0.0 YLLCORNER 0.0 DX 1.33333 DY 1.33333 NODATA_VALUE -99999 <BLANKLINE> 0.000000 0.000000 0.000000 0.000000 0.125000 0.000000 0.000000 0.000000 0.000000
-
cols
()¶ Return a list of the available values.
Returns: Return type: list of strings Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2,1,2,6) >>> print(unidim.cols()) ['x', 'depth', 'u', 'gd_elev', 'q', 'head', 'Froude', 'crit_head']
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1,1,1,5) >>> print(pseudo2d.cols()) ['x', 'depth', 'gd_elev', 'head']
-
csv
()¶ Return the solution results as a CSV string.
Returns: Values are separated by a comma. Lines are separated by an OS specific line separator. Return type: str Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2, 1, 2, 5) >>> print(unidim.csv()) x,depth,u,gd_elev,q,head,Froude,crit_head 100,0.770195,2.59675,5.88374,2,6.65393,0.944702,6.62527 300,0.937035,2.13439,4.67542,2,5.61245,0.703982,5.41695 500,1.1123,1.79808,4.06441,2,5.17671,0.544331,4.80595 700,0.937035,2.13439,3.10854,2,4.04558,0.703982,3.85008 900,0.770195,2.59675,1.03618,2,1.80638,0.944702,1.77771
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1, 1, 1, 5) >>> print(pseudo2d.csv()) x,depth,gd_elev,head 20,0.912229,1.64477,2.55699 60,1.0348,0.844012,1.87881 100,1.2,0.314957,1.51496 140,1.0348,0.281316,1.31611 180,0.912229,0.093772,1.006
>>> twod = pyswashes.TwoDimensional(1,1,1,50,50) >>> print(twod.csv()) x,y,depth,u,v,head,gd_elev,U,Froude,qx,qy,q ... 2.84,1.64,0.0,0.0,0.0,-0.01648,-0.01648,0.0,NaN,0.0,0.0,0.0 2.84,1.72,0.0025,-7.12758e-09,2.37586e-09,-0.0191,-0.0216,7.51313e-09,4.79751e-08,-1.78189e-11,5.93965e-12,1.87828e-11 2.84,1.8,0.0085,-7.12758e-09,1.69704e-09,-0.01694,-0.02544,7.32682e-09,2.5373e-08,-6.05844e-11,1.44249e-11,6.2278e-11 2.84,1.88,0.0125,-7.12758e-09,1.01823e-09,-0.0155,-0.028,7.19994e-09,2.05608e-08,-8.90947e-11,1.27278e-11,8.99993e-11 2.84,1.96,0.0145,-7.12758e-09,3.39408e-10,-0.01478,-0.02928,7.13565e-09,1.89197e-08,-1.0335e-10,4.92142e-12,1.03467e-10 2.84,2.04,0.0145,-7.12758e-09,-3.39408e-10,-0.01478,-0.02928,7.13565e-09,1.89197e-08,-1.0335e-10,-4.92142e-12,1.03467e-10 2.84,2.12,0.0125,-7.12758e-09,-1.01823e-09,-0.0155,-0.028,7.19994e-09,2.05608e-08,-8.90947e-11,-1.27278e-11,8.99993e-11 2.84,2.2,0.0085,-7.12758e-09,-1.69704e-09,-0.01694,-0.02544,7.32682e-09,2.5373e-08,-6.05844e-11,-1.44249e-11,6.2278e-11 2.84,2.28,0.0025,-7.12758e-09,-2.37586e-09,-0.0191,-0.0216,7.51313e-09,4.79751e-08,-1.78189e-11,-5.93965e-12,1.87828e-11 2.84,2.36,0.0,0.0,0.0,-0.01648,-0.01648,0.0,NaN,0.0,0.0,0.0 ...
-
dataframe
()¶ Return a pandas DataFrame with two indices.
Returns: The X in meters is the index. Return type: Pandas dataframe Examples
>>> import pyswashes >>> thacker = pyswashes.TwoDimensional(1, 1, 1, 3, 3)
Get the ground elevation Pandas Series:
>>> print(thacker.dataframe()[pyswashes.pyswashes.GD_ELEVATION]) x y 0.666667 0.666667 0.255556 2.000000 0.077778 3.333330 0.255556 2.000000 0.666667 0.077778 2.000000 -0.100000 3.333330 0.077778 3.333330 0.666667 0.255556 2.000000 0.077778 3.333330 0.255556 Name: gd_elev, dtype: float64
-
static
get_number_from_str
(string)¶ get a parameter string from the swashes comments return the float after ‘:’ and before trailing space
-
np_array
(value)¶ Return a NumPy ndarray of the given value.
Returns: Return type: NumPy ndarray Examples
>>> import pyswashes >>> s = pyswashes.TwoDimensional(1,1,1,5,5) >>> print(s.np_array('depth')) [[0. 0. 0. 0. 0. ] [0. 0. 0.025 0. 0. ] [0. 0.025 0.125 0.025 0. ] [0. 0. 0.025 0. 0. ] [0. 0. 0. 0. 0. ]]
-
np_depth
()¶ Return a numpy array of the water depth. It is a shortcut to np_array().
Returns: Return type: NumPy ndarray Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2,1,2,6) >>> print(unidim.np_depth()) [0.764586 0.87793 1.07331 1.07331 0.87793 0.764586]
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1,1,1,5) >>> print(pseudo2d.np_depth()) [0.912229 1.0348 1.2 1.0348 0.912229]
It is equivalent to calling np_array() with the adequate value parameter:
>>> unidim.np_depth().all() == unidim.np_array(value=pyswashes.pyswashes.DEPTH).all() True
-
np_topo
()¶ Return a NumPy array of the topography (i.e, ground elevation). It is a shortcut to np_array().
Returns: Return type: NumPy ndarray Examples
>>> import pyswashes >>> unidim = pyswashes.OneDimensional(2,1,2,6) >>> print(unidim.np_topo()) [6.04563 4.85287 4.18056 3.70591 2.65771 0.885902]
>>> pseudo2d = pyswashes.PseudoTwoDimensional(1,1,1,5) >>> print(pseudo2d.np_topo()) [1.64477 0.844012 0.314957 0.281316 0.093772]
It is equivalent to calling np_array() with the adequate value parameter:
>>> unidim.np_topo().all() == unidim.np_array(value=pyswashes.pyswashes.GD_ELEVATION).all() True