Giter Site home page Giter Site logo

How to perform port cropping? about scikit-rf HOT 3 CLOSED

Asachoo avatar Asachoo commented on September 23, 2024
How to perform port cropping?

from scikit-rf.

Comments (3)

Asachoo avatar Asachoo commented on September 23, 2024 1

Will this help ? I think there is already a built-in function for your request.

https://scikit-rf.readthedocs.io/en/latest/api/generated/skrf.network.Network.subnetwork.html#skrf.network.Network.subnetwork

Also, should this be in the Discussion thread rather than Issues ? 🤔 We can always convert Discussions to Issues once it is confirmed

scikit-rf/skrf/network.py

Lines 5442 to 5480 in b32ff9c

def subnetwork(ntwk: Network, ports: int, offby:int = 1) -> Network:
"""
Return a subnetwork of a given Network from a list of port numbers.
A subnetwork is Network which S-parameters corresponds to selected ports,
with all non-selected ports considered matched.
The resulting subNetwork is given a new Network.name property
from the initial name and adding the kept ports indices
(ex: 'device' -> 'device13'). Such name should make easier the use
of functions such as n_twoports_2_nport.
Parameters
----------
ntwk : :class:`Network` object
Network to split into a subnetwork
ports : list of int
List of ports to keep in the resultant Network.
Indices are the Python indices (starts at 0)
offby : int
starting value for s-parameters indexes in the sub-Network name parameter.
A value of `1`, assumes that a s21 = ntwk.s[:,1,0]. Default is 1.
Returns
-------
subntwk : :class:`Network` object
Resulting subnetwork from the given ports
See also
--------
Network.subnetwork, n_twoports_2_nport
Examples
--------
>>> tee = rf.data.tee # 3 port Network
>>> tee12 = rf.subnetwork(tee, [0, 1]) # 2 port Network from ports 1 & 2, port 3 matched
>>> tee23 = rf.subnetwork(tee, [1, 2]) # 2 port Network from ports 2 & 3, port 1 matched
>>> tee13 = rf.subnetwork(tee, [0, 2]) # 2 port Network from ports 1 & 3, port 2 matched

Thanks for your tip, your reply solved my problem very well

from scikit-rf.

Asachoo avatar Asachoo commented on September 23, 2024

An ugly attempt to achieve this

def renumbered(self, from_ports: Sequence[int], to_ports: Sequence[int] = None) -> 'Network':
    """
    Return a renumbered Network, leave self alone.

    Parameters
    ----------
    from_ports : list-like
        List of port indices to change. Size between 1 and N_ports.
    to_ports : can be None or list-like
        List of desired port indices. Size between 1 and N_ports.
        None to use automatically generate a List of desired port indices. Size is between 1 and from_ports' size.

    NB: from_ports and to_ports must have same size.

    Returns
    -------
    ntwk : :class:`Network` object
        Resulting renumbered Network

    See Also
    --------
    renumber
    flip
    flipped

    """
    out = self.copy()
    if to_ports:
        out.renumber(from_ports, to_ports)
    else:
        to_ports_idx = npy.ix_(npy.arange(out.s.shape[0], from_ports, from_ports)
        out.s = out.s[to_ports_idx]
        out.z0 = out.z0[:, from_ports]
    return out
        

from scikit-rf.

denzchoe avatar denzchoe commented on September 23, 2024

Will this help ? I think there is already a built-in function for your request.

https://scikit-rf.readthedocs.io/en/latest/api/generated/skrf.network.subnetwork.html#skrf.network.subnetwork


Also, should this be in the Discussion thread rather than Issues ? 🤔
We can always convert Discussions to Issues once it is confirmed


scikit-rf/skrf/network.py

Lines 5442 to 5480 in b32ff9c

def subnetwork(ntwk: Network, ports: int, offby:int = 1) -> Network:
"""
Return a subnetwork of a given Network from a list of port numbers.
A subnetwork is Network which S-parameters corresponds to selected ports,
with all non-selected ports considered matched.
The resulting subNetwork is given a new Network.name property
from the initial name and adding the kept ports indices
(ex: 'device' -> 'device13'). Such name should make easier the use
of functions such as n_twoports_2_nport.
Parameters
----------
ntwk : :class:`Network` object
Network to split into a subnetwork
ports : list of int
List of ports to keep in the resultant Network.
Indices are the Python indices (starts at 0)
offby : int
starting value for s-parameters indexes in the sub-Network name parameter.
A value of `1`, assumes that a s21 = ntwk.s[:,1,0]. Default is 1.
Returns
-------
subntwk : :class:`Network` object
Resulting subnetwork from the given ports
See also
--------
Network.subnetwork, n_twoports_2_nport
Examples
--------
>>> tee = rf.data.tee # 3 port Network
>>> tee12 = rf.subnetwork(tee, [0, 1]) # 2 port Network from ports 1 & 2, port 3 matched
>>> tee23 = rf.subnetwork(tee, [1, 2]) # 2 port Network from ports 2 & 3, port 1 matched
>>> tee13 = rf.subnetwork(tee, [0, 2]) # 2 port Network from ports 1 & 3, port 2 matched

from scikit-rf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.