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.14.0 #363

Merged
merged 3 commits into from
Aug 3, 2024
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
16 changes: 8 additions & 8 deletions pyobs/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import datetime
from datetime import datetime, timezone, timedelta, tzinfo, date
import functools
import logging
from typing import Union, Optional, Any, Dict
Expand Down Expand Up @@ -62,7 +62,7 @@ def __init__(
)

@property
def timezone(self) -> datetime.tzinfo:
def timezone(self) -> tzinfo:
"""Returns the timezone of the observatory."""
return self._timezone

Expand All @@ -72,7 +72,7 @@ def location(self) -> Optional[EarthLocation]:
return self._location

@functools.lru_cache()
def localtime(self, utc: Optional[datetime.datetime] = None) -> datetime.datetime:
def localtime(self, utc: Optional[datetime] = None) -> datetime:
"""Returns the local time at the observatory, either for a given UTC time or for now, if none is given.

Args:
Expand All @@ -83,14 +83,14 @@ def localtime(self, utc: Optional[datetime.datetime] = None) -> datetime.datetim
"""
# get UTC
if utc is None:
utc = datetime.datetime.utcnow()
utc = datetime.now(timezone.utc)
# mark as UTC
utc_dt = pytz.utc.localize(utc)
# convert to local timezone
return utc_dt.astimezone(self._timezone)

@functools.lru_cache()
def night_obs(self, time: Optional[Union[datetime.datetime, Time]] = None) -> datetime.date:
def night_obs(self, time: Optional[Union[datetime, Time]] = None) -> date:
"""Returns the date of the night for the given night, i.e. the date of the start of the night.

Args:
Expand All @@ -109,18 +109,18 @@ def night_obs(self, time: Optional[Union[datetime.datetime, Time]] = None) -> da
time = time.datetime

# get local datetime
if not isinstance(time, datetime.datetime):
if not isinstance(time, datetime):
raise ValueError("Invalid time")
utc_dt = pytz.utc.localize(time)
loc_dt = utc_dt.astimezone(self._timezone)

# get night
if loc_dt.hour < 15:
loc_dt += datetime.timedelta(days=-1)
loc_dt += timedelta(days=-1)
return loc_dt.date()

@functools.lru_cache()
def lst(self, time: Union[datetime.datetime, Time]) -> Longitude:
def lst(self, time: Union[datetime, Time]) -> Longitude:
"""Returns the local sidereal time for a given time.

Args:
Expand Down
6 changes: 3 additions & 3 deletions pyobs/modules/camera/basespectrograph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
import datetime
from datetime import datetime, timezone
import logging
from abc import ABCMeta, abstractmethod
from typing import Tuple, Optional, Dict, Any, NamedTuple, List
Expand All @@ -18,7 +18,7 @@
class ExposureInfo(NamedTuple):
"""Info about a running exposure."""

start: datetime.datetime
start: datetime


