|
| 1 | +import abc |
| 2 | +import dataclasses |
| 3 | +import numpy as np |
| 4 | +import astropy.units as u |
| 5 | +import named_arrays as na |
| 6 | +import optika |
| 7 | + |
| 8 | +__all__ = [ |
| 9 | + "CentralObscuration", |
| 10 | +] |
| 11 | + |
| 12 | + |
| 13 | +@dataclasses.dataclass(eq=False, repr=False) |
| 14 | +class AbstractCentralObscuration( |
| 15 | + optika.mixins.Printable, |
| 16 | + optika.mixins.Translatable, |
| 17 | +): |
| 18 | + @property |
| 19 | + @abc.abstractmethod |
| 20 | + def num_folds(self) -> int: |
| 21 | + """the order of the rotational symmetry of the optical system""" |
| 22 | + |
| 23 | + @property |
| 24 | + @abc.abstractmethod |
| 25 | + def halfwidth(self) -> u.Quantity | na.AbstractScalar: |
| 26 | + """distance from the center to the edge of the obscuration""" |
| 27 | + |
| 28 | + @property |
| 29 | + def radius(self) -> u.Quantity | na.AbstractScalar: |
| 30 | + """ |
| 31 | + distance from the center to a vertex of the obscuration |
| 32 | + """ |
| 33 | + return self.halfwidth / np.cos(360 * u.deg / self.num_folds / 2) |
| 34 | + |
| 35 | + @property |
| 36 | + @abc.abstractmethod |
| 37 | + def remove_last_vertex(self) -> bool: |
| 38 | + """flag controlling whether the last vertex should be removed""" |
| 39 | + |
| 40 | + @property |
| 41 | + def surface(self) -> optika.surfaces.Surface: |
| 42 | + num_folds = self.num_folds |
| 43 | + radius = self.radius |
| 44 | + offset_angle = 360 * u.deg / num_folds |
| 45 | + angle = na.linspace( |
| 46 | + start=0 * u.deg, |
| 47 | + stop=360 * u.deg, |
| 48 | + num=num_folds, |
| 49 | + axis="vertex", |
| 50 | + endpoint=False, |
| 51 | + ) |
| 52 | + if self.remove_last_vertex: |
| 53 | + angle = angle[dict(vertex=slice(None, ~0))] |
| 54 | + angle = angle - offset_angle |
| 55 | + return optika.surfaces.Surface( |
| 56 | + name="obscuration", |
| 57 | + aperture=optika.apertures.PolygonalAperture( |
| 58 | + vertices=na.Cartesian3dVectorArray( |
| 59 | + x=radius * np.cos(angle), |
| 60 | + y=radius * np.sin(angle), |
| 61 | + z=0 * u.mm, |
| 62 | + ), |
| 63 | + inverted=True, |
| 64 | + ), |
| 65 | + transformation=self.transformation, |
| 66 | + ) |
| 67 | + |
| 68 | + |
| 69 | +@dataclasses.dataclass(eq=False, repr=False) |
| 70 | +class CentralObscuration( |
| 71 | + AbstractCentralObscuration, |
| 72 | +): |
| 73 | + num_folds: int = 0 |
| 74 | + halfwidth: u.Quantity | na.AbstractScalar = 0 * u.mm |
| 75 | + remove_last_vertex: bool = False |
| 76 | + translation: u.Quantity | na.AbstractCartesian3dVectorArray = 0 * u.mm |
0 commit comments