From aa3f67ff88fe14356c5f38f28ead2bddaaaf81df Mon Sep 17 00:00:00 2001 From: Deepansh Srivastava <21365911+deepanshs@users.noreply.github.com> Date: Tue, 25 Jun 2024 14:47:37 -0400 Subject: [PATCH 1/5] add units to csdm dependent variables --- src/mrsimulator/simulator/__init__.py | 2 ++ tests/2D_spectrum_tests/test_coaster.py | 3 +++ tests/test_amplitude.py | 1 + 3 files changed, 6 insertions(+) diff --git a/src/mrsimulator/simulator/__init__.py b/src/mrsimulator/simulator/__init__.py index 3f1e9a6d4..f5de4bfcd 100644 --- a/src/mrsimulator/simulator/__init__.py +++ b/src/mrsimulator/simulator/__init__.py @@ -521,11 +521,13 @@ def _as_csdm_object(self, data: np.ndarray, method: Method) -> cp.CSDM: if item.origin_offset != 0 ] + n_dims = len(dim) dv = [ { "type": "internal", "quantity_type": "scalar", "numeric_type": "complex128", + "unit": f"Hz^-{n_dims}", "components": [datum], **self._get_dv_metadata(index), } diff --git a/tests/2D_spectrum_tests/test_coaster.py b/tests/2D_spectrum_tests/test_coaster.py index ac5ad3582..f7bd8bb01 100644 --- a/tests/2D_spectrum_tests/test_coaster.py +++ b/tests/2D_spectrum_tests/test_coaster.py @@ -26,6 +26,9 @@ def process_spectrum(method): sim.config.integration_volume = "hemisphere" sim.run() + n_dim = len(method.spectral_dimensions) + assert str(sim.methods[0].simulation.y[0].unit) == f"Hz^-{n_dim}" + data = sim.methods[0].simulation.y[0].components[0] data /= data.max() return data diff --git a/tests/test_amplitude.py b/tests/test_amplitude.py index 522de5993..64bbee45f 100644 --- a/tests/test_amplitude.py +++ b/tests/test_amplitude.py @@ -26,6 +26,7 @@ def test_static_spinning_integral_amplitude(): sim = pre_setup() sim.run() y_static = sim.methods[0].simulation.y[0].components[0].sum() + assert str(sim.methods[0].simulation.y[0].unit) == "Hz^-1" sim.methods[0].spectral_dimensions[0].events[0].rotor_frequency = 1000 # in Hz sim.run() From ea24de8abe157b9920cb674232ade63ae6d28fa8 Mon Sep 17 00:00:00 2001 From: Deepansh Srivastava <21365911+deepanshs@users.noreply.github.com> Date: Tue, 25 Jun 2024 14:59:25 -0400 Subject: [PATCH 2/5] update unit test format --- tests/2D_spectrum_tests/test_coaster.py | 2 +- tests/test_amplitude.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/2D_spectrum_tests/test_coaster.py b/tests/2D_spectrum_tests/test_coaster.py index f7bd8bb01..982d53a15 100644 --- a/tests/2D_spectrum_tests/test_coaster.py +++ b/tests/2D_spectrum_tests/test_coaster.py @@ -27,7 +27,7 @@ def process_spectrum(method): sim.run() n_dim = len(method.spectral_dimensions) - assert str(sim.methods[0].simulation.y[0].unit) == f"Hz^-{n_dim}" + assert str(sim.methods[0].simulation.y[0].unit) == f"1 / Hz{n_dim}" data = sim.methods[0].simulation.y[0].components[0] data /= data.max() diff --git a/tests/test_amplitude.py b/tests/test_amplitude.py index 64bbee45f..12f785e1d 100644 --- a/tests/test_amplitude.py +++ b/tests/test_amplitude.py @@ -26,7 +26,7 @@ def test_static_spinning_integral_amplitude(): sim = pre_setup() sim.run() y_static = sim.methods[0].simulation.y[0].components[0].sum() - assert str(sim.methods[0].simulation.y[0].unit) == "Hz^-1" + assert str(sim.methods[0].simulation.y[0].unit) == "1 / Hz" sim.methods[0].spectral_dimensions[0].events[0].rotor_frequency = 1000 # in Hz sim.run() From 97bfd3a544ab647afeeaa252491d7f713a4150b8 Mon Sep 17 00:00:00 2001 From: Deepansh Srivastava <21365911+deepanshs@users.noreply.github.com> Date: Tue, 25 Jun 2024 15:48:40 -0400 Subject: [PATCH 3/5] . --- tests/2D_spectrum_tests/test_coaster.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/2D_spectrum_tests/test_coaster.py b/tests/2D_spectrum_tests/test_coaster.py index 982d53a15..86ad5c33c 100644 --- a/tests/2D_spectrum_tests/test_coaster.py +++ b/tests/2D_spectrum_tests/test_coaster.py @@ -27,7 +27,8 @@ def process_spectrum(method): sim.run() n_dim = len(method.spectral_dimensions) - assert str(sim.methods[0].simulation.y[0].unit) == f"1 / Hz{n_dim}" + unit = f"1 / Hz{n_dim}" is n_dim > 1 else "1 / Hz" + assert str(sim.methods[0].simulation.y[0].unit) == unit data = sim.methods[0].simulation.y[0].components[0] data /= data.max() From 0e5f998f79c59fd8c725b51acee41bb726b55407 Mon Sep 17 00:00:00 2001 From: Deepansh Srivastava <21365911+deepanshs@users.noreply.github.com> Date: Tue, 25 Jun 2024 15:49:46 -0400 Subject: [PATCH 4/5] value --- tests/test_shift.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_shift.py b/tests/test_shift.py index 3d75c5475..c5ef71221 100644 --- a/tests/test_shift.py +++ b/tests/test_shift.py @@ -88,6 +88,6 @@ def test_large_shifts(): simulation = sim.methods[0].simulation simulation.x[0].to("ppm", "nmr_frequency_ratio") - max_amp = simulation.x[0].coordinates[int(np.argmax(simulation))] + max_amp = simulation.x[0].coordinates[int(np.argmax(simulation).value)] np.testing.assert_almost_equal(max_amp.value, shift, decimal=1) From 44e935a0caa895ee1a26e553d27518d7a45ba7e4 Mon Sep 17 00:00:00 2001 From: Deepansh Srivastava <21365911+deepanshs@users.noreply.github.com> Date: Tue, 25 Jun 2024 15:50:43 -0400 Subject: [PATCH 5/5] bug fix --- tests/2D_spectrum_tests/test_coaster.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/2D_spectrum_tests/test_coaster.py b/tests/2D_spectrum_tests/test_coaster.py index 86ad5c33c..60f324e05 100644 --- a/tests/2D_spectrum_tests/test_coaster.py +++ b/tests/2D_spectrum_tests/test_coaster.py @@ -27,7 +27,7 @@ def process_spectrum(method): sim.run() n_dim = len(method.spectral_dimensions) - unit = f"1 / Hz{n_dim}" is n_dim > 1 else "1 / Hz" + unit = f"1 / Hz{n_dim}" if n_dim > 1 else "1 / Hz" assert str(sim.methods[0].simulation.y[0].unit) == unit data = sim.methods[0].simulation.y[0].components[0]