Example #1
0
 def testSimpleCases(self):
     for case in simplecases:
         p = case['p0']
         parser = Parser(CircuitTree)
         parsetree = parser.parse(case['eqc']).collapseCircuit()
         s = Spectrum.fromJSON(file(case['specfile']).read())
         pset = ParameterSet.fromTree(parsetree, p)
         eqc_fn, jac_fn = parsetree.getCircuit()
         e = Spectrum.fromCircuit(s.omega, eqc_fn, p)
         p, rmsd = e.fit(s, pset)
         self.assertLess(rmsd, 1e-3,
             msg='Could not fit {} to rmsd 1e-3: got {}'.format(case['specfile'], rmsd))
Example #2
0
 def testZholkovskij(self):
     p = [0.03, 3e-5, 75.0, 0.5, 0.1, 375.0, 0.0002, 0.01, 375.0, 0.97, 1.0, 75.0, 0.5, 0.1]
     parser = Parser(CircuitTree)
     parsetree = parser.parse('(R|C)+Quadlayer').collapseCircuit()
     s = Spectrum.fromJSON(file('cases/zholkovskij.json').read())
     pset = ParameterSet.fromTree(parsetree, p)
     pset.setParameterMapping('R_2{C}', pset.T_MICRO)
     pset.setParameterMapping('Quadlayer_1{t2}', pset.T_MICRO)
     pset.setParameterMapping('Quadlayer_1{t3}', pset.T_MICRO)
     pset.unmaskAll()
     pset.maskParameter('Quadlayer_1{t2}')
     pset.maskParameter('Quadlayer_1{t3}')
     pset.maskParameter('R_2{R}')
     pset.maskParameter('C_2{C}')
     pset.invertMask()
     eqc_fn, jac_fn = parsetree.getCircuit()
     e = Spectrum.fromCircuit(s.omega, eqc_fn, p)
     p, rmsd = e.fit(s, pset)
     self.assertLess(rmsd, 2e-3)
Example #3
0
import numpy as np


class MySpectrum(Spectrum):
    @classmethod
    def fromCSV(cls, filename):
        s = cls()
        for line in file(filename).readlines():
            val = line.split(",")
            s.omega.append(float(val[0]))
            s.Z.append(float(val[1]) + 1j * float(val[2]))


parser = Parser(CircuitTree)
p = [0.03, 3e-5, 75.0, 0.5, 0.1, 375.0, 0.0002, 0.01, 375.0, 0.97, 1.0, 75.0, 0.5, 0.1]
parsetree = parser.parse("(R|C)+Quadlayer").collapseCircuit()
eqc_fn, jac_fn = parsetree.getCircuit()

s = Spectrum.fromJSON(file("cases/zholkovskij.json").read())
# s = MySpectrum.fromCSV('MyCSVDataFile')

e = Spectrum.fromCircuit(s.omega, eqc_fn, p)
pset = ParameterSet.fromTree(parsetree, p)

# Scale transport number t3
pset.setParameterMapping("Quadlayer_1{t2}", pset.T_MICRO)
pset.setParameterMapping("Quadlayer_1{t3}", pset.T_MICRO)

# Fit only t2, t3, R and C:
pset.unmaskAll()
pset.maskParameter("Quadlayer_1{t2}")