def copy(self, other=None): """Copy self to other. if other is None, create new instance other -- ref to other object returns reference to copied object """ # check arguments if other is None: other = FitDataSet(self.name) PDFDataSet.copy(self, other) if isinstance(other, FitDataSet): # assigned attributes other._fitrmin = self._fitrmin other._fitrmax = self._fitrmax other._fitrstep = self._fitrstep other._rcalc_changed = self._rcalc_changed # copied attributes other.constraints = copy.deepcopy(self.constraints) other.initial = copy.deepcopy(self.initial) other.refined = copy.deepcopy(self.refined) # must also update the sampling on the new object st = self.getFitSamplingType() other.setFitSamplingType(st, self.fitrstep) return other
def __setattr__(self, name, value): """Assign refinable variables to self.initial. """ if name in PDFDataSet.refinableVars: self.initial[name] = value else: PDFDataSet.__setattr__(self, name, value) return
def writeObs(self, filename): """Write observed PDF data to a file. filename -- name of file to write to No return value. """ PDFDataSet.write(self, filename) return
def readObsStr(self, datastring): """Read experimental PDF data from a string datastring -- string of raw data returns self """ PDFDataSet.readStr(self, datastring) self._updateRcalcRange() return self
def readObs(self, filename): """Load experimental PDF data from PDFGetX2 or PDFGetN gr file. filename -- file to read from returns self """ PDFDataSet.read(self, filename) self._updateRcalcRange() return self
def __init__(self, name): """Initialize FitDataSet. name -- name of the data set. It must be a unique identifier. """ self.initial = {} self.refined = {} PDFDataSet.__init__(self, name) self.clear() return
def _resampledPDFDataSet(self): """Return instance of PDFDataSet with resampled observed data. Helper method for writeResampledObs and writeResampledObsStr. """ resampled = PDFDataSet(self.name) self.copy(resampled) resampled.robs = self.rcalc resampled.drobs = len(self.rcalc) * [0.0] resampled.Gobs = self.Gtrunc resampled.dGobs = self.dGtrunc return resampled
def clear(self): """Reset all data members to initial empty values. """ PDFDataSet.clear(self) self._rcalc_changed = True self._rcalc = [] self._Gcalc = [] self._dGcalc = [] self._Gtrunc = [] self._dGtrunc = [] self._crw = [] self._fitrmin = None self._fitrmax = None self._fitrstep = None self.constraints = {} self.refined = {} return
def clear(self): """Reset all data members to initial empty values. """ PDFDataSet.clear(self) self._rcalc_changed = True self._rcalc = [] self._Gcalc = [] self._dGcalc = [] self._Gtrunc = [] self._dGtrunc = [] self._crw = [] self._fitrmin = 0.5 self._fitrmax = None self._fitrstep = None self.constraints = {} self.refined = {} return
class TestPDFDataSet(unittest.TestCase): def setUp(self): self.pdfds = PDFDataSet('test data set') return def tearDown(self): self.pdfds = None return # def test___init__(self): # """check PDFDataSet.__init__() # """ # return # # def test_clear(self): # """check PDFDataSet.clear() # """ # return # # def test_setvar(self): # """check PDFDataSet.setvar() # """ # return # # def test_getvar(self): # """check PDFDataSet.getvar() # """ # return # def test_read(self): """check PDFDataSet.read() """ # neutron data ------------------------------------------------- fn_550K = datafile('550K.gr') self.pdfds.read(fn_550K) self.assertEqual('N', self.pdfds.stype) self.assertEqual(32.0, self.pdfds.qmax) # there are 2000 points in the file npts = len(self.pdfds.robs) self.assertEqual(2000, npts) # drobs are all zero self.assertEqual(npts*[0.0], self.pdfds.drobs) # dGobs should be defined self.assertTrue(min(self.pdfds.dGobs) > 0) # x-ray data --------------------------------------------------- fx_Ni = datafile('Ni_2-8.chi.gr') self.pdfds.read(fx_Ni) self.assertEqual('X', self.pdfds.stype) self.assertEqual(40.0, self.pdfds.qmax) # there are 2000 points in the file npts = len(self.pdfds.robs) self.assertEqual(2000, npts) # drobs are all zero self.assertEqual(npts*[0.0], self.pdfds.drobs) # dGobs should be defined self.assertTrue(min(self.pdfds.dGobs) > 0) return def test_readStr(self): """check PDFDataSet.readStr() """ # read Ni xray data, but invalidate the last dGobs fx_Ni = datafile('Ni_2-8.chi.gr') sNi = open(fx_Ni).read() lastdGobs = sNi.rstrip().rindex(' ') sNi_no_dGobs = sNi[:lastdGobs] + " -1.3e-3" self.pdfds.readStr(sNi_no_dGobs) # there are 2000 points in the file npts = len(self.pdfds.robs) self.assertEqual(2000, npts) # dGobs should be all zero self.assertEqual(npts*[0.0], self.pdfds.dGobs) return
class TestPDFDataSet(unittest.TestCase): def setUp(self): self.pdfds = PDFDataSet('test data set') return def tearDown(self): self.pdfds = None return # def test___init__(self): # """check PDFDataSet.__init__() # """ # return # # def test_clear(self): # """check PDFDataSet.clear() # """ # return # # def test_setvar(self): # """check PDFDataSet.setvar() # """ # return # # def test_getvar(self): # """check PDFDataSet.getvar() # """ # return # def test_read(self): """check PDFDataSet.read() """ # neutron data ------------------------------------------------- fn_550K = datafile('550K.gr') self.pdfds.read(fn_550K) self.assertEqual('N', self.pdfds.stype) self.assertEqual(32.0, self.pdfds.qmax) # there are 2000 points in the file npts = len(self.pdfds.robs) self.assertEqual(2000, npts) # drobs are all zero self.assertEqual(npts*[0.0], self.pdfds.drobs) # dGobs should be defined self.failUnless(min(self.pdfds.dGobs) > 0) # x-ray data --------------------------------------------------- fx_Ni = datafile('Ni_2-8.chi.gr') self.pdfds.read(fx_Ni) self.assertEqual('X', self.pdfds.stype) self.assertEqual(40.0, self.pdfds.qmax) # there are 2000 points in the file npts = len(self.pdfds.robs) self.assertEqual(2000, npts) # drobs are all zero self.assertEqual(npts*[0.0], self.pdfds.drobs) # dGobs should be defined self.failUnless(min(self.pdfds.dGobs) > 0) return def test_readStr(self): """check PDFDataSet.readStr() """ # read Ni xray data, but invalidate the last dGobs fx_Ni = datafile('Ni_2-8.chi.gr') sNi = open(fx_Ni).read() lastdGobs = sNi.rstrip().rindex(' ') sNi_no_dGobs = sNi[:lastdGobs] + " -1.3e-3" self.pdfds.readStr(sNi_no_dGobs) # there are 2000 points in the file npts = len(self.pdfds.robs) self.assertEqual(2000, npts) # dGobs should be all zero self.assertEqual(npts*[0.0], self.pdfds.dGobs) return
def writeObsStr(self): """String representation of observed PDF data. Return data string. """ return PDFDataSet.writeStr(self)
def setUp(self): self.pdfds = PDFDataSet('test data set') return