API¶
pastax.simulator
¶
This module provides base pastax.simulator.BaseSimulator classes for pastax.trajectory.Trajectory
and pastax.trajectory.TrajectoryEnsemble simulation in JAX.
BaseSimulator
¶
Bases: Module
Base class for defining differentiable pastax.trajectory.Trajectory or
pastax.trajectory.TrajectoryEnsemble simulators.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str | None
|
The identifier for the simulator. |
Methods:
| Name | Description |
|---|---|
__call__ |
Simulates a |
Source code in pastax/simulator/_base_simulator.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
__call__(dynamics: Callable[[Real[Any, ''], PyTree, PyTree], PyTree], args: PyTree, x0: Location, ts: Real[Array, time], n_samples: Int[Any, ''] | None, key: Key[Array, ''] | None, solver: Callable, dt0: Real[Any, '']) -> Trajectory | TrajectoryEnsemble
¶
Simulates a pastax.trajectory.Trajectory or pastax.trajectory.TrajectoryEnsemble
following the prescribe drift dynamics and physical field(s) args,
from the initial pastax.trajectory.Location x0 at time steps (including t0) ts,
using a given solver.
This method must be implemented by its subclasses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dynamics
|
Callable[[Real[Any, ''], PyTree, PyTree], PyTree]
|
A Callable (including an Example Formulating the displacement at time \(t\) from the position \(\mathbf{X}(t)\) as: \[
d\mathbf{X}(t) = f(t, \mathbf{X}(t), \text{args}) dt
\]
|
required |
args
|
PyTree
|
The PyTree of argument(s) required to compute the |
required |
x0
|
Location
|
The initial |
required |
ts
|
Real[Any, time]
|
The time steps for the simulation outputs, including \(t_0\), unit should be the same as for |
required |
solver
|
Callable
|
The solver to use for the simulation. |
required |
dt0
|
Real[Any, '']
|
The initial time step of the solver, unit should be the same as for |
required |
Returns:
| Type | Description |
|---|---|
Trajectory | TrajectoryEnsemble
|
The simulated |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the method is not implemented by the subclass. |
Source code in pastax/simulator/_base_simulator.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
DiffraxSimulator
¶
Bases: BaseSimulator
Base class for defining differentiable pastax.trajectory.Trajectory or
pastax.trajectory.TrajectoryEnsemble simulators using diffrax library.
Methods:
| Name | Description |
|---|---|
get_diffeqsolve_best_args |
Returns optimal argument values for the |
__call__ |
Simulates a |
Source code in pastax/simulator/_diffrax_simulator.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
get_diffeqsolve_best_args(ts: Real[Any, 'time'], dt0: Real[Any, ''], n_steps: Int[Any, ''] = None, constant_step_size: bool = True, save_at_steps: bool = False, ad_mode: Literal['forward', 'reverse'] = 'forward') -> tuple[Real[Any, ''], dfx.SaveAt, dfx.AbstractStepSizeController, dfx.AbstractAdjoint, Int[Any, ''], Callable[[tuple[int, ...], Key[Array, '']], dfx.AbstractBrownianPath]]
classmethod
¶
Returns optimal argument values for the diffrax.diffeqsolve function.
Significant speedups can be achieved by carefully selecting the arguments passed to diffrax.diffeqsolve,
which is then called internally by the __call__ method.
This method applies general heuristics to determine optimal argument values based on a high-level description
of the problem, derived from its own input arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ts
|
Real[Any, 'time']
|
The time steps for the simulation outputs, including \(t_0\), unit should be the same as for |
required |
dt0
|
Real[Any, '']
|
The initial time step of the solver, unit should be the same as for |
required |
n_steps
|
Int[Any, '']
|
The number of steps to be taken, defaults to |
None
|
constant_step_size
|
bool
|
Whether a constant step size is used, defaults to |
True
|
save_at_steps
|
bool
|
Whether the solution is to be saved at each integration step, defaults to |
False
|
ad_mode
|
Literal['forward', 'reverse']
|
The mode for automatic differentiation, defaults to "forward". |
'forward'
|
Source code in pastax/simulator/_diffrax_simulator.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
__call__(dynamics: Callable[[Real[Any, ''], PyTree, PyTree], PyTree], args: PyTree, x0: Location, ts: Real[Any, 'time'], solver: dfx.AbstractSolver = dfx.Heun(), dt0: Real[Any, ''] = None, saveat: dfx.SaveAt | None = None, stepsize_controller: dfx.AbstractStepSizeController = dfx.ConstantStepSize(), adjoint: dfx.AbstractAdjoint = dfx.ForwardMode(), max_steps: Int[Any, ''] = 4096, throw: bool = False) -> Trajectory | TrajectoryEnsemble
¶
Simulates a pastax.trajectory.Trajectory or pastax.trajectory.TrajectoryEnsemble
following the prescribe drift dynamics and physical field(s) args,
from the initial pastax.trajectory.Location x0 at time steps (including t0) ts,
using given diffrax.AbstractSolver, diffrax.SaveAt, diffrax.AbstractStepSizeController and
diffrax.AbstractAdjoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dynamics
|
Callable[[Real[Any, ''], PyTree, PyTree], PyTree]
|
A Callable (including an Example Formulating the displacement at time \(t\) from the position \(\mathbf{X}(t)\) as: \[
d\mathbf{X}(t) = f(t, \mathbf{X}(t), \text{args}) dt
\]
Parameters¶t : Real[Array, ""]
The current time.
y : Float[Array, "2"]
The current state (latitude and longitude in degrees).
args : PyTree
Any PyTree of argument(s) used by the simulator.
Could be for example one or several Returns¶PyTree The drift dynamics. |
required |
args
|
PyTree
|
The PyTree of argument(s) required to compute the |
required |
x0
|
Location
|
The initial |
required |
ts
|
Real[Any, 'time']
|
The time steps for the simulation outputs, including \(t_0\), unit should be the same as for |
required |
solver
|
AbstractSolver
|
The |
Heun()
|
dt0
|
Real[Any, '']
|
The initial time step of the solver, unit should be the same as for |
None
|
saveat
|
SaveAt
|
The |
None
|
stepsize_controller
|
AbstractStepSizeController
|
The |
ConstantStepSize()
|
adjoint
|
AbstractAdjoint
|
The |
ForwardMode()
|
max_steps
|
Int[Any, '']
|
The maximum number of steps to take, defaults to |
4096
|
throw
|
bool
|
Whether to raise an exception if the integration fails, defaults to |
False
|
Returns:
| Type | Description |
|---|---|
Trajectory | TrajectoryEnsemble
|
The simulated |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the method is not implemented by the subclass. |
Source code in pastax/simulator/_diffrax_simulator.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
DeterministicSimulator
¶
Bases: DiffraxSimulator
Class defining deterministic differentiable pastax.trajectory.Trajectory simulators.
Methods:
| Name | Description |
|---|---|
__call__ |
Simulates a |
Source code in pastax/simulator/_diffrax_simulator.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
__call__(dynamics: Callable[[Real[Any, ''], PyTree, PyTree], PyTree], args: PyTree, x0: Location, ts: Real[Any, 'time'], solver: dfx.AbstractSolver = dfx.Heun(), dt0: Real[Any, ''] = None, saveat: dfx.SaveAt | None = None, stepsize_controller: dfx.AbstractStepSizeController = dfx.ConstantStepSize(), adjoint: dfx.AbstractAdjoint = dfx.ForwardMode(), max_steps: Int[Any, ''] = 4096, throw: bool = True) -> Trajectory
¶
Simulates a pastax.trajectory.Trajectory following the prescribe drift dynamics
and physical field(s) args, from the initial pastax.trajectory.Location x0
at time steps (including t0) ts, using given diffrax.AbstractSolver, diffrax.SaveAt,
diffrax.AbstractStepSizeController and diffrax.AbstractAdjoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dynamics
|
Callable[[Real[Any, ''], PyTree, PyTree], PyTree]
|
A Callable (including an Example Formulating the displacement at time \(t\) from the position \(\mathbf{X}(t)\) as: \[
d\mathbf{X}(t) = f(t, \mathbf{X}(t), \text{args}) dt
\]
Parameters¶t : Real[Any, ""]
The current time.
y : PyTree
The current state (latitude and longitude in degrees).
args : PyTree
The PyTree of argument(s) required to compute the Returns¶PyTree The drift dynamics. |
required |
args
|
PyTree
|
The PyTree of argument(s) required to compute the |
required |
x0
|
Location
|
The initial |
required |
ts
|
Real[Any, 'time']
|
The time steps for the simulation outputs, including \(t_0\), unit should be the same as for |
required |
solver
|
AbstractSolver
|
The |
Heun()
|
dt0
|
Real[Any, '']
|
The initial time step of the solver, unit should be the same as for |
None
|
saveat
|
SaveAt
|
The |
None
|
stepsize_controller
|
AbstractStepSizeController
|
The |
ConstantStepSize()
|
adjoint
|
AbstractAdjoint
|
The |
ForwardMode()
|
max_steps
|
Int[Any, '']
|
The maximum number of steps to take, defaults to |
4096
|
throw
|
bool
|
Whether to raise an exception if the integration fails, defaults to |
True
|
Returns:
| Type | Description |
|---|---|
Trajectory
|
The simulated |
Source code in pastax/simulator/_diffrax_simulator.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
StochasticSimulator
¶
Bases: DiffraxSimulator
Class defining stochastic differentiable pastax.trajectory.TrajectoryEnsemble simulators.
Methods:
| Name | Description |
|---|---|
__call__ |
Simulates a |
Source code in pastax/simulator/_diffrax_simulator.py
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
__call__(dynamics: Callable[[Real[Any, ''], PyTree, PyTree], PyTree], args: PyTree, x0: Location, ts: Real[Any, 'time'], solver: dfx.AbstractSolver = dfx.Heun(), dt0: Real[Any, ''] = None, saveat: dfx.SaveAt | None = None, stepsize_controller: dfx.AbstractStepSizeController = dfx.ConstantStepSize(), adjoint: dfx.AbstractAdjoint = dfx.ForwardMode(), max_steps: Int[Any, ''] = 4096, n_samples: Int[Any, ''] = 100, key: Key[Array, ''] = jrd.key(0), brownian_motion: Callable[[tuple[int, ...], Key[Array, '']], dfx.AbstractBrownianPath] | None = None, throw: bool = True) -> TrajectoryEnsemble
¶
Simulates a pastax.trajectory.TrajectoryEnsemble of n_samples pastax.trajectory.Trajectory
following the prescribe drift dynamics and physical field(s) args,
from the initial pastax.trajectory.Location x0 at time steps (including t0) ts,
using given diffrax.AbstractSolver, diffrax.SaveAt, diffrax.AbstractStepSizeController,
diffrax.AbstractAdjoint and diffrax.AbstractBrownianPath.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dynamics
|
Callable[[Real[Any, ''], PyTree, PyTree], PyTree]
|
A Callable (including an Example Formulating a displacement at time \(t\) from the position \(\mathbf{X}(t)\) as: \[
d\mathbf{X}(t) = f(t, \mathbf{X}(t), \text{args}) \cdot [dt, d\mathbf{W}(t)]
\]
Parameters¶t : Real[Any, ""]
The current time.
y : PyTree
The current state (latitude and longitude in degrees).
args : PyTree
The PyTree of argument(s) required to compute the Returns¶PyTree The drift dynamics. |
required |
args
|
PyTree
|
The PyTree of argument(s) required to compute the |
required |
x0
|
Location
|
The initial |
required |
ts
|
Real[Any, 'time']
|
The time steps for the simulation outputs, including \(t_0\), unit should be the same as for |
required |
solver
|
AbstractSolver
|
The |
Heun()
|
dt0
|
Real[Any, '']
|
The initial time step of the solver, unit should be the same as for |
None
|
saveat
|
SaveAt
|
The |
None
|
stepsize_controller
|
AbstractStepSizeController
|
The |
ConstantStepSize()
|
adjoint
|
AbstractAdjoint
|
The |
ForwardMode()
|
max_steps
|
Int[Any, '']
|
The maximum number of steps to take, defaults to |
4096
|
n_samples
|
Int[Any, '']
|
The number of samples to generate, defaults to |
100
|
key
|
Key[Array, '']
|
The random key for sampling, defaults to |
key(0)
|
brownian_motion
|
Callable[[tuple[int, ...], Key[Array, '']], AbstractBrownianPath] | None
|
A Callable returning the Parameters¶shape : tuple[int, ...] The shape of the Brownian motion. key : Key[Array, ""] The random key for sampling. Returns¶dfx.AbstractBrownianPath
The |
None
|
throw
|
bool
|
Whether to raise an exception if the integration fails, defaults to |
True
|
Returns:
| Type | Description |
|---|---|
TrajectoryEnsemble
|
The simulated |
Source code in pastax/simulator/_diffrax_simulator.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
pastax.dynamics
¶
This module provides dynamics examples to be used with pastax.simulator.BaseSimulator.
LinearUV
¶
Bases: Module
Trainable linear transformation of the Lagrangian drift velocity computed by interpolating in space and time the velocity fields.
Attributes:
| Name | Type | Description |
|---|---|---|
intercept |
(Float[Array, ''] | Float[Array, '2'], optional)
|
The intercept of the linear relation, defaults to |
slope |
(Float[Array, ''] | Float[Array, '2'], optional)
|
The slope of the linear relation, defaults to |
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the Lagrangian drift velocity. |
Notes
As the class inherits from equinox.Module, its intercept and slope attributes can be treated as
trainable parameters.
Source code in pastax/dynamics/_linear_uv.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
__call__(t: Real[Array, ''], y: Float[Array, '2'], args: Gridded) -> Float[Array, '2']
¶
Computes the Lagrangian drift velocity as the linear relation intercept + slope * [v, u].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
Real[Array, '']
|
The current time. |
required |
y
|
Float[Array, '2']
|
The current state (latitude and longitude in degrees). |
required |
args
|
Dataset
|
The |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '2']
|
The Lagrangian drift velocity. |
Source code in pastax/dynamics/_linear_uv.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
SmagorinskyDiffusion
¶
Bases: Module
Trainable Smagorinsky diffusion dynamics.
Formulation
This dynamics allows to formulate a displacement at time \(t\) from the position \(\mathbf{X}(t)\) as:
where \(V = \sqrt{2 K}\) and \(K\) is the Smagorinsky diffusion:
where \(C_s\) is the trainable Smagorinsky constant, \(\Delta x \Delta y\) a spatial scaling factor, and the rest of the expression represents the horizontal diffusion.
Methods:
| Name | Description |
|---|---|
cs |
Returns the Smagorinsky constant. |
_neighborhood |
Restricts the |
_smagorinsky_coefficients |
Computes the Smagorinsky diffusion: \[
K = C_s \Delta x \Delta y \sqrt{\left(\frac{\partial u}{\partial x} \right)^2 +
\left(\frac{\partial v}{\partial y} \right)^2 + \frac{1}{2} \left(\frac{\partial u}{\partial y} +
\frac{\partial v}{\partial x} \right)^2}
\]
where \(C_s\) is the trainable Smagorinsky constant, \(\Delta x \Delta y\) a spatial scaling factor, and the rest of the expression represents the horizontal diffusion. |
_deterministic_dynamics |
Computes the deterministic part of the dynamics: \((\mathbf{u} + \nabla K)(t, \mathbf{X}(t))\). |
_stochastic_dynamics |
Computes the stochastic part of the dynamics: \(V(t, \mathbf{X}(t)) = \sqrt{2 K(t, \mathbf{X}(t))}\). |
Notes
As the class inherits from equinox.Module, its cs attribute can be treated as a trainable parameter.
Source code in pastax/dynamics/_smagorinsky_diffusion.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
cs: Float[Array, '']
property
¶
Returns the Smagorinsky constant.
StochasticSmagorinskyDiffusion
¶
Bases: SmagorinskyDiffusion
Trainable stochastic Smagorinsky diffusion dynamics.
Formulation
This dynamics allows to formulate a displacement at time \(t\) from the position \(\mathbf{X}(t)\) as:
where \(V = \sqrt{2 K}\) and \(K\) is the Smagorinsky diffusion:
where \(C_s\) is the trainable Smagorinsky constant, \(\Delta x \Delta y\) a spatial scaling factor, and the rest of the expression represents the horizontal diffusion.
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the deterministic and stochastic terms of the dynamics and returns them as lineax.PyTreeLinearOperator. |
Source code in pastax/dynamics/_smagorinsky_diffusion.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
__call__(t: Real[Array, ''], y: Float[Array, '2'], args: Gridded) -> lx.PyTreeLinearOperator
¶
Computes the deterministic and stochastic terms of the dynamics and returns them as lineax.PyTreeLinearOperator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
Real[Array, '']
|
The current time. |
required |
y
|
Float[Array, '2']
|
The current state (latitude and longitude). |
required |
args
|
Gridded
|
The |
required |
Returns:
| Type | Description |
|---|---|
PyTreeLinearOperator
|
The stacked deterministic and stochastic parts of the dynamics. |
Source code in pastax/dynamics/_smagorinsky_diffusion.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
from_cs(cs: Real[Any, ''] = 0.1)
classmethod
¶
Initializes the stochastic Smagorinsky diffusion with the given Smagorinsky constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cs
|
Real[Any, '']
|
The Smagorinsky constant, defaults to |
0.1
|
Returns:
| Type | Description |
|---|---|
StochasticSmagorinskyDiffusion
|
The |
Source code in pastax/dynamics/_smagorinsky_diffusion.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
DeterministicSmagorinskyDiffusion
¶
Bases: SmagorinskyDiffusion
Trainable deterministic Smagorinsky diffusion dynamics.
Formulation
This dynamics allows to formulate a displacement at time \(t\) from the position \(\mathbf{X}(t)\) as:
where \(V = \sqrt{2 K}\) and \(K\) is the Smagorinsky diffusion:
where \(C_s\) is the trainable Smagorinsky constant, \(\Delta x \Delta y\) a spatial scaling factor, and the rest of the expression represents the horizontal diffusion.
Methods:
| Name | Description |
|---|---|
__call__ |
Computes the deterministic term of the dynamics. |
Source code in pastax/dynamics/_smagorinsky_diffusion.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
__call__(t: Real[Array, ''], y: Float[Array, '2'], args: Gridded) -> Float[Array, '2']
¶
Computes the deterministic term of the dynamics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
Real[Array, '']
|
The current time. |
required |
y
|
Float[Array, '2']
|
The current state (latitude and longitude). |
required |
args
|
Gridded
|
The |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '2 3']
|
The deterministic part of the dynamics. |
Source code in pastax/dynamics/_smagorinsky_diffusion.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
from_cs(cs: Real[Any, ''] = 0.1)
classmethod
¶
Initializes the deterministic Smagorinsky diffusion with the given Smagorinsky constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cs
|
Real[Any, '']
|
The Smagorinsky constant, defaults to |
0.1
|
Returns:
| Type | Description |
|---|---|
DeterministicSmagorinskyDiffusion
|
The |
Source code in pastax/dynamics/_smagorinsky_diffusion.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
linear_uv(t: Real[Array, ''], y: Float[Array, '2'], args: Gridded) -> Float[Array, '2']
¶
Computes the Lagrangian drift velocity by interpolating in space and time the velocity fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
Real[Array, '']
|
The current time. |
required |
y
|
Float[Array, '2']
|
The current state (latitude and longitude in degrees). |
required |
args
|
Dataset
|
The |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '2']
|
The Lagrangian drift velocity. |
Source code in pastax/dynamics/_linear_uv.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
pastax.trajectory
¶
This module provides classes for handling pastax.trajectory.State, pastax.trajectory.Timeseries,
pastax.trajectory.Trajectory,
and pastax.trajectory.TrajectoryEnsemble in JAX.
State
¶
Bases: Unitful
Class representing a pastax.trajectory.State with a value, unit, and name.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
(str | None, optional)
|
The name of the state, defaults to |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the |
attach_name |
Attaches a name to the [ |
Source code in pastax/trajectory/_state.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
__init__(value: Real[Array, '...'], unit: dict[Unit, int | float] = {}, name: str | None = None)
¶
Initializes the pastax.trajectory.State with given value, unit and name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Real[Array, '...']
|
The value of the state. |
required |
unit
|
dict[Unit, int | float]
|
The unit of the state, defaults to an empty |
{}
|
name
|
str | None
|
The type of the state, defaults to |
None
|
Source code in pastax/trajectory/_state.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
attach_name(name: str) -> State
¶
Attaches a name to the [pastax.trajectory.State].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name to attach to the state. |
required |
Returns:
| Type | Description |
|---|---|
State
|
A new |
Source code in pastax/trajectory/_state.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
Location
¶
Bases: State
Class representing a geographical location with latitude and longitude.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the |
latitude |
Returns the latitude of the |
longitude |
Returns the longitude of the |
distance_on_earth |
Computes the Earth distance between this |
Source code in pastax/trajectory/_states.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
latitude: State
property
¶
Returns the latitude of the pastax.trajectory.Location.
Returns:
| Type | Description |
|---|---|
State
|
The latitude of the |
longitude: State
property
¶
Returns the longitude of the pastax.trajectory.Location.
Returns:
| Type | Description |
|---|---|
State
|
The longitude of the |
__init__(value: Float[Any, '... 2'], unit: dict[Unit, int | float] = unit_converter(UNIT['°']), **_)
¶
Initializes the pastax.trajectory.Location with given latitude and longitude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Float[Array, '... 2'] | Sequence[float]
|
The latitude and longitude of the location. |
required |
unit
|
dict[str, Unit]
|
The |
unit_converter(UNIT['°'])
|
Source code in pastax/trajectory/_states.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
distance_on_earth(other: Location) -> State
¶
Computes the distance in meters between this pastax.trajectory.Location
and another pastax.trajectory.Location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Location
|
The other |
required |
Returns:
| Type | Description |
|---|---|
State
|
The Earth distance in meters between the two |
Notes
This function uses the Haversine formula to compute the distance between two points on the Earth surface.
Source code in pastax/trajectory/_states.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
Displacement
¶
Bases: State
Class representing a pastax.trajectory.Displacement with latitude and longitude components.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the [ |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the |
latitude |
Returns the latitude component of the [ |
longitude |
Returns the longitude component of the [ |
Source code in pastax/trajectory/_states.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
latitude: State
property
¶
Returns the latitude component of the [pastax.trajectory.Displacement].
Returns:
| Type | Description |
|---|---|
State
|
The latitude component of the [ |
longitude: State
property
¶
Returns the longitude component of the [pastax.trajectory.Displacement].
Returns:
| Type | Description |
|---|---|
State
|
The longitude component of the [ |
__init__(value: Real[Any, '... 2'], unit: dict[Unit, int | float] = UNIT['°'], **_)
¶
Initializes the pastax.trajectory.Displacement with given latitude and longitude components and
pastax.utils.Unit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Real[Any, '2']
|
The latitude and longitude components of the [ |
required |
unit
|
dict[str, Unit]
|
The |
UNIT['°']
|
Source code in pastax/trajectory/_states.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
Time
¶
Bases: State
Class representing a pastax.trajectory.Time value.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the [ |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the |
to_datetime |
Converts the |
Source code in pastax/trajectory/_states.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
__init__(value: Real[Any, '...'], unit: dict[Unit, int | float] = UNIT['s'], **_)
¶
Initializes the pastax.trajectory.Time with given time value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Real[Any, '...']
|
The time value. |
required |
unit
|
dict[Unit, int | float]
|
The |
UNIT['s']
|
Source code in pastax/trajectory/_states.py
196 197 198 199 200 201 202 203 204 205 206 207 | |
to_datetime() -> np.ndarray
¶
Converts the pastax.trajectory.Time to a numpy.ndarray of datetime64[s].
Returns:
| Type | Description |
|---|---|
ndarray
|
The |
Source code in pastax/trajectory/_states.py
209 210 211 212 213 214 215 216 217 218 | |
Timeseries
¶
Bases: Unitful
Class representing a [pastax.trajectory.Timeseries].
Attributes:
| Name | Type | Description |
|---|---|---|
states |
State
|
The |
times |
Time
|
The |
length |
int
|
The length of the [ |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the |
value |
Returns the value of the [ |
unit |
Returns the unit of the [ |
name |
Returns the name of the [ |
attach_name |
Attaches a name to the [ |
euclidean_distance |
Computes the Euclidean distance between this |
map |
Applies a function to each |
to_xarray |
Converts the |
from_array |
Creates a |
Source code in pastax/trajectory/_timeseries.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
value: Float[Array, '... time state']
property
¶
Returns the value of the [pastax.trajectory.Timeseries].
Returns:
| Type | Description |
|---|---|
Float[Array, '... time state']
|
The value of the [ |
unit: dict[Unit, int | float]
property
¶
Returns the unit of the [pastax.trajectory.Timeseries].
Returns:
| Type | Description |
|---|---|
dict[Unit, int | float]
|
The unit of the [ |
name: str | None
property
¶
Returns the name of the [pastax.trajectory.Timeseries].
Returns:
| Type | Description |
|---|---|
str | None
|
The name of the [ |
__init__(states: State, times: Time, **_: Any)
¶
Initializes the pastax.trajectory.Timeseries with given pastax.trajectory.State,
pastax.trajectory.Time, and optional parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
states
|
Float[Array, '... time state']
|
The states of the [ |
required |
times
|
Float[Array, 'time']
|
The time points for the [ |
required |
Source code in pastax/trajectory/_timeseries.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
attach_name(name: str) -> Timeseries
¶
Attaches a name to the [pastax.trajectory.Timeseries].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name to attach to the [ |
required |
Returns:
| Type | Description |
|---|---|
Timeseries
|
A new |
Source code in pastax/trajectory/_timeseries.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
euclidean_distance(other: Timeseries | Array) -> Timeseries
¶
Computes the Euclidean distance between this timeseries and another timeseries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Timeseries | Array
|
The other |
required |
Returns:
| Type | Description |
|---|---|
Timeseries
|
The Euclidean distance between the two [ |
Source code in pastax/trajectory/_timeseries.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
map(func: Callable[[State], Unitful | Array]) -> Timeseries
¶
Applies a function to each pastax.trajectory.State in the [pastax.trajectory.Timeseries].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[State], Unitful | Array]
|
The function to apply to each |
required |
Returns:
| Type | Description |
|---|---|
Timeseries
|
The result of applying the function to each |
Source code in pastax/trajectory/_timeseries.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
to_xarray() -> xr.Dataset
¶
Converts the pastax.trajectory.Timeseries to a xarray.Dataset.
Returns:
| Type | Description |
|---|---|
Dataset
|
The corresponding |
Source code in pastax/trajectory/_timeseries.py
176 177 178 179 180 181 182 183 184 185 186 187 188 | |
from_array(values: Float[Array, 'time state'], times: Float[Array, 'time'], unit: dict[Unit, int | float] = {}, name: str | None = None, **kwargs: Any) -> Timeseries
classmethod
¶
Creates a pastax.trajectory.Timeseries from arrays of values and time points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Float[Array, 'time state']
|
The array of values for the timeseries. |
required |
times
|
Float[Array, 'time']
|
The time points for the timeseries. |
required |
unit
|
dict[Unit, int | float]
|
The unit of the timeseries, defaults to an empty dict. |
{}
|
name
|
str | None
|
The name of the timeseries, defaults to None. |
None
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
Timeseries
|
The corresponding |
Source code in pastax/trajectory/_timeseries.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
Trajectory
¶
Bases: Timeseries
Class representing a trajectory with 2D geographical locations over time.
Attributes:
| Name | Type | Description |
|---|---|---|
states |
Location
|
The locations of the trajectory. |
id |
(Int[Array, ''] | None, optional)
|
The ID of the trajectory, defaults to |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the |
latitudes |
Returns the latitudes of the trajectory. |
locations |
Returns the locations of the trajectory. |
longitudes |
Returns the longitudes of the trajectory. |
origin |
Returns the origin of the trajectory. |
lengths |
Returns the cumulative lengths of the trajectory. |
liu_index |
Computes the Liu Index between this trajectory and another trajectory. |
mae |
Computes the Mean Absolute Error (MAE) between this trajectory and another trajectory. |
plot |
Plots the trajectory. |
rmse |
Computes the Root Mean Square Error (RMSE) between this trajectory and another trajectory. |
separation_distance |
Computes the separation distance between this trajectory and another trajectory. |
steps |
Returns the steps of the trajectory. |
to_xarray |
Converts the |
from_array |
Creates a |
from_xarray |
Creates a |
Source code in pastax/trajectory/_trajectory.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
latitudes: State
property
¶
Returns the latitudes of the trajectory.
Returns:
| Type | Description |
|---|---|
State
|
The latitudes of the trajectory. |
locations: Location
property
¶
Returns the locations of the trajectory.
Returns:
| Type | Description |
|---|---|
Location
|
The locations of the trajectory. |
longitudes: State
property
¶
Returns the longitudes of the trajectory.
Returns:
| Type | Description |
|---|---|
State
|
The longitudes of the trajectory. |
origin: Location
property
¶
__init__(locations: Location, times: Time, id: Int[Array, ''] | None = None, *_, **__)
¶
Initializes the Trajectory with given locations, times, and optional trajectory ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
locations
|
Float[Array, '... time 2']
|
The locations for the trajectory. |
required |
times
|
Int[Array, '... time']
|
The time points for the trajectory. |
required |
id
|
Int[Array, ''] | None
|
The ID of the trajectory, defaults to None. |
None
|
Source code in pastax/trajectory/_trajectory.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
lengths() -> Timeseries
¶
Returns the cumulative lengths of the trajectory.
Returns:
| Type | Description |
|---|---|
Timeseries
|
The cumulative lengths of the trajectory. |
Source code in pastax/trajectory/_trajectory.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
liu_index(other: Trajectory) -> Timeseries
¶
Computes the Liu Index (over time) between this trajectory and another trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Trajectory
|
The other trajectory to compare against. |
required |
Returns:
| Type | Description |
|---|---|
Timeseries
|
The Liu Index between the two trajectories. |
Source code in pastax/trajectory/_trajectory.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
mae(other: Trajectory) -> Timeseries
¶
Computes the Mean Absolute Error (MAE) (over time) between this trajectory and another trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Trajectory
|
The other trajectory to compare against. |
required |
Returns:
| Type | Description |
|---|---|
Timeseries
|
The MAE between the two trajectories. |
Source code in pastax/trajectory/_trajectory.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
plot(ax: Axes | None = None, label: str | None = None, color: str | None = None, alpha_factor: float = 1, ti: int | None = None, **kwargs) -> Axes
¶
Plots the trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes | None
|
The matplotlib axis to plot on, defaults to |
None
|
label
|
str | None
|
The label for the plot, defaults to |
None
|
color
|
str | None
|
The color for the plot, defaults to |
None
|
alpha_factor
|
float
|
A factor controlling the overall transparency of the plotted trajectory, defaults to |
1
|
ti
|
int | None
|
The time index to plot up to, defaults to |
None
|
kwargs
|
Additional arguments passed to |
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
The matplotlib axis with the plot. |
Source code in pastax/trajectory/_trajectory.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
rmse(other: Trajectory) -> Timeseries
¶
Computes the Root Mean Square Error (RMSE) (over time) between this trajectory and another trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Trajectory
|
The other trajectory to compare against. |
required |
Returns:
| Type | Description |
|---|---|
Timeseries
|
The RMSE between the two trajectories. |
Source code in pastax/trajectory/_trajectory.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
separation_distance(other: Trajectory) -> Timeseries
¶
Computes the separation distance (over time) between this trajectory and another trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Trajectory
|
The other trajectory to compare against. |
required |
Returns:
| Type | Description |
|---|---|
Timeseries
|
The separation distance between the two trajectories. |
Source code in pastax/trajectory/_trajectory.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
steps() -> Timeseries
¶
Returns the steps of the trajectory.
Returns:
| Type | Description |
|---|---|
Timeseries
|
The steps of the trajectory. |
Source code in pastax/trajectory/_trajectory.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
velocities() -> Timeseries
¶
Returns the velocities of the trajectory.
Returns:
| Type | Description |
|---|---|
Timeseries
|
The velocities of the trajectory. |
Source code in pastax/trajectory/_trajectory.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
to_xarray() -> xr.Dataset
¶
Converts the pastax.trajectory.Trajectory to a xarray.Dataset.
Returns:
| Type | Description |
|---|---|
Dataset
|
The corresponding |
Source code in pastax/trajectory/_trajectory.py
339 340 341 342 343 344 345 346 347 348 | |
from_array(values: Float[Array, '... time 2'], times: Float[Array, 'time'], unit: dict[Unit, int | float] = UNIT['°'], id: Int[Array, ''] | None = None, **_: Any) -> Trajectory
classmethod
¶
Creates a pastax.trajectory.Trajectory from arrays of (latitudes, longitudes) values and time points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Float[Array, '... time 2']
|
The array of (latitudes, longitudes) values for the trajectory. |
required |
times
|
Float[Array, 'time']
|
The time points for the trajectory. |
required |
unit
|
dict[Unit, int | float]
|
Unit of the trajectory locations, defaults to UNIT["°"]. |
UNIT['°']
|
id
|
Int[Array, ''] | None
|
The ID of the trajectory, defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Trajectory
|
The corresponding |
Source code in pastax/trajectory/_trajectory.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
from_xarray(dataset: xr.Dataset, time_varname: str = 'time', lat_varname: str = 'lat', lon_varname: str = 'lon', unit: dict[Unit, int | float] = UNIT['°'], id: Int[Array, ''] | None = None, **_: Any) -> Trajectory
classmethod
¶
Creates a pastax.trajectory.Trajectory from a xarray.Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dataset
|
The |
required |
time_varname
|
str
|
A string indicating the name of the time variable in the dataset, defaults to |
'time'
|
lat_varname
|
str
|
A string indicating the name of the latitude variable in the dataset, defaults to |
'lat'
|
lon_varname
|
str
|
A string indicating the name of the longitude variable in the dataset, defaults to |
'lon'
|
unit
|
dict[Unit, int | float]
|
Unit of the trajectory locations, defaults to UNIT["°"]. |
UNIT['°']
|
id
|
Int[Array, ''] | None
|
The ID of the trajectory, defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Trajectory
|
The corresponding |
Source code in pastax/trajectory/_trajectory.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
TimeseriesEnsemble
¶
Bases: Unitful
Class representing [pastax.trajectory.TimeseriesEnsemble].
Attributes:
| Name | Type | Description |
|---|---|---|
members |
Timeseries
|
The members of the [ |
size |
int
|
The number of members in the [ |
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the |
value |
Returns the value of the [ |
states |
Returns the |
times |
Returns the |
unit |
Returns the unit of the [ |
name |
Returns the name of the [ |
length |
Returns the length of the [ |
attach_name |
Attaches a name to the [ |
crps |
Computes the Continuous Ranked Probability Score (CRPS) for the [ |
ensemble_dispersion |
Computes the |
map |
Applies a function to each |
to_xarray |
Converts the |
from_array |
Creates a |
Source code in pastax/trajectory/_timeseries_ensemble.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
value: Float[Array, 'member time state']
property
¶
Returns the value of the [pastax.trajectory.TimeseriesEnsemble].
Returns:
| Type | Description |
|---|---|
Float[Array, '... member time state']
|
The value of the [ |
states: State
property
¶
Returns the states of the [pastax.trajectory.TimeseriesEnsemble].
Returns:
| Type | Description |
|---|---|
State
|
The states of the [ |
times: Time
property
¶
Returns the time points of the [pastax.trajectory.TimeseriesEnsemble].
Returns:
| Type | Description |
|---|---|
Time
|
The time points of the [ |
unit: dict[Unit, int | float]
property
¶
Returns the unit of the [pastax.trajectory.TimeseriesEnsemble].
Returns:
| Type | Description |
|---|---|
dict[Unit, int | float]
|
The unit of the [ |
name: str | None
property
¶
Returns the name of the [pastax.trajectory.TimeseriesEnsemble].
Returns:
| Type | Description |
|---|---|
str | None
|
The name of the [ |
length: int
property
¶
Returns the length of the [pastax.trajectory.TimeseriesEnsemble].
Returns:
| Type | Description |
|---|---|
int
|
The length of the [ |
__init__(members: Timeseries)
¶
Initializes the pastax.trajectory.TimeseriesEnsemble with pastax.trajectory.Timeseries members.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
members
|
Timeseries
|
The members of the [ |
required |
Source code in pastax/trajectory/_timeseries_ensemble.py
86 87 88 89 90 91 92 93 94 95 96 97 | |
attach_name(name: str) -> TimeseriesEnsemble
¶
Attaches a name to the [pastax.trajectory.TimeseriesEnsemble].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name to attach to the [ |
required |
Returns:
| Type | Description |
|---|---|
TimeseriesEnsemble
|
A new |
Source code in pastax/trajectory/_timeseries_ensemble.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
crps(other: Timeseries, metric_func: Callable[[Timeseries, Timeseries], Unitful | Array], is_metric_symmetric: bool = True) -> Unitful
¶
Computes the Continuous Ranked Probability Score (CRPS) for the [pastax.trajectory.TimeseriesEnsemble].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Timeseries
|
The other timeseries to compare against. |
required |
metric_func
|
Callable[[Timeseries, Timeseries], Unitful | Array]
|
The metric function to use. |
required |
is_metric_symmetric
|
bool
|
Whether the metric function is symmetric,
in which case half of the intra ensemble "distances" are evaluated when computing the ensemble dispersion,
defaults to |
True
|
Returns:
| Type | Description |
|---|---|
Unitful
|
The CRPS for the [ |
Source code in pastax/trajectory/_timeseries_ensemble.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
ensemble_dispersion(metric_func: Callable[[Timeseries, Timeseries], Unitful | Array], is_metric_symmetric: bool = True) -> Unitful
¶
Computes the pastax.trajectory.TimeseriesEnsemble dispersion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric_func
|
Callable[[Timeseries, Timeseries], Unitful | Array]
|
The metric function to use. |
required |
is_metric_symmetric
|
bool
|
Whether the metric function is symmetric,
in which case half of the intra ensemble "distances" are evaluated, defaults to |
True
|
Returns:
| Type | Description |
|---|---|
Unitful
|
The |
Source code in pastax/trajectory/_timeseries_ensemble.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
map(func: Callable[[Timeseries], Unitful | Array]) -> Unitful
¶
Applies a function to each pastax.trajectory.Timeseries of the [pastax.trajectory.TimeseriesEnsemble].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[Timeseries], Unitful | Array]
|
The function to apply to each |
required |
Returns:
| Type | Description |
|---|---|
Unitful
|
The result of applying the function to each |
Source code in pastax/trajectory/_timeseries_ensemble.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
to_xarray() -> xr.Dataset
¶
Converts the pastax.trajectory.TimeseriesEnsemble to a xarray.Dataset.
Returns:
| Type | Description |
|---|---|
Dataset
|
The corresponding |
Source code in pastax/trajectory/_timeseries_ensemble.py
287 288 289 290 291 292 293 294 295 296 297 298 299 | |
from_array(values: Float[Array, 'member time state'], times: Float[Array, 'time'], unit: dict[Unit, int | float] = {}, name: str | None = None, **kwargs: Any) -> TimeseriesEnsemble
classmethod
¶
Creates a pastax.trajectory.TimeseriesEnsemble from arrays of values and time points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Float[Array, 'member time state']
|
The values for the members of the ensemble. |
required |
times
|
Float[Array, 'time']
|
The time points for the timeseries. |
required |
unit
|
dict[Unit, int | float]
|
The unit of the timeseries, defaults to {}. |
{}
|
name
|
str | None
|
The name of the timeseries, defaults to None. |
None
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
TimeseriesEnsemble
|
The corresponding |
Source code in pastax/trajectory/_timeseries_ensemble.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
TrajectoryEnsemble
¶
Bases: TimeseriesEnsemble
Class representing an ensemble of trajectories.
Attributes:
| Name | Type | Description |
|---|---|---|
members |
Trajectory
|
The members of the trajectory ensemble. |
Methods:
| Name | Description |
|---|---|
id |
Returns the IDs of the trajectories. |
latitudes |
Returns the latitudes of the trajectories. |
locations |
Returns the locations of the trajectories. |
longitudes |
Returns the longitudes of the trajectories. |
origin |
Returns the origin of the trajectories. |
crps |
Computes the Continuous Ranked Probability Score (CRPS) for the ensemble. |
liu_index |
Computes the Liu Index for each ensemble trajectory. |
lengths |
Returns the lengths of the trajectories. |
mae |
Computes the Mean Absolute Error (MAE) for each ensemble trajectory. |
plot |
Plots the trajectories. |
rmse |
Computes the Root Mean Square Error (RMSE) for each ensemble trajectory. |
separation_distance |
Computes the separation distance for each ensemble trajectory. |
steps |
Returns the steps of the trajectories. |
to_xarray |
Converts the |
from_array |
Creates a |
Source code in pastax/trajectory/_trajectory_ensemble.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
id: Int[Array, 'member'] | None
property
¶
Returns the IDs of the trajectories.
Returns:
| Type | Description |
|---|---|
Int[Array, 'member'] | None
|
The IDs of the trajectories. |
latitudes: State
property
¶
Returns the latitudes of the trajectories.
Returns:
| Type | Description |
|---|---|
State
|
The latitudes of the trajectories. |
locations: Location
property
¶
Returns the locations of the trajectories.
Returns:
| Type | Description |
|---|---|
Location
|
The locations of the trajectories. |
longitudes: State
property
¶
Returns the longitudes of the trajectories.
Returns:
| Type | Description |
|---|---|
State
|
The longitudes of the trajectories. |
origin: State
property
¶
Returns the origin of the trajectories.
Returns:
| Type | Description |
|---|---|
State
|
The origin of the trajectories. |
liu_index(other: Trajectory) -> TimeseriesEnsemble
¶
Computes the Liu Index for each ensemble trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Trajectory
|
The other trajectory to compare against. |
required |
Returns:
| Type | Description |
|---|---|
TimeseriesEnsemble
|
The Liu Index for each ensemble trajectory. |
Source code in pastax/trajectory/_trajectory_ensemble.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
lengths() -> TimeseriesEnsemble
¶
Returns the lengths of the trajectories.
Returns:
| Type | Description |
|---|---|
TimeseriesEnsemble
|
The lengths of the trajectories. |
Source code in pastax/trajectory/_trajectory_ensemble.py
143 144 145 146 147 148 149 150 151 152 153 | |
mae(other: Trajectory) -> TimeseriesEnsemble
¶
Computes the Mean Absolute Error (MAE) for each ensemble trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Trajectory
|
The other trajectory to compare against. |
required |
Returns:
| Type | Description |
|---|---|
TimeseriesEnsemble
|
The MAE for each ensemble trajectory. |
Source code in pastax/trajectory/_trajectory_ensemble.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
plot(ax: Axes | None = None, label: str | list[str] | None = None, color: str | list[str | float | int] | None = None, alpha_factor: float = 1, ti: int | None = None, **kwargs) -> Axes
¶
Plots the trajectories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes | None
|
The matplotlib axis to plot on, defaults to |
None
|
label
|
str | list[str] | None
|
The label(s) for the plot, defaults to |
None
|
color
|
str | list[str | float | int] | None
|
The color(s) for the plot, defaults to |
None
|
alpha_factor
|
float
|
A factor controlling the overall transparency of the plotted ensemble, defaults to |
1
|
ti
|
int | None
|
The time index to plot up to, defaults to None. |
None
|
kwargs
|
Additional arguments passed to |
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
The matplotlib axis with the plot. |
Source code in pastax/trajectory/_trajectory_ensemble.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
rmse(other: Trajectory) -> TimeseriesEnsemble
¶
Computes the Root Mean Square Error (RMSE) for each ensemble trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Trajectory
|
The other trajectory to compare against. |
required |
Returns:
| Type | Description |
|---|---|
TimeseriesEnsemble
|
The RMSE for each ensemble trajectory. |
Source code in pastax/trajectory/_trajectory_ensemble.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
separation_distance(other: Trajectory) -> TimeseriesEnsemble
¶
Computes the separation distance for each ensemble trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Trajectory
|
The other trajectory to compare against. |
required |
Returns:
| Type | Description |
|---|---|
TimeseriesEnsemble
|
The separation distance for each ensemble trajectory. |
Source code in pastax/trajectory/_trajectory_ensemble.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
steps() -> TimeseriesEnsemble
¶
Returns the steps of the trajectories.
Returns:
| Type | Description |
|---|---|
TimeseriesEnsemble
|
The steps of the trajectories. |
Source code in pastax/trajectory/_trajectory_ensemble.py
289 290 291 292 293 294 295 296 297 298 299 | |
velocities() -> TimeseriesEnsemble
¶
Returns the velocities of the trajectories.
Returns:
| Type | Description |
|---|---|
TimeseriesEnsemble
|
The velocities of the trajectories. |
Source code in pastax/trajectory/_trajectory_ensemble.py
301 302 303 304 305 306 307 308 309 310 311 312 313 | |
to_xarray() -> xr.Dataset
¶
Converts the pastax.trajectory.TrajectoryEnsemble to a xarray.Dataset.
Returns:
| Type | Description |
|---|---|
Dataset
|
The corresponding |
Source code in pastax/trajectory/_trajectory_ensemble.py
315 316 317 318 319 320 321 322 323 324 | |
from_array(values: Float[Array, 'member time 2'], times: Float[Array, 'time'], unit: Unit | dict[Unit, int | float] = UNIT['°'], id: Int[Array, ''] | None = None, **_: dict) -> TrajectoryEnsemble
classmethod
¶
Creates a pastax.trajectory.TrajectoryEnsemble from arrays of values and time points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Float[Array, 'member time 2']
|
The array of (latitudes, longitudes) values for the members of the trajectory ensemble. |
required |
times
|
Float[Array, 'time']
|
The time points for the trajectories. |
required |
unit
|
Unit | dict[Unit, int | float]
|
Unit of the trajectories locations, defaults to UNIT["°"]. |
UNIT['°']
|
id
|
Int[Array, ''] | None
|
The ID of the trajectories, defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
TrajectoryEnsemble
|
The corresponding |
Source code in pastax/trajectory/_trajectory_ensemble.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
to_dataarray() -> dict[str, xr.DataArray]
¶
Converts the pastax.trajectory.TrajectoryEnsemble to a dictionary of xarray.DataArray.
Returns:
| Type | Description |
|---|---|
dict[str, DataArray]
|
A dictionary where keys are the variable names and values are the corresponding |
Source code in pastax/trajectory/_trajectory_ensemble.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
Set
¶
Bases: Module
Base class representing a set of PyTrees.
Attributes:
| Name | Type | Description |
|---|---|---|
size |
int
|
The number of members in the set. |
Source code in pastax/trajectory/_set.py
9 10 11 12 13 14 15 16 17 18 19 20 | |
pastax.gridded
¶
This module provides classes and functions for handling coordinates, grids, and pastax.gridded.Gridded in JAX.
Coordinate
¶
Bases: Module
Class for handling 1D coordinates (i.e. of rectilinear grids).
Attributes:
| Name | Type | Description |
|---|---|---|
indices |
Interpolator1D
|
Interpolator for nearest index interpolation. |
Methods:
| Name | Description |
|---|---|
values |
Returns the coordinate values. |
index |
Returns the nearest index for the given query coordinates. |
from_array |
Creates a |
__getitem__ |
Retrieve an item from the coordinate array. |
Source code in pastax/gridded/_coordinate.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
values: Float[Array, 'dim']
property
¶
Returns the coordinate values.
Returns:
| Type | Description |
|---|---|
Float[Array, 'dim']
|
The coordinate values. |
index(query: Float[Array, 'Nq']) -> Int[Array, 'Nq']
¶
Returns the nearest index interpolation for the given query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
Float[Array, 'Nq']
|
The query array for which the nearest indices are to be found. |
required |
Returns:
| Type | Description |
|---|---|
Int[Array, 'Nq']
|
An array of integers representing the nearest indices. |
Source code in pastax/gridded/_coordinate.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
from_array(values: Float[Array, 'dim'], **interpolator_kwargs: Any) -> Coordinate
classmethod
¶
Create a pastax.gridded.Coordinate object from an array of values.
This method initializes a pastax.gridded.Coordinate object using the provided array of values.
It uses a 1D interpolator to generate indices from values, with the interpolation method set to "nearest".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Float[Array, 'dim']
|
An array of coordinate values. |
required |
**interpolator_kwargs
|
Any
|
Additional keyword arguments for the interpolator. |
{}
|
Returns:
| Type | Description |
|---|---|
Coordinate
|
A |
Source code in pastax/gridded/_coordinate.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
__getitem__(item: Any) -> Float[Array, '...']
¶
Retrieve an item from the coordinate array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
The index or slice used to retrieve the item from the values array. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '...'] | Int[Array, '...']
|
The item retrieved from the coordinate array. |
Source code in pastax/gridded/_coordinate.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
LongitudeCoordinate
¶
Bases: Coordinate
Class for handling 1D longitude coordinates (i.e. of rectilinear grids). This class handles the circular nature of longitudes coordinates.
Attributes:
| Name | Type | Description |
|---|---|---|
indices |
Interpolator1D
|
Interpolator for nearest index interpolation. |
is_periodic |
bool
|
Whether the mesh uses spherical coordinate. |
Methods:
| Name | Description |
|---|---|
values |
Returns the coordinate values. |
index |
Returns the nearest index for the given query coordinates. |
from_array |
Creates a |
Source code in pastax/gridded/_coordinate.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
values: Float[Array, 'dim']
property
¶
Returns the coordinate values.
Returns:
| Type | Description |
|---|---|
Float[Array, 'dim']
|
The coordinate values. |
index(query: Float[Array, 'Nq']) -> Int[Array, 'Nq']
¶
Returns the nearest index interpolation for the given query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
Float[Array, 'Nq']
|
The query array for which the nearest indices are to be found. |
required |
Returns:
| Type | Description |
|---|---|
Int[Array, 'Nq']
|
An array of integers representing the nearest indices. |
Source code in pastax/gridded/_coordinate.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
from_array(values: Float[Array, 'dim'], is_periodic: bool = True, **interpolator_kwargs: Any) -> LongitudeCoordinate
classmethod
¶
Create a LongitudeCoordinate object from an array of values.
This method initializes a LongitudeCoordinate object using the provided array of values. It uses a 1D interpolator to generate indices from values, with the interpolation method set to "nearest".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Float[Array, 'dim']
|
An array of coordinate values. |
required |
is_periodic
|
bool
|
Whether the dimension should be consired periodic, defaults to |
True
|
**interpolator_kwargs
|
Any
|
Additional keyword arguments for the interpolator. |
{}
|
Returns:
| Type | Description |
|---|---|
LongitudeCoordinate
|
A |
Source code in pastax/gridded/_coordinate.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
Field
¶
Bases: Module
Base class for representing a field on a grid.
Methods:
| Name | Description |
|---|---|
values |
Returns the field values. |
__getitem__ |
Retrieves the value(s) at the specified index or slice of the grid. |
Source code in pastax/gridded/_field.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
values: Bool[Array, '...'] | Float[Array, '...'] | Int[Array, '...']
property
¶
Returns the field values.
Returns:
| Type | Description |
|---|---|
Bool[Array, '...'] | Float[Array, '...'] | Int[Array, '...']
|
The gridded values. |
__getitem__(item: Any) -> Bool[Array, '...'] | Float[Array, '...'] | Int[Array, '...']
¶
Retrieve an item from the values array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
The index or slice used to retrieve the item from the values array. |
required |
Returns:
| Type | Description |
|---|---|
Bool[Array, '...'] | Float[Array, '...'] | Int[Array, '...']
|
The item retrieved from the values array. |
Source code in pastax/gridded/_field.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
SpatialField
¶
Bases: Field
Class representing a spatial (2D) field with interpolation capabilities.
Methods:
| Name | Description |
|---|---|
interp |
Interpolates the field at the given coordinates. |
from_array |
Creates a |
Source code in pastax/gridded/_field.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
interp(**coordinates: Float[Array, 'Nq']) -> Bool[Array, '...'] | Float[Array, '...'] | Int[Array, '...']
¶
Interpolates the field at the given coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**coordinates
|
Float[Array, 'Nq']
|
The 2-dimensional points to interpolate to. |
{}
|
Returns:
| Type | Description |
|---|---|
Bool[Array, '...'] | Float[Array, '...'] | Int[Array, '...']
|
Interpolated values at the given coordinates. |
Source code in pastax/gridded/_field.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
from_array(values: Bool[Array, 'lat lon'] | Float[Array, 'lat lon'] | Int[Array, 'lat lon'], latitude: Float[Array, 'lat'], longitude: Float[Array, 'lon'], interpolation_method: str) -> SpatialField
classmethod
¶
Create a pastax.gridded.SpatialField object from given arrays of values, latitude, and longitude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Bool[Array, 'lat lon'] | Float[Array, 'lat lon'] | Int[Array, 'lat lon']
|
A 2D array of values representing the spatial data. |
required |
latitude
|
Float[Array, 'lat']
|
A 1D array of latitude values. |
required |
longitude
|
Float[Array, 'lon']
|
A 1D array of longitude values. |
required |
interpolation_method
|
str
|
The method to use for interpolation. |
required |
Returns:
| Type | Description |
|---|---|
SpatialField
|
A |
Source code in pastax/gridded/_field.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
SpatioTemporalField
¶
Bases: Field
Class representing a spatiotemporal (3D) field with interpolation capabilities.
Methods:
| Name | Description |
|---|---|
interp |
Interpolates the field at the given coordinates. |
from_array |
Creates a |
Source code in pastax/gridded/_field.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
interp(**coordinates: Float[Array, 'Nq']) -> Bool[Array, '...'] | Float[Array, '...'] | Int[Array, '...']
¶
Interpolates the field at the given coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**coordinates
|
Float[Array, 'Nq']
|
The N-dimensional points to interpolate to. |
{}
|
Returns:
| Type | Description |
|---|---|
Bool[Array, '...'] | Float[Array, '...'] | Int[Array, '...']
|
Interpolated values at the given coordinates. |
Source code in pastax/gridded/_field.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
from_array(values: Float[Array, 'time lat lon'], time: Float[Array, 'time'], latitude: Float[Array, 'lat'], longitude: Float[Array, 'lon'], interpolation_method: str) -> SpatioTemporalField
classmethod
¶
Create a pastax.gridded.SpatioTemporalField object from given arrays of values, time, latitude, and
longitude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Float[Array, 'time lat lon']
|
The array of values representing the data over time, latitude, and longitude. |
required |
time
|
Float[Array, 'time']
|
The array of time points. |
required |
latitude
|
Float[Array, 'lat']
|
The array of latitude points. |
required |
longitude
|
Float[Array, 'lon']
|
The array of longitude points. |
required |
interpolation_method
|
str
|
The method to be used for interpolation (e.g., 'linear', 'nearest', ...). |
required |
Returns:
| Type | Description |
|---|---|
SpatioTemporalField
|
A |
Source code in pastax/gridded/_field.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
Gridded
¶
Bases: Module
Class providing some routines for handling gridded spatiotemporal data in JAX.
Attributes:
| Name | Type | Description |
|---|---|---|
cell_area |
Float[Array, 'lat lon']
|
Array of cell areas in square meters. |
coordinates |
Coordinates
|
Coordinates object containing time, latitude, and longitude. |
dx |
Float[Array, 'lat lon-1']
|
Array of longitudinal distances in meters. |
dy |
Float[Array, 'lat-1 lon']
|
Array of latitudinal distances in meters. |
fields |
dict[str, SpatioTemporalField]
|
Dictionary of spatiotemporal fields. |
is_spherical_mesh |
bool
|
Boolean indicating whether the mesh uses spherical coordinates. |
interpolation_method |
Literal['nearest', 'linear', 'cubic', 'cubic2', 'catmull-rom', 'cardinal', 'monotonic', 'monotonic-0', 'akima']
|
String indicating the interpolation method used when interpolating the fields.
For details, see |
use_degrees |
bool
|
Boolean indicating whether distance units are degrees. |
Methods:
| Name | Description |
|---|---|
indices |
Gets nearest indices of the spatio-temporal point |
interp |
Interpolates the given fields at the given coordinates. |
neighborhood |
Extracts a neighborhood of data around a specified point in time and space. |
to_xarray |
Returns the |
from_array |
use_degrees=False, is_uv_mps=True)
Constructs a |
from_xarray |
is_uv_mps=True)
Constructs a |
xarray_to_array |
Converts an |
Source code in pastax/gridded/_gridded.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |
indices(**coordinates: Int[Array, 'Nq'] | Float[Array, 'Nq']) -> tuple[Int[Array, 'Nq'], ...]
¶
Gets the nearest indices of the N-dimensional point specified by the given coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**coordinates
|
Int[Array, 'Nq'] | Float[Array, 'Nq']
|
The N-dimensional point to get the nearest indices. |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[Int[Array, 'Nq'], ...]
|
A tuple of arrays containing the nearest indices of the N-dimensional point. |
Source code in pastax/gridded/_gridded.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
interp(*fields: str, **coordinates: Int[Array, 'Nq'] | Float[Array, 'Nq']) -> dict[str, Bool[Array, 'Nq ...'] | Float[Array, 'Nq ...'] | Int[Array, 'Nq ...']]
¶
Interpolates the given fields at the given coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*fields
|
str
|
Fields names to be interpolated. |
()
|
**coordinates
|
Int[Array, 'Nq'] | Float[Array, 'Nq']
|
The N-dimensional points to interpolate to. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Bool[Array, 'Nq ...'] | Float[Array, 'Nq ...'] | Int[Array, 'Nq ...']]
|
A dict of arrays containing the interpolated values for each field. |
Source code in pastax/gridded/_gridded.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
neighborhood(*fields: str, time: Int[Scalar, ''], latitude: Float[Scalar, ''], longitude: Float[Scalar, ''], t_width: int, x_width: int) -> Gridded
¶
Extracts a neighborhood of data around a specified point in time and space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*fields
|
tuple[str, ...]
|
Fields names to extract from the dataset. |
()
|
time
|
Int[Scalar, '']
|
The time coordinate for the center of the neighborhood. |
required |
latitude
|
Float[Scalar, '']
|
The latitude coordinate for the center of the neighborhood. |
required |
longitude
|
Float[Scalar, '']
|
The longitude coordinate for the center of the neighborhood. |
required |
t_width
|
int
|
The width of the neighborhood in the time dimension. |
required |
x_width
|
int
|
The width of the neighborhood in the spatial dimensions (latitude and longitude). |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
A |
Source code in pastax/gridded/_gridded.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
to_xarray() -> xr.Dataset
¶
Converts the pastax.gridded.Gridded to a xarray.Dataset.
This method constructs an xarray Dataset from the object's fields and coordinates. The fields are added as data variables with coordinates ["time", "latitude", "longitude"]. The coordinates are added as coordinate variables.
Returns:
| Type | Description |
|---|---|
Dataset
|
The corresponding |
Source code in pastax/gridded/_gridded.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
from_array(fields: dict[str, Float[Array, 'time lat lon']], time: Int[Array, 'time'], latitude: Float[Array, 'lat'], longitude: Float[Array, 'lon'], interpolation_method: Literal['nearest', 'linear', 'cubic', 'cubic2', 'catmull-rom', 'cardinal', 'monotonic', 'monotonic-0', 'akima'] = 'linear', is_spherical_mesh: bool = True, use_degrees: bool = False, is_uv_mps: bool = True) -> Gridded
classmethod
¶
Create a pastax.gridded.Gridded object from arrays of fields, time, latitude, and longitude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fields
|
dict[str, Float[Array, 'time lat lon']]
|
A dictionary where keys are fields names and values are 3D arrays representing the field data over time, latitude, and longitude. |
required |
time
|
Int[Array, 'time']
|
A 1D array representing the time dimension. |
required |
latitude
|
Float[Array, 'lat']
|
A 1D array representing the latitude dimension. |
required |
longitude
|
Float[Array, 'lon']
|
A 1D array representing the longitude dimension. |
required |
interpolation_method
|
Literal['nearest', 'linear', 'cubic', 'cubic2', 'catmull-rom', 'cardinal', 'monotonic', 'monotonic-0', 'akima']
|
String indicating the interpolation method used when interpolating the fields, defaults to |
'linear'
|
is_spherical_mesh
|
bool
|
Whether the mesh uses spherical coordinate, defaults to |
True
|
use_degrees
|
bool
|
Whether distance units should be degrees rather than meters, defaults to |
False
|
is_uv_mps
|
bool
|
Whether the velocity data is in m/s, defaults to |
True
|
Returns:
| Type | Description |
|---|---|
Dataset
|
The corresponding |
Source code in pastax/gridded/_gridded.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
from_xarray(dataset: xr.Dataset, fields: dict[str, str], coordinates: dict[str, str], interpolation_method: Literal['nearest', 'linear', 'cubic', 'cubic2', 'catmull-rom', 'cardinal', 'monotonic', 'monotonic-0', 'akima'] = 'linear', is_spherical_mesh: bool = True, is_uv_mps: bool = True, use_degrees: bool = False) -> Gridded
classmethod
¶
Create a pastax.gridded.Gridded object from a xarray.Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dataset
|
The |
required |
fields
|
dict[str, str]
|
A dictionary mapping the target field names (keys) to the source variable names in the dataset (values). |
required |
coordinates
|
dict[str, str]
|
A dictionary mapping the coordinate names ('time', 'latitude', 'longitude') to their corresponding names in the dataset. |
required |
interpolation_method
|
Literal['nearest', 'linear', 'cubic', 'cubic2', 'catmull-rom', 'cardinal', 'monotonic', 'monotonic-0', 'akima']
|
String indicating the interpolation method used when interpolating the fields, defaults to |
'linear'
|
is_spherical_mesh
|
bool
|
Whether the mesh uses spherical coordinate, defaults to |
True
|
is_uv_mps
|
bool
|
Whether the velocity data is in m/s, defaults to |
True
|
use_degrees
|
bool
|
Whether distance unit should be degrees rather than meters, defaults to |
False
|
Returns:
| Type | Description |
|---|---|
Dataset
|
The corresponding |
Source code in pastax/gridded/_gridded.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
xarray_to_array(dataset: xr.Dataset, fields: dict[str, str], coordinates: dict[str, str], transform_fn: Callable[[Array], Array] = lambda x: jnp.asarray(x, dtype=float)) -> tuple[dict[str, Float[Array, '...']], Float[Array, '...'], Float[Array, '...'], Float[Array, '...']]
staticmethod
¶
Converts an xarray.Dataset to arrays of fields and coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Dataset
|
The |
required |
fields
|
dict[str, str]
|
A dictionary mapping the target field names to the source variable names in the dataset. |
required |
coordinates
|
dict[str, str]
|
A dictionary mapping the target coordinate names to the source coordinate names in the dataset. |
required |
transform_fn
|
Callable[[Array], Array]
|
Function converting dataarrays to JAX (or numpy) arrays,
defaults to |
lambda x: asarray(x, dtype=float)
|
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Float[Array, '...']], Float[Array, '...'], Float[Array, '...'], Float[Array, '...']]
|
A tuple containing: - A dictionary of converted fields. - The time coordinate array. - The latitude coordinate array. - The longitude coordinate array. |
Source code in pastax/gridded/_gridded.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |
spatial_derivative(*fields: Float[Array, '(time) lat lon'], dx: Float[Array, 'lat lon-1'], dy: Float[Array, 'lat-1 lon'], is_masked: Bool[Array, 'lat lon']) -> tuple[tuple[Float[Array, '(time) lat lon'], Float[Array, '(time) lat lon']], ...]
¶
Computes spatial derivatives for given fields using central finite differences.
This function calculates the spatial derivatives of the provided fields, taking into account the presence of mask and the grid spacing in both latitude and longitude directions. It uses central finite differences for the computation and leverages JAX for efficient computation and automatic differentiation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*fields
|
Float[Array, '(time) lat lon']
|
Variable number of fields for which the spatial derivatives are to be computed. Each field is a 2D or 3D array with dimensions (latitude, longitude) or (time, latitude, longitude). |
()
|
dx
|
Float[Array, 'lat lon-1']
|
Gridded spacing in the longitude direction. |
required |
dy
|
Float[Array, 'lat-1 lon']
|
Gridded spacing in the latitude direction. |
required |
is_masked
|
Bool[Array, 'lat lon']
|
Boolean array indicating whether a grid point should be masked ( |
required |
Returns:
| Type | Description |
|---|---|
tuple[tuple[Float[Array, '(time) lat lon'], Float[Array, '(time) lat lon']], ...]
|
A tuple containing the spatial derivatives of the input fields. Each derivative is a 2D or 3D array with dimensions (latitude, longitude) or (time, latitude, longitude). For field f1 and f2, returns ((df1_x, df1_y), (df2_x, df2_y)). |
Source code in pastax/gridded/_operators.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
pastax.evaluation
¶
This module provides classes for evaluating simulated pastax.trajectory.Trajectory and
pastax.trajectory.TrajectoryEnsemble.
Evaluation
¶
Bases: Set
Class for accessing and visualizing a dictionary of metric timeseries or timeseries ensemble.
Methods:
| Name | Description |
|---|---|
__init__ |
Initializes the |
get |
Retrieves a metric by key. |
items |
Returns the items of the metrics dictionary. |
keys |
Returns the keys of the metrics dictionary. |
values |
Returns the values of the metrics dictionary. |
plot |
Plots the metrics timeseries or timeseries ensemble up to the time index |
__getitem__ |
Retrieves a metric by key. |
Source code in pastax/evaluation/_evaluation.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
__init__(states: dict[str, Timeseries | tuple[TimeseriesEnsemble, Timeseries, Timeseries]])
¶
Initializes the pastax.evaluation.Evaluation object with a dictionary of metric timeseries or timeseries
ensemble.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
states
|
dict[str, Timeseries | tuple[TimeseriesEnsemble, Timeseries, Timeseries]]
|
The initial metrics dictionary. |
required |
Source code in pastax/evaluation/_evaluation.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
get(key: str) -> Timeseries | TimeseriesEnsemble | tuple[TimeseriesEnsemble, Timeseries, Timeseries] | None
¶
Retrieves a metric by key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key of the metric to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Timeseries | tuple[TimeseriesEnsemble, Timeseries, Timeseries] | None
|
The metrics corresponding to the key. |
Source code in pastax/evaluation/_evaluation.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
items() -> Iterable[tuple[str, Timeseries | TimeseriesEnsemble | tuple[TimeseriesEnsemble, Timeseries, Timeseries]]]
¶
Returns the items of the metrics dictionary.
Returns:
| Type | Description |
|---|---|
tuple[str, Timeseries | tuple[TimeseriesEnsemble, Timeseries, Timeseries]]
|
The items of the metrics dictionary. |
Source code in pastax/evaluation/_evaluation.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
keys() -> Iterable[str]
¶
Returns the keys of the metric timeseries dictionary.
Returns:
| Type | Description |
|---|---|
tuple[str]
|
The keys of the metrics dictionary. |
Source code in pastax/evaluation/_evaluation.py
92 93 94 95 96 97 98 99 100 101 | |
values() -> Iterable[Timeseries | TimeseriesEnsemble | tuple[TimeseriesEnsemble, Timeseries, Timeseries]]
¶
Returns the values of the metrics dictionary.
Returns:
| Type | Description |
|---|---|
tuple[Timeseries | tuple[TimeseriesEnsemble, Timeseries, Timeseries]]
|
The values of the metrics dictionary. |
Source code in pastax/evaluation/_evaluation.py
103 104 105 106 107 108 109 110 111 112 113 114 | |
to_dataarray() -> dict[str, xr.DataArray]
¶
Converts the evaluation results to a dictionary of xarray.DataArrays.
Returns:
| Type | Description |
|---|---|
dict[str, DataArray]
|
A dictionary where keys are the evaluation metric names and values are the corresponding
|
Source code in pastax/evaluation/_evaluation.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
to_dataset() -> xr.Dataset
¶
Converts the evaluation results to a xarray.Dataset.
Returns:
| Type | Description |
|---|---|
Dataset
|
A |
Source code in pastax/evaluation/_evaluation.py
138 139 140 141 142 143 144 145 146 147 | |
plot(fig: Figure, ti: int | None = None)
¶
Plots the metric timeseries or timeseries ensemble up to the time index ti on the figure fig.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
The figure to plot on. |
required |
ti
|
int | None
|
The time index up to which to plot. If |
None
|
Source code in pastax/evaluation/_evaluation.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
__getitem__(key: str) -> Timeseries | TimeseriesEnsemble | tuple[TimeseriesEnsemble, Timeseries, Timeseries]
¶
Retrieves a metric by key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key of the metric to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Timeseries | TimeseriesEnsemble
|
The metric |
Source code in pastax/evaluation/_evaluation.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
BaseEvaluator
¶
Bases: Module
Base class for evaluating trajectories using a set of predefined metrics.
Attributes:
| Name | Type | Description |
|---|---|---|
metrics |
list[Metric]
|
A list of |
Methods:
| Name | Description |
|---|---|
__call__ |
Evaluates the |
Source code in pastax/evaluation/_evaluator.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
__call__(reference_trajectory: Trajectory, simulated_trajectory: Trajectory | TrajectoryEnsemble) -> Evaluation
¶
Evaluates the simulated_trajectory (which might be an ensemble of trajectories)
against the reference_trajectory using self.metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference_trajectory
|
Trajectory
|
The reference |
required |
simulated_trajectory
|
Trajectory | TrajectoryEnsemble
|
The simulated |
required |
Returns:
| Type | Description |
|---|---|
Evaluation
|
The result of the |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This method should be implemented by child classes. |
Source code in pastax/evaluation/_evaluator.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
EnsembleEvaluator
¶
Bases: BaseEvaluator
Class for evaluating an ensemble of simulated trajectories using a set of predefined metrics.
Methods:
| Name | Description |
|---|---|
__call__ |
Evaluates the |
Source code in pastax/evaluation/_evaluator.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
__call__(reference_trajectory: Trajectory, simulated_trajectories: TrajectoryEnsemble) -> Evaluation
¶
Evaluates the simulated_trajectories ensemble against the reference_trajectory using self.metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference_trajectory
|
Trajectory
|
The reference |
required |
simulated_trajectories
|
TrajectoryEnsemble
|
The simulated |
required |
Returns:
| Type | Description |
|---|---|
Evaluation
|
The result of the |
Source code in pastax/evaluation/_evaluator.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
PairEvaluator
¶
Bases: BaseEvaluator
Class for evaluating a simulated trajectory using a set of predefined metrics.
Methods:
| Name | Description |
|---|---|
__call__ |
Evaluates the |
Source code in pastax/evaluation/_evaluator.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
__call__(reference_trajectory: Trajectory, simulated_trajectory: Trajectory) -> Evaluation
¶
Evaluates the simulated_trajectory against the reference_trajectory using self.metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference_trajectory
|
Trajectory
|
The reference |
required |
simulated_trajectory
|
Trajectory
|
The simulated |
required |
Returns:
| Type | Description |
|---|---|
Evaluation
|
The result of the |
Source code in pastax/evaluation/_evaluator.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
LiuIndex
¶
Bases: Metric
The Liu index metric.
Attributes:
| Name | Type | Description |
|---|---|---|
metric_fun |
str
|
The name of the metric function or method: |
Source code in pastax/evaluation/_metric.py
17 18 19 20 21 22 23 24 25 26 27 | |
Mae
¶
Bases: Metric
The Mean Absolute Error metric.
Attributes:
| Name | Type | Description |
|---|---|---|
metric_fun |
str
|
The name of the metric function or method: |
Source code in pastax/evaluation/_metric.py
30 31 32 33 34 35 36 37 38 39 40 | |
Metric
¶
Bases: Module
Base class for metric objects.
Attributes:
| Name | Type | Description |
|---|---|---|
metric_fun |
str
|
The name of the metric function or method. |
Source code in pastax/evaluation/_metric.py
4 5 6 7 8 9 10 11 12 13 14 | |
Rmse
¶
Bases: Metric
The Root Mean Square Error metric.
Attributes:
| Name | Type | Description |
|---|---|---|
metric_fun |
str
|
The name of the metric function or method: |
Source code in pastax/evaluation/_metric.py
43 44 45 46 47 48 49 50 51 52 53 | |
SeparationDistance
¶
Bases: Metric
The Separation distance metric.
Attributes:
| Name | Type | Description |
|---|---|---|
metric_fun |
str
|
The name of the metric function or method: |
Source code in pastax/evaluation/_metric.py
56 57 58 59 60 61 62 63 64 65 66 | |
pastax.utils
¶
This module provides various geographical and pastax.utils.Unit conversion and manipulation utilities in JAX.
EARTH_RADIUS = 6371008.8
module-attribute
¶
float: The radius of the Earth in meters.
UNIT = {'m': Meters(), 'km': Kilometers(), '°': LatLonDegrees(), 's': Seconds(), 'min': Minutes(), 'h': Hours(), 'd': Days()}
module-attribute
¶
A dictionary mapping unit symbols to their corresponding pastax.utils.Unit objects.
Keys
"m" : Meters
Represents meters as a pastax.utils.Unit of measurement.
"km" : Kilometers
Represents kilometers as a pastax.utils.Unit of measurement.
"°" : LatLonDegrees
Represents latitude and longitude degrees as a pastax.utils.Unit of measurement.
"s" : Seconds
Represents seconds as a pastax.utils.Unit of measurement.
"min" : Minutes
Represents minutes as a pastax.utils.Unit of measurement.
"h" : Hours
Represents hours as a pastax.utils.Unit of measurement.
"d" : Days
Represents days as a pastax.utils.Unit of measurement.
Values
Unit
The corresponding pastax.utils.Unit object for each unit symbol.
Unit
¶
Bases: Module
Base class representing pastax.utils.Unit of measurement.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the [ |
Methods:
| Name | Description |
|---|---|
__eq__ |
Checks if two |
__lt__ |
Checks if one |
__hash__ |
Returns the hash of the [ |
__repr__ |
Returns the string representation of the [ |
convert_to |
Converts the |
Source code in pastax/utils/_unit.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
convert_to(unit: Unit, value: Array, exp: int | float = 1, *args) -> Array
¶
Converts the value to the specified [pastax.utils.Unit].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
Unit
|
The |
required |
value
|
Array
|
The value to convert. |
required |
exp
|
int or float
|
The exponent to use for conversion, defaults to 1. |
1
|
*args
|
Additional arguments for conversion. |
()
|
Returns:
| Type | Description |
|---|---|
Array
|
The converted value. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If not implemented by subclasses. |
Source code in pastax/utils/_unit.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
Meters
¶
Bases: Unit
Class representing meters as a pastax.utils.Unit of measurement.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the [ |
Source code in pastax/utils/_unit.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
convert_to(unit: Unit, value: Array, exp: int | float = 1, *args) -> Array
¶
Converts the value to the specified [pastax.utils.Unit].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
Unit
|
The |
required |
value
|
Array
|
The value to convert. |
required |
exp
|
int or float
|
The exponent to use for conversion, defaults to 1. |
1
|
*args
|
Additional arguments for conversion. |
()
|
Returns:
| Type | Description |
|---|---|
Array
|
The converted value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the conversion is not possible. |
Source code in pastax/utils/_unit.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
Kilometers
¶
Bases: Unit
Class representing kilometers as a pastax.utils.Unit of measurement.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the [ |
Source code in pastax/utils/_unit.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
convert_to(unit: Unit, value: Array, exp: int | float = 1, *args) -> Array
¶
Converts the value to the specified [pastax.utils.Unit].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
Unit
|
The |
required |
value
|
Array
|
The value to convert. |
required |
exp
|
int or float
|
The exponent to use for conversion, defaults to 1. |
1
|
*args
|
Additional arguments for conversion. |
()
|
Returns:
| Type | Description |
|---|---|
Array
|
The converted value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the conversion is not possible. |
Source code in pastax/utils/_unit.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
LatLonDegrees
¶
Bases: Unit
Class representing latitude and longitude degrees as a pastax.utils.Unit of measurement.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the [ |
Source code in pastax/utils/_unit.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
convert_to(unit: Unit, value: Array, exp: int | float = 1, *args) -> Array
¶
Converts the value to the specified [pastax.utils.Unit].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
Unit
|
The |
required |
value
|
Array
|
The value to convert. |
required |
exp
|
int or float
|
The exponent to use for conversion, defaults to 1. |
1
|
*args
|
Additional arguments for conversion. |
()
|
Returns:
| Type | Description |
|---|---|
Array
|
The converted value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the conversion is not possible. |
Source code in pastax/utils/_unit.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
Seconds
¶
Bases: Unit
Class representing seconds as a pastax.utils.Unit of measurement.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the [ |
Source code in pastax/utils/_unit.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
convert_to(unit: Unit, value: Array, exp: int | float = 1, *args) -> Array
¶
Converts the value to the specified unit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
Unit
|
The |
required |
value
|
Array
|
The value to convert. |
required |
exp
|
int or float
|
The exponent to use for conversion, defaults to 1. |
1
|
*args
|
Additional arguments for conversion. |
()
|
Returns:
| Type | Description |
|---|---|
Array
|
The converted value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the conversion is not possible. |
Source code in pastax/utils/_unit.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
Minutes
¶
Bases: Unit
Class representing minutes as a pastax.utils.Unit of measurement.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the [ |
Source code in pastax/utils/_unit.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
convert_to(unit: Unit, value: Array, exp: int | float = 1, *args) -> Array
¶
Converts the value to the specified unit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
Unit
|
The |
required |
value
|
Array
|
The value to convert. |
required |
exp
|
int or float
|
The exponent to use for conversion, defaults to 1. |
1
|
*args
|
Additional arguments for conversion. |
()
|
Returns:
| Type | Description |
|---|---|
Array
|
The converted value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the conversion is not possible. |
Source code in pastax/utils/_unit.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
Hours
¶
Bases: Unit
Class representing hours as a pastax.utils.Unit of measurement.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the [ |
Source code in pastax/utils/_unit.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
convert_to(unit: Unit, value: Array, exp: int | float = 1, *args) -> Array
¶
Converts the value to the specified unit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
Unit
|
The |
required |
value
|
Array
|
The value to convert. |
required |
exp
|
int or float
|
The exponent to use for conversion, defaults to 1. |
1
|
*args
|
Additional arguments for conversion. |
()
|
Returns:
| Type | Description |
|---|---|
Array
|
The converted value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the conversion is not possible. |
Source code in pastax/utils/_unit.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
Days
¶
Bases: Unit
Class representing days as a pastax.utils.Unit of measurement.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the [ |
Source code in pastax/utils/_unit.py
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
convert_to(unit: Unit, value: Array, exp: int | float = 1, *args) -> Array
¶
Converts the value to the specified unit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
Unit
|
The |
required |
value
|
Array
|
The value to convert. |
required |
exp
|
int or float
|
The exponent to use for conversion, defaults to 1. |
1
|
*args
|
Additional arguments for conversion. |
()
|
Returns:
| Type | Description |
|---|---|
Array
|
The converted value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the conversion is not possible. |
Source code in pastax/utils/_unit.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
distance_on_earth(latlon1: Float[Array, '... 2'], latlon2: Float[Array, '... 2']) -> Array
¶
Calculates the distance in meters between two points on the Earth's surface.
This function uses the Haversine formula to compute the distance between two (array of) points specified by their latitude and longitude coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latlon1
|
Float[Array, '... 2']
|
A 2-element(s) array containing the latitude and longitude in degrees of the first point(s). |
required |
latlon2
|
Float[Array, '... 2']
|
A 2-element(s) array containing the latitude and longitude in degrees of the second point(s). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
The distance between the two (array of) points in meters. |
Source code in pastax/utils/_geo.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
longitude_in_180_180_degrees(longitude: Array) -> Array
¶
Adjusts an array of longitudes to be within the range of -180 to 180 degrees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
longitude
|
Array
|
An array of longitudes in degrees. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
The input longitudes adjusted to be within the range of -180 to 180 degrees. |
Notes
This function acts as the identity for longitudes that are already within the range of -180 to 180 degrees.
Source code in pastax/utils/_geo.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
degrees_to_meters(arr: Float[Array, '... 2'], latitude: Float[Array, '...']) -> Float[Array, '... 2']
¶
Converts an array of latitude/longitude distances from degrees to meters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Float[Array, '... 2']
|
An array of latitude/longitude distances in degrees. |
required |
latitude
|
Float[Array, '...']
|
The latitude in degrees at which the conversion is to be performed. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '... 2']
|
An array of latitude/longitude distances in meters. |
Source code in pastax/utils/_unit.py
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 | |
degrees_to_kilometers(arr: Float[Array, '... 2'], latitude: Float[Array, '...']) -> Float[Array, '... 2']
¶
Converts an array of latitude/longitude distances from degrees to kilometers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Float[Array, '... 2']
|
An array of latitude/longitude distances in degrees. |
required |
latitude
|
Float[Array, '...']
|
The latitude in degrees at which the conversion is to be performed. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '... 2']
|
An array of latitude/longitude distances in kilometers. |
Source code in pastax/utils/_unit.py
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 | |
meters_to_degrees(arr: Float[Array, '... 2'], latitude: Float[Array, '...']) -> Float[Array, '... 2']
¶
Converts an array of latitude/longitude distances from meters to degrees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Float[Array, '... 2']
|
An array of latitude/longitude distances in meters. |
required |
latitude
|
Float[Array, '...']
|
The latitude in degrees at which the conversion is to be performed. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '... 2']
|
An array of latitude/longitude distances in degrees. |
Source code in pastax/utils/_unit.py
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | |
meters_to_kilometers(arr: Array) -> Array
¶
Converts an array of distances from meters to kilometers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Array
|
An array of distances in meters. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
An array of distances in kilometers. |
Source code in pastax/utils/_unit.py
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | |
kilometers_to_degrees(arr: Float[Array, '... 2'], latitude: Float[Array, '...']) -> Float[Array, '... 2']
¶
Converts an array of latitude/longitude distances from kilometers to degrees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Float[Array, '... 2']
|
An array of latitude/longitude distances in kilometers. |
required |
latitude
|
Float[Array, '...']
|
The latitude in degrees at which the conversion is to be performed. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '... 2']
|
An array of latitude/longitude distances in degrees. |
Source code in pastax/utils/_unit.py
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | |
kilometers_to_meters(arr: Array) -> Array
¶
Converts an array of distances from kilometers to meters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Array
|
An array of distances in kilometers. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
An array of distances in meters. |
Source code in pastax/utils/_unit.py
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 | |
time_in_seconds(arr: Array | ArrayLike) -> Array | ArrayLike
¶
Converts an array of datetime64 values to seconds since the Unix epoch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Array | ArrayLike
|
An array of datetime64 values or a single datetime64 value. |
required |
Returns:
| Type | Description |
|---|---|
Array | ArrayLike
|
An array of integers representing the number of seconds since the Unix epoch. |
Source code in pastax/utils/_unit.py
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 | |
seconds_to_days(arr: Array) -> Array
¶
Converts an array of time durations from seconds to days.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Array
|
An array of time durations in seconds. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
An array of time durations in days. |
Source code in pastax/utils/_unit.py
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | |
units_to_str(unit: dict[Unit, int | float]) -> str
¶
Converts a dictionary of pastax.utils.Unit with their exponents to a string representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit
|
dict[Unit, int or float]
|
A dictionary of |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the |
Source code in pastax/utils/_unit.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
compose_units(unit1: dict[Unit, int | float], unit2: dict[Unit, int | float] | None, mul: Literal[-1, 1]) -> dict[Unit, int | float]
¶
Compose two pastax.utils.Unit dictionaries by combining their values,
optionally multiplying the second dictionary's values by a factor to account for multiplication or division.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit1
|
dict[Unit, int | float]
|
The first |
required |
unit2
|
dict[Unit, int | float]
|
The second |
required |
mul
|
Literal[-1, 1]
|
The multiplier for the second |
required |
Returns:
| Type | Description |
|---|---|
dict[Unit, int | float]
|
The composed |
Source code in pastax/utils/_unit.py
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | |