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

readSLI: take byte order of hdr into consideration #47

Closed
aloboa opened this issue Mar 11, 2019 · 3 comments
Closed

readSLI: take byte order of hdr into consideration #47

aloboa opened this issue Mar 11, 2019 · 3 comments

Comments

@aloboa
Copy link

aloboa commented Mar 11, 2019

When I use readSLI() to read a library with byte order = 1 in its hdr, I get weird values in R, while libraries
that have byte order = 0 result in R obkects with meaningful values.
byte order = 1 : https://lost-contact.mit.edu/afs/enea.it/software/rsi/envi_3.5/spec_lib/jpl_lib/
byte order = 0: https://lost-contact.mit.edu/afs/enea.it/software/rsi/envi_3.5/spec_lib/usgs_min/

I understand that readSLI() assumes byte order = 0 (least significant byte first (LSF) data ),
am I wrong?
If I'm not wrong, could byte order be taken into account by readSLI() ?

@aloboa
Copy link
Author

aloboa commented Mar 14, 2019

I'm trying to modify readSLI() locally on my own, but as soon as I do it with
fix(readSLI)
upon running I get:
Error in .getNumeric(hdr[grep("samples", hdr)]) :
could not find function ".getNumeric"

using a windows box (today) and the github version o RStoolbox

@aloboa
Copy link
Author

aloboa commented Mar 14, 2019

I have circumvented the problem by including .getNumeric() and .bracketRange() in a modified local version
of readSLI() and it works.
The only diferences to the original readSLI() are:
change

        data_type  <- .getNumeric(hdr[grep("data type", hdr)])
        id <- .bracketRange(hdr, "spectra names")

to

        data_type  <- .getNumeric(hdr[grep("data type", hdr)])
        byte_order <- .getNumeric(hdr[grep("byte order", hdr)])
        byte_order <- ifelse(byte_order==0,"little","big") 
        id <- .bracketRange(hdr, "spectra names")

and
x[] <- readBin(path, "numeric", n = 1e+06, size = bytes)
to
x[] <- readBin(path, "numeric", n = 1e+06, size = bytes,endian=byte_order)

bleutner pushed a commit that referenced this issue Mar 15, 2019
@bleutner
Copy link
Owner

Well done, thanks! Fixed now.

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

2 participants