Skip to content

Commit

Permalink
merge #191
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Garrone authored and FabriceSalvaire committed May 4, 2020
1 parent d518d69 commit e8925ec
Show file tree
Hide file tree
Showing 6 changed files with 777 additions and 36 deletions.
66 changes: 59 additions & 7 deletions PySpice/Probe/WaveForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,11 @@ def title(self, value):
##############################################

def __repr__(self):

return '{0.__class__.__name__} {0._name} {1}'.format(self, super().__str__())

##############################################

def __str__(self):

if self._title is not None:
return self._title
else:
Expand All @@ -173,9 +171,7 @@ def __str__(self):
##############################################

def str_data(self):

# Fixme: ok ???

return repr(self.as_ndarray())

####################################################################################################
Expand Down Expand Up @@ -294,7 +290,6 @@ def _get_item(self, name):
##############################################

def __getitem__(self, name):

try:
return self._get_item(name)
except IndexError:
Expand All @@ -304,7 +299,6 @@ def __getitem__(self, name):

@staticmethod
def _format_dict(d):

return os.linesep.join([' '*2 + str(x) for x in d])

##############################################
Expand Down Expand Up @@ -336,7 +330,6 @@ class SensitivityAnalysis(Analysis):
##############################################

def __init__(self, simulation, elements, internal_parameters):

super().__init__(simulation=simulation, elements=elements,
internal_parameters=internal_parameters)

Expand Down Expand Up @@ -415,3 +408,62 @@ def __init__(self, simulation, time, nodes, branches, internal_parameters):
def time(self):
"""Return an Numpy array for the time abscissa"""
return self._time

####################################################################################################

class PoleZeroAnalysis(Analysis):

"""This class implements a Pole-Zero analysis."""

##############################################

def __init__(self, simulation, nodes, branches, internal_parameters):
super().__init__(simulation=simulation, nodes=nodes, branches=branches,
internal_parameters=internal_parameters)

####################################################################################################

class NoiseAnalysis(Analysis):

"""This class implements Noise analysis."""

##############################################

def __init__(self, simulation, nodes, branches, internal_parameters):
super().__init__(simulation=simulation, nodes=nodes, branches=branches,
internal_parameters=internal_parameters)

####################################################################################################

class DistortionAnalysis(Analysis):

"""This class implements Distortion analysis."""

##############################################

def __init__(self, simulation, frequency, nodes, branches, internal_parameters):

super().__init__(simulation=simulation, nodes=nodes, branches=branches,
internal_parameters=internal_parameters)

self._frequency = frequency

##############################################

@property
def frequency(self):
"""Return an Numpy array for the frequency abscissa"""
return self._frequency

####################################################################################################

class TransferFunctionAnalysis(Analysis):

"""This class implements Transfer Function (TF) analysis."""

##############################################

def __init__(self, simulation, nodes, branches, internal_parameters):

super().__init__(simulation=simulation, nodes=nodes, branches=branches,
internal_parameters=internal_parameters)
68 changes: 56 additions & 12 deletions PySpice/Spice/NgSpice/Shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@
####################################################################################################

from PySpice.Config import ConfigInstall
from PySpice.Probe.WaveForm import (OperatingPoint, SensitivityAnalysis,
DcAnalysis, AcAnalysis, TransientAnalysis,
WaveForm)
from PySpice.Probe.WaveForm import (
OperatingPoint, SensitivityAnalysis,
DcAnalysis, AcAnalysis, TransientAnalysis,
PoleZeroAnalysis, NoiseAnalysis, DistortionAnalysis, TransferFunctionAnalysis,
WaveForm,
)
from PySpice.Tools.EnumFactory import EnumFactory
from .SimulationType import SIMULATION_TYPE

Expand Down Expand Up @@ -112,7 +115,6 @@ def __init__(self, ngspice_shared, name, type_, data):
##############################################

def __repr__(self):

return 'variable: {0._name} {0._type}'.format(self)

##############################################
Expand Down Expand Up @@ -188,31 +190,27 @@ def __init__(self, simulation, plot_name):
##############################################

def nodes(self, to_float=False, abscissa=None):

return [variable.to_waveform(abscissa, to_float=to_float)
for variable in self.values()
if variable.is_voltage_node]

##############################################

def branches(self, to_float=False, abscissa=None):

return [variable.to_waveform(abscissa, to_float=to_float)
for variable in self.values()
if variable.is_branch_current]

##############################################

def internal_parameters(self, to_float=False, abscissa=None):

return [variable.to_waveform(abscissa, to_float=to_float)
for variable in self.values()
if variable.is_interval_parameter]

##############################################

def elements(self, abscissa=None):

return [variable.to_waveform(abscissa, to_float=True)
for variable in self.values()]

Expand All @@ -230,13 +228,20 @@ def to_analysis(self):
return self._to_ac_analysis()
elif self.plot_name.startswith('tran'):
return self._to_transient_analysis()
elif self.plot_name.startswith('disto'):
return self._to_distortion_analysis()
elif self.plot_name.startswith('noise'):
return self._to_noise_analysis()
elif self.plot_name.startswith('pz'):
return self._to_polezero_analysis()
elif self.plot_name.startswith('tf'):
return self._to_transfer_function_analysis()
else:
raise NotImplementedError("Unsupported plot name {}".format(self.plot_name))

##############################################

def _to_operating_point_analysis(self):

return OperatingPoint(
simulation=self._simulation,
nodes=self.nodes(to_float=True),
Expand All @@ -247,7 +252,6 @@ def _to_operating_point_analysis(self):
##############################################

def _to_sensitivity_analysis(self):

# Fixme: separate v(vinput), analysis.R2.m
return SensitivityAnalysis(
simulation=self._simulation,
Expand All @@ -258,7 +262,6 @@ def _to_sensitivity_analysis(self):
##############################################

def _to_dc_analysis(self):

# if 'v(v-sweep)' in self:
# sweep_variable = self['v(v-sweep)']
# elif 'v(i-sweep)' in self:
Expand All @@ -281,7 +284,6 @@ def _to_dc_analysis(self):
##############################################

def _to_ac_analysis(self):

frequency = self['frequency'].to_waveform(to_real=True)
return AcAnalysis(
simulation=self._simulation,
Expand All @@ -304,6 +306,48 @@ def _to_transient_analysis(self):
internal_parameters=self.internal_parameters(abscissa=time),
)

##############################################

def _to_polezero_analysis(self):
return PoleZeroAnalysis(
simulation=self._simulation,
nodes=self.nodes(),
branches=self.branches(),
internal_parameters=self.internal_parameters(),
)

##############################################

def _to_noise_analysis(self):
return NoiseAnalysis(
simulation=self._simulation,
nodes=self.nodes(),
branches=self.branches(),
internal_parameters=self.internal_parameters(),
)

##############################################

def _to_distortion_analysis(self):
frequency = self['frequency'].to_waveform(to_real=True)
return DistortionAnalysis(
simulation=self._simulation,
frequency=frequency,
nodes=self.nodes(),
branches=self.branches(),
internal_parameters=self.internal_parameters(),
)

##############################################

def _to_transfer_function_analysis(self):
return TransferFunctionAnalysis(
simulation=self._simulation,
nodes=self.nodes(),
branches=self.branches(),
internal_parameters=self.internal_parameters(),
)

####################################################################################################

class NgSpiceShared:
Expand Down
Loading

0 comments on commit e8925ec

Please sign in to comment.