Skip to content

Commit

Permalink
Merge pull request #48 from ArtesiaWater/dev
Browse files Browse the repository at this point in the history
Release 0.3.1
  • Loading branch information
OnnoEbbens authored Dec 15, 2020
2 parents 5351efd + e9743e7 commit fd23d73
Show file tree
Hide file tree
Showing 27 changed files with 600 additions and 352 deletions.
32 changes: 18 additions & 14 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ installed on your computer. We recommend using the
`Anaconda Distribution <https://www.continuum.io/downloads>`_
of Python.

Installing `hydropandas`
------------------------
Installing hydropandas
----------------------

Install the module by typing::

Expand All @@ -22,7 +22,8 @@ Please note that some of the dependencies cannot be installed automatically
on Windows. If you do not have these packages already you can install them
manually using the following instructions:

Download these packages from `Christoph Gohlke's website<https://www.lfd.uci.edu/~gohlke/pythonlibs>`
Download these packages from `Christoph Gohlke's website <https://www.lfd.uci.edu/~gohlke/pythonlibs>`_ :

- GDAL
- Fiona
- Shapely
Expand All @@ -35,19 +36,22 @@ version. Also the architecture should match (i.e. 64bits vs 32bits). For example

- GDAL-3.1.4-cp38-cp38-win_amd64.whl

This is the GDAL version for Python 3.8 (as can be seen from the cp38 in the name),
for 64-bits Python (as derived from the amd64 in the name).
This is the GDAL version for Python `3.8` (as can be seen from the `cp38` in the name),
for `64-bits` Python (as derived from the `amd64` in the name).

Once you have downloaded the correct files, open Anaconda Prompt, and navigate to
the directory in which you saved your downloads. Now type the following commands
(the order is important):
1. `pip install GDAL-3.1.4-cp38-cp38-win_amd64.whl`
2. `pip install Fiona-1.8.17-cp38-cp38-win_amd64.whl`
3. `pip install Shapely-1.7.1-cp38-cp38-win_amd64.whl`
4. `pip install python_snappy-0.5.4-cp38-cp38-win_amd64.whl`
5. `pip install fastparquet-0.4.1-cp38-cp38-win_amd64.whl`

After you've done this you can install hydropandas using `pip install hydropandas`
the directory in which you saved your downloads. Now use the following commands
to install the packages (the order is important)::

pip install GDAL-3.1.4-cp38-cp38-win_amd64.whl
pip install Fiona-1.8.17-cp38-cp38-win_amd64.whl
pip install Shapely-1.7.1-cp38-cp38-win_amd64.whl
pip install python_snappy-0.5.4-cp38-cp38-win_amd64.whl
pip install fastparquet-0.4.1-cp38-cp38-win_amd64.whl

After you've done this you can install hydropandas using::

pip install hydropandas

