Skip to content

Commit

Permalink
Added moon masker for night pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanHydrogen committed Aug 21, 2024
1 parent 56cd1a5 commit 104cbe3
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 46 deletions.
3 changes: 3 additions & 0 deletions example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ pipelines:
# Under which limiting magnitude a pixel is considered cloudy (in mag)
threshold: 5.5

# Apparent size of the moon in the allsky image in degree
moon_apparent_size: 0.5

coverage_info:
# Altitude which is considered to be the lower boundary of the zenith to average for the zenith cloud fraction measurement (in degree)
zenith_altitude: 80
2 changes: 2 additions & 0 deletions night_integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ modules:
cloud_map:
threshold: 5.5

moon_apparent_size: 10.0

coverage_info:
zenith_altitude: 80

Expand Down

This file was deleted.

18 changes: 18 additions & 0 deletions pyobs_cloudcover/pipeline/night/moon_masker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import datetime

import numpy as np
from cloudmap_rs import SkyPixelQuery, AltAzCoord

from astroplan import Observer


class MoonMasker:
def __init__(self, moon_apparent_size: float, observer: Observer):
self._moon_apparent_size = moon_apparent_size
self._observer = observer

def __call__(self, sky_query: SkyPixelQuery, obs_time: datetime.datetime) -> SkyPixelQuery:
moon_alt_az = self._observer.moon_altaz(obs_time)
sky_query.mask_radius(AltAzCoord(moon_alt_az.alt.rad, moon_alt_az.az.rad), np.deg2rad(self._moon_apparent_size))

return sky_query
4 changes: 4 additions & 0 deletions pyobs_cloudcover/pipeline/night/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pyobs_cloudcover.pipeline.night.lim_magnitude_map_generator.lim_magnitude_map_generator import LimMagnitudeMapGenerator
from pyobs_cloudcover.pipeline.night.preprocessor.preprocessor import Preprocessor
from pyobs_cloudcover.pipeline.night.star_reverse_matcher.star_reverse_matcher import StarReverseMatcher
from pyobs_cloudcover.pipeline.night.moon_masker import MoonMasker
from pyobs_cloudcover.pipeline.pipeline import Pipeline


Expand All @@ -24,6 +25,7 @@ def __init__(self,
star_reverse_matcher: StarReverseMatcher,
lim_magnitude_map_generator: LimMagnitudeMapGenerator,
cloud_map_generator: CloudMapGenerator,
moon_masker: MoonMasker,
coverage_info_calculator: CoverageInfoCalculator) -> None:

