import numpy as np import h5py from scipy import interpolate import sys np.set_printoptions(threshold=sys.maxsize) filename1 = "IPE_State.apex.201303160000.h5" filename2 = "new_IPE_State.apex.201303160000.h5" f1 = h5py.File(filename1, 'r') f2 = h5py.File(filename2, 'w') g1 = h5py.File('IPE_Grid.h5', 'r') g2 = h5py.File('new_IPE_Grid.h5', 'r') z1 = g1['apex_grid/altitude'][()] z2 = g2['apex_grid/altitude'][()] q1 = g1['apex_grid/q'][()] q2 = g2['apex_grid/q'][()] #print (q1[0,6,:]) #print (q2[0,0,:]) tube_max1 = g1['apex_grid/tube_max'][()] tube_max2 = g2['apex_grid/tube_max'][()] print (z1.shape) print (z2.shape) nmp1 = q1.shape[0] nmp2 = q2.shape[0] nlp1 = q1.shape[1] nlp2 = q2.shape[1] npts1 = q1.shape[2] npts2 = q2.shape[2] # Names of the groups in HDF5 file. for key in f1.keys(): print(key) # Get the HDF5 group group = f1[key] gx = f2.create_group('apex') # Checkout what keys are inside that group #for key in group.keys(): # print(key) #data = group[some_key_inside_the_group].value # Do whatever you want with data x1 = np.linspace(0, 2*np.pi-2*np.pi/nmp1, nmp1) * 180/np.pi x2 = np.linspace(0, 2*np.pi-2*np.pi/nmp2, nmp2) * 180/np.pi #data2 = np.zeros((nmp2,nlp2,npts2)) for key in group.keys(): data1 = group[key][()] #print (key, "Min/Max: ", np.min(data1), np.max(data1)) data2 = np.zeros((nmp2,nlp2,npts2)) for i in range(data1.shape[0]): for j in range(6, data1.shape[1]): print (key, "Min/Max1: ", i, j, \ np.min(data1[i,j,0:tube_max1[j]]), \ np.max(data1[i,j,0:tube_max1[j]])) #data2[i,j-6,0:tube_max2[j-6]-1] = np.interp( \ # q2[i,j-6,0:tube_max2[j-6]-1], \ # q1[i,j,0:tube_max1[j]-1], \ # data1[i,j,0:tube_max1[j]-1]) data2[i,j-6,:] = interpolate.griddata( \ #q1[i,j,0:tube_max1[j]], \ z1[j,:], \ data1[i,j,:], \ #q2[i,j-6,0:tube_max2[j-6]], \ z2[j-6,:], \ method='nearest') print (key, "Min/Max2: ", i, j-6, \ np.min(data2[i,j-6,0:tube_max2[j-6]]), \ np.max(data2[i,j-6,0:tube_max2[j-6]])) #print (key, "Min/Max: ", np.min(data2), np.max(data2)) gx.create_dataset(key,data=data2) f1.close() f2.close() g1.close() g2.close()