For installing in development mode, clone the repository and install by
typing the following from the module root directory::
Expand Down
10 changes: 5 additions & 5 deletions examples/01_groundwater_observations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
],
"source": [
"# reading a dino csv file\n",
"fname = r'../tests/data/2019-Dino-test/Grondwaterstanden_Put/B33F0080001_1.csv'\n",
"fname = '../tests/data/2019-Dino-test/Grondwaterstanden_Put/B33F0080001_1.csv'\n",
"gw = hpd.GroundwaterObs.from_dino(fname=fname, verbose=True)"
]
},
Expand Down Expand Up @@ -717,8 +717,8 @@
}
],
"source": [
"fname1 = r'../tests/data/2019-Dino-test/Grondwaterstanden_Put/B33F0080001_1.csv'\n",
"fname2 = r'../tests/data/2019-Dino-test/Grondwaterstanden_Put/B33F0133001_1.csv'\n",
"fname1 = '../tests/data/2019-Dino-test/Grondwaterstanden_Put/B33F0080001_1.csv'\n",
"fname2 = '../tests/data/2019-Dino-test/Grondwaterstanden_Put/B33F0133001_1.csv'\n",
"gw1 = hpd.GroundwaterObs.from_dino(fname=fname1, verbose=False)\n",
"gw2 = hpd.GroundwaterObs.from_dino(fname=fname2, verbose=False)\n",
"\n",
Expand Down Expand Up @@ -1774,7 +1774,7 @@
],
"source": [
"# read using a .zip file with data\n",
"dinozip = r'../tests/data/2019-Dino-test/dino.zip'\n",
"dinozip = '../tests/data/2019-Dino-test/dino.zip'\n",
"dino_gw = hpd.ObsCollection.from_dino(dirname=dinozip, keep_all_obs=False, \n",
" verbose=False)\n",
"dino_gw"
Expand Down Expand Up @@ -1802,4 +1802,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
19 changes: 12 additions & 7 deletions examples/02_knmi_observations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@
"**attributes**\n",
"\n",
"A `KnmiObs` object has the following attributes:\n",
"- `name`: station name and variable\n",
"- `x`: x-coördinate in m RD\n",
"- `y`: y-coördinate in m RD\n",
"- `station`: station number\n",
"- `meta`: dictionary with other metadata"
"\n",
"* `name`: station name and variable\n",
"* `x`: x-coördinate in m RD\n",
"* `y`: y-coördinate in m RD\n",
"* `station`: station number\n",
"* `meta`: dictionary with other metadata"
]
},
{
Expand Down Expand Up @@ -195,6 +196,7 @@
"## Get KNMI data<a id=reading></a>\n",
"\n",
"There are 2 main functions to obtain KNMI data:\n",
"\n",
"1. `KnmiObs.from_knmi`\n",
"2. `KnmiObs.from_nearest_xy`\n",
"\n",
Expand Down Expand Up @@ -230,6 +232,7 @@
"**read options**\n",
"\n",
"The `KnmiObs.from_knmi` method contains the following keyword arguments:\n",
"\n",
"- `stn`: station number.\n",
"- `variable`: the type of measurement you want to get. For a list of all variable names check: http://projects.knmi.nl/klimatologie/daggegevens/selectie.cgi\n",
"- `startdate`: the start date of the time series you want, default is 1st of January 2019.\n",
Expand All @@ -239,6 +242,8 @@
"- `raise_exception`: option to raise an error when the requested time series is empty.\n",
"- `verbose`: option to print additional information to the screen.\n",
"\n",
"***\n",
"\n",
"The 3 examples below give a brief summary of these options"
]
},
Expand Down Expand Up @@ -902,9 +907,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
}
2 changes: 1 addition & 1 deletion examples/03_pastastore_from_observations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -662,4 +662,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
4 changes: 2 additions & 2 deletions hydropandas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .obs_collection import ObsCollection
from .observation import (GroundwaterObs, GroundwaterQualityObs, KnmiObs,
ModelObs, WaterlvlObs)
from .observation import (Obs, GroundwaterObs, GroundwaterQualityObs,
KnmiObs, ModelObs, WaterlvlObs)
from .extensions import geo as _geo
from .extensions import gwobs as _gwobs
from .extensions import plots as _plots
Expand Down
9 changes: 5 additions & 4 deletions hydropandas/extensions/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def distance_nearest_point(point_gdf1, pts=pts_gdf2):
lambda row: distance_nearest_point(row.geometry), axis=1)

return gdf1[['nearest point', 'distance nearest point']]

