Skip to content

Commit

Permalink
Refs #629 HidraWorkspace can save units to the project file
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Borreguero <[email protected]>
  • Loading branch information
jmborr committed Sep 7, 2020
1 parent af879f5 commit 99224ee
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pyrs/core/workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,10 @@ def save_experimental_data(self, hidra_project, sub_runs=None, ignore_raw_counts
# Convert each sample log to a numpy array
sample_log_value = self.get_sample_log_values(sample_log_name=log_name,
sub_runs=sub_runs)
sample_log_units = self.get_sample_log_units(log_name)

# Add log value to project file
hidra_project.append_experiment_log(log_name, sample_log_value)
hidra_project.append_experiment_log(log_name, sample_log_value, units=sample_log_units)
# END-FOR

# Save default mask
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_project_file_rw.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import pytest


def test_rw_raw():
def test_rw_raw(test_data_dir):
"""Test read a project to workspace and write in the scope of raw data
Returns
-------
"""
raw_project_name = os.path.join(os.getcwd(), 'tests/data/HZB_Raw_Project.h5')
raw_project_name = os.path.join(test_data_dir, 'HZB_Raw_Project.h5')

# Read to workspace
source_project = HidraProjectFile(raw_project_name, 'r')
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ def test_nexus_to_project(nexusfile, projectfile):
# extract the powder patterns and add them to the project file
addPowderToProject(projectfile)

# cleanup
os.remove(projectfile)
# cleanup os.remove(projectfile)

# [('/HFIR/HB2B/IPTS-22331/nexus/HB2B_1431.nxs.h5', 'HB2B_1431.h5')],

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/pyrs/projectfile/test_file_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@ def assert_allclose_structured_numpy_arrays(expected, calculated):
return


@pytest.fixture(scope='module')
def project_HB2B_938(test_data_dir):
r"""A hidra project containing, among other things, units in the logs"""
return HidraProjectFile(os.path.join(test_data_dir, 'HB2B_938_v2.h5'), HidraProjectFileMode.READONLY)


class TestHidraProjectFile:

def test_read_sample_logs(self, project_HB2B_938):
sample_logs = project_HB2B_938.read_sample_logs()
assert sample_logs.units('vx') == 'mm'

def test_append_experiment_log(self, tmpdir):
project = HidraProjectFile(os.path.join(tmpdir, 'project_file.hdf'), HidraProjectFileMode.OVERWRITE)
group = project._project_h5[HidraConstants.RAW_DATA][HidraConstants.SAMPLE_LOGS]
Expand Down

0 comments on commit 99224ee

Please sign in to comment.