In [25]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import h5py
import PIVutils
from importlib import reload

saveFolder = './'

In [26]:
X, Y, U, V, Cond, Prof = PIVutils.importMatlabPIVdata('/Users/Owen/Dropbox/Data/ABL/SBL PIV data/RNV45-RI2.mat',['X','Y','U','V'],['Cond','Prof'])


['#refs#', 'AutoCorr', 'Cond', 'Corr', 'CorrT', 'Err', 'PercentMissing', 'Prof', 'Quad', 'Swirl', 'U', 'V', 'W', 'X', 'Y', 'source']

In [28]:
f = h5py.File('/Users/Owen/Dropbox/Python Codes/ASIIT/Data/testSave3.hdf5','w')

In [ ]:
Uset = f.create_dataset("U", data=U)

In [ ]:
Uset.dtype

In [ ]:
"U" in f

In [ ]:
f.close()

In [15]:
f = h5py.File('/Users/Owen/Dropbox/Python Codes/ASIIT/Data/testSave.hdf5','r')

In [ ]:
a = f.keys()

In [ ]:
list(f.keys())

In [ ]:
names = ['X','Y','V']
data = [X,Y,V]

In [ ]:
range(len(names))

In [ ]:
for i in range(len(names)):
    print(i)

In [ ]:
for i in range(len(names)):
    f.create_dataset(names[i], data=data[i])

In [ ]:
f.close()

In [57]:
reload(PIVutils)
PIVutils.saveDataset('/Users/Owen/Dropbox/Python Codes/ASIIT/Data/testSave4.hdf5',\
                    ['X','Y','U','V'],[X,Y,U,V],\
                     ['Cond','Prof'],[Cond,Prof])


Delete original file (default: no) [y/N] y
Original file deleted
File saved

In [ ]:
f.close()

In [7]:
Cond.items()


Out[7]:
dict_items([('dk', array([ 31.38018001])), ('L111', array([ 0.04891709])), ('ks', array([ 10.68830707])), ('Utau_PantonMax', array([ 0.0949339])), ('Retau_TotStress', array([ 748.62788899])), ('delstar', array([ 0.02438436])), ('Cf_PantonMax', array([ 0.00749185])), ('origin', array([ 0.0001])), ('Hama', array([-7.05])), ('Red', array([ 12714.77563644])), ('a', array([  8.06503645e-05])), ('kplus', array([ 25.07740805])), ('dt', array([ 0.000358])), ('nu', array([  1.55575887e-05])), ('isRough', array([ 1.])), ('isHeat', array([ 0.])), ('Retau', array([ 786.93357875])), ('dks', array([ 11.93164181])), ('Cf_TotStress', array([ 0.00693337])), ('Retheta', array([ 1514.28371385])), ('Utau_TotStress', array([ 0.09132699])), ('WakeFac', array([ 1.97213652])), ('Uinf', array([ 1.55110735])), ('Cf', array([ 0.00766106])), ('H', array([ 1.60547525])), ('theta', array([ 0.01518825])), ('rho', array([ 1.18216354])), ('dXplus', array([ 7.9626003])), ('yminHard', array([ 0.])), ('Tinf', array([ 298.3])), ('ymin', array([ 0.])), ('delta', array([ 0.12752905])), ('k', array([ 4.064])), ('Utau', array([ 0.096])), ('L122', array([ 0.01408296])), ('mu', array([  1.83916141e-05])), ('ksplus', array([ 65.95350341])), ('P', array([ 101207.54]))])

In [11]:
a = list(Cond.items())

In [23]:
a[0][0]


Out[23]:
'dk'

In [18]:
len(list(Cond.items()))


Out[18]:
38

In [32]:
CondSet = f.create_group("Cond2") #,(len(list(Cond.items())),)

In [33]:
for i in list(Cond.items()):
    CondSet.create_dataset(i[0], data=i[1])
    #h.create_dataset(i[0], data=i[1])

In [50]:
reload(PIVutils)
X, Y, U, V, Cond, Prof = PIVutils.loadDataset('/Users/Owen/Dropbox/Python Codes/ASIIT/Data/testSave4.hdf5',\
                                                      ['X','Y','U','V'],['Cond','Prof'])


[]
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-50-c4b0bd122000> in <module>()
      1 reload(PIVutils)
----> 2 X, Y, U, V, Cond, Prof = PIVutils.loadDataset('/Users/Owen/Dropbox/Python Codes/ASIIT/Data/testSave4.hdf5',                                                      ['X','Y','U','V'],['Cond','Prof'])

/Users/Owen/Dropbox/Python Codes/ASIIT/PIVutils.py in loadDataset(path, mats, structs)
     30 
     31     for i in mats:
---> 32         Temp = np.asarray(f[i])
     33         if Temp.ndim == 2:
     34             Temp = np.transpose(Temp,(1,0))

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/ilan/minonda/conda-bld/work/h5py/_objects.c:2696)()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/ilan/minonda/conda-bld/work/h5py/_objects.c:2654)()

/Users/Owen/anaconda/lib/python3.5/site-packages/h5py/_hl/group.py in __getitem__(self, name)
    164                 raise ValueError("Invalid HDF5 object reference")
    165         else:
--> 166             oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
    167 
    168         otype = h5i.get_type(oid)

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/ilan/minonda/conda-bld/work/h5py/_objects.c:2696)()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/ilan/minonda/conda-bld/work/h5py/_objects.c:2654)()

