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 __init__(self, CacheLoc=None): """ Args: WaveData: The raw data to save to the cache. Formatted as XXX AddMethod : Method to call when data is available. If no cache, this is all the data immediately. If we use a cache, this is after we save the data CacheLoc: Where to save the cache. If 'None', then we don't use a cache, we just save the rawdata """ self.CacheLoc = CacheLoc self.UseCache = CacheLoc is not None if (self.UseCache): pGenUtil.ensureDirExists(CacheLoc) # "extensions" is used to keep track of what extensions belong to which # data... self.WaveNameMap = dict() self.pool = Pool(NThreads)
def __init__(self,CacheLoc=None): """ Args: WaveData: The raw data to save to the cache. Formatted as XXX AddMethod : Method to call when data is available. If no cache, this is all the data immediately. If we use a cache, this is after we save the data CacheLoc: Where to save the cache. If 'None', then we don't use a cache, we just save the rawdata """ self.CacheLoc = CacheLoc self.UseCache = CacheLoc is not None if (self.UseCache): pGenUtil.ensureDirExists(CacheLoc) # "extensions" is used to keep track of what extensions belong to which # data... self.WaveNameMap = dict() self.pool = Pool(NThreads)
def LoadPxpFilesFromDirectory(directory): """ Given a directory, load all the pxp files into a wave Args: directory: loads all directories Returns: see LoadAllWavesFromPxp """ allFiles = pGenUtil.getAllFiles(directory,ext=".pxp") d = [] for f in allFiles: d.extend(LoadAllWavesFromPxp(f)) return d
def SourceFilename(self): """ Returns the source file for this wave Returns: Source filename, without extension or path """ SrcPath = self.Note["SourceFile"] # convert the path to just a simple file (without extension) # remove everything except the file name (including the extension) fileWithExt = pGenUtil.getFileFromPath(SrcPath) # return everything before the extension return os.path.splitext(fileWithExt)[0]
def GetTimeSepForce(binaryFilePath): """ Given a path to a binary file, reads in (the assumed generic/default) dataset, and gets the columns for time, separatio, and force Returns: tuple of (time,sep,force) arrays Raises: IoError """ # make sure we have the right extensions # XXX throw error otherwise? mFile = pGenUtil.ensureEnds(binaryFilePath, DEFAULT_HDF5_EXTENSION) time = ReadHDF5FileDataSet(mFile)[:, COLUMN_TIME] sep = ReadHDF5FileDataSet(mFile)[:, COLUMN_SEP] force = ReadHDF5FileDataSet(mFile)[:, COLUMN_FORCE] return time, sep, force
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."