Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imagefiles yaml text #604

Merged
merged 2 commits into from
Jan 16, 2024

Conversation

donald-e-boyce
Copy link
Collaborator

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])

Copy link
Collaborator

@psavery psavery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! It's a great imporovement!

In HEXRDGUI, we do create temporary yaml files in some places such as here. This PR will simplify that code so we don't have to make temporary files.

hexrd/imageseries/load/imagefiles.py Show resolved Hide resolved
@psavery
Copy link
Collaborator

psavery commented Jan 15, 2024

@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.

@donald-e-boyce donald-e-boyce merged commit 29e7c6f into HEXRD:master Jan 16, 2024
6 checks passed
@donald-e-boyce donald-e-boyce deleted the imagefiles-yaml-text branch January 24, 2024 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants