Search code examples
gisgeospatialbinr-raster

NSIDC sea ice .bin file to raster()


I am trying to follow the example give here under "A polar example"

This example uses sea-ice data in .bin format to plot as raster. I am trying the same with a different file available from the original ftp server of the National Snow and Ice Data Center. Hence, I assume there should be no issue. However, when I try to prompt R run the following script

# from NSIDC sea ice concentration file
baseurl <- "ftp://sidads.colorado.edu/pub/DATASETS/"

f2 <- paste(baseurl, 
        "nsidc0051_gsfc_nasateam_seaice/final-gsfc/north/daily/2013/nt_20130111_f17_v1.1_n.bin",
        sep='')

if (!file.exists(basename(f2))) download.file(f2, basename(f2), mode = "wb")
ice2 <- raster(basename(f2))

Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", : Cannot create a RasterLayer object from this file.

Where am I going wrong? is the .bin file corrupted? Any help appreciated!

Thanks!


Solution

  • ok, found a solution on github that works really nice.

    https://github.com/cran/raster/blob/master/R/nsidcICE.R

    Just replace in line 14 of the script

    hemi <- tolower(substr(bx, 21L, 21L)) 
    

    by

    hemi <- tolower(substr(bx, 22L, 22L)),
    

    as the new name structure differs slightly from the original one by one digit namly a dot in the v1.1 sequence!

    Compare:

    "nt_19781119_f07_v01_s.bin" 
    

    to the version I was interested in

    "nt_20130111_f17_v1.1_n.bin"