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

PDS3 Image decodes Lunar Reconnaissance Orbiter Camera Narrow Angle Camera EDR images as signed 8-bit images instead of unsigned 8-bit images #78

Open
benmoseley opened this issue Jul 2, 2020 · 3 comments

Comments

@benmoseley
Copy link

Problem: The LROC NAC EDR images contain 8-bit unsigned raw instrument DN counts, although the PDS3Image class decodes them to signed 8-bit integers. This leads to incorrect DN values in the imported numpy image array.

Reason: This is because the EDR binary files have "SAMPLE_TYPE = LSB_INTEGER" in their PDS3 header, which is interpreted by PDS3Image class as a signed integer.

Solution: I am unsure if this is an issue with the PDS3Image class mapping from SAMPLE_TYPE values to numpy dtypes, or if the EDR file header SAMPLE_TYPE values are incorrect. Potentially the SAMPLE_TYPE mapping should be updated, or a specific exception for NAC EDR images could be made.

@AndrewAnnex
Copy link
Member

Hey @benmoseley, if you need a more immediate solution (as I am aware of FDL) I would recommend trying to use gdal's pds driver via the rasterio project which should probably do the right thing and get your edr loaded to the correct numpy dtype.

Confusingly in the pds3 spec here: "https://pds.jpl.nasa.gov/datastandards/pds3/standards/sr/Chapter03.pdf" LSB_INTEGER maps to "1-, 2-, and 4-byte signed integers" so logically the data would be 4 byte signed not 8 byte unsigned. If the data really is unsigned then the pds label should say "LSB_UNSIGNED_INTEGER" instead but it would still be 4 byte according to the spec. I don't know who is correct in this situation, but I would be surprised if such a significant error in the label was present.

@cmillion
Copy link

cmillion commented Jul 3, 2020

SAMPLE_TYPE in PDS3 is all over the place in terms of what it maps to. This kind of issue is common.

@benmoseley
Copy link
Author

Thanks both, I came up with a simple workaround for this problem below, which works fine for this particular problem.

class PDS3ImageEDR(PDS3Image):
    """EDR image class, extends PDS3Image class by fixing LROC NAC EDR images decoding bug.
    """
    
    # this fixes the decoding bug by overriding the class SAMPLE_TYPE and DTYPES attributes
    
    SAMPLE_TYPES = {
        'LSB_INTEGER': '<u',
    }

    DTYPES = {
        '<u': 'LSB_INTEGER',
    }

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

No branches or pull requests

3 participants