NetworkCollection

class pmrf.network_collection.NetworkCollection(networks: Iterable[Network] | None | str = None, name: str | None = None, params: dict | None = None)

Bases: object

A container for a collection of scikit-rf Networks.

Unlike NetworkSet, which is designed for statistical analysis of a set of networks with identical topology and frequency (e.g., Monte Carlo analysis), a NetworkCollection is a general-purpose container. It supports networks with different frequencies, port counts, and names.

It behaves like a list (ordered) and a dictionary (lookup by name).

Parameters:
  • networks (list of Network, optional) – A list of Networks to initialize the collection.

  • name (str, optional) – A name for the collection.

  • params (dict, optional) – A dictionary of parameters associated with the collection itself.

Variables:
  • networks (list) – The list of Network objects.

  • name (str) – The name of the collection.

classmethod from_dir(directory: str, pattern: str = '*.s*p', name: str | None = None) NetworkCollection

Create a NetworkCollection from a directory of Touchstone files.

Parameters:
  • directory (str) – Path to the directory.

  • pattern (str, optional) – Glob pattern to match files. Default is “*.s*p”.

  • name (str, optional) – Name of the collection. Defaults to directory name.

Return type:

NetworkCollection

classmethod from_zip(zip_file: str, name: str | None = None) NetworkCollection

Create a NetworkCollection from a zip file of Touchstone files.

__add__(other: NetworkCollection) NetworkCollection

Concatenate two collections into a new one.

Handles name collisions by appending an incrementing suffix (e.g., _1, _2) to the incoming networks.

__getitem__(key: int | str | slice) Network | NetworkCollection

Get a network by index or name.

Parameters:

key (int, str, or slice) – If int, returns the network at that index. If str, returns the network with that name. If slice, returns a new NetworkCollection.

__len__()
add(ntwk: Network) None

Add a Network to the collection.

Parameters:

ntwk (skrf.Network) – The network to add. Its .name attribute must be set and unique within the collection.

Raises:
  • ValueError – If the network has no name or the name already exists.

  • TypeError – If ntwk is not a scikit-rf Network.

apply(func: Callable[[Network], Network]) None

Apply a function to every network in the collection in-place.

Parameters:

func (callable) – A function that accepts a Network and returns a Network.

common_frequency(mode: str = 'intersection', npoints: int | None = None) ndarray

Compute a common frequency vector for the collection.

Parameters:
  • mode ({'intersection', 'union', 'min_npoints', 'max_npoints'}, optional)

  • npoints (int, optional)

copy() NetworkCollection

Return a deep copy of the collection.

filter(func: Callable[[Network], bool]) NetworkCollection

Return a new NetworkCollection containing only networks where func(ntwk) is True.

Parameters:

func (callable) – A function that accepts a Network and returns a boolean.

Return type:

NetworkCollection

interpolate(freq_or_mode: Frequency | ndarray | str = 'intersection', npoints: int | None = None, **kwargs) NetworkCollection

Return a new NetworkCollection where all networks are interpolated to a common frequency.

Parameters:
  • freq_or_mode (skrf.Frequency, np.ndarray, or str) – If ‘intersection’ or ‘union’, calculates the common vector. If a vector/Frequency object, uses that explicitly.

  • npoints (int, optional) – Number of points (if using mode string).

  • kwargs – Passed to Network.interpolate.

Return type:

NetworkCollection

interpolate_self(freq_or_mode: Frequency | ndarray | str = 'intersection', npoints: int | None = None, **kwargs) None

Interpolate all networks in the collection in-place to a common frequency.

Parameters:
  • freq_or_mode (skrf.Frequency, np.ndarray, or str) – If ‘intersection’ or ‘union’, calculates the common vector. If a vector/Frequency object, uses that explicitly.

  • npoints (int, optional) – Number of points (if using mode string).

  • kwargs – Passed to Network.interpolate_self.

keys() List[str]

Return a list of network names.

pop(key: int | str) Network

Remove a network from the collection by index or name.

Parameters:

key (int or str) – The index or name of the network to remove.

Returns:

The removed network object.

Return type:

skrf.Network

Raises:
  • TypeError – If key is not an int or str.

  • KeyError – If a string key is not found in the collection.

  • IndexError – If an int key is out of bounds.

renormalize(z_new, s_def=None)
summary() str

Return a string summary of the collection.

to_dataframe(attrs: List[str] | None = None) DataFrame

Convert the collection summary to a pandas DataFrame.

Parameters:

attrs (list of str, optional) – List of attributes to extract from each network (e.g. [‘name’, ‘nports’]). Defaults to name, ports, and frequency range.

Return type:

pd.DataFrame

to_dict() Dict[str, Network]

Convert the collection to a dictionary {name: network}.

Returns:

A dictionary where keys are network names and values are the Network objects.

Return type:

dict

write(directory: str = '.') None

Write all networks in the collection to Touchstone files in the specified directory.