Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoBektesevic committed Aug 19, 2024
1 parent fe26398 commit 1b81849
Show file tree
Hide file tree
Showing 13 changed files with 1,785 additions and 829 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ dependencies = [
"PyYAML>=6.0"
]

[project.scripts]
archiveheaders = "kbmod.mocking.dump_headers:main"

[project.urls]
Documentation = "https://epyc.astro.washington.edu/~kbmod/"
Repository = "https://github.com/dirac-institute/kbmod"
Expand Down
2 changes: 1 addition & 1 deletion src/kbmod/mocking/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from . import utils
from .catalogs import *
from .headers import *
from .fits_data import *
from .data import *
from .fits import *
from .callbacks import *
68 changes: 55 additions & 13 deletions src/kbmod/mocking/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,82 @@
from astropy.time import Time
import astropy.units as u


__all__ = [
"IncrementObstime",
"ObstimeIterator",
"ObstimeIterator"
]


class IncrementObstime:
"""Endlessly incrementing FITS-standard timestamp.
Parameters
----------
start : `astropy.time.Time`
Starting timestamp, or a value from which AstroPy can instantiate one.
dt : `float` or `astropy.units.Quantity`
Size of time-step to take. Assumed to be in days by default.
Examples
--------
>>> from kbmod.mocking import IncrementObstime
>>> obst = IncrementObstime("2021-01-01T00:00:00.0000", 1)
>>> obst()
'2021-01-01T00:00:00.000'
>>> obst()
'2021-01-02T00:00:00.000'
>>> import astropy.units as u
>>> obst = IncrementObstime("2021-01-01T00:00:00.0000", 1*u.hour)
>>> obst(); obst()
'2021-01-01T00:00:00.000'
'2021-01-01T01:00:00.000'
"""
default_unit = "day"
def __init__(self, start, dt):
self.start = Time(start)
if not isinstance(dt, u.Quantity):
dt = dt * getattr(u, self.default_unit)
self.dt = dt

def __call__(self, header_val):
def __call__(self, header=None):
curr = self.start
self.start += self.dt
return curr.fits


class ObstimeIterator:
def __init__(self, obstimes, **kwargs):
self.obstimes = Time(obstimes, **kwargs)
self.generator = (t for t in obstimes)
"""Iterate through given timestamps.
def __call__(self, header_val):
return Time(next(self.generator)).fits
Parameters
----------
obstimes : `astropy.time.Time`
Starting timestamp, or a value from which AstroPy can instantiate one.
Raises
------
StopIteration
When all the obstimes are exhausted.
class DitherValue:
def __init__(self, value, dither_range):
self.value = value
self.dither_range = dither_range
Examples
--------
>>> from astropy.time import Time
>>> times = Time(range(60310, 60313, 1), format="mjd")
>>> from kbmod.mocking import ObstimeIterator
>>> obst = ObstimeIterator(times)
>>> obst(); obst(); obst(); obst()
'2024-01-01T00:00:00.000'
'2024-01-02T00:00:00.000'
'2024-01-03T00:00:00.000'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/local/tmp/kbmod/src/kbmod/mocking/callbacks.py", line 49, in __call__
def __call__(self, header_val):
return self.value + random.uniform(self.dither_range)
StopIteration
"""
def __init__(self, obstimes, **kwargs):
self.obstimes = Time(obstimes, **kwargs)
self.generator = (t for t in obstimes)

def __call__(self, header=None):
return Time(next(self.generator)).fits
Loading

0 comments on commit 1b81849

Please sign in to comment.