コード例 #1
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))
コード例 #2
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()