def test_copy(): # Test the ability to copy from one data file to another testDF = DataFile.DataFile(os.path.join('data','dmc2018n000401.hdf')) testDFDict = testDF.__dict__ dfCopy = DataFile.DataFile(testDF) # Perform copy assert(dfCopy._debugging == False) assert(dfCopy==testDF)
def test_plot(): dataFile = os.path.join('data','dmc2018n{:06d}.hdf'.format(401)) df = DataFile.DataFile(dataFile) fig,ax = plt.subplots() Ax = df.plotDetector() dataFile = os.path.join('data','dmc2018n{:06d} - Copy.hdf'.format(401)) df = DataFile.DataFile(dataFile) fig,ax = plt.subplots() Ax = df.plotDetector()
def test_load(): testDF = DataFile.DataFile(os.path.join('data','dmc2018n000401.hdf')) assert(testDF.twoTheta.shape == (400,1)) assert(testDF.counts.shape == (400,1)) assert(testDF.correctedTwoTheta.shape == (400,1)) # If detector is assumed to be flat, twoTheta and correctedTwoTheta are the same assert(np.all(np.isclose(testDF.correctedTwoTheta,testDF.twoTheta,atol=1e-4))) testDF = DataFile.DataFile(os.path.join('data','dmc2018n000401 - Copy.hdf')) assert(testDF.twoTheta.shape == (400,100)) assert(testDF.counts.shape == (400,100)) assert(testDF.correctedTwoTheta.shape == (400,100))
def __init__(self, dataFiles=None, **kwargs): """DataSet object to hold a series of DataFile objects Kwargs: - dataFiles (list): List of data files to be used in reduction (default None) Raises: - NotImplemetedError - AttributeError """ if dataFiles is None: self.dataFiles = [] else: if isinstance( dataFiles, (str, DataFile.DataFile )): # If either string or DataFile instance wrap in a list dataFiles = [dataFiles] try: self.dataFiles = [DataFile.DataFile(dF) for dF in dataFiles] except TypeError: raise AttributeError( 'Provided dataFiles attribute is not itterable, filepath, or of type DataFile. Got {}' .format(dataFiles)) self._getData()
def test_init(): df = DataFile.DataFile() try: df = DataFile.DataFile(r'Wrong\Path') # File not found assert False except FileNotFoundError: assert True testDF = DataFile.DataFile('DEBUG') assert(testDF._debugging == True) df = DataFile.DataFile(filePath=os.path.join('data','dmc2018n000401.hdf')) path,name = os.path.split(os.path.join('data','dmc2018n000401.hdf')) assert(df.folder == path) assert(df.fileName == name)
def test_masking_2D(): df = DataFile.DataFile() # An empty data file raises error on making a mask try: df.generateMask() assert False except RuntimeError: assert True df = DataFile.DataFile(os.path.join('data','dmc2018n000401 - Copy.hdf')) df.generateMask(maxAngle=90) # No points are masked assert(np.all(df.mask==np.ones_like(df.counts,dtype=bool))) df.generateMask(maxAngle=-1) # All points are masked assert(np.all(df.mask==np.zeros_like(df.counts,dtype=bool))) df.generateMask(maxAngle=7) # All points are masked total = np.size(df.counts) maskTotal = np.sum(df.mask) assert(total>maskTotal)
def test_init(): ds = DataSet.DataSet() assert (len(ds) == 0) df = DataFile.DataFile( os.path.join('data', 'dmc2018n{:06d}.hdf'.format(402))) ds2 = DataSet.DataSet([df]) assert (len(ds2) == 1) ds3 = DataSet.DataSet(dataFiles=df) print(ds3.__dict__) print(ds2.__dict__) assert (ds2 == ds3)