-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b234f6e
commit 4a49e93
Showing
21 changed files
with
255 additions
and
2,903 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
37 changes: 37 additions & 0 deletions
37
pyobs_cloudcover/pipeline/night/altaz_map_generator/altaz_map_generator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import functools | ||
from typing import List, Optional, Tuple | ||
|
||
import numpy as np | ||
import numpy.typing as npt | ||
from cloudmap_rs import AltAzCoord | ||
|
||
from pyobs_cloudcover.world_model import WorldModel | ||
|
||
|
||
class AltAzMapGenerator: | ||
def __init__(self, model: WorldModel, limiting_altitude: float): | ||
self._model = model | ||
self._limiting_altitude = limiting_altitude | ||
|
||
@functools.lru_cache(maxsize=None) | ||
def __call__(self, image_height: int, image_width: int) -> List[List[Optional[AltAzCoord]]]: | ||
x = np.arange(0, image_width) | ||
y = np.arange(0, image_height) | ||
|
||
meshed_x, meshed_y = np.meshgrid(x, y) | ||
|
||
alt, az = self._model.pix_to_altaz(meshed_x, meshed_y) | ||
alt_az_coords = np.dstack((alt, az)) | ||
|
||
return [ | ||
[ | ||
self._alt_az_convert(coord) | ||
for coord in row | ||
] for row in alt_az_coords | ||
] | ||
|
||
def _alt_az_convert(self, alt_az_coords: Tuple[float, float]) -> Optional[AltAzCoord]: | ||
if alt_az_coords[0] < np.deg2rad(self._limiting_altitude): | ||
return None | ||
else: | ||
return AltAzCoord(*alt_az_coords) |
12 changes: 12 additions & 0 deletions
12
pyobs_cloudcover/pipeline/night/altaz_map_generator/altaz_map_generator_factory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from pyobs_cloudcover.pipeline.night.altaz_map_generator.altaz_map_generator import AltAzMapGenerator | ||
from pyobs_cloudcover.pipeline.night.catalog.catalog_constructor_options import CatalogConstructorOptions | ||
from pyobs_cloudcover.world_model import WorldModel | ||
|
||
|
||
class AltAzMapGeneratorFactory(object): | ||
def __init__(self, options: CatalogConstructorOptions, model: WorldModel): | ||
self._limiting_altitude = options.alt_filter | ||
self._model = model | ||
|
||
def __call__(self) -> AltAzMapGenerator: | ||
return AltAzMapGenerator(self._model, self._limiting_altitude) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import datetime | ||
|
||
from astroplan import Observer | ||
from astropy.coordinates import Angle | ||
|
||
|
||
class HourAngleConverter(object): | ||
def __init__(self, observer: Observer): | ||
self._observer = observer | ||
|
||
def __call__(self, ra: Angle, obs_time: datetime.datetime) -> float: | ||
lst = self._observer.local_sidereal_time(obs_time) | ||
self._lst = Angle(lst, unit="hourangle") | ||
|
||
return float((self._lst - ra).rad) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import datetime | ||
from typing import Union, Tuple | ||
|
||
import numpy as np | ||
from astroplan import Observer | ||
from astropy.coordinates import Angle, SkyCoord | ||
from astropy.wcs import WCS | ||
from numpy import typing as npt | ||
|
||
from pyobs_cloudcover.world_model import WorldModel | ||
from pyobs_cloudcover.world_model.hour_angle_converter import HourAngleConverter | ||
|
||
from astropy import units as u | ||
|
||
|
||
class WCSModel(WorldModel): | ||
def __init__(self, wcs: WCS, observer: Observer, config_obs_time: datetime.datetime) -> None: | ||
self._wcs = wcs | ||
self._observer = observer | ||
self._config_obs_time = config_obs_time | ||
|
||
self._ha_conv = HourAngleConverter(observer) | ||
|
||
def pix_to_altaz(self, x: Union[npt.NDArray[np.float_], float], y: Union[npt.NDArray[np.float_], float]) -> \ | ||
Union[Tuple[npt.NDArray[np.float_], npt.NDArray[np.float_]], Tuple[float, float]]: | ||
|
||
coord = self._wcs.pixel_to_world(x, y) | ||
ha = self._ha_conv(Angle(coord.ra.deg, unit="deg"), self._config_obs_time) | ||
|
||
coord = SkyCoord(ra=ha * u.rad, dec=coord.dec, location=self._observer.location, obstime=self._config_obs_time) | ||
coord = coord.transform_to("altaz") | ||
return coord.alt.rad, coord.az.rad | ||
|
||
def altaz_to_pix(self, alt: Union[npt.NDArray[np.float_], float], az: Union[npt.NDArray[np.float_], float]) -> \ | ||
Union[Tuple[npt.NDArray[np.float_], npt.NDArray[np.float_]], Tuple[float, float]]: | ||
|
||
coord = SkyCoord(alt=alt * u.rad, az=az * u.rad, frame="altaz", | ||
location=self._observer.location, obstime=self._config_obs_time) | ||
coord = coord.transform_to(frame="icrs") | ||
ha = self._ha_conv(Angle(coord.ra.deg, unit="deg"), self._config_obs_time) | ||
|
||
coord = SkyCoord(ra=ha * u.rad, dec=coord.dec, location=self._observer.location, obstime=self._config_obs_time) | ||
|
||
pixel = self._wcs.world_to_pixel(coord) | ||
return pixel[0], pixel[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import datetime | ||
|
||
from astroplan import Observer | ||
from astropy.wcs import WCS | ||
from pyobs.images import Image | ||
|
||
from astropy import units as u | ||
from pyobs_cloudcover.world_model.wcs_model import WCSModel | ||
|
||
|
||
class WCSModelLoader(object): | ||
def __init__(self, file_path: str) -> None: | ||
self._file_path = file_path | ||
|
||
def __call__(self) -> WCSModel: | ||
wcs_image = Image.from_file(self._file_path) | ||
|
||
wcs = WCS(header=wcs_image.header) | ||
config_obs_time = datetime.datetime.fromisoformat(wcs_image.header["DATE-OBS"]) | ||
|
||
observer = Observer( | ||
latitude=wcs_image.header["LATITUDE"] * u.deg, | ||
longitude=wcs_image.header["LONGITUD"] * u.deg, | ||
elevation=wcs_image.header["HEIGHT"] * u.m, | ||
) | ||
|
||
return WCSModel(wcs=wcs, observer=observer, config_obs_time=config_obs_time) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.