Coder Social home page Coder Social logo

iamsaswata / imdlib Goto Github PK

View Code? Open in Web Editor NEW
28.0 28.0 14.0 8.21 MB

Download and process binary IMD meteorological data in Python

Home Page: https://imdlib.readthedocs.io

License: MIT License

Python 95.19% Shell 3.14% Makefile 0.76% Batchfile 0.91%
gridded-data imd python

imdlib's People

Contributors

iamsaswata avatar pratiman-91 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

imdlib's Issues

change of input arguments

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)

Hi! Still your code have some problems

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.

ValueError: Dataset.plot cannot be called directly. Use an explicit plot method

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(...)

Feature request: function to directly open a data file

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.

Not able to download 2022 data

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```

to_csv add lat and lon if None is selected

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'

error in imdlib respiratory

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:"

Date-wise download from realtime grid data section on IMD website

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.

Update version.py

The current version is 0.1.17 but version.py shows 0.1.16. Update it in the next release.

Clip by Shape files

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.

Add new feature get_data. If a variable is assigned then it should open all the downloaded files as well.

CURRENT VERSION:

import imdlib as imd

Downloading 8 years of rainfall data for India

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)

Opeining the downloaded dataset

data = imd.open_data(variable, start_yr, end_yr,'yearwise', file_dir)

POSSIBLE VERSION:
import imdlib as imd

Downloading 8 years of rainfall data for India

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

download and open dataset

data = imd.get_data(variable, start_yr, end_yr, fn_format='yearwise', file_dir=file_dir)

Resolution for IMD tmax/tmin data

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

rainfall data size of data-length mismatch

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

imdlib/imdlib/core.py

Lines 318 to 323 in 148ce10

data = np.array(list(map(lambda x: x, temp)))
# Added for new url (dated:Oct 10, 2022)
# Removing first element for rain for new url: https://imdpune.gov.in/lrfindex.php
if var_type == 'rain':
data = data[1:]

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.