Reading .mat files

An initial attempt to load the files into Python


In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import modred as mr
import pandas as pd

In [2]:
1+1


Out[2]:
2

In [11]:
import h5py
f = h5py.File('/Users/Owen/Dropbox/Data/ABL/Heat Flux Data/Processed Results/N/Neutral45_2.mat')
list(f.keys())


Out[11]:
['Cond',
 'PercentMissing',
 'Prof',
 'Swirl',
 'U',
 'V',
 'Vort',
 'W',
 'X',
 'Y',
 'source']

In [4]:
swirl = np.asarray(f['Swirl'])
X  = np.asarray(f['X'])
Y  = np.asarray(f['Y'])
U  = np.asarray(f['U'])
V  = np.asarray(f['V'])

Import all data in different structures


In [5]:
k = f["Cond"].keys()

In [6]:
d= f["Cond"]["delta"]

In [7]:
list(k)


Out[7]:
['Cf',
 'Cf_PantonMax',
 'Cf_TotStress',
 'H',
 'Hama',
 'P',
 'Red',
 'Retau',
 'Retau_TotStress',
 'Retheta',
 'Tinf',
 'Uinf',
 'Utau',
 'Utau_PantonMax',
 'Utau_TotStress',
 'WakeFac',
 'a',
 'dXplus',
 'delstar',
 'delta',
 'delta99',
 'dk',
 'dks',
 'dt',
 'isHeat',
 'isRough',
 'k',
 'kplus',
 'ks',
 'ksplus',
 'mu',
 'nu',
 'origin',
 'rho',
 'theta',
 'ymin',
 'yminHard']

In [9]:
d.value


Out[9]:
array([[ 0.12752905]])

In [76]:
L  = [i**2 for i in range(10)]       #list comprehensions  (also look up generator expressions)
L


Out[76]:
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

In [87]:
D = {1:2, 'abc':4}        #Defining a dictionary object
D['abc']


Out[87]:
4

In [83]:
D['Cf']


Out[83]:
array([ 0.00766106])

In [8]:
k = f["Cond"].keys()     #Longer way to generate a pandas Series with all the values in Cond

Cond = pd.Series()
for i in list(k):
    #d = f["Cond"][i].value[0]
    #print(i, " = ", f["Cond"][i].value[0])
    s1 = pd.Series(f["Cond"][i].value[0], index = [i])
    Cond = Cond.append(s1)

In [72]:
Cond['Uinf']


Out[72]:
1.5511073539843001

In [96]:
Cond = {k : f["Cond"][k].value[0]       #Generate a dictionary linking all values in cond with their names
     for k in f['Cond'].keys()}

In [97]:
Cond['Uinf']      #look up in pandas or dictionary object is the same


Out[97]:
array([ 1.55110735])

In [124]:
k = f["Prof"].keys()                 #Once again long way to generate pandas object with all profiles
Prof = pd.Series()
for i in list(k):
    d = f["Prof"][i].value
    #print(i, " = " , f["Prof"][i].value)
    s1 = pd.Series(f["Prof"][i].value, index = [i])
    Prof = Prof.append(s1)


---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-124-a36d80a84582> in <module>()
      4     d = f["Prof"][i].value
      5     #print(i, " = " , f["Prof"][i].value)
----> 6     s1 = pd.Series(f["Prof"][i].value, index = [i])
      7     Prof = Prof.append(s1)

/Users/Owen/anaconda/lib/python3.5/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
    225             else:
    226                 data = _sanitize_array(data, index, dtype, copy,
--> 227                                        raise_cast_failure=True)
    228 
    229                 data = SingleBlockManager(data, index, fastpath=True)

/Users/Owen/anaconda/lib/python3.5/site-packages/pandas/core/series.py in _sanitize_array(data, index, dtype, copy, raise_cast_failure)
   2918     elif subarr.ndim > 1:
   2919         if isinstance(data, np.ndarray):
