[R] Fwd: problem writing .bil files in netcdf
Abdoulaye Sarr
abdoulayesar at gmail.com
Mon Sep 5 11:38:41 CEST 2016
---------- Forwarded message ----------
From: Abdoulaye SARR <abdoulayesar at gmail.com>
Date: Mon, Jan 1, 2001 at 4:02 AM
Subject: Re: [R] problem writing .bil files in netcdf
To: Michael Sumner <mdsumner at gmail.com>
Cc: r-help at r-project.org
Hi Michael,
I had a problem with my mac hopefully solve now.
For the issue i submitted, I tried your suggestion with writeRaster which
creates a netcdf file. The problem when I look the results by displaying as
graph I seen the
values starting by -9000 and mainly are located in the continent
boundaries, so how to add in write taste the undef values and have precip
from 0 to x.
For the loop if successful is toe write each day in a separate netcdf file,
if done it will be easy to concatenate using nco or cdo.
To convert each day in netcdf I need to have an appropriate loop in a
script. I have to process many years.
Cheers,
Le 2 sept. 2016 à 15:09, Michael Sumner <mdsumner at gmail.com> a écrit :
On Fri, 2 Sep 2016 at 00:43 Abdoulaye SARR <abdoulayesar at gmail.com> wrote:
> Dear List,
>
> I have daily rainfall data in .bil format and can get info of the file
> using rgdal:
>
> > library(rgdal)
> > GDALinfo("/1981/v2p19810101.bil")
> rows 1600
> columns 1500
> bands 1
> lower left origin.x -20
> lower left origin.y -40
> res.x 0.05
> res.y 0.05
> ysign -1
> oblique.x 0
> oblique.y 0
> driver EHdr
> projection NA
>
> How can I read all daily file and write them as netcdf files and
> concatenate as one yearly file and also avoid boundary pixels alter
> rainfall values.
>
>
Hi,
You can read the single .bil and write it to NetCDF with raster (and the
rgdal and ncdf4) package:
library(raster)
r <- raster("/1981/v2p19810101.bil")
writeRaster(r, "v2p19810101.nc")
But, if you read in multi .bil files and build a multilayer raster, i.e.
st <- stack(list.files("/1981", pattern = "bil$", full.names = TRUE))
you *can* write it out to NetCDF, very similar to above with writeRaster,
but I think it will generate a variable (an netcdf array) for each layer.
To really write to .nc in a specific way you'll need to delve into the
standard tools in ncdf4, to create a file, create
variables/dimensions/attributes,
and then populate the variable, in this case probably one 3rd-level slice
for each .bil. That might be better done at the command line, say with nco
(the "nc operators"). There are copy-create idioms which is probably the
way to go if you have a template data file or CDF specification.
There may be some higher level tools in other packages on CRAN, check the
reverse depends/imports/suggests on CRAN for ncdf4. Also you should explore
RNetCDF which has an independent implementation.
(raster really blitzes the field in terms of high-level tools here, but it
has limits, with writing NetCDF *in specific ways* being one of them. GDAL
has similar limitations, since it sees the world in this
"array-as-2d-bands" way).
HTH, at least a little.
Cheers, Mike.
Best regards,
>
> Eus
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.
> org/posting-guide.html <http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
--
Dr. Michael Sumner
Software and Database Engineer
Australian Antarctic Division
203 Channel Highway
Kingston Tasmania 7050 Australia
[[alternative HTML version deleted]]
More information about the R-help
mailing list