Commit 62609035 authored by Sean Leavey's avatar Sean Leavey
Browse files

Allow multiple op-amps to be displayed

parent 2dfaf66e
......@@ -363,7 +363,7 @@ def library_search(query, sort_a0, sort_gbw, sort_delay, sort_vnoise, sort_vcorn
writer.writerows(rows)
@library.command("opamp")
@click.argument("model", type=str)
@click.argument("models", type=str, nargs=-1, metavar="[MODEL]...")
@click.option("--show/--no-show", is_flag=True, default=True, show_default=True,
help="Show op-amp data.")
@click.option("--plot/--no-plot", is_flag=True, default=False,
......@@ -373,17 +373,20 @@ def library_search(query, sort_a0, sort_gbw, sort_delay, sort_vnoise, sort_vcorn
@click.option("--npoints", type=int, default=1000, show_default=True, help="Plot number of points.")
@click.option("--save-figure", type=click.File("wb", lazy=False), multiple=True,
help="Save image of figure to file. Can be specified multiple times.")
def opamp_tools(model, show, plot, fstart, fstop, npoints, save_figure):
library_opamp = LIBRARY.get_opamp(model)
if show:
print(repr(library_opamp))
opamp = OpAmp(model=OpAmpLibrary.format_name(model), node1="input", node2="gnd",
node3="output", **LIBRARY.get_data(model))
def opamp_tools(models, show, plot, fstart, fstop, npoints, save_figure):
opamps = []
for model in models:
library_opamp = LIBRARY.get_opamp(model)
if show:
print(repr(library_opamp))
opamp = OpAmp(model=OpAmpLibrary.format_name(model), node1="input", node2="gnd",
node3="output", **LIBRARY.get_data(model))
opamps.append(opamp)
# Determine whether to generate plot.
generate_plot = plot or save_figure
if generate_plot:
plotter = OpAmpGainPlotter(opamp, fstart=fstart, fstop=fstop, npoints=npoints)
plotter.plot()
plotter = OpAmpGainPlotter(fstart=fstart, fstop=fstop, npoints=npoints)
plotter.plot(opamps)
if save_figure:
for save_path in save_figure:
# NOTE: use figure file's name so that Matplotlib can identify the file type
......
......@@ -792,10 +792,9 @@ class SpectralDensityPlotter(MplGroupPlotter):
class OpAmpGainPlotter(BodePlotter):
def __init__(self, opamp, frequencies=None, fstart=None, fstop=None, npoints=1000):
title = f"{opamp.model} open loop gain"
def __init__(self, frequencies=None, fstart=None, fstop=None, npoints=1000,
title="Open loop gain"):
super().__init__(title=title)
self.opamp = opamp
if frequencies is None:
if any([param is None for param in (fstart, fstop, npoints)]):
raise ValueError("either frequencies, or all of fstart, fstop and npoints must be "
......@@ -803,14 +802,15 @@ class OpAmpGainPlotter(BodePlotter):
frequencies = np.logspace(np.log10(fstart), np.log10(fstop), npoints)
self.frequencies = np.array(frequencies)
@property
def response(self):
gain = np.array([self.opamp.gain(frequency) for frequency in self.frequencies])
def response(self, opamp):
gain = np.array([opamp.gain(frequency) for frequency in self.frequencies])
series = Series(self.frequencies, gain)
return Response(source=self.opamp.node1, sink=self.opamp.node3, series=series)
response = Response(source=opamp.node1, sink=opamp.node3, series=series)
response.label = opamp.model
return response
def plot(self):
super().plot([self.response])
def plot(self, opamps):
super().plot([self.response(opamp) for opamp in opamps])
def show(self):
plt.show()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment