In [1]:
import hydroengine as he

import json
from shapely.geometry import mapping, shape

import pandas as pd

import matplotlib.pyplot as plt
%matplotlib inline  
import seaborn as sns

sns.set(color_codes=True)

Query lake ids only (Ethiopia)


In [3]:
# Ethiopia
geometry = { "type": "Point", "coordinates": [37.375, 11.572] }
id_only = True
lake_ids = he.get_lakes(geometry, id_only)

print(lake_ids)


[154, 179548, 1400918, 1401012, 1401267, 1401708, 1401571, 1401471, 1401480, 1401360, 1401326]

In [4]:
lake_id = lake_ids[0]

In [5]:
ts = he.get_lake_time_series(lake_id, 'water_area')

In [6]:
d = pd.DataFrame(ts)
d['time'] = pd.to_datetime(d['time'], unit='ms')
plt.plot(d.time, d.water_area, '.')


Out[6]:
[<matplotlib.lines.Line2D at 0x2a6f2343358>]

In [7]:
lake = he.get_lake_by_id(lake_id)

In [8]:
s = shape(lake['geometry'])
s


Out[8]:

In [9]:
lake['properties']


Out[9]:
{'Continent': 'Africa',
 'Country': 'Ethiopia',
 'Depth_avg': 9.3,
 'Dis_avg': 170.151,
 'Elevation': 1786,
 'Grand_id': 0,
 'Hylak_id': 154,
 'Lake_area': 3059.34,
 'Lake_name': 'Tana',
 'Lake_type': 1,
 'Poly_src': 'SWBD',
 'Pour_lat': 11.573725,
 'Pour_long': 37.407008,
 'Res_time': 1931.8,
 'Shore_dev': 2.47,
 'Shore_len': 484.93,
 'Slope_100': -1.0,
 'Vol_res': 0.0,
 'Vol_src': 1,
 'Vol_total': 28400.0,
 'Wshd_area': 15133.2}

In [2]:
# Crashes
lake_id = 17
ts = he.get_lake_time_series(lake_id, 'water_area')


---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
<ipython-input-2-24a75baaead1> in <module>()
      1 # Crashes
      2 lake_id = 17
----> 3 ts = he.get_lake_time_series(lake_id, 'water_area')

d:\src\github\hydro-engine\src\py\hydroengine\hydroengine.py in get_lake_time_series(lake_id, variable, scale)
     39     r = requests.post(SERVER_URL + '/get_lake_time_series', json=data)
     40 
---> 41     return json.loads(r.text)
     42 
     43 def download_lake_variable(lake_id, variable, path, scale):

C:\Program Files\Anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    317             parse_int is None and parse_float is None and
    318             parse_constant is None and object_pairs_hook is None and not kw):
--> 319         return _default_decoder.decode(s)
    320     if cls is None:
    321         cls = JSONDecoder

C:\Program Files\Anaconda3\lib\json\decoder.py in decode(self, s, _w)
    337 
    338         """
--> 339         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    340         end = _w(s, end).end()
    341         if end != len(s):

C:\Program Files\Anaconda3\lib\json\decoder.py in raw_decode(self, s, idx)
    355             obj, end = self.scan_once(s, idx)
    356         except StopIteration as err:
--> 357             raise JSONDecodeError("Expecting value", s, err.value) from None
    358         return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

In [ ]:
d = pd.DataFrame(ts)
d['time'] = pd.to_datetime(d['time'], unit='ms')
plt.plot(d.time, d.water_area, '.')