self._preprocess = preprocess
Expand All @@ -32,6 +34,7 @@ def __init__(self,
self._alt_az_list_generator = alt_az_list_generator
self._lim_magnitude_map_generator = lim_magnitude_map_generator
self._cloud_map_generator = cloud_map_generator
self._moon_masker = moon_masker
self._coverage_info_calculator = coverage_info_calculator

def __call__(self, image: npt.NDArray[np.float_], obs_time: datetime.datetime) -> CloudCoverageInfo:
Expand All @@ -46,5 +49,6 @@ def __call__(self, image: npt.NDArray[np.float_], obs_time: datetime.datetime) -
lim_mag_map = self._lim_magnitude_map_generator(catalog, matches, alt_az_list)
cloud_map = self._cloud_map_generator(lim_mag_map)
sky_query = SkyPixelQuery(alt_az_list, cloud_map)
sky_query = self._moon_masker(sky_query, obs_time)

return self._coverage_info_calculator(sky_query, obs_time)
3 changes: 3 additions & 0 deletions pyobs_cloudcover/pipeline/night/pipeline_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pyobs_cloudcover.cloud_info_calculator import CloudInfoCalculatorFactory
from pyobs_cloudcover.pipeline.night.cloud_map_generator.cloud_map_generator_factory import CloudMapGeneratorFactory
from pyobs_cloudcover.pipeline.night.lim_magnitude_map_generator.lim_magnitude_map_generator_factory import LimMagnitudeMapGeneratorFactory
from pyobs_cloudcover.pipeline.night.moon_masker import MoonMasker
from pyobs_cloudcover.pipeline.night.pipeline import NightPipeline
from pyobs_cloudcover.pipeline.night.pipeline_options import NightPipelineOptions
from pyobs_cloudcover.pipeline.night.preprocessor.preprocessor_factory import PreprocessorFactory
Expand Down Expand Up @@ -37,6 +38,7 @@ def __call__(self, options: NightPipelineOptions) -> NightPipeline:
lin_mag_map_generator = lim_mag_map_generator_factory()
cloud_map_generator = cloud_map_generator_factory()
coverage_info_calculator = coverage_info_calculator_factory()
moon_masker = MoonMasker(options.moon_apparent_size, self._observer)

pipeline = NightPipeline(
preprocessor,
Expand All @@ -45,6 +47,7 @@ def __call__(self, options: NightPipelineOptions) -> NightPipeline:
star_reverse_matcher,
lin_mag_map_generator,
cloud_map_generator,
moon_masker,
coverage_info_calculator
)

Expand Down
8 changes: 6 additions & 2 deletions pyobs_cloudcover/pipeline/night/pipeline_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def __init__(self,
star_matcher_options: StarReverseMatcherOptions,
lim_mag_map_generator_options: LimMagnitudeMapGeneratorOptions,
cloud_generator_options: CloudMapGeneratorOptions,
altaz_grid_options: AltAzGridOptions
altaz_grid_options: AltAzGridOptions,
moon_apparent_size: float
) -> None:

self.model_options = model_options
Expand All @@ -29,6 +30,7 @@ def __init__(self,
self.star_matcher_options = star_matcher_options
self.lim_mag_map_generator_options = lim_mag_map_generator_options
self.cloud_generator_options = cloud_generator_options
self.moon_apparent_size = moon_apparent_size

@classmethod
def from_dict(cls, options: Dict[str, Dict[str, Any]]) -> NightPipelineOptions:
Expand All @@ -39,12 +41,14 @@ def from_dict(cls, options: Dict[str, Dict[str, Any]]) -> NightPipelineOptions:
lim_mag_map_generator_options = LimMagnitudeMapGeneratorOptions.from_dict(options.get("lim_mag_map", {}))
cloud_map_generator_options = CloudMapGeneratorOptions.from_dict(options.get("cloud_map", {}))
altaz_grid_generator = AltAzGridOptions.from_dict(options.get("altaz_grid", {}))
moon_apparent_size = options.get("moon_apparent_size", 10)

return cls(model_options,
preprocessor_options,
catalog_options,
star_matcher_options,
lim_mag_map_generator_options,
cloud_map_generator_options,
altaz_grid_generator
altaz_grid_generator,
moon_apparent_size
)
5 changes: 4 additions & 1 deletion tests/integration/test_night_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pyobs_cloudcover.pipeline.night.cloud_map_generator.cloud_map_generator import CloudMapGenerator
from pyobs_cloudcover.pipeline.night.lim_magnitude_map_generator.lim_magnitude_map_generator import \
LimMagnitudeMapGenerator
from pyobs_cloudcover.pipeline.night.moon_masker import MoonMasker
from pyobs_cloudcover.pipeline.night.pipeline import NightPipeline
from pyobs_cloudcover.pipeline.night.preprocessor.image_binner import ImageBinner
from pyobs_cloudcover.pipeline.night.preprocessor.image_masker import ImageMasker
Expand Down Expand Up @@ -53,9 +54,11 @@ def test_night_pipeline() -> None:
cloud_map_gen = CloudMapGenerator(0.5)
lim_mag_map_generator = LimMagnitudeMapGenerator(50.0)

moon_masker = MoonMasker(10, observer)

coverage_change_calculator = CoverageChangeCalculator()
cloud_coverage_info_calculator = CoverageInfoCalculator(coverage_change_calculator)

pipeline = NightPipeline(preprocessor, catalog_constructor, altaz_list_generator, reverse_matcher, lim_mag_map_generator, cloud_map_gen, cloud_coverage_info_calculator)
pipeline = NightPipeline(preprocessor, catalog_constructor, altaz_list_generator, reverse_matcher, lim_mag_map_generator, cloud_map_gen, moon_masker, cloud_coverage_info_calculator)

pipeline(image, obs_time)
4 changes: 3 additions & 1 deletion tests/integration/test_night_pipeline_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def test_night_pipeline() -> None:
},
"cloud_map": {
"threshold": 0.5
}
},

"moon_apparent_size": 10.0
}

pipeline_options = NightPipelineOptions.from_dict(pipeline_kwargs)
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/test_pipeline_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def test_night_pipeline() -> None:
},
"cloud_map": {
"threshold": 0.5
}
},
"moon_apparent_size": 10.0

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import numpy as np

from pyobs_cloudcover.pipeline.night.cloud_coverage_calculator.coverage_change_calculator import \
CoverageChangeCalculator
from pyobs_cloudcover.cloud_info_calculator.coverage_change_calculator import CoverageChangeCalculator


def test_fist():
cloud_map = np.ones((2, 2))
calculator = CoverageChangeCalculator(threshold=0.5)
def test_first():
cloud_map = [True, True, False]
calculator = CoverageChangeCalculator()
assert calculator(cloud_map) is None


def test_call_nan_filter():
calculator = CoverageChangeCalculator(threshold=0.5)
calculator._last_map = np.identity(2)
calculator = CoverageChangeCalculator()
calculator._last_map = [True, True, False, False]

cloud_map = np.ones((2, 2))
cloud_map[0, 0] = np.nan
cloud_map = [None, True, True, True]

assert calculator(cloud_map) == 2/3


def test_multi_call():
calculator = CoverageChangeCalculator(threshold=0.5)
calculator(np.ones((2, 2)))
assert calculator(np.identity(2)) == 0.5
assert calculator(np.zeros((2, 2))) == 0.5
calculator = CoverageChangeCalculator()
calculator([True, True, False, False])
assert calculator([False, True, False, True]) == 0.5
assert calculator([True, True, True, True]) == 0.5

0 comments on commit 104cbe3

Please sign in to comment.