def buildHDF(inputFile, inputData, inputLabels, debug=False): """Creates a HDF file based on the data given, two possible datasets can be built, 25band set and 32 band set""" #Generate HDF5 file for input data stored as a list of datacube HDFile = dcb_HDF5.openTable(inputFile) data_gp = dcb_HDF5.build25BandGroup(HDFile, "data") #determine the number of bands in the data, as well as band wavelenghts bands = inputData.shape() data_gp.attrs["RPArrowPrism"] = str(bands[2]) + ' Bands' label_gp = dcb_HDF5.build25BandGroup(HDFile, 'label') for p, data in enumerate( inputData ): #with fix in create_bsq_dataset, now masks and data should be in same data struct if debug: if p == len(inputData) - 1: print(p, inputData[p].Name, "LAST ITEM") if (inputData[p].Name == data.Name): print(inputData[p].Name) labelSet = dcb_HDF5.addDataset(label_gp, inputData[p].Name, inputData[p].MaskData, debug) dataSet = dcb_HDF5.addDataset(data_gp, inputData[p].Name, inputData[p].HSdata, debug) dataSet.attrs["units"] = "AU" labelSet.attrs["Parent_DCB"] = inputData[p].Name dcb_HDF5.saveClose(HDFile) #add label to file under correct filename
def buildHDF(inputFile, inputData, inputLabels, debug=False): """Creates a HDF file based on the data given, two possible datasets can be built, 25band set and 32 band set""" # Generate HDF5 file for input data stored as a list of datacube HDFile = dcb_HDF5.openTable(inputFile) data_gp = dcb_HDF5.build25BandGroup(HDFile, "data") # determine the number of bands in the data, as well as band wavelenghts bands = inputData.shape() data_gp.attrs["RPArrowPrism"] = str(bands[2]) + " Bands" label_gp = dcb_HDF5.build25BandGroup(HDFile, "label") for p, data in enumerate( inputData ): # with fix in create_bsq_dataset, now masks and data should be in same data struct if debug: if p == len(inputData) - 1: print(p, inputData[p].Name, "LAST ITEM") if inputData[p].Name == data.Name: print(inputData[p].Name) labelSet = dcb_HDF5.addDataset(label_gp, inputData[p].Name, inputData[p].MaskData, debug) dataSet = dcb_HDF5.addDataset(data_gp, inputData[p].Name, inputData[p].HSdata, debug) dataSet.attrs["units"] = "AU" labelSet.attrs["Parent_DCB"] = inputData[p].Name dcb_HDF5.saveClose(HDFile) # add label to file under correct filename
def readHDF(inputFile, debug=False): a = [] with HDF.File(inputFile, "r+") as f: if debug: print(f.name) l = list(f.keys()) # extract keys in root dir of HDF file data = f["Data"] masks = f["Masks"] j = getKeys(f, "Masks") k = getKeys(f, "Data") wbc, oth, count = [], [], 0 # settings some initial values mT = f["data/" + k[count]][..., 0] for p in k: if debug: print(count) # remove later m1 = f["Masks/" + j[count]][...] # Likewise for the mask data if debug: print(np.shape(m1)) d1 = f["Data/" + [count]][...] # numpy style referencing to return nnumpy array of data if debug: print(np.shape(d1)) if count == 0: if debug: print("wat") # to be removed wbc = d1[m1.astype(bool)] # compile a dataset of wbc vectors oth = d1[np.invert(m1.astype(bool))] # compile a dataset of non-wbc vectors tot = d1[mT.astype(bool)] # compile a dataset of all vectors cls = m1.ravel() else: wbc = np.vstack((wbc, d1[m1.astype(bool)])) oth = np.vstack((oth, d1[np.invert(m1.astype(bool))])) tot = np.vstack((tot, d1[mT.astype(bool)])) # appending vectors into band*(x*y) array cls = np.hstack((cls, m1.ravel())) count += 1 if debug: print(np.shape(wbc)) print(np.shape(oth)) print(np.shape(tot)) print(cls.shape) e = dcb_HDF5.saveClose(f) if e: print("File " + inputFile + " saved Successfully!")
def readHDF(inputFile, debug=False): a = [] with HDF.File(inputFile, 'r+') as f: if debug: print(f.name) l = list(f.keys()) #extract keys in root dir of HDF file data = f["Data"] masks = f["Masks"] j = getKeys(f, "Masks") k = getKeys(f, "Data") wbc, oth, count = [], [], 0 # settings some initial values mT = f["data/" + k[count]][..., 0] for p in k: if debug: print(count) # remove later m1 = f["Masks/" + j[count]][...] #Likewise for the mask data if debug: print(np.shape(m1)) d1 = f["Data/" + [count]][ ...] #numpy style referencing to return nnumpy array of data if debug: print(np.shape(d1)) if count == 0: if debug: print('wat') #to be removed wbc = d1[m1.astype(bool)] #compile a dataset of wbc vectors oth = d1[np.invert( m1.astype(bool))] #compile a dataset of non-wbc vectors tot = d1[mT.astype(bool)] #compile a dataset of all vectors cls = m1.ravel() else: wbc = np.vstack((wbc, d1[m1.astype(bool)])) oth = np.vstack((oth, d1[np.invert(m1.astype(bool))])) tot = np.vstack((tot, d1[mT.astype(bool)] )) # appending vectors into band*(x*y) array cls = np.hstack((cls, m1.ravel())) count += 1 if debug: print(np.shape(wbc)) print(np.shape(oth)) print(np.shape(tot)) print(cls.shape) e = dcb_HDF5.saveClose(f) if (e): print("File " + inputFile + " saved Successfully!")
maskSet = dcb_HDF5.addDataset(m_group,maskList[p].Name,maskList[p].MaskData) maskSet.attrs["Parent_DCB"] = dataList[p].Name #data.setMaskData(maskList[p].MaskData) #hsList.append(data) if p == len(dataList)-1: print(p, data.Name, "LAST ITEM") #only happens when last iteration of for loop runs print(data.Name + str(p)) tTable = dcb_HDF5.addDataset(d_group,data.Name,dataList[p].HSdata) tTable.attrs["units"] = "AU" HDFile.flush() #tTable = thesis_TABLE.addTable2Group(d_group,HDFile,data) #thesis_TABLE.add25Vector2DataCube(tTable,data) dcb_HDF5.saveClose(HDFile) ddd = dataList[1].HSdata #print(np.shape(ddd)[2]) im2 = dataList[1].MaskData rd = ddd[im2.astype(bool)] #returns masked by im2 id = ddd[np.invert(im2.astype(bool))] #print([np.shape(rd), np.count_nonzero(im2)]) #print([np.shape(ddd), np.shape(im2)]) samp = ddd[:,:,0] #out = Image.fromarray(im2[:,:,0]) maskplot = plt.imshow(np.float32(im2)) dataplot = plt.imshow(np.float32(samp)) #imshow only works with 32bit grayscale scipy.misc.imsave(pathName+'Mask.png', im2)