### Clone and Setup pyimpspec Development Environment Source: https://github.com/vyrjana/pyimpspec/blob/main/README.md Commands to clone the repository from GitHub and install the necessary development dependencies using pip. This is the standard procedure for setting up a local development environment for the project. ```bash git clone https://github.com/vyrjana/pyimpspec.git pip install -r ./dev-requirements.txt ``` -------------------------------- ### Install Optional Dependencies with pip (Bash) Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_installing.md Installs optional dependencies, such as 'cvxopt', for pyimpspec using pip. This is typically done by specifying extras in the install command. ```bash pip install pyimpspec[cvxopt] ``` -------------------------------- ### Check pip Installation (Bash) Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_installing.md Verifies if pip is installed on the system. This is a prerequisite for installing Python packages. ```bash pip --version ``` -------------------------------- ### Install pyimpspec using pipx (Bash) Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_installing.md Installs pyimpspec and its dependencies using pipx, which automatically manages virtual environments. ```bash pipx install pyimpspec ``` -------------------------------- ### Install Optional Dependencies with pipx (Bash) Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_installing.md Installs optional dependencies, such as 'cvxopt', into an existing pyimpspec installation managed by pipx. ```bash pipx inject pyimpspec cvxopt ``` -------------------------------- ### Install pyimpspec using pip (Bash) Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_installing.md Installs pyimpspec and its dependencies using pip. This method requires manual management of Python virtual environments. ```bash pip install pyimpspec ``` -------------------------------- ### Performing a Kramers-Kronig Test Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_kramers_kronig.md This example demonstrates how to perform a full Kramers-Kronig test on a dataset. It shows both the high-level wrapper function and the manual step-by-step workflow involving evaluation, RC suggestion, and representation selection. ```python from pyimpspec import ( DataSet, KramersKronigResult, generate_mock_data, perform_kramers_kronig_test, ) from pyimpspec.analysis.kramers_kronig import ( evaluate_log_F_ext, suggest_num_RC, suggest_representation, ) from typing import Dict, List, Tuple data: DataSet = generate_mock_data("CIRCUIT_1", noise=5e-2, seed=42)[0] # High-level test execution test: KramersKronigResult = perform_kramers_kronig_test(data) # Manual workflow equivalent Z_evaluations = evaluate_log_F_ext(data, admittance=False) Z_suggested_F_ext, Z_tests, Z_minimized_statistic = Z_evaluations[0] Z_suggestion = suggest_num_RC(Z_tests) Y_evaluations = evaluate_log_F_ext(data, admittance=True) Y_tests = Y_evaluations[0][1] Y_suggestion = suggest_num_RC(Y_tests) suggestion = suggest_representation([Z_suggestion, Y_suggestion]) test, scores, lower_limit, upper_limit = suggestion ``` -------------------------------- ### Import pyimpspec in Python Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_installing.md Demonstrates how to import the pyimpspec library in a Python script or interactive session after installation and activation of the virtual environment. ```python import pyimpspec ``` -------------------------------- ### Check pipx Installation (Bash) Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_installing.md Verifies if pipx is installed. pipx is a tool for managing Python applications in isolated environments. ```bash pipx --version ``` -------------------------------- ### Perform DRT Analysis using pyimpspec Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_drt.md Demonstrates how to generate mock impedance data and perform DRT analysis using either specific method functions (e.g., TR-NNLS) or the general wrapper function. The example shows the import of necessary classes and functions, data generation, and the execution of the analysis. ```python from pyimpspec import ( DataSet, DRTResult, calculate_drt, generate_mock_data, ) from pyimpspec.analysis.drt import ( BHTResult, LMResult, MRQFitResult, TRNNLSResult, TRRBFResult, calculate_drt_bht, calculate_drt_lm, calculate_drt_mrq_fit, calculate_drt_tr_nnls, calculate_drt_tr_rbf, ) data: DataSet = generate_mock_data("CIRCUIT_1", noise=5e-2, seed=42)[0] drt: TRNNLSResult = calculate_drt_tr_nnls(data, lambda_value=1e-4) drt: DRTResult = calculate_drt(data, method="tr-nnls", lambda_value=1e-4) assert isinstance(drt, TRNNLSResult) ``` -------------------------------- ### GPL Interactive Mode Notice Source: https://github.com/vyrjana/pyimpspec/blob/main/LICENSES/LICENSE-cvxopt.txt This snippet displays the standard copyright and licensing notice that appears when a program licensed under the GNU GPL starts in interactive mode. It informs users about the program's origin, warranty, and redistribution conditions. ```text Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. ``` -------------------------------- ### Define Circuit Elements in pyimpspec Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs_circuit.md Examples of how to instantiate common circuit elements within the pyimpspec framework. These classes represent physical components used to build impedance models. ```python from pyimpspec.circuit.elements import Resistor, Inductor, Gerischer, HavriliakNegami # Instantiate a standard resistor r = Resistor(R=1000) # Instantiate an ideal inductor l = Inductor(L=1e-6) # Instantiate a Gerischer element g = Gerischer(Y=1, k=1) # Instantiate a Havriliak-Negami element hn = HavriliakNegami(dC=1e-6, tau=1, a=0.9, b=0.9) ``` -------------------------------- ### Process EIS Data using Pyimpspec Command-Line Interface (Bash) Source: https://context7.com/vyrjana/pyimpspec/llms.txt Demonstrates various command-line operations provided by Pyimpspec for parsing, plotting, testing, fitting, and analyzing EIS data. These commands allow users to perform common EIS tasks directly from the terminal without writing Python scripts. Examples include parsing data files, generating Bode plots, performing Kramers-Kronig tests, fitting equivalent circuits, and calculating DRT. ```Bash # Parse data file and output as CSV pyimpspec parse "data.dta" \ --output-to \ --output-format csv \ --output-dir "./output" # Plot impedance data as Bode plot pyimpspec plot "data.dta" \ --type bode \ --output-to \ --plot-format svg # Perform Kramers-Kronig test pyimpspec test "data.dta" \ --no-capacitance \ --mu-criterion 0.7 # Fit circuit to data pyimpspec fit "data.dta" \ --circuit "R(RC)(RW)" # Calculate DRT pyimpspec drt "data.dta" \ --method tr-nnls \ --lambda 1e-4 # Perform Z-HIT analysis pyimpspec zhit "data.dta" # Use mock data with wildcards pyimpspec zhit "" # Mock data with custom parameters pyimpspec zhit "" # Generate/view configuration file pyimpspec config -h ``` -------------------------------- ### Access Configuration Help Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_cli.md Displays the help menu for the configuration subcommand to manage default arguments. ```bash pyimpspec config -h ``` -------------------------------- ### Use Circuit Placeholders and Wildcards Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_cli.md Shows how to use built-in circuit placeholders and wildcards to process multiple immittance spectra. ```bash pyimpspec zhit "" pyimpspec zhit "" ``` -------------------------------- ### Initialize pyimpspec library Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs.md Demonstrates how to import the main pyimpspec module and the matplotlib-based plotting sub-module for impedance spectroscopy tasks. ```python import pyimpspec from pyimpspec import mpl ``` -------------------------------- ### Registering a Custom Circuit Element Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_circuit.md Demonstrates how to define a new circuit element by subclassing Element, implementing the _impedance method, and registering it with metadata including parameters and equations. ```python from pyimpspec import ( ComplexImpedances, Frequencies, Circuit, Element, ElementDefinition, ParameterDefinition, register_element, parse_cdc, ) from numpy import pi, inf class SomeNewElement(Element): def _impedance(self, f: Frequencies, X: float, a: float) -> ComplexImpedances: return 1 / (X * (1j * 2 * pi * f)**a) register_element( ElementDefinition( Class=SomeNewElement, symbol="Ude", name="Some new element", description="User-defined element of some type.", equation="1/(X*(2*pi*f*I)^a)", parameters=[ ParameterDefinition( symbol="X", unit="Some unit", description="Description of this parameter", value=1e-6, lower_limit=1e-24, upper_limit=inf, fixed=False, ), ParameterDefinition( symbol="a", unit="", description="Some exponent", value=0.5, lower_limit=0.0, upper_limit=1.0, fixed=False, ), ], ), ) circuit: Circuit = parse_cdc("Ude") ``` -------------------------------- ### Circuit Fitting Workflow Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_fitting.md Demonstrates the complete workflow for fitting circuit parameters using PyImpSpec, from data generation to exporting fitted parameters as a markdown table. ```APIDOC ## Circuit Fitting Workflow ### Description This example illustrates the process of fitting an electrical circuit using the `pyimpspec` library. It covers generating mock data, defining a circuit structure, performing the fit, and visualizing the results. ### Method This is a conceptual workflow and does not map to a single HTTP request. It involves sequential execution of Python code. ### Endpoint N/A ### Parameters N/A ### Request Example ```python from schemdraw import Drawing from pandas import DataFrame from pyimpspec import ( Circuit, DataSet, FitResult, fit_circuit, generate_mock_data, ) from pyimpspec.utils import parse_cdc # Generate mock data for a circuit data: DataSet = generate_mock_data("CIRCUIT_1", noise=5e-2, seed=42)[0] # Define the circuit structure circuit: Circuit = parse_cdc("R(RC)(RW)") # Fit the circuit to the data fit: FitResult = fit_circuit(circuit, data) # Get the SymPy representation of the circuit print(fit.circuit.to_sympy()) # Generate a drawing of the fitted circuit with running counts drawing: Drawing = fit.circuit.to_drawing(running=True) # Export fitted parameters to a pandas DataFrame and then to markdown df: DataFrame = fit.to_parameters_dataframe(running=True) parameters: str = df.to_markdown(index=False) print(parameters) ``` ### Response #### Success Response (200) This workflow produces output to the console and potentially generates image files (e.g., circuit drawings). The primary textual output is the markdown table of fitted parameters. #### Response Example ``` R_0 + 1/(2*I*pi*C_2*f + 1/R_1) + 1/(Y_4*(2*I*pi*f)**n_4 + 1/R_3) | Element | Parameter | Value | Std. err. (%) | Unit | Fixed | |:----------|:------------|--------------:|----------------:|:----------|:--------| | R_0 | R | 99.9526 | 0.0270415 | ohm | No | | R_1 | R | 200.295 | 0.0161802 | ohm | No | | C_2 | C | 7.98617e-07 | 0.00251256 | F | No | | R_3 | R | 499.93 | 0.0228977 | ohm | No | | W_4 | Y | 0.000400664 | 0.0303443 | S*s^(1/2) | No | ``` ``` -------------------------------- ### Install pyimpspec in editable mode Source: https://github.com/vyrjana/pyimpspec/blob/main/tests/README.md Installs the current package in editable mode, allowing changes to the source code to be reflected immediately without re-installation. This is a prerequisite for running tests locally. ```bash pip install --editable . ``` -------------------------------- ### TransmissionLineModelBlockingOpen Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs_circuit.md Initializes a blocking porous electrode transmission line model with a perfectly reflective inner boundary. ```APIDOC ## POST /circuit/elements/TransmissionLineModelBlockingOpen ### Description Creates a model for a blocking porous electrode with a perfectly reflective inner boundary (Model b). ### Method POST ### Endpoint /circuit/elements/TransmissionLineModelBlockingOpen ### Parameters #### Request Body - **R_i** (float) - Optional - Ionic resistance - **Y** (float) - Optional - Interfacial admittance - **n** (float) - Optional - Phase angle - **L** (float) - Required - Pore length ### Request Example { "R_i": 1.0, "Y": 0.005, "n": 0.8, "L": 1.0 } ### Response #### Success Response (200) - **model** (string) - Tlmbo ``` -------------------------------- ### GET /fitted_parameter Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs_fitting.md Methods for interacting with individual FittedParameter objects. ```APIDOC ## GET /fitted_parameter ### Description Accessors for individual parameter properties such as value, error, and fixed status. ### Methods - **get_value()**: Returns the fitted value (float). - **get_error()**: Returns the absolute standard error (float). - **get_relative_error()**: Returns the relative standard error (float). - **get_unit()**: Returns the parameter unit (str). - **is_fixed()**: Returns whether the parameter was fixed (bool). ``` -------------------------------- ### Perform Kramers-Kronig Tests Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_cli.md Demonstrates running Kramers-Kronig tests on impedance spectra with specific parameters like mu-criterion. ```bash pyimpspec test "path to some file" --no-capacitance --mu-criterion 0.7 ``` -------------------------------- ### GET /to_statistics_dataframe Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs_fitting.md Retrieves the statistical summary of the circuit fit. ```APIDOC ## GET /to_statistics_dataframe ### Description Returns a pandas DataFrame containing statistics related to the circuit fit process. ### Method GET ### Endpoint /to_statistics_dataframe ### Response #### Success Response (200) - **DataFrame** (pandas.DataFrame) - A table containing fit statistics. ``` -------------------------------- ### GET /pyimpspec/elements Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs_circuit.md Retrieve a mapping of element symbols to their corresponding classes. ```APIDOC ## GET /pyimpspec/elements ### Description Returns a dictionary that maps element symbols to their corresponding classes. ### Method GET ### Endpoint pyimpspec.get_elements(default_only=False, private=False) ### Parameters #### Query Parameters - **default_only** (bool) - Optional - Return only default elements. - **private** (bool) - Optional - Include private elements. ### Response #### Success Response (200) - **result** (Dict[str, Type[Element]]) - Mapping of symbols to element classes. ``` -------------------------------- ### GET /to_peaks_dataframe Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs_drt.md Exports peak data into a pandas DataFrame format. ```APIDOC ## GET /to_peaks_dataframe ### Description Get the peaks as a pandas.DataFrame object. ### Method GET ### Endpoint /to_peaks_dataframe ### Parameters #### Query Parameters - **threshold** (float) - Optional - Minimum peak height threshold. - **columns** (List[str]) - Optional - Labels for column headers. ### Response #### Success Response (200) - **dataframe** (pandas.DataFrame) - The resulting peak data table. ``` -------------------------------- ### Fit Circuit and Generate Parameters DataFrame (Python) Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_fitting.md This snippet demonstrates fitting a circuit to generated data using PyImpSpec. It shows how to generate mock data, parse a circuit definition, perform the fit, convert the fitted circuit to a SymPy expression, and then generate a markdown-formatted DataFrame of the fitted parameters with running counts. ```python from schemdraw import Drawing from pandas import DataFrame from pyimpspec import ( Circuit, DataSet, FitResult, fit_circuit, generate_mock_data, ) data: DataSet = generate_mock_data("CIRCUIT_1", noise=5e-2, seed=42)[0] circuit: Circuit = parse_cdc("R(RC)(RW)") fit: FitResult = fit_circuit(circuit, data) fit.circuit.to_sympy() drawing: Drawing = fit.circuit.to_drawing(running=True) df: DataFrame = fit.to_parameters_dataframe(running=True) parameters: str = df.to_markdown(index=False) ``` -------------------------------- ### GET /to_parameters_dataframe Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs_fitting.md Retrieves the fitted parameters and their estimated errors as a pandas DataFrame. ```APIDOC ## GET /to_parameters_dataframe ### Description Returns a pandas DataFrame containing fitted parameters and their corresponding estimated standard errors. ### Method GET ### Endpoint /to_parameters_dataframe ### Parameters #### Query Parameters - **running** (bool) - Optional - Whether or not to use running counts as the lower indices of elements. ### Response #### Success Response (200) - **DataFrame** (pandas.DataFrame) - A table containing parameter values and errors. ``` -------------------------------- ### GET /generate_fit_identifiers Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs_fitting.md Generates the mapping of circuit elements to lmfit-compatible parameter identifiers. ```APIDOC ## GET /generate_fit_identifiers ### Description Generates identifiers for circuit elements that can be used to define constraints in the fitting process. ### Method GET ### Endpoint /generate_fit_identifiers ### Parameters #### Query Parameters - **circuit** (Circuit) - Required - The circuit object to process. ### Request Example { "circuit": "R1-C1" } ### Response #### Success Response (200) - **identifiers** (dict) - A dictionary mapping elements to FitIdentifiers. #### Response Example { "R1": {"R": "R1_R"}, "C1": {"C": "C1_C"} } ``` -------------------------------- ### Get Time Constants - PyImpspec Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs_kramers_kronig.md Retrieves the time constants that were utilized during the fitting process. ```python def get_time_constants(): """Get the time constants that were used during fitting. * **Return type:** [`TimeConstants`](apidocs_typing.md#pyimpspec.TimeConstants) """ pass ``` -------------------------------- ### GET /statistics/dataframe Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs_drt.md Retrieves statistical data related to the DRT analysis as a pandas DataFrame. ```APIDOC ## GET /statistics/dataframe ### Description Returns the statistical summary of the DRT analysis as a pandas DataFrame. ### Method GET ### Endpoint /to_statistics_dataframe ### Response #### Success Response (200) - **dataframe** (pandas.DataFrame) - A DataFrame containing the statistical metrics. #### Response Example { "dataframe": "| Metric | Value |\n|---|---|\n| Mean | 0.45 |\n| Std Dev | 0.12 |" ``` -------------------------------- ### Suggest Optimal RC Elements (Method 6 - Log-Sum Apex) Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs_kramers_kronig.md Suggests the optimal number of RC elements by analyzing the approximate position of the apex in a plot of log-sum of impedance components versus the number of RC elements. This method accounts for the trade-off between increasing the number of RC elements and the resulting decrease in component magnitudes, which can lead to overfitting. ```python def suggest_num_RC_method_6(tests, lower_limit=0, upper_limit=0, relative_scores=True): """Suggest the optimal number of RC elements to use based on the approximate position of the apex in a plot of $\log{\Sigma_{k=1}^{N_\tau} |\tau_k / R_k|}$ versus the number of RC elements. If the tests were performed on the admittance representation of the immittance data, then $C_k$ is substituted for $R_k$. The sum grows initially as the number of RC elements increases. However, the magnitudes of the fitted $R_k$ (or $C_k$) also tend to increase, which causes the magnitudes of the corresponding $C_k$ (or $R_k$) to decrease. Thus, the sum begins to decline despite the increasing number of RC elements and the fitted impedance spectrum begins to oscillate (i.e., overfitting takes place). The apex should coincide with or be near the optimum. References: - [V. Yrjänä and J. Bobacka, 2024, Electrochim. Acta, 504, 144951](https://doi.org/10.1016/j.electacta.2024.144951) * **Parameters:** * **tests** (List[[`KramersKronigResult`](#pyimpspec.KramersKronigResult)]) – The test results to evaluate. * **lower_limit** (*int* *,* *optional*) – The lower limit to enforce for the number of RC elements. If this value is less than one, then no limit is enforced. If both the lower and upper limit are greater than zero, then the lower limit must have a smaller value than the upper limit. * **upper_limit** (*int* *,* *optional*) – The upper limit to enforce for the number of RC elements. If this value is less than one, then no limit is enforced. If both the lower and upper limit are greater than zero, then the upper limit must have a greater value than the lower limit. * **relative_scores** (*bool* *,* *optional*) – Return relative scores ranging from 0.0 to 1.0 (from worst to best) rather than the raw values. * **Returns:** A dictionary mapping the number of RC elements to its corresponding score. * **Return type:** Dict[int, float] """ pass ``` -------------------------------- ### GET /peaks/dataframe Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs_drt.md Converts peak data into a pandas DataFrame for easier analysis and reporting. ```APIDOC ## GET /peaks/dataframe ### Description Returns the DRT peaks as a pandas DataFrame object, suitable for generating tables or further data manipulation. ### Method GET ### Endpoint /to_peaks_dataframe ### Parameters #### Query Parameters - **threshold** (float) - Optional - The minimum peak height threshold. - **columns** (List[str]) - Optional - Custom labels for the DataFrame column headers. ### Response #### Success Response (200) - **dataframe** (pandas.DataFrame) - A DataFrame containing the peak data. #### Response Example { "dataframe": "| Time Constant | Gamma |\n|---|---|\n| 0.01 | 0.5 |\n| 0.1 | 1.2 |" ``` -------------------------------- ### GET /get_peaks Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs_drt.md Retrieves time constants and gammas for peaks exceeding a specified magnitude threshold. ```APIDOC ## GET /get_peaks ### Description Get the time constants (in seconds) and gammas (in ohms) of peaks with magnitudes greater than the threshold. ### Method GET ### Endpoint /get_peaks ### Parameters #### Query Parameters - **threshold** (float) - Optional - Minimum peak height threshold relative to the tallest peak. ### Response #### Success Response (200) - **data** (Tuple[TimeConstants, Gammas, TimeConstants, Gammas]) - Returns peak data. ``` -------------------------------- ### Create Circuit Elements Directly in PyImpspec Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_circuit.md Demonstrates how to build a circuit by directly instantiating and nesting Element and Connection objects like Resistor, Capacitor, Series, and Parallel. This method provides granular control over circuit construction. ```python from pyimpspec import Circuit, Series, Parallel, Resistor, Capacitor, Warburg from numpy import inf, sqrt R_sol: Resistor = ( Resistor(R=20) .set_fixed(R=True) .set_label("sol") ) C_dl: Capacitor = ( Capacitor() .set_label("dl") .set_values(C=25e-6) .set_lower_limits(C=-inf) .set_upper_limits(C=1e-3) ) R_ct: Resistor = ( Resistor(R=100) .set_label("ct") .set_lower_limits(R=50) .set_upper_limits(R=200) ) W_diff: Warburg = ( Warburg(Y=1/(sqrt(2)*300)) .set_label("diff") .set_lower_limits(Y=-inf) .set_upper_limits(Y=1.5*1/(sqrt(2)*300)) ) inner_series: Series = Series([R_ct, W_diff]) parallel: Parallel = Parallel([C_dl, inner_series]) outer_series: Series = Series([R_sol, parallel]) circuit: Circuit = Circuit(outer_series) circuit.to_string(3) ``` -------------------------------- ### GET /circuit/serialize Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_circuit.md Serializes a circuit object into a CDC string, including metadata and versioning for compatibility. ```APIDOC ## GET /circuit/serialize ### Description Serializes a circuit object into a versioned CDC string. This is useful for storing circuits while ensuring compatibility across different API versions. ### Method GET ### Endpoint /circuit/serialize ### Parameters #### Query Parameters - **decimals** (integer) - Optional - Number of decimal places for numerical values. Defaults to 12. ### Request Example GET /circuit/serialize?decimals=3 ### Response #### Success Response (200) - **serialized_string** (string) - The versioned CDC string representation. #### Response Example { "serialized_string": "!V=1![R{R=2.000E+01F...}]" } ``` -------------------------------- ### Perform Kramers-Kronig Test and Suggest RC Elements Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_kramers_kronig.md Demonstrates how to execute a Kramers-Kronig test on a dataset and manually tune the RC element suggestion process using the mu-criterion. This approach allows for fine-grained control over the optimization parameters. ```python from pyimpspec import (DataSet, KramersKronigResult, generate_mock_data, perform_kramers_kronig_test) from pyimpspec.analysis.kramers_kronig import (evaluate_log_F_ext, suggest_num_RC) from typing import List, Tuple mu_criterion: float = 0.85 data: DataSet = generate_mock_data("CIRCUIT_1", noise=5e-2, seed=42)[0] test: KramersKronigResult = perform_kramers_kronig_test(data, mu_criterion=mu_criterion) evaluations: List[Tuple[float, List[KramersKronigResult], float]] = evaluate_log_F_ext(data) optimum_log_Fext: Tuple[float, List[KramersKronigResult], float] = evaluations[0] tests: List[KramersKronigResult] = optimum_log_Fext[1] suggestion: Tuple[KramersKronigResult, Dict[int, float], int, int] = suggest_num_RC(tests, mu_criterion=mu_criterion) test, scores, lower_limit, upper_limit = suggestion ``` -------------------------------- ### Perform Z-HIT Analysis Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_zhit.md Demonstrates how to generate mock immittance data and perform the Z-HIT analysis using the pyimpspec library. ```python from pyimpspec import DataSet, ZHITResult, generate_mock_data, perform_zhit data: DataSet = generate_mock_data("CIRCUIT_2_INVALID", noise=5e-2, seed=42)[0] zhit: ZHITResult = perform_zhit(data) ``` -------------------------------- ### Upgrade pyimpspec with pip (Bash) Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_installing.md Upgrades an existing pyimpspec installation to the latest version using pip. ```bash pip install pyimpspec --upgrade ``` -------------------------------- ### GET /peaks Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs_drt.md Retrieves time constants and gamma values for peaks exceeding a specified relative magnitude threshold. ```APIDOC ## GET /peaks ### Description Retrieves the time constants (in seconds) and gamma values (in ohms) for peaks with magnitudes greater than the specified threshold. ### Method GET ### Endpoint /get_peaks ### Parameters #### Query Parameters - **threshold** (float) - Optional - The minimum peak height threshold (relative to the height of the tallest peak). ### Response #### Success Response (200) - **result** (Tuple[TimeConstants, Gammas]) - A tuple containing the time constants and gamma values. #### Response Example { "time_constants": [0.01, 0.1, 1.0], "gammas": [0.5, 1.2, 0.8] } ``` -------------------------------- ### Build Circuits with CircuitBuilder Context Manager in PyImpspec Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_circuit.md Illustrates using the CircuitBuilder context manager for a more intuitive and hierarchical way to construct circuits. This method simplifies the process of nesting connections and adding elements. ```python from pyimpspec import Circuit, CircuitBuilder, Resistor, Capacitor, Warburg from numpy import inf, sqrt with CircuitBuilder() as outer_series: outer_series.add( Resistor(R=20) .set_label("sol") .set_fixed(R=True) ) with outer_series.parallel() as parallel: parallel.add( Capacitor(C=25e-6) .set_label("dl") .set_lower_limits(C=-inf) .set_upper_limits(C=1e-3) ) with parallel.series() as inner_series: inner_series.add( Resistor(R=100) .set_label("ct") .set_lower_limits(R=50) .set_upper_limits(R=200) ) inner_series.add( Warburg(Y=1/(sqrt(2)*300)) .set_label("diff") .set_lower_limits(Y=-inf) .set_upper_limits(Y=1.5*1/(sqrt(2)*300)) ) circuit: Circuit = outer_series.to_circuit() circuit.to_string(3) ``` -------------------------------- ### POST /analysis/kramers-kronig/suggest-rc-method-6 Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/apidocs_kramers_kronig.md Suggests the optimal number of RC elements based on the apex position of the log sum of time constants versus RC element count. ```APIDOC ## POST /analysis/kramers-kronig/suggest-rc-method-6 ### Description Suggests the optimal number of RC elements by identifying the apex in a plot of log sum of time constants, helping to detect the onset of overfitting. ### Method POST ### Endpoint /analysis/kramers-kronig/suggest-rc-method-6 ### Parameters #### Request Body - **tests** (List[KramersKronigResult]) - Required - The test results to evaluate. - **lower_limit** (int) - Optional - Lower limit for the number of RC elements. - **upper_limit** (int) - Optional - Upper limit for the number of RC elements. - **relative_scores** (bool) - Optional - Return relative scores (0.0 to 1.0) instead of raw values. ### Response #### Success Response (200) - **result** (Dict[int, float]) - A dictionary mapping the number of RC elements to its corresponding score. ``` -------------------------------- ### Upgrade pyimpspec with pipx (Bash) Source: https://github.com/vyrjana/pyimpspec/blob/main/docs/source/guide_installing.md Upgrades an existing pyimpspec installation to the latest version using pipx, including any injected dependencies. ```bash pipx upgrade pyimpspec --include-injected ```