Skip to content

Attribute error when using function get2BeamPloss leaving Z_1 as default to None #10

@emacchia

Description

@emacchia

When calling power2b = beam.get2BeamPloss(Z, tau_s=tau_s), with Z_1 left as default to None, the function incorrectly assumes Z_1 exists, even though it’s an optional argument. Hence:

```AttributeError: 'NoneType' object has no attribute 'Zr'```

This happens because if the beam spectrum max frequency is lower than the impedance max frequency, then in power.py we hit the branch

elif np.max(f) < np.max(Z_0.f):
    ...
    Zreal_1 = Z_1.Zr[mask]   # <-- unconditional access to Z_1

which incorrectly assumes Z_1 exists, even though it’s an optional argument. It tries to crop the impedance to the spectrum bandwidth, but mistakenly crops Z_1 too.

Possible fix:
in the elif np.max(f) < np.max(Z_0.f): block (in power.py), remove or guard the Z_1 line, changing

Zreal_1 = Z_1.Zr[mask]

to

if Z_1 is not None:
    Zreal_1 = Z_1.Zr[mask]

This should make Z_1 truly optional.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions