In [2]:
from pydelft import grd, dep
import matplotlib.pyplot as plt
import numpy as np
import sys 
import os
%matplotlib inline

In [7]:
gfname = '../test_data/natori_10_v1.0.grd'
dfname = '../test_data/natori_10_v1.0.dep'

dep.py


In [14]:
grd_fname = None

f = open(dfname, 'r')
lines = f.readlines()

if '\t' in lines[0]:
    delimiter = '\t'
else:
    delimiter = 'space'
print('Delimiter = %s' % delimiter)


z = []

if delimiter != 'space':
    for line in lines:
        for s in line.split('%s' % delimiter):
            z.append(float(s))
else:
    for line in lines:
        for s in line.split():
            z.append(float(s))

# Reshape depth
if grd_fname:
    grid = grd.grd()
    grid.read_grd(grd_fname)
    z = np.ma.masked_equal(z, -999.)
    z = np.ma.compressed(z)
    z = np.reshape(z, (grid.m, grid.n))
else:
    if delimiter != 'space':
        z = np.reshape(z, (np.size(lines),
            np.size(line.split('%s' % delimiter))))
        z = z[:-1, :-1] # get rid of -999. Nans
        z = np.reshape(z, (np.size(lines)-1, np.size(line.split())-1))

        z = z[:-1, :-1] # get rid of -999. Nans
    else:
        a = np.where(np.array(z) == -999.)
        cols = np.max(np.ediff1d(a))
        rows = np.size(np.array_split(a[0],np.where(np.diff(a[0])!=1)[0]+1))
        z = np.reshape(z, (rows, cols))


Delimiter = space
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.4/site-packages/numpy/core/fromnumeric.py in reshape(a, newshape, order)
    217     try:
--> 218         reshape = a.reshape
    219     except AttributeError:

AttributeError: 'list' object has no attribute 'reshape'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-14-5bb11bb68c6c> in <module>()
     41         cols = np.max(np.ediff1d(a))
     42         rows = np.size(np.array_split(a[0],np.where(np.diff(a[0])!=1)[0]+1))
---> 43         z = np.reshape(z, (rows, cols))

/usr/local/lib/python3.4/site-packages/numpy/core/fromnumeric.py in reshape(a, newshape, order)
    218         reshape = a.reshape
    219     except AttributeError:
--> 220         return _wrapit(a, 'reshape', newshape, order=order)
    221     return reshape(newshape, order=order)
    222 

/usr/local/lib/python3.4/site-packages/numpy/core/fromnumeric.py in _wrapit(obj, method, *args, **kwds)
     43     except AttributeError:
     44         wrap = None
---> 45     result = getattr(asarray(obj), method)(*args, **kwds)
     46     if wrap:
     47         if not isinstance(result, mu.ndarray):

ValueError: total size of new array must be unchanged

In [ ]:
np.shape(z)

Test functionality


In [9]:
sedanka_grid = grd.grd()
sedanka_depth = dep.dep()

sedanka_grid.read_grd(gfname)
sedanka_depth.read_dep(dfname)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.4/site-packages/numpy/core/fromnumeric.py in reshape(a, newshape, order)
    217     try:
--> 218         reshape = a.reshape
    219     except AttributeError:

AttributeError: 'list' object has no attribute 'reshape'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-9-373d83721df7> in <module>()
      3 
      4 sedanka_grid.read_grd(gfname)
----> 5 sedanka_depth.read_dep(dfname)

/Users/slaselle/GitHub/pydelft/dep.py in read_dep(self, fname, grd_fname)
     98                 cols = np.max(np.ediff1d(a))
     99                 rows = np.size(np.array_split(a[0],np.where(np.diff(a[0])!=1)[0]+1))
--> 100                 z = np.reshape(z, (rows, cols))
    101 
    102 

/usr/local/lib/python3.4/site-packages/numpy/core/fromnumeric.py in reshape(a, newshape, order)
    218         reshape = a.reshape
    219     except AttributeError:
--> 220         return _wrapit(a, 'reshape', newshape, order=order)
    221     return reshape(newshape, order=order)
    222 

/usr/local/lib/python3.4/site-packages/numpy/core/fromnumeric.py in _wrapit(obj, method, *args, **kwds)
     43     except AttributeError:
     44         wrap = None
---> 45     result = getattr(asarray(obj), method)(*args, **kwds)
     46     if wrap:
     47         if not isinstance(result, mu.ndarray):

ValueError: total size of new array must be unchanged

In [4]:
sedanka_depth = dep(dfname, gfname)
sedanka_depth.plot_dep()



In [4]: