iamsaswata / imdlib Goto Github PK
View Code? Open in Web Editor NEWDownload and process binary IMD meteorological data in Python
Home Page: https://imdlib.readthedocs.io
License: MIT License
Download and process binary IMD meteorological data in Python
Home Page: https://imdlib.readthedocs.io
License: MIT License
I was trying to download imd gridded data, but got the error:
File Download Failed! Error: 404 Client Error: Not Found for url: https://imdpune.gov.in/Clim_Pred_LRF_New/rainfall.php
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
use of
data = imd.open_data(start_yr, end_yr, 'rain','yearwise', file_dir)
instead of
data = imd.open_data((start_yr, end_yr), 'rain','yearwise', file_dir)
and if only one year is given then it can be treated as a single year
data = imd.open_data(year, 'rain','yearwise', file_dir)
It can't write tiff file with CRS. and not ignoring no data. I am also a GIS developer and want to collaborate with you to solve this also add some more features to this.
Adding a new feature using https://pratiman-91.github.io/2020/10/06/IMD-grided-to-GeoTIFF.html
I used the library successfully before updating the python version on conda.
Requesting support for python >= 3.7
Thank you for the tutorial but I could not get the visualisation working.
# Python version.
Python 3.7.10
>>> xr_objecct.mean('time').plot()
ValueError Traceback (most recent call last)
<ipython-input-50-befe6e3c72d0> in <module>
----> 1 xr_objecct.mean('time').plot()
/usr/local/lib/python3.7/site-packages/xarray/plot/dataset_plot.py in __call__(self, *args, **kwargs)
185 def __call__(self, *args, **kwargs):
186 raise ValueError(
--> 187 "Dataset.plot cannot be called directly. Use "
188 "an explicit plot method, e.g. ds.plot.scatter(...)"
189 )
ValueError: Dataset.plot cannot be called directly. Use an explicit plot method, e.g. ds.plot.scatter(...)
Hi, there is a simpler (or you can say, more low-level) requirement that I think many folks will have :
For any one-off downloaded .GRD file from the IMD webiste, like: "Maxtemp_MaxT_1979.GRD" (that's the file naming done by the server when you download directly from browser), imdlib should provide a function to directly open a raw file.
Instead of having to supply a containing folder, start/end year and other params,
So, we should have a command like:
imdlib.open_data_file_year('tmax', 'Maxtemp_MaxT_1979.GRD', 1979)
Am trying to make a function and submit a PR.
Hi Saswata, thanks for creating this library. This work adds a lot of value to my work. However I am stuck with an issue and your help would really be appreciated.
I am trying to download the data for 2022 and getting the following error
Downloading: rain for year 2022
Download Successful !!!
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
Input In [1], in <module>
4 end_yr = 2022
5 variable = 'rain' # other options are ('tmin'/ 'tmax')
----> 6 data = imd.get_data(variable, start_yr, end_yr, fn_format='monthwise')
File /opt/conda/lib/python3.9/site-packages/imdlib/core.py:497, in get_data(var_type, start_yr, end_yr, fn_format, file_dir, sub_dir, proxies)
493 f.write(response.content)
495 print("Download Successful !!!")
--> 497 data = open_data(var_type, start_yr, end_yr, fn_format, file_dir)
498 return data
500 except requests.exceptions.HTTPError as e:
File /opt/conda/lib/python3.9/site-packages/imdlib/core.py:327, in open_data(var_type, start_yr, end_yr, fn_format, file_dir)
325 # Check consistency of data points
326 if len(data) != nlen:
--> 327 raise Exception("Error in file reading,"
328 "mismatch in size of data-length")
330 # Reshape data into a shape of
331 # (days_in_year, lon_size_class, lat_size_class)
332 data = np.transpose(np.reshape(data, (days_in_year, lat_size_class,
333 lon_size_class), order='C'), (0, 2, 1))
Exception: Error in file reading,mismatch in size of data-length```
import imdlib as imd
start_yr =2018
end_yr = 2018
variable = 'rain' # other options are ('tmin'/ 'tmax')
data = imd.open_data((start_yr, end_yr), 'rain','yearwise')
data.to_csv('test.csv')
Traceback (most recent call last):
File "", line 1, in
File "C:\ProgramData\Miniconda3\lib\site-packages\imdlib\core.py", line 77, in to_csv
self.lat_array, self.lon_array)
File "C:\ProgramData\Miniconda3\lib\site-packages\imdlib\util.py", line 26, in get_lat_lon
lat_index = np.abs(lat_rage - lat).argmin()
TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'
hello, i am doing a research on some Meteorological data but keep getting same error.
"File "/home/vaibhav/PycharmProjects/pythonProject/venv/lib/python3.8/site-packages/imdlib/core.py", line 314, in open_data
with open(fname, 'rb') as f:"
Need to add netCDF-4 or scipy as a requirement for creating netcdf files
Hi Saswata, first of all thanks a ton for making this amazing lib which made the gridded data usage a breeze.
There is a separate section in IMD website: https://imdpune.gov.in/lrfindex.php
where there is gridded real time data : It offers date-wise .grd downloads.
Would this library support downloading/opening those too?
I'm actually looking more for how to properly open and read those files than downloading them. How are you opening the yearwise files - inside are they directly xarray data? Or is some transformation needed?
If some modification may be needed, then can you point me to some places in the code where to do, I know python and might be able to make a PR for the same.
New Feature to_netcdf must include the CF conventions. This will help to maintain the compatibility in other software.
https://unidata.github.io/python-training/workshop/XArray/xarray-and-cf/
Might be help at later stage.
The current version is 0.1.17
but version.py shows 0.1.16
. Update it in the next release.
I would like to express my sincere gratitude for the creation of the imdlib Python package. Your dedication to developing this valuable tool has greatly contributed to simplifying data manipulation and analysis, particularly in the context of meteorological data.
How do to trim a rainfall dataset based on a shapefile or the extent of the shapefiles? I want to download data for the Ganga Basin instead of the whole of India.
Thank you.
For the conda package the current recipe is available in https://github.com/iamsaswata/imdlib/tree/master/conda The documentation to add a new recipe to conda-forge is at https://conda-forge.org/#contribute . It is probably a good idea if you could add it there and become the conda-forge maintainer for imdlib too. This can make the process a lot easier. Thanks!
CURRENT VERSION:
import imdlib as imd
start_yr = 2010
end_yr = 2018
variable = 'rain' # other options are ('tmin'/ 'tmax')
file_dir = (r'C:\Users\imdlib\Desktop') #Path to save the files
imd.get_data(variable, start_yr, end_yr, fn_format='yearwise', file_dir=file_dir)
data = imd.open_data(variable, start_yr, end_yr,'yearwise', file_dir)
POSSIBLE VERSION:
import imdlib as imd
start_yr = 2010
end_yr = 2018
variable = 'rain' # other options are ('tmin'/ 'tmax')
file_dir = (r'C:\Users\imdlib\Desktop') #Path to save the files
data = imd.get_data(variable, start_yr, end_yr, fn_format='yearwise', file_dir=file_dir)
Hi,
I can see the latest version is now supporting the 0.5 x 0.5 degree data, so when downloading the real-time tmin/tmax data, is there any parameter that should be used to specify which resolution is needed, or does it automatically downloads 0.5 x 0.5 degree data?
Thanks in advance
Exception: Error in file reading,mismatch in size of data-length occurs when handling rainfall data for any year. I have updated the library to 0.1.15 and the issue still persisted. I got around the problem with commenting out the lines 322 and 323 in core.py
Lines 318 to 323 in 148ce10
am i making some stupid mistake or is it problem with the imd data being changed to old format that makes the new code reduntant?
Need to add matplotlib as a requirement
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.