Reputation: 21
I have a GrADS formatted (Raw Binary) file with a control file as follows:
dset data.bin
undef -999.
options template
title Example data
xdef 720 linear 0.25 0.50
ydef 360 linear -89.75 0.50
tdef 1 linear 00Z01JAN1990 1yr
zdef 1 linear 1 1
vars 1
dat 0 99 Estimated data
ENDVARS
Does anyone have an idea of how to convert or reformat it into a common 2D raster file format using R or Python?
The expected output is a 2D map (which is usually as a raster file or 2D array) something like this map: Example of output
Upvotes: 2
Views: 1524
Reputation: 306
You may want to try this python package xgrads
, which will parse the ctl file and load the raw binary data into a widely-used data struct xarray
in earth science:
from xgrads import open_CtlDataset
# load the data into xarray.Dataset
dset = open_CtlDataset('data.ctl')
Then it is straightforward to have the data plotted as:
dset['dat'].plot()
Note that if the ctl and binary files are in the same folder, then the first line of ctl should be dset ^data.bin
. If they are not in the same folder, you should specify the absolute path of the .bin
file.
Hope this helps.
Upvotes: 1
Reputation: 8176
You can use CDO (Climate Data Operator) to do this by one line of code like
cdo -f nc import_binary Temp.ctl try.nc
But CDO installation in Windows is bit tricky. You can install Ubuntu subsystem within Windows and then install CDO within Ubuntu. After that install CDO in Ubuntu subsystem following the steps provided here https://zoomadmin.com/HowToInstall/UbuntuPackage/cdo. Then open the terminal in the directory where the .ctl file is there, then execute the above code.
Upvotes: 1