ajwdewit / pcse

Repository for the Python Crop Simulation Environment
Other
191 stars 127 forks source link

Fixing fill value #49

Closed LeaTresch closed 3 years ago

LeaTresch commented 3 years ago

Hi! I cloned the repo in order to use PCSE with the new NASA Power API. However, it's not usable as it is because of a KeyError in line 318 of nasapower.py (folder pcse/db). The dictionnary powerdata["header"] has a key name fill_value and not fillValue. I executed the class NASAPowerWeatherDataProvider with the right key and everything seems to work! I tried it on the master branch. Thanks! Léa

Amarounek commented 3 years ago

With fill_value, I am getting TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'.

I cannot find the bug so far...

Whole error:

TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
d:\Wheat_WLP.py in <module>
     32 wdp = NASAPowerWeatherDataProvider(latitude=15.746417, longitude=16.398476)
     33 
---> 34 print(wdp)
     35 
     36 df = pd.DataFrame(wdp.export())

~\scoop\apps\python39\3.9.4\lib\site-packages\pcse\base\weather.py in __str__(self)
    389         msg += "Longitude: %6.3f\n" % self.longitude
    390         msg += "Data available for %s - %s\n" % (self.first_date, self.last_date)
--> 391         msg += "Number of missing days: %i\n" % self.missing
    392         return msg
    393 

~\scoop\apps\python39\3.9.4\lib\site-packages\pcse\base\weather.py in missing(self)
    296     @property
    297     def missing(self):
--> 298         missing = (self.last_date - self.first_date).days - len(self.store) + 1
    299         return missing
    300 

TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'
ajwdewit commented 3 years ago

Thanks for bringing this up. I will have a look at the NASApower weatherdataprovider because I see some confusing behaviour that I have to sort out first.

Allard

mishagrol commented 3 years ago

@Amarounek perhaps this error is caused by the fact that the NASA POWER API returns NaN values for the PRECTOTCORR parameter for all dates, and the NASAPowerWeatherDataProvider class removes rows from pandas df if there is a NaN, the result is an empty pandas df.

I sent a mail to NASA, and they promised to return the Daily precipitation parameter:

We are planning to have the Daily precipitation back online in a week or less.

TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'

Amarounek commented 3 years ago

@mishagrol Thanks for the suggestion! I was just trying the updated PCSE remotely and on local machine and now it is running fine. Don't know where the issue was...

ajwdewit commented 3 years ago

I just updated PCSE to 5.5.0 and as far as I can see the NASAPowerWeatherDataProvider works, it includes the fix on the fill value. Give it a try if you like.