avalentino / pyepr

Python bindings for ENVISAT Product Reader API
https://pyepr.readthedocs.io
GNU General Public License v3.0
13 stars 2 forks source link

Sub-dataset reading errors for geo-location grids #9

Closed avalentino closed 10 years ago

avalentino commented 10 years ago

Reading MERIS datasets using the xoffset and yoffset options returns incorrect data for of geo-location grids.

Sample code to reproduce the issue:

import epr

# Open MERIS product
product = epr.Product(myProduct)

# Define a pixel of interest and a box around
centerx = 894
centery = 1930
width = 5
height = 5

# Get full radiance_1 array
dataset = product.get_band('radiance_1')
radiance_1 = dataset.read_as_array()   # This gives the correct complete array of radiance_1
print radiance_1[centery,centerx]          # This gives the correct radiance_1 of pixel of interest

# Get full latitude array
dataset = product.get_band('latitude')
latitude = dataset.read_as_array()   # This gives the correct complete array of latitude
print latitude[centery,centerx]          # This gives the correct latitude of pixel of interest

# Get sub-array of radiance_1
dataset = product.get_band('radiance_1')
raster = dataset.read_as_array(width,height,xoffset=centerx-width/2,yoffset=centery-height/2) # This gives the correct sub-array of radiance_1 around the pixel
print raster[height/2][width/2]  # This gives exactly the same result as radiance_1[centery,centerx]

# Now get sub-array of latitude
dataset = product.get_band('latitude')
raster = dataset.read_as_array(width,height,xoffset=centerx-width/2,yoffset=centery-height/2)
print raster[height/2][width/2]  # Now this is different than latitude[centery,centerx] 

Bug reported via email by Constant Mazeran

avalentino commented 10 years ago

The issue is in the C library and has been fixed with commit bcdev/epr-api@8e42f43249ae68e3755a0f051cf27bc8c8763848.

Unit tests of pyepr has been updated but the relevant test will only be active for EPR C API > 2.3.1 (the current version is 2.3).