コード例 #1
0
def test_extract_switching_losses_from_wfm(filename_sim, ton=30e-6, toff=40e-6):

    # viewer = DoublePulseViewerBokeh()
    viewer = DoublePulseViewerPlotly()

    LTR = LTSpiceRawRead(filename_sim)
    # print(LTR.get_trace_names())
    # print(LTR.get_raw_property())
    steps = LTR.get_steps()

    time = LTR.get_trace("time")  # Zero is always the X axis
    v_QLS = LTR.get_trace("V(d_ls)")
    i_QLS = LTR.get_trace("Ix(u4:DRAININ)")

    switching_energy_lut = pd.DataFrame(columns=['step', 'current', 'voltage', 'eon', 'eoff'])
    for step in range(len(steps)):

        Eon, Eoff = calc_sw_losses_ltspice(time=time.get_wave(step), vds=v_QLS.get_wave(step), id=i_QLS.get_wave(step), ton=ton, toff=toff)
        
        step_label = ''.join(['{0}={1} '.format(k, v) for k, v in LTR.steps[step].items()])
        print(f"Step {step_label} Eon={Eon}, Eoff={Eoff}")

        switching_energy_lut = switching_energy_lut.append({'step': step,
                                                            'current': LTR.steps[step].get('idc'), 'voltage': LTR.steps[step].get('vdc'),
                                                            'eon': Eon, 'eoff': Eoff},
                                                            ignore_index=True)

        viewer.add_time_wfm(time=time.get_wave(step), vds=v_QLS.get_wave(step), id=i_QLS.get_wave(step), label=step_label)

    switching_energy_lut.to_csv("./Eloss_DoublePulseTester_EPC8009_sync.csv")

    plot_single_switching_energy_map(switching_energy_lut)