class BaseSpectrograph(Module, SpectrumFitsHeaderMixin, ISpectrograph, metaclass=ABCMeta):
Expand Down Expand Up @@ -90,7 +90,7 @@ async def __expose(self, broadcast: bool) -> Tuple[Optional[fits.HDUList], Optio
header_futures_before = await self.request_fits_headers(before=True)

# do the exposure
self._exposure = ExposureInfo(start=datetime.datetime.utcnow())
self._exposure = ExposureInfo(start=datetime.now(timezone.utc))
try:
hdulist = await self._expose(abort_event=self.expose_abort)
if hdulist is None or hdulist[0].data is None:
Expand Down
4 changes: 2 additions & 2 deletions pyobs/modules/camera/basevideo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import ABCMeta
from collections.abc import Coroutine
from datetime import datetime
from datetime import datetime, timezone
import io
import logging
import time
Expand Down Expand Up @@ -366,7 +366,7 @@ async def _set_image(self, data: NDArray[Any]) -> None:
# store everything
logging.info("Preparing to catch next image...")
self._next_image = NextImage(
date_obs=datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%f"),
date_obs=datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f"),
image_type=self._image_type,
header_futures=await self.request_fits_headers(),
broadcast=broadcast,
Expand Down
4 changes: 2 additions & 2 deletions pyobs/modules/camera/dummycamera.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import glob
import logging
from datetime import datetime
from datetime import datetime, timezone
from typing import Tuple, NamedTuple, Dict, Any, Optional, TYPE_CHECKING, List

from pyobs.interfaces import IWindow, IBinning, ICooling, IGain
Expand Down Expand Up @@ -122,7 +122,7 @@ async def _expose(self, exposure_time: float, open_shutter: bool, abort_event: a

# start exposure
log.info("Starting exposure with {0:s} shutter...".format("open" if open_shutter else "closed"))
date_obs = datetime.utcnow()
date_obs = datetime.now(timezone.utc)
self._exposing = True

# request image
Expand Down
4 changes: 2 additions & 2 deletions pyobs/modules/camera/dummyspectrograph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import threading
import time
from datetime import datetime
from datetime import datetime, timezone
from typing import Any
import numpy as np
from astropy.io import fits
Expand Down Expand Up @@ -43,7 +43,7 @@ async def _expose(self, abort_event: threading.Event) -> fits.HDUList:
# do exposure
log.info("Starting exposure...")
exposure_time = 1.0
date_obs = datetime.utcnow()
date_obs = datetime.now(timezone.utc)
self._exposing = True
steps = 10
for i in range(steps):
Expand Down
5 changes: 4 additions & 1 deletion pyobs/robotic/lco/scripts/autofocus.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Union, Tuple, Optional, Any
from typing import Union, Tuple, Optional, Any, cast

from pyobs.interfaces import IRoof, ITelescope, IAcquisition, IAutoFocus
from pyobs.robotic import TaskRunner
Expand Down Expand Up @@ -154,5 +154,8 @@ async def run(
raise ValueError("No autofocus given.")
await autofocus.auto_focus(self._count, self._step, self._exptime)

# finally, stop telescope
await cast(ITelescope, telescope).stop_motion()


__all__ = ["LcoAutoFocusScript"]
4 changes: 2 additions & 2 deletions pyobs/robotic/scripts/conditional.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

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

Expand Down Expand Up @@ -45,7 +45,7 @@ async def run(
task_archive: Optional[TaskArchive] = None,
) -> None:
# evaluate condition
ret = eval(self.condition, {"now": datetime.datetime.utcnow()})
ret = eval(self.condition, {"now": datetime.now(timezone.utc)})

# run scripts
if ret:
Expand Down
12 changes: 6 additions & 6 deletions pyobs/utils/average.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import datetime
from datetime import datetime, timezone
from typing import List, Optional, Tuple

import numpy as np
Expand All @@ -7,16 +7,16 @@
class RollingTimeAverage(object):
def __init__(self, interval: float):
self._interval = interval
self._values: List[Tuple[datetime.datetime, float]] = []
self._start_time = datetime.datetime.utcnow()
self._values: List[Tuple[datetime, float]] = []
self._start_time = datetime.now(timezone.utc)

def clear(self) -> None:
self._values = []
self._start_time = datetime.datetime.utcnow()
self._start_time = datetime.now(timezone.utc)

def add(self, value: float) -> None:
# add value
now = datetime.datetime.utcnow()
now = datetime.now(timezone.utc)
self._values.append((now, value))

# clean up
Expand All @@ -28,7 +28,7 @@ def average(self, min_interval: Optional[float] = None) -> Optional[float]:
return None

# get time
now = datetime.datetime.utcnow()
now = datetime.now(timezone.utc)

# go no values older than now-interval?
if min_interval:
Expand Down
8 changes: 4 additions & 4 deletions pyobs/utils/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
__title__ = "Time"

import datetime
from datetime import datetime, timezone, date, timedelta
from typing import cast

import astropy.time
Expand Down Expand Up @@ -43,10 +43,10 @@ def now(cls) -> "Time":
such a subclass) at the current time.
"""
# call `utcnow` immediately to be sure it's ASAP
dtnow = datetime.datetime.utcnow()
dtnow = datetime.now(timezone.utc)
return cast(Time, Time(val=dtnow, format="datetime", scale="utc") + Time._now_offset)

def night_obs(self, observer: Observer) -> datetime.date:
def night_obs(self, observer: Observer) -> date:
"""Returns the night for this time, i.e. the date of the start of the current night.

Args:
Expand All @@ -65,7 +65,7 @@ def night_obs(self, observer: Observer) -> datetime.date:

# get night
if loc_dt.hour < 15:
loc_dt += datetime.timedelta(days=-1)
loc_dt += timedelta(days=-1)
return loc_dt.date()


Expand Down
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.13.4"
version = "1.14.0"
description = "robotic telescope software"
authors = ["Tim-Oliver Husser <[email protected]>"]
license = "MIT"
Expand Down
Loading