IMDLIB

· ☕ 2 min read · 🤖 Saswata Nandi

Description

This is a python package to handle binary grided data from Indian Meterological department (IMD).

Installation

IMDLIB can be installed via pip, conda, or using the source file from Github. It is tested for both Windows and Linux platforms with 64 bit architecture only.

Installation using pip.

1
pip install imdlib

Installation using conda.

1
conda install -c iamsaswata imdlib

Installation from source file.

1
pip install git+https://github.com/iamsaswata/imdlib.git

IMDLIB is currently built with the following plugins. You need to have a python version >= 3.5 and install the below dependencies before installing IMDLIB from source.

Plugin Version No
certifi [2019.11.28]
numpy [1.18.1]
pandas [0.25.3]
python-dateutil [ 2.8.1 ]
pytest [5.3.4]
pytz [ 2019.3]
xarray [0.14.1]

Usage

Reading binary dataset

One major purposes of IMDLIB is to process gridded IMD meterological dataset. The original data is available in .grd file format. IMDLIB can read .grd file in xarray style and will create a IMD class objetct.

1
2
3
4
5
6
7
8
9
import imdlib as imd

start_yr =2018
end_yr = 2018
variable = 'rain' # other options are ('tmin'/ 'tmax')
file_format = 'yearwise' # other option (None), which will assume deafult imd naming convention
file_dir = '/home/data/imd' # other option keep it blank
data = imd.open_data((start_yr, end_yr), 'rain','yearwise', file_dir)
data
<imdlib.core.IMD at 0x7f39b0960750>

file_dir should refer to top-lev directory. It should contain 3 sub-directories. rain, tmin, and tmax.

if file_dir exist, but no subdirectory, it will try to find the files in file_dir. But be careful if you are using file_format = 'yearwise', as it will not differentiate between 2018.grd for rainfall and 2018.grd for tmin.

if file_dir is not given, it will look for the associate subdirectories and files from the current directory.

Get shape of IMD objecct

1
data.shape
(365, 135 129)

Get numpy. ndarray

1
np_array = data.data

Get xarray object

1
2
xr_objecct = data.get_xarray()
type(xr_objecct)
xarray.core.dataarray.DataArray

Display mean rainfall in Map

1
xr_objecct.mean('time').plot()

png

Processing and Saving

1
2
3
4
5
6
7
8
9
# Get data for a given coordinare and convert to csv file
data.to_csv(self, file_name, lat=None, lon=None, out_dir=None)

# Get data for a given coordinare and convert to twxt file
data.to_ascii(self, file_name, lat=None, lon=None, out_dir=None)

# Convert to netcdf file
data.to_netcdf(self, file_name, out_dir=None)

License

IMDLIB is available under MIT the open source license.


Saswata Nandi
WRITTEN BY
Saswata Nandi
PhD Student in Hydrology