Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.6.12 #310

Merged
merged 3 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _build_request_data(self):
"scale_high": scale * 1.1,
"radius": self._radius,
"crpix-x": self._header["CRPIX1"],
"crpix-y": self._header["CRPIX1"],
"crpix-y": self._header["CRPIX2"],
"nx": self._header["NAXIS1"],
"ny": self._header["NAXIS2"],
"x": self._catalog["x"].tolist(),
Expand Down
1 change: 1 addition & 0 deletions pyobs/robotic/scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from .sequential import SequentialRunner
from .parallel import ParallelRunner
from .selector import SelectorScript
from .conditional import ConditionalRunner
58 changes: 58 additions & 0 deletions pyobs/robotic/scripts/conditional.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from __future__ import annotations

import datetime
import logging
from typing import Any, Dict, Optional, List, TYPE_CHECKING

if TYPE_CHECKING:
from pyobs.robotic import TaskRunner, TaskSchedule, TaskArchive
from pyobs.robotic.scripts import Script

log = logging.getLogger(__name__)


class ConditionalRunner(Script):
"""Script for running an if condition."""

__module__ = "pyobs.modules.robotic"

def __init__(
self,
condition: str,
true: Dict[str, Any],
false: Optional[Dict[str, Any]] = None,
**kwargs: Any,
):
"""Initialize a new ConditionalRunner.

Args:
condition: condition to check
true: script to run if condition is evaluated as True
false: script to run otherwise.
"""
Script.__init__(self, **kwargs)
self.condition = condition
self.true = true
self.false = false

async def can_run(self) -> bool:
return True

async def run(
self,
task_runner: TaskRunner,
task_schedule: Optional[TaskSchedule] = None,
task_archive: Optional[TaskArchive] = None,
) -> None:
# evaluate condition
ret = eval(self.condition, {"now": datetime.datetime.utcnow()})

# run scripts
if ret:
await self.get_object(self.true, Script).run(task_runner, task_schedule, task_archive)
else:
if self.false is not None:
await self.get_object(self.false, Script).run(task_runner, task_schedule, task_archive)


__all__ = ["ConditionalRunner"]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "pyobs-core"
packages = [{ include = "pyobs" }]
version = "1.6.11"
version = "1.6.12"
description = "robotic telescope software"
authors = ["Tim-Oliver Husser <[email protected]>"]
license = "MIT"
Expand Down