|
| 1 | +import matplotlib.pyplot as plt |
1 | 2 | import neo |
2 | 3 | import pytest |
3 | 4 | import quantities as pq |
4 | 5 | from brian2 import Network, NeuronGroup, asarray, mm, mm2, ms, mwatt, nmeter, np, um |
5 | 6 |
|
6 | 7 | import cleo |
7 | | -from cleo.light import GaussianEllipsoid, KoehlerBeam, Light, LightModel, fiber473nm |
| 8 | +from cleo.light import ( |
| 9 | + GaussianEllipsoid, |
| 10 | + KoehlerBeam, |
| 11 | + Light, |
| 12 | + LightModel, |
| 13 | + fiber473nm, |
| 14 | + plot_spectra, |
| 15 | +) |
| 16 | +from cleo.opto import chr2_4s |
8 | 17 | from cleo.utilities import normalize_coords, unit_safe_allclose |
9 | 18 |
|
10 | 19 |
|
@@ -106,6 +115,27 @@ def test_reset(): |
106 | 115 | assert light.value == 0 |
107 | 116 |
|
108 | 117 |
|
| 118 | +def test_plot_spectra_sorts_wavelengths(): |
| 119 | + sorted_opsin = chr2_4s() |
| 120 | + unsorted_opsin = chr2_4s() |
| 121 | + unsorted_opsin.spectrum = unsorted_opsin.spectrum[::-1] |
| 122 | + original_spectrum = unsorted_opsin.spectrum.copy() |
| 123 | + |
| 124 | + sorted_fig, sorted_ax = plot_spectra(sorted_opsin) |
| 125 | + unsorted_fig, unsorted_ax = plot_spectra(unsorted_opsin) |
| 126 | + |
| 127 | + np.testing.assert_allclose( |
| 128 | + unsorted_ax.lines[0].get_xdata(), sorted_ax.lines[0].get_xdata() |
| 129 | + ) |
| 130 | + np.testing.assert_allclose( |
| 131 | + unsorted_ax.lines[0].get_ydata(), sorted_ax.lines[0].get_ydata() |
| 132 | + ) |
| 133 | + assert unsorted_opsin.spectrum == original_spectrum |
| 134 | + |
| 135 | + plt.close(sorted_fig) |
| 136 | + plt.close(unsorted_fig) |
| 137 | + |
| 138 | + |
109 | 139 | def test_coords(): |
110 | 140 | light = Light(light_model=fiber473nm(), coords=[[0, 0, 0], [1, 1, 1]] * mm) |
111 | 141 | assert light.n == 2 |
|
0 commit comments