|
3 | 3 | from astropy.time import Time
|
4 | 4 | import astropy.units as u
|
5 | 5 |
|
| 6 | + |
6 | 7 | __all__ = [
|
7 | 8 | "IncrementObstime",
|
8 |
| - "ObstimeIterator", |
| 9 | + "ObstimeIterator" |
9 | 10 | ]
|
10 | 11 |
|
11 | 12 |
|
12 | 13 | class IncrementObstime:
|
| 14 | + """Endlessly incrementing FITS-standard timestamp. |
| 15 | +
|
| 16 | + Parameters |
| 17 | + ---------- |
| 18 | + start : `astropy.time.Time` |
| 19 | + Starting timestamp, or a value from which AstroPy can instantiate one. |
| 20 | + dt : `float` or `astropy.units.Quantity` |
| 21 | + Size of time-step to take. Assumed to be in days by default. |
| 22 | +
|
| 23 | + Examples |
| 24 | + -------- |
| 25 | + >>> from kbmod.mocking import IncrementObstime |
| 26 | + >>> obst = IncrementObstime("2021-01-01T00:00:00.0000", 1) |
| 27 | + >>> obst() |
| 28 | + '2021-01-01T00:00:00.000' |
| 29 | + >>> obst() |
| 30 | + '2021-01-02T00:00:00.000' |
| 31 | + >>> import astropy.units as u |
| 32 | + >>> obst = IncrementObstime("2021-01-01T00:00:00.0000", 1*u.hour) |
| 33 | + >>> obst(); obst() |
| 34 | + '2021-01-01T00:00:00.000' |
| 35 | + '2021-01-01T01:00:00.000' |
| 36 | + """ |
13 | 37 | default_unit = "day"
|
14 | 38 | def __init__(self, start, dt):
|
15 | 39 | self.start = Time(start)
|
16 | 40 | if not isinstance(dt, u.Quantity):
|
17 | 41 | dt = dt * getattr(u, self.default_unit)
|
18 | 42 | self.dt = dt
|
19 | 43 |
|
20 |
| - def __call__(self, header_val): |
| 44 | + def __call__(self, header=None): |
21 | 45 | curr = self.start
|
22 | 46 | self.start += self.dt
|
23 | 47 | return curr.fits
|
24 | 48 |
|
25 | 49 |
|
26 | 50 | class ObstimeIterator:
|
27 |
| - def __init__(self, obstimes, **kwargs): |
28 |
| - self.obstimes = Time(obstimes, **kwargs) |
29 |
| - self.generator = (t for t in obstimes) |
| 51 | + """Iterate through given timestamps. |
30 | 52 |
|
31 |
| - def __call__(self, header_val): |
32 |
| - return Time(next(self.generator)).fits |
| 53 | + Parameters |
| 54 | + ---------- |
| 55 | + obstimes : `astropy.time.Time` |
| 56 | + Starting timestamp, or a value from which AstroPy can instantiate one. |
33 | 57 |
|
| 58 | + Raises |
| 59 | + ------ |
| 60 | + StopIteration |
| 61 | + When all the obstimes are exhausted. |
34 | 62 |
|
35 |
| -class DitherValue: |
36 |
| - def __init__(self, value, dither_range): |
37 |
| - self.value = value |
38 |
| - self.dither_range = dither_range |
| 63 | + Examples |
| 64 | + -------- |
| 65 | + >>> from astropy.time import Time |
| 66 | + >>> times = Time(range(60310, 60313, 1), format="mjd") |
| 67 | + >>> from kbmod.mocking import ObstimeIterator |
| 68 | + >>> obst = ObstimeIterator(times) |
| 69 | + >>> obst(); obst(); obst(); obst() |
| 70 | + '2024-01-01T00:00:00.000' |
| 71 | + '2024-01-02T00:00:00.000' |
| 72 | + '2024-01-03T00:00:00.000' |
| 73 | + Traceback (most recent call last): |
| 74 | + File "<stdin>", line 1, in <module> |
| 75 | + File "/local/tmp/kbmod/src/kbmod/mocking/callbacks.py", line 49, in __call__ |
39 | 76 |
|
40 |
| - def __call__(self, header_val): |
41 |
| - return self.value + random.uniform(self.dither_range) |
| 77 | + StopIteration |
| 78 | + """ |
| 79 | + def __init__(self, obstimes, **kwargs): |
| 80 | + self.obstimes = Time(obstimes, **kwargs) |
| 81 | + self.generator = (t for t in obstimes) |
42 | 82 |
|
| 83 | + def __call__(self, header=None): |
| 84 | + return Time(next(self.generator)).fits |
0 commit comments