コード例 #2
0
 def test_axis_sync():  # Test axis sync
     LW = LTSpiceRawWrite()
     tx = Trace('time', np.arange(0.0, 3e-3, 997E-11))
     vy = Trace('N001', np.sin(2 * np.pi * tx.data * 10000))
     vz = Trace('N002', np.cos(2 * np.pi * tx.data * 9970))
     LW.add_trace(tx)
     LW.add_trace(vy)
     LW.add_trace(vz)
     LW.save("teste_w.raw")
     LR = LTSpiceRawRead("..\\test_files\\testfile.raw")
     LW.add_traces_from_raw(LR, ('V(out)', ), force_axis_alignment=True)
     LW.save("merge.raw")
     test = """
コード例 #3
0
def createSample(freq, amp, gainVal, N):
    filename = f'{meAbsPath}\\SPICE\\GainStage_samp{N}.asc'
    # os.system(f'cp {meAbsPath}\\SPICE\\GainStage2_zzz3.asc {filename}')
    # set_SPICE_params(filename, freq, amp, int(freq/10), gainVal)

    # LTC = LTCommander(filename)
    # raw, log = LTC.run()
    raw = 'D:/Documents/CCRMA/Research/Klon_Centaur/GainStageML/SPICE/GainStage2_zzz2.raw'
    LTR = LTSpiceRawRead(raw)

    # try:
    #     LTR = LTSpiceRawRead(raw)
    # except:
    #     LTR = LTSpiceRawRead(f'{meAbsPath}\\SPICE\\GainStage_samp{N}_run.raw')

    Vo = LTR.get_trace("V(vout)")
    Vi = LTR.get_trace("V(vi)")
    x = LTR.get_trace('time') # Gets the time axis
    step = LTR.get_steps()[0]
    # plt.plot(x.get_time_axis(step), Vi.get_wave(step))
    # plt.plot(x.get_time_axis(step), Vo.get_wave(step))

    FS = 44100.0
    t = np.arange(0.0, 0.2, 1.0 / FS)
    x_interp = interpolate.interp1d(x.get_time_axis(step), Vi.get_wave(step))
    y_interp = interpolate.interp1d(x.get_time_axis(step), Vo.get_wave(step))
    x = x_interp(t)
    y = y_interp(t)

    # plt.plot(t, x, '--')
    # plt.plot(t, y, '--')
    # plt.show()
    g = np.ones_like(x) * gainVal

    samples = [np.array([x, g, y])]
    savemat(f'Samples\\sample{N}.mat', { 'samples': np.asarray(samples) })
コード例 #4
0
from PyLTSpice.LTSpice_RawRead import LTSpiceRawRead
from mpl_toolkits.mplot3d import Axes3D
import scipy.signal
import matplotlib.pyplot as plt
import numpy as np

LTR = LTSpiceRawRead("llavetriang.raw")

corr = []
corr_maxes = []
step_vars = []
least_distorted_steps = []
time = LTR.get_trace(0)
vin = LTR.get_trace("V(vin)")
vout = LTR.get_trace("V(vout)")

for i in LTR.get_steps():
    corr.append(scipy.signal.correlate(vin.get_wave(i), vout.get_wave(i)))
    step_vars.append(LTR.steps[i])
    corr_maxes.append(np.max(corr[i]))

least_distorted_steps.append(np.where(corr_maxes == np.max(corr_maxes)))
plt.show()
print("Least distorted: ")

for i in range(len(least_distorted_steps)):
    print(LTR.steps[(least_distorted_steps[i][0][0])])

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = [(i['freqs'] / 1000) for i in step_vars]
コード例 #5
0
ファイル: analysis.py プロジェクト: samflash3/KlonCentaur
import os
import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate
from scipy.io import wavfile
from PyLTSpice.LTSpice_RawRead import LTSpiceRawRead

raw = 'D:/Documents/CCRMA/Research/Klon_Centaur/SubCircuits/FeedForward1/SPICE/FF1.raw'
LTR = LTSpiceRawRead(raw)

LTR

Vo = LTR.get_trace("V(vout)")
Vi = LTR.get_trace("V(vin)")
x = LTR.get_trace('time')  # Gets the time axis
step = LTR.get_steps()[0]
# plt.plot(x.get_time_axis(step), Vi.get_wave(step))
# plt.plot(x.get_time_axis(step), Vo.get_wave(step))

FS = 44100.0
t = np.arange(0.0, 2.0, 1.0 / FS)
x_interp = interpolate.interp1d(x.get_time_axis(step), Vi.get_wave(step))
y_interp = interpolate.interp1d(x.get_time_axis(step), Vo.get_wave(step))
x = x_interp(t)
y = y_interp(t)

# plt.plot(t, x, '--')
# plt.plot(t, y, '--')
# plt.show()

# wavfile.write('square.wav', int(FS), (x * 0.999 * 2**15).astype(np.int16))
コード例 #6
0
from PyLTSpice.LTSpice_RawRead import LTSpiceRawRead
from mpl_toolkits.mplot3d import Axes3D
import scipy.signal
import matplotlib.pyplot as plt
import numpy as np

LTR = LTSpiceRawRead("cshsen.raw")

corr = []
corr_maxes = []
step_vars = []
least_distorted_steps = []
time = LTR.get_trace(0).get_wave(0)
vin = LTR.get_trace("V(vin)").get_wave(0)
vout = LTR.get_trace("V(vout)").get_wave(0)

pow_in = []
pow_out = []
power_restored = []

pow_in.append(0)
pow_out.append(0)
for j in range(len(time)):
    pow_in[0] = pow_in[0] + abs(vin[j])**2
    pow_out[0] = pow_out[0] + abs(vout[j])**2

power_restored.append(pow_out[0] / pow_in[0])

print(round(power_restored[0], 6))
コード例 #7
0
from PyLTSpice.LTSpice_RawRead import LTSpiceRawRead
import scipy.signal
import matplotlib.pyplot as plt
import numpy as np

LTR = LTSpiceRawRead("32llave.raw")

t = LTR.get_trace(0)
vin = LTR.get_trace("V(vin)")
vout = LTR.get_trace("V(vout)")

pow_in = []
pow_out = []
power_restored = []

for i in LTR.get_steps():
    pow_in.append(0)
    pow_out.append(0)
    for j in range(len(t.get_wave(i))):
        pow_in[i] = pow_in[i] + abs(vin.get_wave(i)[j])**2
        pow_out[i] = pow_out[i] + abs(vout.get_wave(i)[j])**2

for i in LTR.get_steps():
    power_restored.append(pow_out[i] / pow_in[i])

plt.plot(power_restored)
plt.show()
コード例 #8
0
from PyLTSpice.LTSpiceBatch import LTCommander
from PyLTSpice.LTSpice_RawRead import LTSpiceRawRead

# TEXT -224 760 Left 2 !.tran 0.2\n.probe v(Vout)\n.probe v(Vi)

# # get script absolute path
# meAbsPath = os.path.dirname(os.path.realpath(__file__))
# # select spice model
# LTC = LTCommander(meAbsPath + "\\SPICE\\GainStage2_zzz.asc")

# raw, log = LTC.run()

# print(raw)
raw = 'D:\\Documents\\CCRMA\\Research\\Klon_Centaur\\GainStageML\\SPICE\\GainStage2_zzz_run.raw'

LTR = LTSpiceRawRead(raw)

print(LTR.get_trace_names())
# print(LTR.get_raw_property())

Vo = LTR.get_trace("V(vout)")
Vi = LTR.get_trace("V(vi)")
x = LTR.get_trace('time') # Gets the time axis
step = LTR.get_steps()[0]
plt.plot(x.get_time_axis(step), Vi.get_wave(step))
plt.plot(x.get_time_axis(step), Vo.get_wave(step))

# print(1.0 / 44100)
# print(np.diff(x.get_time_axis(step)))

FS = 44100.0
コード例 #9
0
ファイル: ltspice.py プロジェクト: sillyTig3r94/Tokyo
#config source typ here

#config = lt_ult.set_params(tool_name)
# =============================================================================
#                       NEW LTSPICE CONFIGURATION
# =============================================================================
setting = import_tool_setting()

ltspice_setup(setting, database)
# =============================================================================
#                       RUN LTSPICE.ASC
# =============================================================================
LTC_BHA.run()

LTR_BHA = LTSpiceRawRead(raw_path)

#export_tool_param()
#
#import_tool_param()

# =============================================================================
#                       COLLECTING DATA
# =============================================================================

LTC_BHA.__del__()

V, I, P, Generator, Battery = lt_ult.get_tool(LTR_BHA, setting)

# =============================================================================
#                       OUTPUT CALCULATION
コード例 #10
0
    def add_traces_from_raw(self, other: LTSpiceRawRead,
                            trace_filter: Union[list, tuple], **kwargs):
        skip_doc = """
        *(Not fully implemented)*

        Merge two LTSpiceRawWrite classes together resulting in a new instance
        :param other: another instance of the LTSpiceRawWrite class.
        :type other: LTSpiceRawWrite
        :param trace_filter: A list of signals that should be imported into the new file
        :type trace_filter: list
        :keyword force_axis_alignment: If two raw files don't have the same axis, an attempt is made to sync the two
        :keyword admissible_error: maximum error allowed in the sync between the two axis
        :keyword rename_format: when adding traces with the same name, it is possible to define a rename format.
            For example, if there are two traces named N001 in order to avoid duplicate names the
            rename format can be defined as "{}_{kwarg_name} where kwarg_name is passed as a keyword
            argument of this function

        :keyword step: by default only step 0 is added from the second raw. It is possible to add other steps, by
            using this keyword parameter. This is useful when we want to "flatten" the multiple step runs into the same 
            view.
        :keyword: minimum_timestep: This parameter forces the two axis to sync using a minimum time step. That is, all
            time increments that are less than this parameter will be suppressed.
        :return: A new instance of LTSpiceRawWrite with
        :rtype: LTSpiceRawWrite
        """
        for flag in other.get_raw_property('Flags').split(' '):
            if flag in ('real', 'complex'):
                other_flag_num_type = flag
                break
        else:
            other_flag_num_type = 'real'

        if (self.flag_numtype != other_flag_num_type) or (
                self._traces[0].type != other.get_trace(0).type):
            raise ValueError("The two instances should have the same type")
        force_axis_alignment = kwargs.get('force_axis_alignment', False)
        admissible_error = kwargs.get('admissible_error', 1e-11)
        rename_format = kwargs.get('rename_format', '{}')
        from_step = kwargs.get('step', 0)
        minimum_timestep = kwargs.get('fixed_timestep', 0.0)

        if len(self._traces
               ) == 0:  # if no X axis is present, copy from the first one
            new_axis = Trace(
                other.get_trace(0).name, other.get_axis(from_step))
            self._traces.append(new_axis)
            force_axis_alignment = False
        my_axis = self._traces[0].get_wave()
        other_axis = other.get_axis()

        if force_axis_alignment or minimum_timestep > 0.0:
            new_axis = []
            if minimum_timestep > 0.0:
                raise NotImplementedError
            else:
                i = 0  # incomming data counter
                e = 0  # existing data counter
                existing_data = {}
                incoming_data = {}
                new_traces = {}
                updated_traces = {}

                for new_trace in trace_filter:
                    new_traces[new_trace] = []
                    incoming_data[new_trace] = other.get_trace(
                        new_trace).get_wave(from_step)
                for trace in self._traces[1:]:  # not considering axis
                    updated_traces[trace.name] = []
                    existing_data[trace.name] = self.get_trace(
                        trace.name).get_wave()

                axis_name = self._traces[
                    0].name  # Saving the trace name for recreating all the traces

                while e < len(my_axis) - 1 and i < len(other_axis) - 1:
                    error = other_axis[i] - my_axis[e]
                    if abs(error) < admissible_error:
                        new_axis.append(my_axis[e])
                        i += 1
                        e += 1
                    elif error < 0:
                        # Other axis is smaller
                        new_axis.append(other_axis[i])
                        i += 1
                    else:
                        new_axis.append(my_axis[e])
                        e += 1
                    for trace in incoming_data:
                        new_traces[trace].append(incoming_data[trace][i])
                    for trace in existing_data:
                        updated_traces[trace].append(existing_data[trace][e])

                self._traces.clear()  # Cleaning class list of traces
                # Creating the New Axis
                self._traces.append(Trace(axis_name, new_axis))
                # Now recreating all tre traces
                for trace in incoming_data:
                    self._traces.append(Trace(trace, incoming_data[trace]))
                for trace in existing_data:
                    self._traces.append(Trace(trace, existing_data[trace]))

        else:
            assert len(self._traces[0]) == len(other.get_axis(
            )), "The two instances should have the same size"
            for trace in trace_filter:
                data = other.get_trace(trace).get_wave(from_step)
                self._traces.append(
                    Trace(rename_format.format(trace, **kwargs), data))
コード例 #11
0
from PyLTSpice.LTSpice_RawRead import LTSpiceRawRead

from matplotlib import pyplot as plt

LTR = LTSpiceRawRead("TRAN - STEP.raw")

print(LTR.get_trace_names())
print(LTR.get_raw_property())

IR1 = LTR.get_trace("I(R1)")
x = LTR.get_trace('time')  # Gets the time axis
steps = LTR.get_steps()
for step in range(len(steps)):
    # print(steps[step])
    plt.plot(x.get_time_axis(step), IR1.get_wave(step), label=steps[step])

plt.legend()  # order a legend
plt.show()