[R-sig-Geo] make a raster from Aquarius files

Ben Tupper btupper at bigelow.org
Fri Dec 1 15:35:06 CET 2017


Hi,

Those Aquarius files look quite different from others I have used from OBPG (mostly MODISA and SeaWiFS). 

As a short-cut alternative, you could read all of the values into a matrix and make a global raster from that.  An example is shown below.  You can also subset the extraction as you have shown, but it might be easier to subset after making the raster using raster::crop()

CHeers,
Ben


### START

library(raster)
library(ncdf4)
library(rasterVis)

filename = "Q20151522015181.L3m_MO_SCIA_V5.0_SSS_1deg"

nc = ncdf4::nc_open(filename)
m = ncdf4::ncvar_get(nc, 'l3m_data')
ncdf4::nc_close(nc)
r = raster::raster(t(m))
rasterVis::levelplot(r)

### END

> On Dec 1, 2017, at 6:24 AM, Michael Sumner <mdsumner at gmail.com> wrote:
> 
> That file name does not correspond to the standard patterns used by the
> oceancolor site. All the L3m products from there are now (NetCDF 4.0) .nc
> and so will work fine with raster/ncdf4.  (Some years ago they were HDF4 -
> without an extension, as the shortcuts in the image thumbnails hints
> (SMI/HDF and BIN/HDF - SMI/L3m standard mapped image in your case).
> 
> I think you've got some other provider's version of a file, but there's not
> enough information here to know where you got it or what form it's in. I'm
> happy to look if you can point us to the source of
> Q20151522015181.L3m_MO_SCISM_V5.0_SSS_1deg.
> 
> But otherwise, can you share with us the output of
> 
> nc.data<-nc_open("Q20151522015181.L3m_MO_SCISM_V5.0_SSS_1deg")
> print(nc.data)
> 
> and if you're on a suitable system with HDF4 support a gdalinfo output of
> the file would be useful too.
> 
> Given that you can read it with ncdf4, and if it actually is NetCDF4 (not
> HDF4 or something else) you might help raster work with it by renaming it
> to "Q20151522015181.L3m_MO_SCISM_V5.0_SSS_1deg.nc" since (unlike GDAL and
> the NetCDF lib itself) raster uses explicit extension to dispatch to
> different format logic code, though it ultimately sends it down to rgdal to
> deal with if it can't recognize it - which is why I'm surprised you can't
> get it to work and ( I'm guessing wildly now):
> 
> Do you not have rgdal installed?
> 
> 
> What system are you on? Please use sessionInfo() to share details.
> 
> Cheers, Mike.
> On Fri, 1 Dec 2017, 06:14 Antonio Silva, <aolinto.lst at gmail.com> wrote:
> 
>> Hello
>> 
>> Some time ago I prepared scripts to extract temperature data from Modis
>> Aqua files. It can be found at https://gist.github.com/aolinto
>> 
>> HDF files can be downloaded at https://oceancolor.gsfc.nasa.gov/cgi/l3
>> 
>> I got the Aquarius sea surface salinity smoothed file from June 2015.
>> 
>> I could open and read the file:
>> 
>> library(ncdf4)
>> library(raster)
>> 
>> nc.data<-nc_open("Q20151522015181.L3m_MO_SCISM_V5.0_SSS_1deg")
>> print(nc.data)
>> dim(ncvar_get(nc.data,"l3m_data"))
>> ncvar_get(nc.data,"l3m_data")[c(110:160),c(110:117)]
>> 
>> But I could not prepare a raster from it. I tryed many things as:
>> 
>> rst.data <-
>> raster("Q20151522015181.L3m_MO_SCISM_V5.0_SSS_1deg",varname="l3m_data")
>> Error in .local(.Object, ...) :
>>  `AQUARIUS/Q20151522015181.L3m_MO_SCISM_V5.0_SSS_1deg' not recognised as a
>> supported file format.
>> 
>> Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",
>> :
>>  Cannot create a RasterLayer object from this file.
>> 
>> and variations with band and layer.
>> 
>> I would greatly appreciate any suggestions to solve this issue.
>> 
>> Thanks
>> 
>> --
>> Antônio Olinto Ávila da Silva
>> Fisheries Institute
>> São Paulo, Brasil
>> 
>>        [[alternative HTML version deleted]]
>> 
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 
> -- 
> Dr. Michael Sumner
> Software and Database Engineer
> Australian Antarctic Division
> 203 Channel Highway
> Kingston Tasmania 7050 Australia
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecocast Reports: http://seascapemodeling.org/ecocast.html
Tick Reports: https://report.bigelow.org/tick/
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/



More information about the R-sig-Geo mailing list