Skip to content

Commit

Permalink
Integrated application
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanHydrogen committed Apr 19, 2024
1 parent 94948d4 commit 97ded87
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 16 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
22 changes: 19 additions & 3 deletions example.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
49 changes: 46 additions & 3 deletions pyobs_cloudcover/application.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions pyobs_cloudcover/web_api/server.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions pyobs_cloudcover/web_api/server_factory.py
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit 97ded87

Please sign in to comment.