Skip to content

Extent not detected from lon & lat vars in netcdf files from Acolite AC products #1796

@arthurdegrandpre

Description

@arthurdegrandpre

Hi,

I have been using terra to work with satellite imagery, and have come across issues when reading some netcdf products.

Specifically, when opening outputs from Acolite atmospheric correction where lon and lat are stored as vars, terra does not recognize the extent of the data. In some cases, an additionnal var is included with the Acolite products containing projection information, preventing the issue.

When the first two vars are lon and lat, without any projection var, this results in the following warning message :
"vobjtovarid4: **** WARNING **** I was asked to get a varid for dimension named x BUT this dimension HAS NO DIMVAR! Code will probably fail at this point"

And the following SpatRaster properties :
extent : 0.2840993, 17542.72, 0.5, 17542.5 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs

Neither lon or lat vars are included in the bands of the SpatRaster object.

I am able to bypass this issue by using the ncdf4 library the following way:

image = ncdf4::nc_open(image_path)

lon = ncdf4::ncvar_get(image, image$var[[1]])
lat = ncdf4::ncvar_get(image, image$var[[2]])
b1 = ncdf4::ncvar_get(image, image$var[[3]])

r = terra::rast(b1, ext=c(range(lon), range(lat)), crs="+proj=lonlat")

Is there any way to force terra to read the product into a valid georeferencing? (In this case that would be WGS84)

Many thanks,
Arthur

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions