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

Can't save correctly with new data type #71

Open
percurnicus opened this issue Mar 30, 2017 · 0 comments · May be fixed by #74
Open

Can't save correctly with new data type #71

percurnicus opened this issue Mar 30, 2017 · 0 comments · May be fixed by #74

Comments

@percurnicus
Copy link
Member

Im running into a problem with saving an image after I convert the data to a different dtype. I need to convert because I have to make changes to the data and I was having problems making the needed changes with uint8. I also had to make changes to the label and need those changes seen in the new file. Here is how to recreate the problem:

>>> from planetaryimage import PDS3Image
>>> import numpy as np
>>> old_im = PDS3Image.open('tests/mission_data/0615ML0026220010301833C00_DXXX.IMG')
>>> old_im.data
array([[[ 8,  5,  8, ...,  5,  7,  4],
        [ 2,  2,  5, ...,  4,  4,  4],
        [72, 55, 84, ..., 30, 41, 26],
        ...,
        [54, 34, 51, ..., 82, 62, 42],
        [71, 51, 71, ..., 79, 75, 59],
        [52, 34, 50, ..., 44, 64, 45]]], dtype=uint8)
>>> old_im.data = old_im.data.astype(np.int64)
>>> new_im = 'new_im.IMG'
>>> old_im.save(new_im)
>>> PDS3Image.open(new_im).data
array([[[ 576460752303423488,  360287970189639680,  576460752303423488,
         ...,  360287970189639680,  504403158265495552,  288230376151711744],
        [ 144115188075855872,  144115188075855872,  360287970189639680,
         ...,  288230376151711744,  288230376151711744,  288230376151711744],
        [5188146770730811392, 3963167672086036480, 6052837899185946624,
         ..., 2161727821137838080, 2954361355555045376, 1873497444986126336],
        ...,
        [3891110078048108544, 2449958197289549824, 3674937295934324736,
         ..., 5908722711110090752, 4467570830351532032, 3026418949592973312],
        [5116089176692883456, 3674937295934324736, 5116089176692883456,
         ..., 5692549928996306944, 5404319552844595200, 4251398048237748224],
        [3746994889972252672, 2449958197289549824, 3602879701896396800,
         ..., 3170534137668829184, 4611686018427387904, 3242591731706757120]]])

I think this is part of a larger bug because I don't get the same array when I just save it as is:

>>> from planetaryimage import PDS3Image
>>> old_im = PDS3Image.open('tests/mission_data/0615ML0026220010301833C00_DXXX.IMG')
>>> old_im.data
array([[[ 8,  5,  8, ...,  5,  7,  4],
        [ 2,  2,  5, ...,  4,  4,  4],
        [72, 55, 84, ..., 30, 41, 26],
        ...,
        [54, 34, 51, ..., 82, 62, 42],
        [71, 51, 71, ..., 79, 75, 59],
        [52, 34, 50, ..., 44, 64, 45]]], dtype=uint8)
>>> new_im = 'new_im.IMG'
>>> old_im.save(new_im)
>>> PDS3Image.open(new_im).data
array([[[ 32,  32,  32, ...,   7,   4,   4],
        [  5,   2,   5, ...,   2,   1,   4],
        [  5,   2,   2, ...,  44,  57,  40],
        ...,
        [118,  95, 107, ...,  56,  81,  54],
        [ 80,  55,  83, ...,  87, 105,  84],
        [104,  89,  95, ...,  71,  91,  45]]], dtype=uint8)

Looking at the test for save, it doesn't seem like the data is tested to be correct, only the surrounding parameters. I can write a test to expose this bug but I wanted to check if I was using save correctly before I did so.

@percurnicus percurnicus linked a pull request Sep 5, 2017 that will close this issue
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 a pull request may close this issue.

1 participant