pyet-org / pyet

:sunflower: pyet is a Python package to estimate reference and potential evaporation.
https://pyet.readthedocs.io/
MIT License
117 stars 29 forks source link

pm-fao56 method does not work for my Xarray.dataArray data #42

Closed Engel23 closed 1 year ago

Engel23 commented 1 year ago

Hi there! I am trying to use the pm-fao-56 method in pyet for gridded Xarray.dataArray data (CMIP6 climate data from a climate model). However, I get two Attribute errors every time, namely; 'DataArray' object has no attribute 'index' and 'DataArray' object has no attribute 'time'. The pandas.DatetimeIndex with which the date is retrieved does not seem to work for my dataArrays.

I have not yet discovered how to solve this and looking at the Xarray.dataArray example 2: 'Estimate PET for gridded data' (https://github.com/pyet-org/pyet/blob/master/examples/00_example_paper.ipynb) does not shed more light on the situation. I would be very grateful if someone could help me a bit further!

Have a good day!

mvremec commented 1 year ago

Hi @Engel23, Thank you for raising this issue.

Based on your description, it seems that the name of your DataArray's ("yourDataArray") time dimension is neither "time" or "index".

  1. You can check whether this is the case with: yourDataArray.dims It should return something like "({'time': 3672, 'y': 17, 'x': 20})" or "({'time': 3672, 'latitude': 17, 'longitude': 20})". If it does not return 'time', you can fix this by changing the current name of the time dimension (for example, let's call it "timeindex"): newDataArray = yourDataArray.rename_dims({"timeindex":"time"}) You should now be able to check the time dimension of the "newDataArray" with: newDataArray.time It should return an array with a dtype = 'datetime64[ns]' You should now be able to use "newDataArray" with PyEt.

I hope this answer solves your question. Please let me know! Is the CMIP6 data publicly available? If so, I can create an example using a subset of the data.

Best, Matevz


Why did this probably happen? In the FAO-56 method, the Day of the year (DOY) is needed to compute extraterrestrial radiation. In PyEt, DOY is obtained from the time dimension of the input Pandas.Series or xarray.DataArray. We have designed PyEt with an assumption that the xarray.DataArray time dimension is called "time" or "index". This is usually the case; however, there might be exceptions. That's why it's good to communicate on such issues. Thank you for that!

How to solve this in future versionsof PyEt? Add a function that raises an error if the name of the time dimension in xarray.DataArray is not "time".

43

Engel23 commented 1 year ago

Hi @mvremec, Thank you for your quick response and for your help, the dimension name was indeed where it went wrong since my dimension had a different name due to prior calculations. The pm-fao56 method seems to work now for my data! The CMIP6 data is publicly available here (https://esgf-node.llnl.gov/search/cmip6/), note that the variables needed for the pyet package (tasmax, tasmin, etc) are distributed into different netcdf files.

Again thank you for your help! Best, Engel

mvremec commented 1 year ago

Hi @Engel23, I am very glad to hear that. I have added an example with CMIP6 data I downloaded from Copernicus (https://cds.climate.copernicus.eu/) and will probably extend it to the data from your link. Thank you for that! Example 9: https://github.com/pyet-org/pyet/blob/dev/examples/09_CMIP6_data.ipynb

I wish you lots of fun and exciting work with PyEt! Best, Matevz