API reference

Load data

imdlib.load(var, start[, end, source, ...])

Load IMD gridded data, downloading and caching the files as needed.

Cache

imdlib.cache.info([cache_dir])

Print the cache location and what is cached: periods, number of files, size and download dates per source and variable.

imdlib.cache.clear([var, years, source, ...])

Delete cached files (and their manifest entries).

imdlib.cache.set_dir(path)

Set the cache directory for the rest of this Python session.

imdlib.cache.get_dir([cache_dir])

Return the cache directory that imdlib.load() uses.

imdlib.cache.unlock([cache_dir])

Remove a leftover lock file of the cache, e.g. after a crash.

Download and read data

imdlib.get_data(var_type, start_yr[, ...])

Function to download binary data and return an IMD class object time range is tuple or list or numpy array of 2 int number

imdlib.open_data(var_type, start_yr[, ...])

Function to read binary data and return an IMD class object time range is tuple or list or numpy array of 2 int number

imdlib.get_real_data(var_type, start_dy[, ...])

Function to download real-time IMD data at daily timescale

imdlib.open_real_data(var_type, start_dy[, ...])

Function to read real-time binary data and return an IMD class object

IMD data object

imdlib.IMD(data, cat, start_day, end_day, ...)

Class to handle binary (.grd) IMD gridded meteorological data.

Convert and export

imdlib.IMD.get_xarray()

The data as an xarray.Dataset (dimensions time, lat, lon).

imdlib.IMD.to_csv([file_name, lat, lon, out_dir])

imdlib.IMD.to_netcdf([file_name, out_dir])

imdlib.IMD.to_geotiff([file_name, out_dir])

Regions

imdlib.IMD.region([state, district, city, ...])

Area-weighted mean time series of named regions of India.

imdlib.regions.search(text[, type, state, limit])

Find regions by part of their name.

imdlib.regions.list(type[, state, basin])

Official names of all regions of a type.

imdlib.regions.info()

Sources and counts of the region data shipped with IMDLIB.

imdlib.RegionError

A region could not be used (base class of the region errors).

imdlib.RegionNotFoundError

No region of the requested type has this name.

imdlib.AmbiguousRegionError

The name fits more than one region; add state= or district=.

Compare with past years

imdlib.history(var, start[, end, state, ...])

Compare a day, month, season or year at a place with the same period in past years.

Process gridded data

imdlib.IMD.copy()

Function to make a non-immutable copy of the IMD object.

imdlib.IMD.clip([shapefile, state, ...])

The data of one region: a state, district, CWC basin or sub-basin, or the polygons of a shapefile.

imdlib.IMD.remap(dnew)

Function to change resolution of IMD object.

imdlib.IMD.fill_na()

Function to fill missing data in IMD object.

imdlib.IMD.spatial_mean([weighted])

Compute area-weighted spatial mean, returning a time series.

imdlib.IMD.climatology()

Compute monthly climatology (long-term monthly mean).

imdlib.IMD.anomaly([climatology])

Compute monthly anomaly (departure from climatology).

Climate indices

imdlib.IMD.compute([method, scale])

Compute climate indices, trends or drought indices in place.

imdlib.compute.cdd(imd_obj[, threshold])

Function for finding Consecutive Dry Days in a year

imdlib.compute.cwd(imd_obj[, threshold])

Function for finding Consecutive Wet Days in a year

imdlib.compute.d64(imd_obj[, threshold])

Function for finding number of heavy rainfall days in a year

imdlib.compute.dr(imd_obj[, threshold])

Function for finding total Rainy days in a year

imdlib.compute.dtr_anu(tmx, **kwargs)

Function for annual mean Diurnal Temperature Range

imdlib.compute.mnadt_anu(imd_obj)

Function for minimum Annual Daily Tmin (Coolest night)

imdlib.compute.mxadt(imd_obj)

Function for maximum Annual Daily Tmax (Hottest Day)

imdlib.compute.pci(imd_obj)

Function for finding Precipitation concentration index

imdlib.compute.rtwd(imd_obj[, threshold])

Function for finding Total precipitation in wet days in a year

imdlib.compute.rx5d(imd_obj)

Function for Maximum Max 5 day rainfall in a year

imdlib.compute.rxa(imd_obj)

Function for Maximum annual rainfall

imdlib.compute.sdii(imd_obj)

Function for finding Simple precipitation intensity index

Drought indices

imdlib.drought.spi(imd_obj, **kwargs)

Compute Standardized Precipitation Index (SPI).

imdlib.drought.spei(imd_obj, **kwargs)

Compute Standardized Precipitation Evapotranspiration Index (SPEI).

Extreme temperature events

imdlib.IMD.heatwave([output, count, ...])

Detect heat waves using IMD's two-gate classification system.

imdlib.IMD.coldwave([output, count, ...])

Detect cold waves using IMD's two-gate classification system.

Trend analysis

imdlib.compute.anu_trend(imd_obj)

Function for annual trend analysis

imdlib.compute.mmk_hr(x_old[, alpha, lag])

This function checks the Modified Mann-Kendall (MK) test using Hamed and Rao (1998) method.

imdlib.compute.sen_percerntage(x)

Computes change magnitude as percentage of mean from Sen's slope estimator

imdlib.compute.sens_slope(x)

This method proposed by Theil (1950) and Sen (1968) to estimate the magnitude of the monotonic trend.

imdlib.compute.spr(x)

Computes Spearman’s rho test statistics (Zsr) for trend analysis

Date and grid utilities

imdlib.util.LeapYear(year)

Check leap year or not

imdlib.util.get_filename(year, var_type, ...)

Get filename for reading the file content in future

imdlib.util.get_filename_realtime(day, ...)

Get filename for reading the real-time file content in future

imdlib.util.get_lat_lon(lat, lon, lat_rage, ...)

Check INDEX of closest lat lon for a given co-ordinate

imdlib.util.parse_date_input(start[, end])

Parse date input that can be int year or 'YYYY-MM-DD' string.

imdlib.util.total_days(starting_day, ending_day)

Calculate to no of days for a given starting and ending day

imdlib.compute.bk_point(data)

This method provides index (last date) of every year from daily data.

imdlib.compute.bk_point_month(data)

This method provides index (last date) of every month from daily data.