diff options
| author | Paul Garlick <pgarlick@tourbillion-technology.com> | 2020-07-08 13:45:00 +0100 | 
|---|---|---|
| committer | Paul Garlick <pgarlick@tourbillion-technology.com> | 2020-07-08 13:56:05 +0100 | 
| commit | 971c0ae976608a346a5ce459e1f7f5df17e42ab1 (patch) | |
| tree | 0983c7f2cb8bf8bfcfdaf3e43a285f801b2fba01 /python | |
| parent | 57eb09e7029bcb33d0fbe37e9e7e4ba96a97a65f (diff) | |
| download | fullSWOF-utils-971c0ae976608a346a5ce459e1f7f5df17e42ab1.tar.gz | |
python: slope.py: Deduce grid dimensions from file data.
* python/slope.py: Import math module.  Use file data instead of
file header.
Diffstat (limited to 'python')
| -rwxr-xr-x | python/slope.py | 24 | 
1 files changed, 15 insertions, 9 deletions
| diff --git a/python/slope.py b/python/slope.py index 4a5fa4b..eb4850b 100755 --- a/python/slope.py +++ b/python/slope.py @@ -3,21 +3,27 @@  import matplotlib.colors as colors  import matplotlib.pyplot as plt  import numpy as np +import math  import os  with open('./topography.txt', "r") as data: -    while True: -        p = data.tell() -        line = data.readline() -        col1, col2, col3 = line.strip().split() -        if col2 == 'ncols': NXCELL = int(col3) #number of cells in x direction -        if col2 == 'nrows': NYCELL = int(col3) #number of cells in y direction -        if not line.startswith('#'): -            data.seek(p) # go back one line -            break +    # while True: +    #     p = data.tell() +    #     line = data.readline() +    #     col1, col2, col3 = line.strip().split() +    #     if col2 == 'ncols': NXCELL = int(col3) #number of cells in x direction +    #     if col2 == 'nrows': NYCELL = int(col3) #number of cells in y direction +    #     if not line.startswith('#'): +    #         data.seek(p) # go back one line +    #         break      x, y, z = np.loadtxt(data, delimiter=' ', unpack=True) +xmax   = (x[0]+x[-1])                     # domain extent in x-direction +ymax   = (y[0]+y[-1])                     # domain extent in y-direction +NXCELL = int(math.sqrt(len(x)*xmax/ymax)) # number of cells in x-direction +NYCELL = int(len(x)/NXCELL)               # number of cells in y-direction +  # first reshape to 2-D array then rotate by ninety degrees and flip in  # vertical direction to conform to FullSWOF indexing convention  x_co = np.flipud(np.rot90(np.reshape(x, (NXCELL,NYCELL)))) # x co-ordinates | 
