def test_empty_spec_dims(): # Empty list empty_method = Method(channels=["1H"], spectral_dimensions=[]) error = ( r".*Method has empty spectral_dimensions. At least one SpectralDimension " r"is needed with at least one Event..*") with pytest.raises(AttributeError, match=error): empty_method.summary() # No events empty_method.spectral_dimensions = [SpectralDimension(events=[])] error = (r".*Method has no Events. At least one SpectralDimension " r"is needed with at least one Event..*") with pytest.raises(AttributeError, match=error): empty_method.summary()
def args_summary_tests(the_method): # Pass drop_constant_columns=False df = the_method.summary(drop_constant_columns=False) assert df.shape[0] == 6 assert df.shape[1] == len(ALL_PARAMS) assert set(df.columns) == set(ALL_PARAMS) # Pass drop_constant_columns=True (default) df = the_method.summary(drop_constant_columns=True) props_should_be = ["rotor_frequency", "freq_contrib"] assert df.shape[0] == 6 assert df.shape[1] == len(REQUIRED + props_should_be) assert set(df.columns) == set(REQUIRED + props_should_be) # Make sure columns always present are not dropped even if constant event_ = [{"label": "all labels the same", "fraction": 0.2}] all_SpectralEvents_spec_dims = [{"events": event_ * 5}] the_method = Method( name="all-spectral-method-1", channels=["1H", "13C"], spectral_dimensions=all_SpectralEvents_spec_dims, ) df = the_method.summary(drop_constant_columns=True) assert df.shape[0] == 5 assert df.shape[1] == len(REQUIRED + ["freq_contrib"]) assert set(df.columns) == set(REQUIRED + ["freq_contrib"])
def method3_df(): method3 = Method( channels=["1H"], spectral_dimensions=[ { "label": "Spectral Spectral Mixing", "events": [ { "fraction": 0.1, "transition_query": [ {"ch1": {"P": [1, 1]}}, {"ch1": {"P": [2]}}, ], }, { "fraction": 0.9, "transition_query": [ {"ch1": {"P": [-1, -1]}}, {"ch1": {"P": [-2]}}, ], }, {"mixing_query": {"ch1": {"tip_angle": np.pi, "phase": 0}}}, ], } ], ) return method3.summary()
def method1_df(): method1 = Method( channels=["1H"], spectral_dimensions=[ { "label": "Spectral and Constant Duration Event", "events": [ {"fraction": 1}, {"duration": 1.5}, ], }, { "label": "Mixing and Spectral Event", "events": [ {"fraction": 0.5}, {"mixing_query": {"ch1": {"tip_angle": np.pi / 2, "phase": 0}}}, {"fraction": 0.5}, ], }, ], ) return method1.summary()
def method2_df(): method2 = Method( channels=["1H"], spectral_dimensions=[ { "label": "Mixing, Spectral, Mixing, Mixing, ConstantDuration ", "events": [ { "mixing_query": { "ch1": {"tip_angle": np.pi / 2, "phase": 0.3}, "ch2": { "tip_angle": 10 / 180 * np.pi, "phase": 10 / 180 * np.pi, }, } }, {"fraction": 1, "transition_query": [{"P": [1], "D": [0]}]}, { "mixing_query": { "ch1": {"tip_angle": np.pi, "phase": 0.15}, "ch2": { "tip_angle": 20 / 180 * np.pi, "phase": 20 / 180 * np.pi, }, } }, { "mixing_query": { "ch1": {"tip_angle": 3 * np.pi / 2, "phase": 0}, "ch2": { "tip_angle": 30 / 180 * np.pi, "phase": 30 / 180 * np.pi, }, } }, {"duration": 1.5, "transition_query": [{"P": [-1], "D": [2]}]}, ], }, { "label": "Spectral, Spectral, ConstantDuration, ConstantDuration", "events": [ {"fraction": 0.2}, {"fraction": 0.8}, {"duration": 1.3}, {"duration": 0.6}, ], }, { "label": "Mixing, Mixing, Mixing, Spectral, ConstantDuration, Spectral", "events": [ { "mixing_query": { "ch1": {"tip_angle": 1.2, "phase": np.pi}, "ch2": { "tip_angle": 40 / 180 * np.pi, "phase": 40 / 180 * np.pi, }, } }, { "mixing_query": { "ch1": {"tip_angle": 0.75, "phase": np.pi / 4}, "ch2": { "tip_angle": 50 / 180 * np.pi, "phase": 50 / 180 * np.pi, }, } }, { "mixing_query": { "ch1": {"tip_angle": 0.33, "phase": np.pi / 3}, "ch2": { "tip_angle": 60 / 180 * np.pi, "phase": 60 / 180 * np.pi, }, } }, {"fraction": 0.5}, {"duration": 1.5}, {"fraction": 0.5}, ], }, ], ) return method2.summary(drop_constant_columns=False)