def get_nearest_polygon(self, gdf=None,
xcol_obs='x', ycol_obs='y',
verbose=False):
Expand All @@ -197,12 +197,13 @@ def get_nearest_polygon(self, gdf=None,
"""

gdf_obs = self._obj.to_gdf(xcol=xcol_obs, ycol=ycol_obs)

for i, point in gdf_obs.geometry.items():
distances = [point.distance(pol) for pol in gdf.geometry.values]
if (np.array(distances)==np.min(distances)).sum()>1:
if (np.array(distances) == np.min(distances)).sum() > 1:
raise ValueError('multiple polygons are nearest')
gdf_obs.loc[i, 'nearest polygon'] = gdf.iloc[np.argmin(distances)].name
gdf_obs.loc[i, 'nearest polygon'] = gdf.iloc[np.argmin(
distances)].name
gdf_obs.loc[i, 'distance nearest polygon'] = np.min(distances)

return gdf_obs[['nearest polygon', 'distance nearest polygon']]
Expand Down
71 changes: 31 additions & 40 deletions hydropandas/extensions/gwobs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import numpy as np
import pandas as pd
import xarray as xr
import scipy.interpolate as intp

from . import accessor

Expand Down Expand Up @@ -204,31 +202,27 @@ def get_modellayer_from_filter(ftop, fbot, zvec, left=-999, right=999,
print(f"- piezometer filter spans {lay_fbot - lay_ftop +1} layers."
" checking length per layer")
print(" - length per layer:")
# check which layer has the biggest length of the filter
length_layers = np.zeros(lay_fbot-lay_ftop+1)

# check which layer has the biggest length of the filter
length_layers = np.zeros(lay_fbot - lay_ftop + 1)
for i in range(len(length_layers)):
if i==0:
length_layers[i] = ftop - zvec[lay_ftop+1]
elif (i+1)==len(length_layers):
length_layers[i] = zvec[lay_ftop+i] - fbot
if i == 0:
length_layers[i] = ftop - zvec[lay_ftop + 1]
elif (i + 1) == len(length_layers):
length_layers[i] = zvec[lay_ftop + i] - fbot
else:
length_layers[i] = zvec[lay_ftop+i] - zvec[lay_ftop+1+i]
length_layers[i] = zvec[lay_ftop + i] - zvec[lay_ftop + 1 + i]

if verbose:
print(f" - lay {lay_ftop+i}: {length_layers[i]:.2f}")

# choose layer with biggest length
rel_layer = np.argmax(length_layers)
lay_out = lay_ftop + rel_layer
if verbose:
print(f" - selected layer: {lay_out}")
return lay_out

raise ValueError(
'Something is wrong with the input. Please submit an issue if you'
' think this is a bug.')

return np.nan


Expand Down Expand Up @@ -470,7 +464,7 @@ def get_modellayers(self, gwf, verbose=False):
name='modellayer')

return modellayers

def get_regis_layers(self, verbose=False):
"""Get the regis layer per observation.
Expand All @@ -483,10 +477,8 @@ def get_regis_layers(self, verbose=False):
-------
pd.Series with the names of the regis layer of each observation
"""


return self._obj.obs.apply(lambda o: o.gwobs.get_regis_layer(verbose))



@accessor.register_obs_accessor("gwobs")
Expand Down Expand Up @@ -521,52 +513,51 @@ def get_modellayer_modflow(self, gwf, left=-999, right=999, verbose=False):
left=left, right=right,
verbose=verbose)
return modellayer

def get_regis_layer(self, verbose=False):
"""find the name of the REGIS layer based on the filter depth.
Parameters
----------
verbose : boolean, optional
Print additional information to the screen (default is False).
Returns
-------
str
name of REGIS layer
"""
import xarray as xr

if np.isnan(self._obj.bovenkant_filter) or np.isnan(self._obj.onderkant_filter):
return 'nan'
#connect to regis netcdf

# connect to regis netcdf
regis_url = r'http://www.dinodata.nl:80/opendap/REGIS/REGIS.nc'
regis_ds = xr.open_dataset(regis_url, decode_times=False)
#rename layer in regis netcdf

# rename layer in regis netcdf
regis_ds = regis_ds.rename({'layer': 'layer_old'})
regis_ds.coords['layer'] = regis_ds.layer_old.astype(str)
regis_ds = regis_ds.swap_dims({'layer_old': 'layer'})
#get zvec regis netcdf
z = regis_ds['bottom'].sel(x=self._obj.x, y=self._obj.y,

# get zvec regis netcdf
z = regis_ds['bottom'].sel(x=self._obj.x, y=self._obj.y,
method='nearest').dropna(dim='layer')
ztop = regis_ds['top'].sel(x=self._obj.x, y=self._obj.y,
ztop = regis_ds['top'].sel(x=self._obj.x, y=self._obj.y,
method='nearest').max()
zvec = np.concatenate([[ztop.values],z.values])
#get index of regis model layer
zvec = np.concatenate([[ztop.values], z.values])

# get index of regis model layer
layer_i = get_modellayer_from_filter(self._obj.bovenkant_filter,
self._obj.onderkant_filter,
zvec,
zvec,
left=-999, right=999,
verbose=verbose)
if layer_i==999:

if layer_i == 999:
return 'above'
elif layer_i==-999:
elif layer_i == -999:
return 'below'

return str(z.layer[layer_i].values)
Loading

0 comments on commit fd23d73

Please sign in to comment.