h5py/h5o.pyx in h5py.h5o.open (/Users/ilan/minonda/conda-bld/work/h5py/h5o.c:3582)()

KeyError: "Unable to open object (Object 'x' doesn't exist)"

In [39]:
Cond


Out[39]:
{'Cf': 0.0076610579589133591,
 'Cf_PantonMax': 0.0074918467973898051,
 'Cf_TotStress': 0.006933373522790112,
 'H': 1.6054752531196497,
 'Hama': -7.0499999999999998,
 'L111': 0.048917088904289918,
 'L122': 0.01408295959529623,
 'P': 101207.54000000001,
 'Red': 12714.775636442091,
 'Retau': 786.93357875137474,
 'Retau_TotStress': 748.62788898952772,
 'Retheta': 1514.2837138546236,
 'Tinf': 298.29999999999995,
 'Uinf': 1.5511073539843001,
 'Utau': 0.096000000000000002,
 'Utau_PantonMax': 0.094933895709910385,
 'Utau_TotStress': 0.091326992879154884,
 'WakeFac': 1.9721365198257796,
 'a': 8.0650364539647717e-05,
 'dXplus': 7.9626003043704197,
 'delstar': 0.024384356322846527,
 'delta': 0.12752905154228211,
 'dk': 31.380180005482803,
 'dks': 11.931641808817851,
 'dt': 0.00035799999999999997,
 'isHeat': 0.0,
 'isRough': 1.0,
 'k': 4.0640000000000001,
 'kplus': 25.077408052276315,
 'ks': 10.68830707338484,
 'ksplus': 65.953503412230035,
 'mu': 1.8391614107786999e-05,
 'nu': 1.5557588694441888e-05,
 'origin': 0.0001,
 'rho': 1.1821635389009606,
 'theta': 0.015188248012832658,
 'ymin': 0.0,
 'yminHard': 0.0}

In [48]:
import os
file = '/Users/Owen/Dropbox/Python Codes/ASIIT/Data/testSave2.hdf5'
if os.path.exists(file):
    del(file)
    print("Original file deleted")

In [58]:
f = h5py.File('/Users/Owen/Dropbox/Python Codes/ASIIT/Data/RNV45-thumbs.hdf5','r')

In [60]:
list(f.keys())


Out[60]:
['Cond',
 'Prof',
 'S',
 'Sr',
 'ThumbParams',
 'U',
 'Ur',
 'V',
 'Vr',
 'X',
 'Y',
 'Yind_Pro',
 'Yind_Ret',
 'missVecs',
 'missVecs_Ret',
 'x',
 'y']

In [61]:
list(f['ThumbParams'].keys())


Out[61]:
['BoxSize',
 'NoiseFilt',
 'ThreshPro',
 'ThreshRet',
 'ThreshSTD',
 'interpVecs',
 'noEdge',
 'num_features_Pro',
 'num_features_Ret']

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

In [66]:
Cond


Out[66]:
{'Cf': 0.0076610579589133591,
 'Cf_PantonMax': 0.0074918467973898051,
 'Cf_TotStress': 0.006933373522790112,
 'H': 1.6054752531196497,
 'Hama': -7.0499999999999998,
 'L111': 0.048917088904289918,
 'L122': 0.01408295959529623,
 'P': 101207.54000000001,
 'Red': 12714.775636442091,
 'Retau': 786.93357875137474,
 'Retau_TotStress': 748.62788898952772,
 'Retheta': 1514.2837138546236,
 'Tinf': 298.29999999999995,
 'Uinf': 1.5511073539843001,
 'Utau': 0.096000000000000002,
 'Utau_PantonMax': 0.094933895709910385,
 'Utau_TotStress': 0.091326992879154884,
 'WakeFac': 1.9721365198257796,
 'a': 8.0650364539647717e-05,
 'dXplus': 7.9626003043704197,
 'delstar': 0.024384356322846527,
 'delta': 0.12752905154228211,
 'dk': 31.380180005482803,
 'dks': 11.931641808817851,
 'dt': 0.00035799999999999997,
 'isHeat': 0.0,
 'isRough': 1.0,
 'k': 4.0640000000000001,
 'kplus': 25.077408052276315,
 'ks': 10.68830707338484,
 'ksplus': 65.953503412230035,
 'mu': 1.8391614107786999e-05,
 'nu': 1.5557588694441888e-05,
 'origin': 0.0001,
 'rho': 1.1821635389009606,
 'theta': 0.015188248012832658,
 'ymin': 0.0,
 'yminHard': 0.0}

In [67]:
Prof


Out[67]:
{'TotStress': 0.0065605701277112131,
 'U': 0.45342252330851934,
 'Udef': 11.434216986206049,
 'Uplus': 4.7231512844637429,
 'V': -0.0036935270827917047,
 'Ydef': 0.019288046467070372,
 'Yplus': 15.1784114334545,
 'Ypos': 0.0023597862720489502,
 'dUdy': 94.353155029355676,
 'dUdy_fitPoly': 35.123678246180503,
 'dUdy_fitPow': 113.38981643742413,
 'u': 0.03088171972466552,
 'uv': -0.0040817223267138446,
 'v': 0.0035503651353636654}

In [ ]: