def PushSourceIfNeeded(ToSave, force=False): """ Pushes a single wave object as a binary file if it doesn't already exist (and if force is False). Saves the full note, as well as 'DataY'. Args: ToSave: Wave object (See ProcessSingleWave) to save out. Most likely, this will be a concatenation; columns of (e.g.) time, distance, force force: if true, force creates the file Returns: None """ # check if the file already exists FileName = BinaryHDF5Io.GetFileSaveName(ToSave.GetNoteElement()) # get the pull path (to the actual database...) FullPath = IgorUtil.getDatabaseFile(FileName) if (pGenUtil.isfile(FullPath) and not force): # don't do anything return else: # save the file out, using a blank string for the file name # (ie: just the folder) DatabasePath = IgorUtil.getDatabaseFolder() # XXX TODO: check that path exists to file? try: BinaryHDF5Io.\ SaveWaveGroupAsTimeSepForceHDF5(FolderPath=DatabasePath, WaveGroup=ToSave) except: print("XXX file saving disabled [off campus?]")
def PushSourceIfNeeded(ToSave,force=False): """ Pushes a single wave object as a binary file if it doesn't already exist (and if force is False). Saves the full note, as well as 'DataY'. Args: ToSave: Wave object (See ProcessSingleWave) to save out. Most likely, this will be a concatenation; columns of (e.g.) time, distance, force force: if true, force creates the file Returns: None """ # check if the file already exists FileName = BinaryHDF5Io.GetFileSaveName(ToSave.GetNoteElement()) # get the pull path (to the actual database...) FullPath = IgorUtil.getDatabaseFile(FileName) if (pGenUtil.isfile(FullPath) and not force): # don't do anything return else: # save the file out, using a blank string for the file name # (ie: just the folder) DatabasePath = IgorUtil.getDatabaseFolder() # XXX TODO: check that path exists to file? try: BinaryHDF5Io.\ SaveWaveGroupAsTimeSepForceHDF5(FolderPath=DatabasePath, WaveGroup=ToSave) except: print("XXX file saving disabled [off campus?]")
def ReadHDF5File(inFile): """ Reads in an HDF5, does *not* do any maintenane on the file (cleaning,etc) Args: inFile: path to the file Returns: Nothing Raises: IoError """ if (not pGenUtil.isfile(inFile)): mErr = ("ReadHDF5File : File {:s} not found.".format(inFile) + "Do you need to connect to a netwrok drive to find your data?") raise IOError(mErr) # POST: the file at least exists mFile = h5py.File(inFile, READ_MODE) return mFile
def ReadHDF5File(inFile): """ Reads in an HDF5, does *not* do any maintenane on the file (cleaning,etc) Args: inFile: path to the file Returns: Nothing Raises: IoError """ if (not pGenUtil.isfile(inFile)): mErr = ("ReadHDF5File : File {:s} not found.".format(inFile) + "Do you need to connect to a netwrok drive to find your data?") raise IOError(mErr) # POST: the file at least exists mFile = h5py.File(inFile, READ_MODE) return mFile
def AssertDataSavedCorrectly(AssociatedWaveData): """ Tests the binary file is saved properly. Doesn't check for notes (assumes that is OK), but *does* check for data matching. Args: AssociatedWaveData: a WaveDataGroup object (see Model) Returns: None """ # make a copy of the wave, to use as meta data... mEle = AssociatedWaveData.GetNoteElement() SavedFilePath = BinaryHDF5Io.GetFileSaveName(mEle) DataFilePath = IgorUtil.getDatabaseFile(SavedFilePath) assert pGenUtil.isfile(DataFilePath) , "File {:s} wasn't saved.".\ format(DataFilePath) # POST: file exists. Hooray! Is it correct? readObj = BinaryHDF5Io.LoadHdfFileIntoWaveObj(DataFilePath) correctObj = AssociatedWaveData.CreateTimeSepForceWaveObject() # note we overload "==" to check that notes *and* data match assert (readObj == correctObj) , "File read back in doesn't match."
def AssertDataSavedCorrectly(AssociatedWaveData): """ Tests the binary file is saved properly. Doesn't check for notes (assumes that is OK), but *does* check for data matching. Args: AssociatedWaveData: a WaveDataGroup object (see Model) Returns: None """ # make a copy of the wave, to use as meta data... mEle = AssociatedWaveData.GetNoteElement() SavedFilePath = BinaryHDF5Io.GetFileSaveName(mEle) DataFilePath = IgorUtil.getDatabaseFile(SavedFilePath) assert pGenUtil.isfile(DataFilePath) , "File {:s} wasn't saved.".\ format(DataFilePath) # POST: file exists. Hooray! Is it correct? readObj = BinaryHDF5Io.LoadHdfFileIntoWaveObj(DataFilePath) correctObj = AssociatedWaveData.CreateTimeSepForceWaveObject() # note we overload "==" to check that notes *and* data match assert (readObj == correctObj), "File read back in doesn't match."