diff options
| -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 | 
