-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add map_ind* methods * if -> elif * Add offset tests * tests for maps
- Loading branch information
Showing
8 changed files
with
100 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,31 @@ | ||
def map_ind_points(tune, setpoints, units="same"): | ||
... | ||
__all__ = ["map_ind_points", "map_ind_limits"] | ||
|
||
import copy | ||
|
||
def map_ind_limits(tune, min, max, units="same"): | ||
... | ||
import numpy as np | ||
|
||
from ._transition import Transition | ||
from ._tune import Tune | ||
|
||
|
||
def map_ind_points(instrument, arrangement, tune, setpoints, units=None): | ||
md = {"arrangement": arrangement, "tune": tune, "setpoints": setpoints, "units": units} | ||
to_replace = instrument[arrangement][tune] | ||
if units is not None: | ||
setpoints = wt.units.convert(setpoints, units, to_replace.ind_units) | ||
instr = copy.deepcopy(instrument) | ||
instr[arrangement]._tunes[tune] = Tune( | ||
setpoints, to_replace(setpoints), dep_units=to_replace.dep_units | ||
) | ||
instr._transition = Transition("map_ind_points", instrument, metadata=md) | ||
instr._load = None | ||
return instr | ||
|
||
|
||
def map_ind_limits(instrument, arrangement, tune, min, max, units=None): | ||
to_replace = instrument[arrangement][tune] | ||
points = np.linspace(min, max, len(to_replace)) | ||
instr = map_ind_points(instrument, arrangement, tune, points, units) | ||
md = {"arrangement": arrangement, "tune": tune, "min": min, "max": max, "units": units} | ||
instr._transition = Transition("map_ind_limits", instrument, metadata=md) | ||
return instr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import attune | ||
import numpy as np | ||
|
||
import pytest | ||
|
||
|
||
def test_map_ind_points(): | ||
tune = attune.Tune(np.linspace(1300, 1400, 20), np.linspace(-5, 5, 20)) | ||
arr = attune.Arrangement("test_map", {"test": tune}) | ||
inst0 = attune.Instrument({"test_map": arr}, {"test": attune.Motor("tune")}) | ||
|
||
inst1 = attune.map_ind_points(inst0, "test_map", "test", np.linspace(1310, 1450, 25)) | ||
|
||
test_points = np.linspace(1310, 1400, 14) | ||
np.testing.assert_allclose( | ||
inst1["test_map"]["test"](test_points), inst0["test_map"]["test"](test_points) | ||
) | ||
assert len(inst1["test_map"]["test"]) == 25 | ||
|
||
|
||
def test_map_ind_limits(): | ||
tune = attune.Tune(np.linspace(1300, 1400, 20), np.linspace(-5, 5, 20)) | ||
arr = attune.Arrangement("test_map", {"test": tune}) | ||
inst0 = attune.Instrument({"test_map": arr}, {"test": attune.Motor("tune")}) | ||
|
||
inst1 = attune.map_ind_limits(inst0, "test_map", "test", 1310, 1450) | ||
|
||
test_points = np.linspace(1310, 1400, 14) | ||
np.testing.assert_allclose( | ||
inst1["test_map"]["test"](test_points), inst0["test_map"]["test"](test_points) | ||
) | ||
assert len(inst1["test_map"]["test"]) == len(inst0["test_map"]["test"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import attune | ||
import numpy as np | ||
|
||
import pytest | ||
|
||
|
||
def test_offset_by(): | ||
tune = attune.Tune(np.linspace(1300, 1400, 20), np.linspace(-5, 5, 20)) | ||
arr = attune.Arrangement("test_offset", {"test": tune}) | ||
inst0 = attune.Instrument({"test_offset": arr}, {"test": attune.Motor("tune")}) | ||
|
||
inst1 = attune.offset_by(inst0, "test_offset", "test", 1.0) | ||
|
||
np.testing.assert_allclose( | ||
inst1["test_offset"]["test"].dependent, inst0["test_offset"]["test"].dependent + 1.0 | ||
) | ||
np.testing.assert_allclose( | ||
inst1["test_offset"]["test"].independent, inst0["test_offset"]["test"].independent | ||
) | ||
|
||
|
||
def test_offset_to(): | ||
tune = attune.Tune(np.linspace(1300, 1400, 20), np.linspace(-5, 5, 20)) | ||
arr = attune.Arrangement("test_offset", {"test": tune}) | ||
inst0 = attune.Instrument({"test_offset": arr}, {"test": attune.Motor("tune")}) | ||
|
||
inst1 = attune.offset_to(inst0, "test_offset", "test", 1.0, 1300) | ||
|
||
np.testing.assert_allclose(inst1["test_offset"]["test"].dependent, np.linspace(1, 11, 20)) | ||
np.testing.assert_allclose( | ||
inst1["test_offset"]["test"].independent, inst0["test_offset"]["test"].independent | ||
) |