Beispiel #1
0
 def __init__(self, params, finite_bounds=False, parent=None):
     super(LimitsModel, self).__init__(parent)
     self.params = params
     self.finite_bounds = finite_bounds
     self.varys = curvefitter.varys(self.params)
     self.fitted_params = np.where(self.varys)[0]
     self.names = curvefitter.names(self.params)
Beispiel #2
0
 def __init__(self, params, finite_bounds=False, parent=None):
     super(LimitsModel, self).__init__(parent)
     self.params = params
     self.finite_bounds = finite_bounds
     self.varys = curvefitter.varys(self.params)
     self.fitted_params = np.where(self.varys)[0]
     self.names = curvefitter.names(self.params)
    def add_layer(self, insertpoint):
        params = self.params
        values = curvefitter.values(params)

        if not reflect.is_proper_abeles_input(values):
            raise ValueError('The size of the parameter array passed'
                             ' to reflectivity should be 4 * coefs[0] + 8')

        oldlayers = int(values[0])

        self.params['nlayers'].value = oldlayers + 1
        self.beginInsertRows(QtCore.QModelIndex(), insertpoint + 1,
                             insertpoint + 1)

        values = curvefitter.values(self.params)
        varys = curvefitter.varys(self.params)
        bounds = curvefitter.bounds(self.params)

        #do the insertion
        startP = 4 * insertpoint + 8

        values = np.insert(values, startP, [0] * 4)
        dummy = [varys.insert(startP, i) for i
                 in [True] * 4]
        dummy = [bounds.insert(startP, i) for i
                 in [(None, None)] * 4]

        bounds = np.array(bounds)
        names = ReflectivityFitFunction.parameter_names(nparams=values.size)

        #clear the parameters
        map(self.params.pop, self.params.keys())

        # reinsert parameters
        parlist = zip(names,
                      values,
                      varys,
                      bounds.T[0],
                      bounds.T[1],
                      [None] * values.size)

        for para in parlist:
            self.params.add(*para)

        self.endInsertRows()
    def remove_layer(self, which_layer):
        params = self.params
        values = curvefitter.values(params)
        if int(values[0]) == 0:
            return False

        if not reflect.is_proper_abeles_input(values):
            raise ValueError('The size of the parameter array passed'
                             ' to reflectivity should be 4 * coefs[0] + 8')

        oldlayers = int(values[0])

        self.beginRemoveRows(QtCore.QModelIndex(), which_layer, which_layer)

        self.params['nlayers'].value = oldlayers - 1

        startP = 4 * (which_layer - 1) + 8

        #get rid of parameters we don't need anymore
        names_lost = curvefitter.names(self.params)[startP: startP + 4]
        map(self.params.pop, names_lost)

        # but now we need to rejig parameters names
        # the only way to do this is to pop them all and readd
        values = curvefitter.values(self.params)
        varys = curvefitter.varys(self.params)
        bounds = np.array(curvefitter.bounds(self.params))
        names = ReflectivityFitFunction.parameter_names(values.size)
        map(self.params.pop, self.params.keys())

        parlist = zip(names,
                      values,
                      varys,
                      bounds.T[0],
                      bounds.T[1],
                      [None] * values.size)

        for para in parlist:
            self.params.add(*para)

        self.endRemoveRows()