From 971c0ae976608a346a5ce459e1f7f5df17e42ab1 Mon Sep 17 00:00:00 2001 From: Paul Garlick Date: Wed, 8 Jul 2020 13:45:00 +0100 Subject: python: slope.py: Deduce grid dimensions from file data. * python/slope.py: Import math module. Use file data instead of file header. --- python/slope.py | 24 +++++++++++++++--------- 1 file 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 -- cgit