| 1 | """ |
| 2 | freespace (:mod:`skrf.media.freespace`) |
| 3 | ======================================== |
| 4 | |
| 5 | A plane-wave (TEM Mode) in Freespace. |
| 6 | |
| 7 | Represents a plane-wave in a homogeneous freespace, defined by |
| 8 | the space's relative permittivity and relative permeability. |
| 9 | |
| 10 | .. autosummary:: |
| 11 | :toctree: generated/ |
| 12 | |
| 13 | Freespace |
| 14 | |
| 15 | |
| 16 | """ |
| 17 | from __future__ import annotations |
| 18 | |
| 19 | from typing import TYPE_CHECKING |
| 20 | |
| 21 | from numpy import ones, real, sqrt |
| 22 | from scipy.constants import epsilon_0, mu_0 |
| 23 | |
| 24 | from ..constants import NumberLike |
| 25 | from ..data import materials |
| 26 | from .media import Media |
| 27 | |
| 28 | if TYPE_CHECKING: |
| 29 | from ..frequency import Frequency |
| 30 | |
| 31 | |
| 32 | class Freespace(Media): |
| 33 | r""" |
| 34 | A plane-wave (TEM Mode) in Freespace. |
| 35 | |
| 36 | A Freespace media can be constructed in two ways: |
| 37 | |
| 38 | * from complex, relative permativity and permeability OR |
| 39 | * from real relative permativity and permeability with loss tangents. |
| 40 | |
| 41 | There is also a method to initialize from a |
| 42 | existing distributed circuit, appropriately named |
| 43 | :func:`Freespace.from_distributed_circuit` |
| 44 | |
| 45 | |
| 46 | Parameters |
| 47 | ---------- |
| 48 | frequency : :class:`~skrf.frequency.Frequency` object |
| 49 | frequency band of this transmission line medium |
| 50 | z0_port : number, array-like, or None |
| 51 | `z0_port` is the port impedance for networks generated by the media. |
| 52 | If `z0_port` is not None, the networks generated by the media are |
| 53 | renormalized (or in other words embedded) from the characteristic |
| 54 | impedance z0 of the media to `z0_port`. |
| 55 | Else if `z0_port` is None, the networks port impedances will be the raw |
| 56 | characteristic impedance z0 of the media. |
| 57 | (Default is None) |
| 58 | z0_override : number, array-like, or None |
| 59 | `z0_override` override the characteristic impedance for the media. |
| 60 | If `z0_override` is not None, the networks generated by the media have |
| 61 | their characteristic impedance `z0` overridden by `z0_override`. |
| 62 | (Default is None) |
| 63 | z0 : number, array-like, or None |
| 64 | deprecated parameter, alias to `z0_override` if `z0_override` is None. |
| 65 | Emit a deprecation warning. |
| 66 | ep_r : number, array-like |
| 67 | complex relative permittivity. negative imaginary is lossy. |
| 68 | mu_r : number, array-like |
| 69 | complex relative permeability. negative imaginary is lossy. |
| 70 | ep_loss_tan : None, number, array-like |
| 71 | electric loss tangent (of the permativity). |
| 72 | If not None, imag(ep_r) is ignored. |
| 73 | mu_loss_tan : None, number, array-like |
| 74 | magnetic loss tangent (of the permeability). |
| 75 | If not None, imag(mu_r) is ignored. |
| 76 | rho : number, array-like, string or None |
| 77 | resistivity (ohm-m) of the conductor walls. If array-like |
| 78 | must be same length as frequency. if str, it must be a key in |
| 79 | :data:`skrf.data.materials`. |
| 80 | Default is None (lossless). |
| 81 | \*args, \*\*kwargs : arguments and keyword arguments |
| 82 | |
| 83 | |
| 84 | Examples |
| 85 | -------- |
| 86 | >>> from skrf.media.freespace import Freespace |
| 87 | >>> from skrf.frequency import Frequency |
| 88 | >>> f = Frequency(75,110,101,'ghz') |
| 89 | >>> Freespace(frequency=f, ep_r=11.9) |
| 90 | >>> Freespace(frequency=f, ep_r=11.9-1.1j) |
| 91 | >>> Freespace(frequency=f, ep_r=11.9, ep_loss_tan=.1) |
| 92 | >>> Freespace(frequency=f, ep_r=11.9-1.1j, mu_r = 1.1-.1j) |
| 93 | |
| 94 | """ |
| 95 | |
| 96 | def __init__(self, frequency: Frequency | None = None, |
| 97 | z0_port: NumberLike | None = None, |
| 98 | z0_override: NumberLike | None = None, |
| 99 | z0: NumberLike | None = None, |
| 100 | ep_r: NumberLike = 1+0j, mu_r: NumberLike = 1+0j, |
| 101 | ep_loss_tan: NumberLike | None = None, |
| 102 | mu_loss_tan: NumberLike | None = None, |
| 103 | rho: NumberLike | str | None = None, |
| 104 | *args, **kwargs): |
| 105 | Media.__init__(self, frequency = frequency, |
| 106 | z0_port = z0_port, z0_override = z0_override, z0 = z0) |
| 107 | self.ep_r = ep_r |
| 108 | self.mu_r = mu_r |
| 109 | self.rho = rho |
| 110 | |
| 111 | self.ep_loss_tan = ep_loss_tan |
| 112 | self.mu_loss_tan = mu_loss_tan |
| 113 | |
| 114 | def __str__(self) -> str: |
| 115 | f = self.frequency |
| 116 | output = 'Freespace Media. %i-%i %s. %i points'%\ |
| 117 | (f.f_scaled[0], f.f_scaled[-1], f.unit, f.npoints) |
| 118 | return output |
| 119 | |
| 120 | def __repr__(self) -> str: |
| 121 | return self.__str__() |
| 122 | |
| 123 | @property |
| 124 | def ep(self) -> NumberLike: |
| 125 | r""" |
| 126 | Complex dielectric permittivity. |
| 127 | |
| 128 | If :math:`\tan\delta_e` is not defined: |
| 129 | |
| 130 | .. math:: |
| 131 | |
| 132 | \varepsilon = \varepsilon_0 \varepsilon_r |
| 133 | |
| 134 | otherwise, |
| 135 | |
| 136 | .. math:: |
| 137 | |
| 138 | \varepsilon = \varepsilon_0 \Re[\varepsilon_r] (1 - j\tan\delta_e) |
| 139 | |
| 140 | where :math:`\tan\delta_e` is the electric loss tangent. |
| 141 | |
| 142 | Returns |
| 143 | ------- |
| 144 | ep : number or array-like |
| 145 | Complex dielectric permittivity in F/m. |
| 146 | |
| 147 | """ |
| 148 | |
| 149 | if self.ep_loss_tan is not None: |
| 150 | ep_r = real(self.ep_r)*(1 - 1j*self.ep_loss_tan) |
| 151 | else: |
| 152 | ep_r = self.ep_r |
| 153 | return ep_r*epsilon_0 |
| 154 | |
| 155 | @property |
| 156 | def mu(self) -> NumberLike: |
| 157 | r""" |
| 158 | Complex dielectric permeability. |
| 159 | |
| 160 | If :math:`\tan\delta_m` is not defined: |
| 161 | |
| 162 | .. math:: |
| 163 | |
| 164 | \mu = \mu_0 \mu_r |
| 165 | |
| 166 | otherwise, |
| 167 | |
| 168 | .. math:: |
| 169 | |
| 170 | \mu = \mu_0 \Re[\mu_r] (1 - j\tan\delta_m) |
| 171 | |
| 172 | where :math:`\tan\delta_m` is the magnetic loss tangent. |
| 173 | |
| 174 | Returns |
| 175 | ------- |
| 176 | mu : number |
| 177 | Complex permeability in H/m. |
| 178 | """ |
| 179 | if self.mu_loss_tan is not None: |
| 180 | mu_r = real(self.mu_r)*(1 -1j*self.mu_loss_tan) |
| 181 | else: |
| 182 | mu_r = self.mu_r |
| 183 | return mu_r*mu_0 |
| 184 | |
| 185 | |
| 186 | @classmethod |
| 187 | def from_distributed_circuit(cls, dc, *args, **kwargs) -> Media: |
| 188 | r""" |
| 189 | Initialize a freespace from :class:`~skrf.media.distributedCircuit.DistributedCircuit`. |
| 190 | |
| 191 | Parameters |
| 192 | ---------- |
| 193 | dc: :class:`~skrf.media.distributedCircuit.DistributedCircuit` |
| 194 | a DistributedCircuit object |
| 195 | \*args, \*\*kwargs : |
| 196 | passed to `Freespace.__init__ |
| 197 | |
| 198 | Notes |
| 199 | ----- |
| 200 | Here are the details:: |
| 201 | |
| 202 | w = dc.frequency.w |
| 203 | z= dc.Z/(w*mu_0) |
| 204 | y= dc.Y/(w*epsilon_0) |
| 205 | ep_r = -1j*y |
| 206 | mu_r = -1j*z |
| 207 | |
| 208 | See Also |
| 209 | -------- |
| 210 | skrf.media.distributedCircuit.DistributedCircuit |
| 211 | |
| 212 | """ |
| 213 | w = dc.frequency.w |
| 214 | z= dc.Z/(w*mu_0) |
| 215 | y= dc.Y/(w*epsilon_0) |
| 216 | |
| 217 | |
| 218 | kw={} |
| 219 | kw['ep_r'] = -1j*y |
| 220 | kw['mu_r'] = -1j*z |
| 221 | |
| 222 | kwargs.update(kw) |
| 223 | return cls(frequency=dc.frequency, **kwargs) |
| 224 | |
| 225 | @property |
| 226 | def rho(self) -> NumberLike: |
| 227 | """ |
| 228 | Conductivity in ohm*m. |
| 229 | |
| 230 | Parameters |
| 231 | ---------- |
| 232 | val : float, array-like or str |
| 233 | the resistivity in ohm*m. If array-like must be same length |
| 234 | as self.frequency. if str, it must be a key in |
| 235 | :data:`~skrf.data.materials`. |
| 236 | |
| 237 | Examples |
| 238 | -------- |
| 239 | >>> wg.rho = 2.8e-8 |
| 240 | >>> wg.rho = 2.8e-8 * ones(len(wg.frequency)) |
| 241 | >>> wg.rho = 'al' |
| 242 | >>> wg.rho = 'aluminum' |
| 243 | """ |
| 244 | return self._rho |
| 245 | |
| 246 | @rho.setter |
| 247 | def rho(self, val): |
| 248 | if isinstance(val, str): |
| 249 | self._rho = materials[val.lower()]['resistivity(ohm*m)'] |
| 250 | else: |
| 251 | self._rho=val |
| 252 | |
| 253 | @property |
| 254 | def ep_with_rho(self) -> NumberLike: |
| 255 | r""" |
| 256 | Complex permittivity with resistivity absorbed into its imaginary component. |
| 257 | |
| 258 | .. math:: |
| 259 | |
| 260 | \varepsilon - j \frac{1}{\rho\omega} |
| 261 | |
| 262 | See Also |
| 263 | -------- |
| 264 | rho |
| 265 | ep |
| 266 | """ |
| 267 | if self.rho is not None: |
| 268 | return self.ep -1j/(self.rho*self.frequency.w) |
| 269 | else: |
| 270 | return self.ep |
| 271 | |
| 272 | @property |
| 273 | def gamma(self) -> NumberLike: |
| 274 | r""" |
| 275 | Propagation Constant, :math:`\gamma`. |
| 276 | |
| 277 | Defined as, |
| 278 | |
| 279 | .. math:: |
| 280 | |
| 281 | \gamma = \sqrt{ Z^{'} Y^{'}} |
| 282 | |
| 283 | Returns |
| 284 | ------- |
| 285 | gamma : np.ndarray |
| 286 | Propagation Constant, |
| 287 | |
| 288 | Note |
| 289 | ---- |
| 290 | The components of propagation constant are interpreted as follows: |
| 291 | |
| 292 | * positive real(gamma) = attenuation |
| 293 | * positive imag(gamma) = forward propagation |
| 294 | """ |
| 295 | ep = self.ep_with_rho |
| 296 | return 1j*self.frequency.w * sqrt(ep*self.mu) |
| 297 | |
| 298 | @property |
| 299 | def z0_characteristic(self) -> NumberLike: |
| 300 | r""" |
| 301 | Characteristic Impedance, :math:`z_0`. |
| 302 | |
| 303 | .. math:: |
| 304 | |
| 305 | Z_0 = \sqrt{ \frac{Z^{'}}{Y^{'}}} |
| 306 | |
| 307 | Returns |
| 308 | ------- |
| 309 | z0_characteristic : np.ndarray |
| 310 | Characteristic Impedance in units of ohms |
| 311 | """ |
| 312 | ep = self.ep_with_rho |
| 313 | return sqrt(self.mu/ep)*ones(len(self)) |
| 314 | |
| 315 | def plot_ep(self): |
| 316 | """ |
| 317 | Plot the real and imaginary part of the complex permittivity. |
| 318 | """ |
| 319 | self.plot(self.ep_r.real, label=r'ep_r real') |
| 320 | self.plot(self.ep_r.imag, label=r'ep_r imag') |
| 321 | |
| 322 | def plot_mu(self): |
| 323 | """ |
| 324 | Plot the real and imaginary part of the complex permeability. |
| 325 | """ |
| 326 | self.plot(self.mu_r.real, label=r'mu_r real') |
| 327 | self.plot(self.mu_r.imag, label=r'mu_r imag') |
| 328 | |
| 329 | def plot_ep_mu(self): |
| 330 | """ |
| 331 | Plot the real and imaginary part of the complex permittivity with resistivity. |
| 332 | """ |
| 333 | self.plot_ep() |
| 334 | self.plot_mu() |