-> 2920             raise Exception('Data must be 1-dimensional')
   2921         else:
   2922             subarr = _asarray_tuplesafe(data, dtype=dtype)

Exception: Data must be 1-dimensional

In [99]:
Prof = {k : f["Prof"][k].value       #Generate a dictionary linking all values in cond with their names
     for k in f['Prof'].keys()}

In [122]:
Prof = pd.Series({k : f["Prof"][k].value       #Generate a pandas series from the dictionary
     for k in f['Prof'].keys()})

In [123]:
Prof['U']


Out[123]:
array([[ 0.45342252],
       [ 0.57517629],
       [ 0.64734552],
       [ 0.69517523],
       [ 0.73423424],
       [ 0.76830475],
       [ 0.79868198],
       [ 0.82615088],
       [ 0.85109742],
       [ 0.87394854],
       [ 0.89507748],
       [ 0.9146698 ],
       [ 0.93290643],
       [ 0.95012068],
       [ 0.96660341],
       [ 0.98252511],
       [ 0.99790738],
       [ 1.01271951],
       [ 1.02705902],
       [ 1.04111397],
       [ 1.05500919],
       [ 1.06875369],
       [ 1.08225632],
       [ 1.09541443],
       [ 1.10811254],
       [ 1.12018675],
       [ 1.13156542],
       [ 1.14245016],
       [ 1.15310912],
       [ 1.16361449],
       [ 1.17397355],
       [ 1.18424813],
       [ 1.19451301],
       [ 1.20475746],
       [ 1.21488573],
       [ 1.22476869],
       [ 1.23428833],
       [ 1.24342934],
       [ 1.25232323],
       [ 1.26117083],
       [ 1.27001564],
       [ 1.27878151],
       [ 1.28750017],
       [ 1.29620807],
       [ 1.30482462],
       [ 1.31325355],
       [ 1.32148061],
       [ 1.32955632],
       [ 1.33756194],
       [ 1.34553263],
       [ 1.35341247],
       [ 1.36113784],
       [ 1.36867781],
       [ 1.37601451],
       [ 1.38319874],
       [ 1.39028384],
       [ 1.3972886 ],
       [ 1.40428248],
       [ 1.411226  ],
       [ 1.41806879],
       [ 1.42482936],
       [ 1.43147483],
       [ 1.43796488],
       [ 1.44435721],
       [ 1.45063336],
       [ 1.45675166],
       [ 1.46274383],
       [ 1.46854537],
       [ 1.4740909 ],
       [ 1.47944098],
       [ 1.48462515],
       [ 1.48965989],
       [ 1.49458744],
       [ 1.49938707],
       [ 1.50399536],
       [ 1.50843265],
       [ 1.51269798],
       [ 1.51674237],
       [ 1.52053081],
       [ 1.52407889],
       [ 1.52742024],
       [ 1.53051882],
       [ 1.53332631],
       [ 1.53586559],
       [ 1.53816485],
       [ 1.54026933],
       [ 1.54223446],
       [ 1.54400228],
       [ 1.54550687],
       [ 1.54679191],
       [ 1.54786889],
       [ 1.54874676],
       [ 1.5494945 ],
       [ 1.55012569],
       [ 1.5505857 ],
       [ 1.55086365],
       [ 1.55101809],
       [ 1.55110735],
       [ 1.55110156],
       [ 1.55091518],
       [ 1.5505818 ],
       [ 1.55018522],
       [ 1.54976897],
       [ 1.549339  ],
       [ 1.54885178],
       [ 1.54831427],
       [ 1.54772765],
       [ 1.54705476],
       [ 1.54633086],
       [ 1.54562906],
       [ 1.54497034],
       [ 1.54434726],
       [ 1.54376949],
       [ 1.5432302 ],
       [ 1.54263597],
       [ 1.54189257],
       [ 1.54113783],
       [ 1.54052205],
       [ 1.53998011],
       [ 1.53941405],
       [ 1.53875803],
       [ 1.53803295],
       [ 1.53738971]])

