In [20]:
import numpy as np
from PyQt4 import QtGui
import sys
import os
import matplotlib.pyplot as plt
import mpl_toolkits.basemap.pyproj as pyproj
from pydelft import dep, grd

In [21]:
fname = r'z:\Aleutians\models\sedanka_2d_profiles\eq_sources\nesting_try2\10m\run4\asp_onethird_stardust_rotated.dep'
grd_fname = r'z:\Aleutians\models\sedanka_2d_profiles\eq_sources\nesting_try2\10m\run4\sedanka_rotated_onethird_WGS84.grd'
# Read lines
f = open(fname, 'r')
lines = f.readlines()

if '\t' in lines[0]:
    delimiter = '\t'
else:
    delimiter = 'space'

z = []

# 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':
        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 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))


# update the class
self.depth = z
self.filename = fname
self.delimiter = delimiter

fname = None

f.close()


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-21-f342b71116c3> in <module>()
     15 if grd_fname:
     16     grid = grd.grd()
---> 17     grid.read_grd(grd_fname)
     18     z = np.ma.masked_equal(z, -999.)
     19     z = np.ma.compressed(z)

C:\Users\slaselle@usgs.gov\Documents\GitHub\pydelft\grd.py in read_grd(self, fname, nan_value)
     83         coordinate_system = [h for h in header if 'Coordinate System' in h][0].rstrip('\n').split('=')[1]
     84         shape = header[np.where(header == [h for h in header if 'Coordinate System' in h][0])[0][0]+1].split()
---> 85         m, n = int(shape[1]), int(shape[0])
     86 
     87         # Read the coordinates

ValueError: invalid literal for int() with base 10: 'Value'

In [9]:
np.shape(z)


Out[9]:
(206724,)

In [12]:
test = np.ma.masked_equal(z, -999.)
rtest = np.ma.compressed(test)

In [14]:
rtest.shape


Out[14]:
(205761,)

In [16]:
newtest = rtest.reshape((641,321))

In [18]:
%matplotlib inline
plt.pcolormesh(newtest)


Out[18]:
<matplotlib.collections.QuadMesh at 0x8766898>

In [ ]: