Skip to content

Commit

Permalink
Added named_arrays.TemporalSpectralDirectionalVectorArray. (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
byrdie authored Feb 2, 2024
1 parent 1558f30 commit 3bef9ab
Show file tree
Hide file tree
Showing 5 changed files with 397 additions and 3 deletions.
2 changes: 2 additions & 0 deletions named_arrays/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ._vectors.vectors_directional import *
from ._vectors.vectors_spectral_positional import *
from ._vectors.vectors_spectral_directional import *
from ._vectors.vectors_temporal_spectral_directional import *
from ._matrices.matrices import *
from ._matrices.cartesian.matrices_cartesian import *
from ._matrices.cartesian.matrices_cartesian_2d import *
Expand All @@ -28,4 +29,5 @@
from ._matrices.matrices_directional import *
from ._matrices.matrices_spectral_positional import *
from ._matrices.matrices_spectral_directional import *
from ._matrices.matrices_temporal_spectral_directional import *
from ._functions.functions import *
41 changes: 41 additions & 0 deletions named_arrays/_matrices/matrices_temporal_spectral_directional.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from __future__ import annotations
from typing import Type

import dataclasses
import named_arrays as na

__all__ = [
'AbstractTemporalSpectralDirectionalMatrixArray',
'TemporalSpectralDirectionalMatrixArray',
]


@dataclasses.dataclass(eq=False, repr=False)
class AbstractTemporalSpectralDirectionalMatrixArray(
na.AbstractTemporalSpectralDirectionalVectorArray,
):

@property
def type_abstract(self) -> Type[AbstractTemporalSpectralDirectionalMatrixArray]:
return AbstractTemporalSpectralDirectionalMatrixArray

@property
def type_explicit(self) -> Type[TemporalSpectralDirectionalMatrixArray]:
return TemporalSpectralDirectionalMatrixArray

@property
def type_vector(self) -> Type[na.TemporalSpectralDirectionalVectorArray]:
return na.TemporalSpectralDirectionalVectorArray

@property
def determinant(self) -> na.ScalarLike:
return NotImplementedError


@dataclasses.dataclass(eq=False, repr=False)
class TemporalSpectralDirectionalMatrixArray(
na.TemporalSpectralDirectionalVectorArray,
AbstractTemporalSpectralDirectionalMatrixArray,
na.AbstractExplicitMatrixArray,
):
pass
6 changes: 3 additions & 3 deletions named_arrays/_vectors/tests/test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,19 +665,19 @@ class AbstractTestAbstractWcsVector(
):
def test_crval(self, array: na.AbstractWcsVector):
result = array.crval
assert isinstance(result, array.type_abstract)
assert isinstance(result, na.AbstractVectorArray)

def test_crpix(self, array: na.AbstractWcsVector):
result = array.crpix
assert isinstance(result, na.AbstractCartesianNdVectorArray)

def test_cdelt(self, array: na.AbstractWcsVector):
result = array.cdelt
assert isinstance(result, array.type_abstract)
assert isinstance(result, na.AbstractVectorArray)

def test_pc(self, array: na.AbstractWcsVector):
result = array.pc
assert isinstance(result, array.type_matrix)
assert isinstance(result, na.AbstractMatrixArray)
components = result.components
for c in components:
assert isinstance(components[c], na.AbstractVectorArray)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
import pytest
import numpy as np
import astropy.units as u
import named_arrays as na
from ..tests import test_vectors
from ..cartesian.tests import test_vectors_cartesian

_num_x = test_vectors_cartesian._num_x
_num_y = test_vectors_cartesian._num_y
_num_z = test_vectors_cartesian._num_z
_num_distribution = test_vectors_cartesian._num_distribution


def _temporal_spectral_directional_arrays() -> (
list[na.TemporalSpectralDirectionalVectorArray]
):
return [
na.TemporalSpectralDirectionalVectorArray(
time=10 * u.s,
wavelength=500 * u.nm,
direction=na.Cartesian2dVectorArray(1, 2) * u.mm,
),
na.TemporalSpectralDirectionalVectorArray(
time=na.linspace(0, 10, axis="y", num=_num_y) * u.s,
wavelength=na.linspace(400, 600, axis="y", num=_num_y) * u.nm,
direction=na.Cartesian2dVectorLinearSpace(
1, 2, axis="y", num=_num_y
).explicit
* u.mm,
),
]


def _temporal_spectral_directional_arrays_2() -> (
list[na.TemporalSpectralDirectionalVectorArray]
):
return [
na.TemporalSpectralDirectionalVectorArray(
time=20 * u.s,
wavelength=400 * u.nm,
direction=na.Cartesian2dVectorArray(3, 4) * u.m,
),
na.TemporalSpectralDirectionalVectorArray(
time=na.NormalUncertainScalarArray(10 * u.s, width=1 * u.s),
wavelength=na.NormalUncertainScalarArray(400 * u.nm, width=1 * u.nm),
direction=na.Cartesian2dVectorArray(
x=na.NormalUncertainScalarArray(3, width=1) * u.m,
y=na.NormalUncertainScalarArray(4, width=1) * u.m,
),
),
]


def _temporal_spectral_directional_items() -> (
list[na.AbstractArray | dict[str, int | slice | na.AbstractArray]]
):
return [
dict(y=0),
dict(y=slice(0, 1)),
dict(y=na.ScalarArrayRange(0, 2, axis="y")),
]


class AbstractTestAbstractTemporalSpectralDirectionalVectorArray(
test_vectors_cartesian.AbstractTestAbstractCartesianVectorArray,
):

@pytest.mark.parametrize(
argnames="item", argvalues=_temporal_spectral_directional_items()
)
def test__getitem__(
self,
array: na.AbstractSpectralVectorArray,
item: dict[str, int | slice | na.AbstractArray] | na.AbstractArray,
):
super().test__getitem__(array=array, item=item)

@pytest.mark.parametrize("array_2", _temporal_spectral_directional_arrays_2())
class TestUfuncBinary(
test_vectors_cartesian.AbstractTestAbstractCartesianVectorArray.TestUfuncBinary
):
pass

@pytest.mark.parametrize("array_2", _temporal_spectral_directional_arrays_2())
class TestMatmul(
test_vectors_cartesian.AbstractTestAbstractCartesianVectorArray.TestMatmul,
):
pass

class TestArrayFunctions(
test_vectors_cartesian.AbstractTestAbstractCartesianVectorArray.TestArrayFunctions,
):

@pytest.mark.parametrize("array_2", _temporal_spectral_directional_arrays_2())
class TestAsArrayLikeFunctions(
test_vectors_cartesian.AbstractTestAbstractCartesianVectorArray.TestArrayFunctions.TestAsArrayLikeFunctions,
):
pass

@pytest.mark.parametrize(
argnames="where",
argvalues=[
np._NoValue,
True,
na.ScalarArray(True),
],
)
class TestReductionFunctions(
test_vectors_cartesian.AbstractTestAbstractCartesianVectorArray.TestArrayFunctions.TestReductionFunctions,
):
pass

@pytest.mark.parametrize(
argnames="q",
argvalues=[
0.25,
25 * u.percent,
na.ScalarLinearSpace(0.25, 0.75, axis="q", num=3, endpoint=True),
],
)
class TestPercentileLikeFunctions(
test_vectors_cartesian.AbstractTestAbstractCartesianVectorArray.TestArrayFunctions.TestPercentileLikeFunctions,
):
pass

class TestNamedArrayFunctions(
test_vectors_cartesian.AbstractTestAbstractCartesianVectorArray.TestNamedArrayFunctions,
):
@pytest.mark.skip
class TestPltPlotLikeFunctions(
test_vectors_cartesian.AbstractTestAbstractCartesianVectorArray.TestNamedArrayFunctions.TestPltPlotLikeFunctions,
):
pass


@pytest.mark.parametrize("array", _temporal_spectral_directional_arrays())
class TestTemporalSpectralDirectionalVectorArray(
AbstractTestAbstractTemporalSpectralDirectionalVectorArray,
test_vectors_cartesian.AbstractTestAbstractExplicitCartesianVectorArray,
):
@pytest.mark.parametrize(
argnames="item",
argvalues=[
dict(y=0),
dict(y=slice(None)),
],
)
@pytest.mark.parametrize(
argnames="value",
argvalues=[
700 * u.nm,
],
)
def test__setitem__(
self,
array: na.ScalarArray,
item: dict[str, int | slice | na.ScalarArray] | na.ScalarArray,
value: float | na.ScalarArray,
):
super().test__setitem__(array=array, item=item, value=value)


class AbstractTestAbstractImplicitTemporalSpectralDirectionalVectorArray(
AbstractTestAbstractTemporalSpectralDirectionalVectorArray,
test_vectors_cartesian.AbstractTestAbstractImplicitCartesianVectorArray,
):
pass


class AbstractTestAbstractParameterizedTemporalSpectralDirectionalVectorArray(
AbstractTestAbstractImplicitTemporalSpectralDirectionalVectorArray,
test_vectors_cartesian.AbstractTestAbstractParameterizedCartesianVectorArray,
):
pass


class AbstractTestAbstractTemporalSpectralDirectionalVectorSpace(
AbstractTestAbstractParameterizedTemporalSpectralDirectionalVectorArray,
test_vectors_cartesian.AbstractTestAbstractCartesianVectorSpace,
):
pass


def _temporal_spectral_directional_linear_spaces() -> (
list[na.TemporalSpectralDirectionalVectorLinearSpace]
):
return [
na.TemporalSpectralDirectionalVectorLinearSpace(
start=400 * u.nm,
stop=600 * u.nm,
axis="y",
num=_num_y,
)
]


@pytest.mark.parametrize("array", _temporal_spectral_directional_linear_spaces())
class TestTemporalSpectralDirectionalVectorLinearSpace(
AbstractTestAbstractTemporalSpectralDirectionalVectorSpace,
test_vectors_cartesian.AbstractTestAbstractCartesianVectorLinearSpace,
):
pass


@pytest.mark.parametrize(
argnames="array",
argvalues=[
na.ExplicitTemporalWcsSpectralDirectionalVectorArray(
time=10 * u.s,
crval=na.SpectralDirectionalVectorArray(
wavelength=500 * u.nm,
direction=na.Cartesian2dVectorArray(1, 1) * u.deg,
),
crpix=na.CartesianNdVectorArray(
dict(
wavelength=1,
x=2,
y=3,
)
),
cdelt=na.SpectralDirectionalVectorArray(
wavelength=1 * u.nm,
direction=na.Cartesian2dVectorArray(1, 1) * u.arcsec,
),
pc=na.SpectralDirectionalMatrixArray(
wavelength=na.CartesianNdVectorArray(dict(wavelength=1, x=0, y=0)),
direction=na.Cartesian2dMatrixArray(
x=na.CartesianNdVectorArray(dict(wavelength=0, x=1, y=0)),
y=na.CartesianNdVectorArray(dict(wavelength=0, x=0, y=1)),
),
),
shape_wcs=dict(wavelength=5, x=_num_x, y=_num_y),
),
],
)
class TestExplicitTemporalWcsSpectralDirectionalVectorArray(
AbstractTestAbstractImplicitTemporalSpectralDirectionalVectorArray,
test_vectors.AbstractTestAbstractWcsVector,
):
pass
Loading

0 comments on commit 3bef9ab

Please sign in to comment.