In [109]:



Out[109]:
0     [[0.00656057012771], [0.00891317125211], [0.00...
1     [[0.453422523309], [0.575176287133], [0.647345...
2     [[11.4342169862], [10.165948613], [9.414185741...
3     [[4.72315128446], [5.99141965763], [6.74318252...
4     [[-0.00369352708279], [-0.00350899331086], [-0...
5     [[0.0192880464671, 0.0294065628443, 0.03952507...
6     [[15.1784114335, 23.1410117378, 31.1036120422,...
7     [[0.00235978627205, 0.00365019106865, 0.004940...
8     [[94.3531550294], [75.1403745717], [46.4966292...
9     [[35.1236782462], [35.1236782462], [35.1236782...
10    [[113.389816437], [68.1967890102], [47.7661072...
11    [[0.0308817197247], [0.0310900588378], [0.0313...
12    [[-0.00408172232671], [-0.00637070780078], [-0...
13    [[0.00355036513536], [0.00534670466723], [0.00...
dtype: object

Now start looking at the data


In [21]:
for i in range(1):
    plt.figure()
    plt.imshow(swirl[i].T, cmap='RdBu', origin='lower');
    plt.clim([-50, 50])



In [27]:
for i in range(1):
    plt.figure()
    plt.pcolor(X.T,Y.T,swirl[i].T, cmap='RdBu');
    plt.clim([-50, 50])
    plt.axis('equal')
    plt.axis([0, X.max(), 0, Y.max()])
    #plt.yaxis([0, Y.max()])



In [18]:
Y.max()


Out[18]:
0.15978917145729066

In [29]:
num_modes = 50;
modes, eig_vals = mr.compute_POD_matrices_snaps_method(U, list(range(num_modes)))


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-29-cc223aa528ee> in <module>()
      1 num_modes = 50;
----> 2 modes, eig_vals = mr.compute_POD_matrices_snaps_method(U, list(range(num_modes)))

/Users/Owen/anaconda/lib/python3.5/site-packages/modred/pod.py in compute_POD_matrices_snaps_method(vecs, mode_indices, inner_product_weights, atol, rtol, return_all)
     67     vec_space = VectorSpaceMatrices(weights=inner_product_weights)
     68     # compute decomp
---> 69     vecs = util.make_mat(vecs)
     70     correlation_mat = \
     71         vec_space.compute_symmetric_inner_product_mat(vecs)

/Users/Owen/anaconda/lib/python3.5/site-packages/modred/util.py in make_mat(array)
     16     if array.ndim == 1:
     17         array = array.reshape((array.shape[0], 1))
---> 18     return np.mat(array)
     19 
     20 def make_iterable(arg):

/Users/Owen/anaconda/lib/python3.5/site-packages/numpy/matrixlib/defmatrix.py in asmatrix(data, dtype)
     96 
     97     """
---> 98     return matrix(data, dtype=dtype, copy=False)
     99 
    100 def matrix_power(M, n):

/Users/Owen/anaconda/lib/python3.5/site-packages/numpy/matrixlib/defmatrix.py in __new__(subtype, data, dtype, copy)
    258             else:
    259                 intype = N.dtype(dtype)
--> 260             new = data.view(subtype)
    261             if intype != data.dtype:
    262                 return new.astype(intype)

/Users/Owen/anaconda/lib/python3.5/site-packages/numpy/matrixlib/defmatrix.py in __array_finalize__(self, obj)
    303                 return
    304             elif (ndim > 2):
--> 305                 raise ValueError("shape too large to be a matrix.")
    306         else:
    307             newshape = self.shape

ValueError: shape too large to be a matrix.

In [1]:
a = U.shape


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-84d9dd0524b9> in <module>()
----> 1 a = U.shape

NameError: name 'U' is not defined

In [ ]: