rsoft_cad.femsim package
Submodules
rsoft_cad.femsim.curve_fitting module
- rsoft_cad.femsim.curve_fitting.sigmoid_decay(x, a, b, c, d, e)[source]
Function combining linear decay with sigmoid drop-off a + b*x + c/(1 + np.exp(d*(x-e)))
a, b: linear component parameters c, d, e: sigmoid component parameters e: position of the sigmoid midpoint
- rsoft_cad.femsim.curve_fitting.double_exp_decay(x, A, B, C, D, E)[source]
Double exponential decay function.
Parameters:
- xarray-like
Independent variable (taper length in microns)
- Afloat
Asymptotic value (baseline)
- Bfloat
Amplitude of first exponential term
- Cfloat
Decay constant for first exponential term
- Dfloat
Amplitude of second exponential term
- Efloat
Decay constant for second exponential term
Returns:
- yarray-like
Dependent variable (effective index)
- rsoft_cad.femsim.curve_fitting.polynomial(x, a, b, c, d, e, f, g, h, i)[source]
Simple polynomial function for fitting.
Parameters:
- xarray-like
Independent variable
- a, b, c, …float
Polynomial coefficients
Returns:
- yarray-like
a*x^2 + b*x + c
- rsoft_cad.femsim.curve_fitting.fit_index_data(index_data_real: Dict[int, List[float]], index_data_imag: Dict[int, List[float]], x_values: List[float], fit_function: Callable | None = None) Dict[int, Dict[str, Any]][source]
Fits real and imaginary index data and stores results in a defaultdict.
Parameters:
- index_data_realDict[int, List[float]]
Dictionary mapping indices to lists of real component values
- index_data_imagDict[int, List[float]]
Dictionary mapping indices to lists of imaginary component values
- x_valuesList[float]
X-axis values for fitting (e.g., taper lengths)
- fit_functioncallable, optional
Function to use for fitting. Default is a simple polynomial fit.
Returns:
- fit_resultsDict[int, Dict[str, Any]]
Dictionary containing fitted parameters and functions for each index
- rsoft_cad.femsim.curve_fitting.plot_fit_results(ax: Axes, x_values: List[float], unique_indices: List[int], fit_results: Dict[int, Dict[str, Any]], cmap: ScalarMappable, component_type: str) None[source]
Plot the fitted curves on the axes.
Parameters:
- axplt.Axes
Matplotlib axes to plot on
- x_valuesList[float]
X-axis values
- unique_indicesList[int]
List of unique mode indices
- fit_resultsDict[int, Dict[str, Any]]
Dictionary containing fitted parameters and functions
- cmapplt.cm.ScalarMappable
Color map for different indices
- component_typestr
Component type (‘real’ or ‘imag’)
rsoft_cad.femsim.data_processing module
- rsoft_cad.femsim.data_processing.extract_run_names(file_paths: List[str]) List[str][source]
Extract ‘run_XXX’ parts from a list of file paths.
- rsoft_cad.femsim.data_processing.get_z_positions_from_runs(dataframe: DataFrame, file_paths: List[str]) Tuple[List[float], List[str]][source]
Extract z_pos values from a DataFrame based on run names found in file paths.
- Parameters:
dataframe (pd.DataFrame) – DataFrame with ‘filename’ and ‘z_pos’ columns
file_paths (List[str]) – List of file paths containing run_XXX.nef files
- Returns:
- A tuple containing:
List of z_pos values corresponding to the run names
List of run names extracted from file paths
- Return type:
- rsoft_cad.femsim.data_processing.process_nef_files(folder_path: str, include_subfolders: bool = True) Tuple[Dict[int, List[float]], Dict[int, List[float]], List[str], List[str]][source]
Process multiple .nef files and extract relevant data.
- Parameters:
- Returns:
Dictionary of real index data by mode index
Dictionary of imaginary index data by mode index
List of file names
List of file paths
- Return type:
Tuple containing
- rsoft_cad.femsim.data_processing.create_dataframe_from_nef_data(index_data: Dict[int, List[float]], x_values: List[float], index_id: int) DataFrame[source]
Create a DataFrame from NEF data for a specific mode index.
rsoft_cad.femsim.femsim_param_scan module
rsoft_cad.femsim.femsim_plot module
NEF File Plotter - Entry point
This script serves as the entry point for the NEF file plotter tool, parsing command-line arguments and orchestrating the plotting workflow.
rsoft_cad.femsim.outlier_detection module
- rsoft_cad.femsim.outlier_detection.remove_outliers_by_zscore(df: DataFrame, x_column: str, y_column: str, window_size: float = 5000, z_threshold: float = 3) DataFrame[source]
Remove outliers from data using local z-scores within moving windows.
- Parameters:
df (pd.DataFrame) – DataFrame containing the data
x_column (str) – Name of the column to use as x-axis (e.g., ‘taper_length’)
y_column (str) – Name of the column to check for outliers (e.g., ‘real_n_eff’)
window_size (float) – Size of windows to calculate local z-scores
z_threshold (float) – Z-score threshold to identify outliers
- Returns:
DataFrame with outliers removed
- Return type:
pd.DataFrame
- rsoft_cad.femsim.outlier_detection.apply_outlier_removal(index_data: Dict[int, List[float]], unique_indices: List[int], x_values: List[float], window_size: float, z_threshold: float) Dict[int, List[float]][source]
Apply outlier removal to a set of index data.
- Parameters:
- Returns:
Updated index data with outliers removed
- Return type:
rsoft_cad.femsim.utils module
rsoft_cad.femsim.visualisation module
- rsoft_cad.femsim.visualisation.setup_figure(plot_type: str) Tuple[Figure, Axes | Tuple[Axes, Axes]][source]
Set up the figure and axes for plotting.
- Parameters:
plot_type (str) – Type of plot (‘real’, ‘imag’, or ‘both’)
- Returns:
Figure object
Axes object(s)
- Return type:
Tuple containing
- rsoft_cad.femsim.visualisation.plot_component(ax: Axes, x_values: List[float], x_labels: List[str], unique_indices: List[int], index_data: Dict[int, List[float]], total_files: int, cmap: ScalarMappable, component_type: str, use_filename_as_x: bool) None[source]
Plot a component (real or imaginary) of the effective index.
- Parameters:
ax (plt.Axes) – Matplotlib axes to plot on
x_values (List[float]) – X-axis values
x_labels (List[str]) – X-axis labels
unique_indices (List[int]) – List of unique mode indices
index_data (Dict[int, List[float]]) – Dictionary of data by mode index
total_files (int) – Total number of files (for padding)
cmap (plt.cm.ScalarMappable) – Color map for different indices
component_type (str) – Component type (‘real’ or ‘imag’)
use_filename_as_x (bool) – If True, use filenames as x-axis
- rsoft_cad.femsim.visualisation.plot_components(plot_type: str, ax1: Axes, ax2: Axes | None, x_values: List[float], x_labels: List[str], unique_indices: List[int], index_data_real: Dict[int, List[float]], index_data_imag: Dict[int, List[float]], total_files: int, cmap: Any, use_filename_as_x: bool) None[source]
Plot the specified components (real and/or imaginary) based on plot_type.
- Parameters:
plot_type (str) – Type of plot (‘real’, ‘imag’, or ‘both’)
ax1 (plt.Axes) – Primary axes object
ax2 (Optional[plt.Axes]) – Secondary axes object (for ‘both’ type)
x_values (List[float]) – X-axis values
x_labels (List[str]) – X-axis labels
unique_indices (List[int]) – List of unique mode indices
index_data_real (Dict[int, List[float]]) – Real component data by mode index
index_data_imag (Dict[int, List[float]]) – Imaginary component data by mode index
total_files (int) – Total number of files
cmap (Any) – Color map for different indices
use_filename_as_x (bool) – If True, use filenames as x-axis
- rsoft_cad.femsim.visualisation.add_legend(fig: Figure, ax1: Axes, plot_type: str) None[source]
Add a legend to the figure.
- Parameters:
fig (plt.Figure) – Figure object
ax1 (plt.Axes) – Primary axes object
plot_type (str) – Type of plot (‘real’, ‘imag’, or ‘both’)
- rsoft_cad.femsim.visualisation.save_figure(fig: Figure, folder_path: str, output_path: str | None, plot_type: str) None[source]
Save the figure to a file.
- rsoft_cad.femsim.visualisation.plot_combined_nef_files(folder_path: str, include_subfolders: bool = False, save_plot: bool = False, output_path: str | None = None, plot_type: str = 'real', max_indices: int | None = None, use_filename_as_x: bool = True, remove_outliers: bool = False, window_size: float = 5000, z_threshold: float = 3, colormap: str = 'viridis', plot_indices: List[int] | None = None, fit_data: bool = False, fit_function: Callable | None = None) Figure | None[source]
Plot multiple .nef files with each index as a separate line.
- Parameters:
folder_path (str) – Path to the folder containing .nef files
include_subfolders (bool) – If True, search for files in subfolders as well
save_plot (bool) – If True, save the plot as PNG file
output_path (Optional[str]) – Path to save the plot (if None, generates a default name)
plot_type (str) – ‘real’, ‘imag’, or ‘both’ to specify which part to plot
max_indices (Optional[int]) – Maximum number of indices to plot (None for all)
use_filename_as_x (bool) – If True, use filenames as x-axis; otherwise use file index
remove_outliers (bool) – If True, apply outlier removal using z-score method
window_size (float) – Window size for outlier detection (in x-axis units)
z_threshold (float) – Z-score threshold for outlier detection
colormap (str) – Colormap for plot (default: viridis)
plot_indices (Optional[List[int]]) – Specific mode indices to plot
fit_data (bool) – If True, apply curve fitting to the data points
fit_function (Optional[Callable]) – Function to use for fitting (default: polynomial)
- Returns:
The figure object or None if no files found
- Return type:
Optional[plt.Figure]