Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_param_names(self):
""" Converts circuit string to names and units """
# parse the element names from the circuit string
names = self.circuit.replace('p', '').replace('(', '').replace(')', '')
names = names.replace(',', '-').replace(' ', '').split('-')
full_names, all_units = [], []
for name in names:
num_params = check_and_eval(name[0]).num_params
units = check_and_eval(name[0]).units
if num_params > 1:
for j in range(num_params):
full_name = '{}_{}'.format(name, j)
if full_name not in self.constants.keys():
full_names.append(full_name)
all_units.append(units[j])
else:
if name not in self.constants.keys():
full_names.append(name)
all_units.append(units[0])
return full_names, all_units
def get_param_names(self):
""" Converts circuit string to names and units """
# parse the element names from the circuit string
names = self.circuit.replace('p', '').replace('(', '').replace(')', '')
names = names.replace(',', '-').replace(' ', '').split('-')
full_names, all_units = [], []
for name in names:
num_params = check_and_eval(name[0]).num_params
units = check_and_eval(name[0]).units
if num_params > 1:
for j in range(num_params):
full_name = '{}_{}'.format(name, j)
if full_name not in self.constants.keys():
full_names.append(full_name)
all_units.append(units[j])
else:
if name not in self.constants.keys():
full_names.append(name)
all_units.append(units[0])
return full_names, all_units
def __str__(self):
""" Defines the pretty printing of the circuit"""
to_print = '\n'
if self.name is not None:
to_print += 'Name: {}\n'.format(self.name)
to_print += 'Circuit string: {}\n'.format(self.circuit)
to_print += "Fit: {}\n".format(self._is_fit())
if len(self.constants) > 0:
to_print += '\nConstants:\n'
for name, value in self.constants.items():
units = check_and_eval(name[0]).units
if '_' in name:
unit = units[int(name.split('_')[-1])]
else:
unit = units[0]
to_print += ' {:>5} = {:.2e} [{}]\n'.format(name, value, unit)
names, units = self.get_param_names()
to_print += '\nInitial guesses:\n'
for name, unit, param in zip(names, units, self.initial_guess):
to_print += ' {:>5} = {:.2e} [{}]\n'.format(name, param, unit)
if self._is_fit():
params, confs = self.parameters_, self.conf_
to_print += '\nFit parameters:\n'
for name, unit, param, conf in zip(names, units, params, confs):
to_print += ' {:>5} = {:.2e}'.format(name, param)
to_print += ' (+/- {:.2e}) [{}]\n'.format(conf, unit)