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

Robust writing of with missing header values #76

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

TobyDunneAbyss
Copy link
Contributor

When reading an e57 file with missing headers, writing will fail.

The gettattr function does not use the default value provided and instead raises an exception.
This wrapper function provided the expected behaviour, i.e. returning the default value on error.

@dancergraham
Copy link
Collaborator

Hello, thank you very much for this - it looks like a great fix for this problem. Would you be able to provide a test or sample code for it as well ?

@dancergraham
Copy link
Collaborator

I tried adding this test to the repo but all except the name work even without this fix - can you suggest a better way to test it?

def test_read_write_default_values(e57_path, temp_e57_write):
    e57 = pye57.E57(e57_path)
    default_values = {"rotation": [1, 0, 0, 0],
                      "translation": [0, 0, 0],
                      "temperature": 0,
                      "relativeHumidity": 0,
                      "atmosphericPressure": 0,
                      "name": "Scan 4",
                      }
    with pye57.E57(temp_e57_write, mode="w") as e57_write:
        raw_data_0 = e57.read_scan_raw(0)
        e57_write.write_scan_raw(raw_data_0)
    written = pye57.E57(temp_e57_write)
    written_header = written.get_header(0)
    assert np.allclose(written_header.rotation, default_values["rotation"])
    assert np.allclose(written_header.translation, default_values["translation"])
    assert written_header.temperature == default_values["temperature"]
    assert written_header.relativeHumidity == default_values["relativeHumidity"]
    assert written_header.atmosphericPressure == default_values["atmosphericPressure"]
    assert written_header.name == default_values["name"]

@dancergraham
Copy link
Collaborator

Also if you can recreate the PR from a branch, not from master, and allow me to make modifications, that will make merging easier - otherwise I think I will need to create a separate branch from my own account

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.

3 participants