def create_sample_frame(import_file: str): """Import a file with pycompwa and convert it to a `~pandas.DataFrame`.""" events = pwa.read_ascii_data(import_file) frame = convert.events_to_pandas( events=events, model=f"{SCRIPT_DIR}/files/kinematics_three.xml" ) return frame
def _read_ascii_with_header(filename, particles=None): """Import ASCII file **with** header.""" event_collection = pwa.read_ascii_data(filename) frame = convert.events_to_pandas(event_collection) particles_in_frame = frame.pwa.particles if isinstance(particles, list) \ and len(particles_in_frame) != len(particles): raise exception.DataException( f'The number of particles in argument particles ({particles}) ' 'does not have the same number of particles as inferred from ' f'the ASCII header of file ({particles_in_frame})') return frame
def test_events_to_pandas(has_weights): """Test :func:`~.events_to_pandas`.""" events = import_events(has_weights) with pytest.raises(exception.ConfigurationConflict): convert.events_to_pandas(events, f'{SCRIPT_DIR}/files/kinematics_two.xml') frame = convert.events_to_pandas(events) assert frame.pwa.particles == [22, '111-1', '111-2'] del frame xml_filename = f'{SCRIPT_DIR}/files/kinematics_three.xml' frame = convert.events_to_pandas(events, model=xml_filename) assert frame.pwa.particles == ['gamma', 'pi0-1', 'pi0-2'] data_set = pwa.compute_kinematic_variables(events, xml_filename) frame_kinematics = convert.data_set_to_pandas(data_set) append(frame, frame_kinematics) assert len(frame.pwa.other_columns) == 16 assert 'theta_2_4_vs_3' in frame.pwa.other_columns assert isclose(sqrt(frame['mSq_(2,3,4)'].mean()), 3.097, abs_tol=1e-3)
def import_pandas(weights: bool = False): """Import the pickled frame.""" events = import_events(weights) frame = convert.events_to_pandas( events=events, model=f'{SCRIPT_DIR}/files/kinematics_three.xml') return frame