HEXRD / hexrd

A cross-platform, open-source library for the analysis of X-ray diffraction data.
Other
55 stars 26 forks source link

Imagefiles yaml text #604

Closed donald-e-boyce closed 7 months ago

donald-e-boyce commented 7 months ago

This pull request allows you to load an imageseries of type image-files by passing the yaml text directly to the open()command instead of writing it to a file first and then loading the file. This is just a convenience for writing raw data processing scripts.

I also have a test file that verifies this, but since it involves a large data file, I chose not to submit it here. I suggest we add an imageseries directory to the hexrd-examples repository, where we can take advantage of existing large data files.

Here is the test script:


import pytest

from hexrd import imageseries

@pytest.fixture
def image_files_fmt():
    return "image-files"

@pytest.fixture
def yaml_tmpl():
    return """image-files:
  directory: .
  files: RUBY_*
options:
  empty-frames: %(n_ef)d
  max-file-frames: %(maxff)d
  max-total-frames: %(maxtf)d
meta: {}
"""

def  test_yaml_text(image_files_fmt, yaml_tmpl, tmp_path):
    """Verify that yaml file and yaml text give same result"""
    d = dict(n_ef=1, maxff=10, maxtf=15)
    p = tmp_path / "image-files.yml"
    yaml_text = yaml_tmpl % d
    with open(p, "w") as f:
        f.write(yaml_text)
    ims_f = imageseries.open(p, image_files_fmt)
    ims_t = imageseries.open(yaml_text, image_files_fmt)

    assert len(ims_f) == len(ims_t)
    assert len(ims_f) == 15
    assert np.all(ims_f[0] == ims_t[0])
psavery commented 7 months ago

@donald-e-boyce By the way, can we re-use the image series located here for the tests? You could obtain them in the pytests via the example_repo_path fixture, like so:

@pytest.fixture
def example_repo_imageseries_path(example_repo_path):
    return example_repo_path / 'NIST_RUBY/multiruby_dexelas/imageseries'

def test_name(example_repo_imageseries_path):
     # example_repo_imageseries_path will point to the directory containing the image series.