diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 86d4083..fcfc28b 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -10,8 +10,8 @@ jobs: - name: Check out repository code uses: actions/checkout@v4 - - name: Install poetry - run: pipx install poetry + #- name: Install poetry + # run: pipx install poetry - name: Install maturin run: pipx install maturin @@ -20,10 +20,10 @@ jobs: uses: actions/setup-python@v5 with: python-version: '3.11' - cache: 'poetry' + cache: 'maturin' - - run: poetry install --all-extras - - run: poetry run maturin develop --release + #- run: poetry install --all-extras + - run: poetry run maturin develop --release --all-features - run: poetry run pytest -v mypy: @@ -34,8 +34,8 @@ jobs: - name: Check out repository code uses: actions/checkout@v4 - - name: Install poetry - run: pipx install poetry + #- name: Install poetry + # run: pipx install poetry - name: Install maturin run: pipx install maturin @@ -44,8 +44,8 @@ jobs: uses: actions/setup-python@v5 with: python-version: '3.11' - cache: 'poetry' + cache: 'maturin' - - run: poetry install --all-extras - - run: poetry run maturin develop --release + #- run: poetry install --all-extras + - run: poetry run maturin develop --release --all-features - run: poetry run mypy ./pyobs_cloudcover \ No newline at end of file diff --git a/example.yaml b/example.yaml index 16b59bf..b7f60b8 100644 --- a/example.yaml +++ b/example.yaml @@ -1,8 +1,24 @@ class: pyobs_cloudcover.application.Application +image_sender: "allskycam" + model: class: pyobs_cloudcover.world_model.SimpleModel - args: [4.81426598e-03, 2.00000000e+00, 1.06352627e+03, 7.57115607e+02, 5.11194838e+02] + a0: 4.81426598e-03 + F: 2.00000000e+00 + R: 1.06352627e+03 + c_x: 7.57115607e+02 + c_y: 5.11194838e+02 + +server: + url: "localhost" + port: 8080 + +measurement_log: + url: "" + bucket: "" + org: "" + token: "" pipelines: night: @@ -12,13 +28,13 @@ pipelines: options: preprocessor: - mask_filepath: "" + mask_filepath: "tests/integration/mask.npy" bin_size: 2 bkg_sigma_clip: 3.0 bkg_box_size: (5, 5) catalog: - filepath: "" + filepath: "tests/integration/catalog.csv" filter: alt: 30.0 v_mag: 7.0 diff --git a/pyobs_cloudcover/application.py b/pyobs_cloudcover/application.py index cad8e3c..3398680 100644 --- a/pyobs_cloudcover/application.py +++ b/pyobs_cloudcover/application.py @@ -1,14 +1,57 @@ +import datetime +from typing import Dict, Any + +from pyobs.events import NewImageEvent, Event from pyobs.modules import Module +from pyobs.object import get_object +from pyobs_cloudcover.measurement_log.influx import Influx +from pyobs_cloudcover.pipeline.pipeline_controller_factory import PipelineControllerFactory from pyobs_cloudcover.web_api.server import Server +from pyobs_cloudcover.web_api.server_factory import ServerFactory +from pyobs_cloudcover.world_model import WorldModel class Application(Module): - def __init__(self) -> None: + def __init__(self, + image_sender: str, + model: Dict[str, Any], + server: Dict[str, Any], + measurement_log: Dict[str, Any], + pipelines: Dict[str, Dict[str, Any]]) -> None: + super(Application, self).__init__() - #self._server = Server() + self._image_sender = image_sender + + world_model: WorldModel = get_object(model, WorldModel) + + server_factory = ServerFactory(self.observer, world_model) + self._server = server_factory(server) + + self._measurement_log = Influx(**measurement_log) + + pipeline_controller_factory = PipelineControllerFactory(self.observer, world_model) + self._pipeline_controller = pipeline_controller_factory(pipelines) async def open(self) -> None: await super(Application, self).open() - #await self._server.start() + await self._server.start() + + await self.comm.register_event(NewImageEvent, self.process_new_image) + + async def process_new_image(self, event: Event, sender: str) -> None: + if not isinstance(event, NewImageEvent): + return + + if sender != self._image_sender: + return + + image = await self.vfs.read_image(event.filename) + + obs_time = datetime.datetime.strptime(image.header["DATE-OBS"], "%Y-%m-%dT%H:%M:%S.%f") + + measurement = self._pipeline_controller(image.data, obs_time) + + if measurement is not None: + self._server.set_measurement(measurement) \ No newline at end of file diff --git a/pyobs_cloudcover/web_api/server.py b/pyobs_cloudcover/web_api/server.py index a6078f9..a919159 100644 --- a/pyobs_cloudcover/web_api/server.py +++ b/pyobs_cloudcover/web_api/server.py @@ -1,5 +1,6 @@ from aiohttp import web +from pyobs_cloudcover.cloud_coverage_info import CloudCoverageInfo from pyobs_cloudcover.web_api.coverage_query_executor import CoverageQueryExecutor @@ -14,6 +15,9 @@ def __init__(self, query_executor: CoverageQueryExecutor, url: str = "localhost" app.add_routes([web.get("/query", self.query)]) self._runner = web.AppRunner(app) + def set_measurement(self, measurement: CloudCoverageInfo) -> None: + self._query_executor.set_measurement(measurement) + async def start(self) -> None: await self._runner.setup() site = web.TCPSite(self._runner, 'localhost', self._port) diff --git a/pyobs_cloudcover/web_api/server_factory.py b/pyobs_cloudcover/web_api/server_factory.py new file mode 100644 index 0000000..6ee0ee1 --- /dev/null +++ b/pyobs_cloudcover/web_api/server_factory.py @@ -0,0 +1,18 @@ +from typing import Dict, Any + +from astroplan import Observer + +from pyobs_cloudcover.pipeline.night.star_reverse_matcher.window import ImageWindow +from pyobs_cloudcover.web_api.coverage_query_executor import CoverageQueryExecutor +from pyobs_cloudcover.web_api.server import Server +from pyobs_cloudcover.world_model import WorldModel + + +class ServerFactory(object): + def __init__(self, observer: Observer, model: WorldModel) -> None: + window = ImageWindow(10) + self._executor = CoverageQueryExecutor(model, observer, window) + + def __call__(self, config: Dict[str, Any]) -> Server: + server = Server(query_executor=self._executor, **config) + return server diff --git a/pyproject.toml b/pyproject.toml index da8126a..550755a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,5 +36,21 @@ classifiers = [ "Programming Language :: Python :: Implementation :: PyPy", ] dynamic = ["version"] + +dependencies = [ + "pyobs-core[full]>=1.13.0", + "influxdb-client>=1.42.0" +] + +[project.optional-dependencies] +test = [ + "pytest>=7.4.0", + "pytest-cov>=4.1.0", + "pytest-mock>=3.11.1", + "pytest-asyncio>=0.21.1", + "mypy>=1.9.0" +] + [tool.maturin] features = ["pyo3/extension-module"] +python-packages = ["pyobs_cloudcover"] \ No newline at end of file