Skip to content

Commit

Permalink
add raster scans
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Morris committed May 30, 2024
1 parent 91d4694 commit ab787d4
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 46 deletions.
100 changes: 71 additions & 29 deletions docs/source/tutorials/custom-map-simulations.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions maria/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from . import utils # noqa
from ._version import __version__, __version_tuple__ # noqa
from .instrument import Band, all_instruments, get_instrument # noqa
from .instrument import Band, Instrument, all_instruments, get_instrument # noqa
from .map import Map, mappers # noqa
from .plan import all_plans, get_plan # noqa
from .plan import Plan, all_plans, get_plan # noqa
from .sim import Simulation # noqa
from .site import all_regions, all_sites, get_site # noqa
from .site import Site, all_regions, all_sites, get_site # noqa
4 changes: 4 additions & 0 deletions maria/plan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ def __post_init__(self):
self.time = np.arange(self.time_min, self.time_max, self.dt)
self.n_time = len(self.time)

# convert radius to width / height
if "width" in self.scan_options:
self.scan_options["radius"] = 0.5 * self.scan_options.pop("width")

# this is in pointing_units
x_scan_offsets, y_scan_offsets = getattr(patterns, self.scan_pattern)(
self.time,
Expand Down
44 changes: 36 additions & 8 deletions maria/plan/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,45 @@ def grid(time, radius=1, speed=None, n=17, turnaround_time=5): # noqa
)


def back_and_forth(time, speed, x_throw=1, y_throw=0, turnaround_time=5): # noqa
def smooth_sawtooth(phase, width=0.5, smoothness=0.5):
smooth_phase = sp.ndimage.gaussian_filter1d(
phase, sigma=smoothness * np.gradient(phase).mean()
)
smooth_sawtooth = sp.signal.sawtooth(smooth_phase, width=width)
return 2 * (smooth_sawtooth - smooth_sawtooth.min()) / smooth_sawtooth.ptp() - 1


def raster(time, radius=1, height=None, speed=0.5, n=16, turnaround_time=0.5):
width = 2 * radius
height = height or width

sample_rate = 1 / np.gradient(time).mean()
scan_period = 2 * np.pi * np.sqrt(x_throw**2 + y_throw**2) / speed
phase = 2 * np.pi * time / scan_period

sawtooth = sp.signal.sawtooth(phase, width=0.5)
smooth_sawtooth = sp.ndimage.gaussian_filter(
sawtooth, sigma=turnaround_time * sample_rate
) # noqa
start_time = time.min()

ts, xs, ys = [], [], []

n_scans = 2 * n + 1
phase = np.linspace(0, np.pi * n_scans, n_scans * 256)
raster_period = 2 * n_scans * np.sqrt(width**2 + (height / n_scans) ** 2) / speed

while start_time < time.max():
xs.extend(0.5 * width * sp.signal.sawtooth(phase, width=0.5))
ys.extend(height * np.linspace(0.5, -0.5, len(phase)))
ts.extend(start_time + np.linspace(0, raster_period, len(phase)))
start_time = ts[-1] + np.sqrt(width**2 + height**2) / speed

return x_throw * smooth_sawtooth, y_throw * smooth_sawtooth
offsets = sp.interpolate.interp1d(ts, np.c_[xs, ys].T)(time)

return sp.ndimage.gaussian_filter1d(
offsets, sigma=turnaround_time * sample_rate, axis=-1
)


def back_and_forth(time, speed, width, turnaround_time=5): # noqa
return raster(
time, speed=speed, width=width, height=0, turnaround_time=turnaround_time
)


def stare(time):
Expand Down
5 changes: 2 additions & 3 deletions maria/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
def test_map_sim():
map_filename = fetch("maps/cluster.fits", refresh=True)

f090 = Band(center=90, width=20, sensitivity=5e-5) # in GHz # in K sqrt(s)

f150 = Band(center=150, width=30, sensitivity=5e-5) # in GHz # in K sqrt(s)
f090 = Band(center=90, width=20, sensitivity=5e-5)
f150 = Band(center=150, width=30, sensitivity=5e-5)

array = {"field_of_view": 0.02, "bands": [f090, f150]}

Expand Down
8 changes: 5 additions & 3 deletions maria/tests/test_plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import maria


@pytest.mark.parametrize("plan_name", maria.all_plans)
def test_get_plan(plan_name):
plan = maria.get_plan(plan_name)
@pytest.mark.parametrize(
"scan_pattern", ["stare", "daisy", "raster", "grid", "back_and_forth"]
)
def test_pattern(scan_pattern):
plan = maria.Plan(scan_pattern=scan_pattern)

0 comments on commit ab787d4

Please sign in to comment.