Skip to content

Commit

Permalink
Merge 9dc07cc into 7d1241f
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarnhart committed Feb 28, 2020
2 parents 7d1241f + 9dc07cc commit 4005bb3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ install:
script:
- pip install pytest pytest-cov coveralls
- pip install jupyter pandas plotnine holoviews tqdm rasterio
- pip install terrainbento --pre
- pip install --pre terrainbento
- pytest umami tests/ --doctest-modules --cov=umami --cov-report=xml:$(pwd)/coverage.xml -vvv
after_success: coveralls
32 changes: 12 additions & 20 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,38 @@ environment:
matrix:

- TARGET_ARCH: x64
CONDA_NPY: 111
CONDA_INSTALL_LOCN: C:\\Miniconda37-x64
CONDA_PY: 3.6
PYTHON: "C:\\Python38-x64"
MINICONDA: "C:\\Miniconda3"

- TARGET_ARCH: x64
CONDA_NPY: 111
CONDA_INSTALL_LOCN: C:\\Miniconda36-x64
CONDA_PY: 3.7
PYTHON: "C:\\Python37-x64"
MINICONDA: "C:\\Miniconda3"

- TARGET_ARCH: x64
CONDA_NPY: 111
CONDA_INSTALL_LOCN: C:\\Miniconda37-x64
CONDA_PY: 3.8
PYTHON: "C:\\Python36-x64"
MINICONDA: "C:\\Miniconda3"

platform:
- x64

os: Previous Visual Studio 2015

init:
- "ECHO %CONDA_INSTALL_LOCN% %CONDA_PY% %HOME% %PLATFORM%"
- "ECHO %PYTHON% %MINICONDA% %HOME% %PLATFORM%"
- "ECHO %APPVEYOR_REPO_BRANCH%"

install:
- cmd: call %CONDA_INSTALL_LOCN%\Scripts\activate.bat
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
- cmd: call %MINICONDA%\Scripts\activate.bat
- "python -VV"
- cmd: conda update --yes --quiet conda
- cmd: set PYTHONUNBUFFERED=1
- cmd: conda config --set always_yes yes
- cmd: pip install pytest
- cmd: pip install jupyter pandas plotnine holoviews tqdm
- cmd: pip install terrainbento --pre
- cmd: conda install rasterio -c conda-forge
- cmd: conda install landlab -c conda-forge
- cmd: conda install numpy statsmodels landlab terrainbento twine pytest pytest-cov pytest-datadir rasterio -c conda-forge
- cmd: conda install jupyter pandas plotnine holoviews tqdm -c conda-forge
- cmd: conda info
- cmd: conda list

build: false

test_script:
- pip install numpy
- pip install -e .
- pytest -vvv

Expand Down
45 changes: 21 additions & 24 deletions notebooks/OtherIO_options.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"\n",
"import rasterio\n",
"\n",
"from landlab import imshow_grid, RasterModelGrid, VoronoiDelaunayGrid\n",
"from landlab import imshow_grid, RasterModelGrid, HexModelGrid\n",
"\n",
"from umami import Metric"
]
Expand Down Expand Up @@ -252,11 +252,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 3: Use irregular data and a `VoronoiDelaunayGrid`\n",
"## Step 3: Use irregular data and a `HexModelGrid`\n",
"\n",
"As a final example, we will look at specifying umami with an irregular grid. We won't import any standard format of irregular data but will create some by interpolating the regular data using the scipy tool [RegularGridInterpolator](https://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.interpolate.RegularGridInterpolator.html).\n",
"\n",
"We use a tenth as many grid nodes as we had in the prior example. This is just for speed, feel free to adjust the value for `factor` to change this. \n",
"We use a smaller number of nodes as we had in the prior example. This is just for speed, feel free to adjust the value for `factor` to change this. \n",
"\n",
"We start by creating a set of grid node locations in x and y. "
]
Expand All @@ -267,15 +267,13 @@
"metadata": {},
"outputs": [],
"source": [
"factor = 11\n",
"nnodes = int(rmg.x_of_node.size / factor)\n",
"np.random.seed(27)\n",
"factor = 5\n",
"dx = rmg.spacing[0] * factor\n",
"\n",
"# select a random subset of x_of_node and y_of_node and permute by a small quantity.\n",
"# permute only in x, which allows the ordering of nodes to be maintained \n",
"index = np.linspace(0, rmg.x_of_node.size-1, nnodes, dtype=int)\n",
"random_x = rmg.x_of_node[index] + 0.4 * rmg.spacing[0] * np.random.randn(index.size)\n",
"random_y = rmg.y_of_node[index] "
"hmg = HexModelGrid((int(rmg.shape[0]/factor*1.2), int(rmg.shape[1]/factor)+1), \n",
" dx, \n",
" node_layout=\"rect\", \n",
" xy_of_lower_left=rmg.xy_of_lower_left)"
]
},
{
Expand All @@ -292,7 +290,7 @@
"outputs": [],
"source": [
"plt.plot(rmg.x_of_node, rmg.y_of_node, 'k.', markersize=2, label=\"Raster Points\")\n",
"plt.plot(random_x, random_y, 'm.', label=\"Irregular Points\")\n",
"plt.plot(hmg.x_of_node, hmg.y_of_node, 'm.', label=\"Irregular Points\")\n",
"plt.xlim(-105.40, -105.375)\n",
"plt.ylim(40.00, 40.025)"
]
Expand All @@ -314,14 +312,14 @@
" rmg.x_of_node.reshape(rmg.shape)[0, :]),\n",
" z.reshape(rmg.shape), bounds_error=False, fill_value=None)\n",
"\n",
"interp_z = interp_obj((random_y, random_x))"
"interp_z = interp_obj((hmg.y_of_node, hmg.x_of_node))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we create a `VoronoiDelaunayGrid` and add `topographic__elevation` to it. \n",
"Next we create a `HexModelGrid` and add `topographic__elevation` to it. \n",
"\n",
"One nice feature of the `imshow_grid` function is that it works for both regular and irregular grids. "
]
Expand All @@ -332,10 +330,9 @@
"metadata": {},
"outputs": [],
"source": [
"vdg = VoronoiDelaunayGrid(random_x, random_y)\n",
"z = vdg.add_field(\"topographic__elevation\", interp_z, at=\"node\")\n",
"z = hmg.add_field(\"topographic__elevation\", interp_z, at=\"node\")\n",
"\n",
"imshow_grid(vdg, z, cmap=\"terrain\")"
"imshow_grid(hmg, z, cmap=\"terrain\")"
]
},
{
Expand Down Expand Up @@ -367,8 +364,8 @@
" }\n",
"}\n",
"\n",
"vmg_metric = Metric(vdg, metrics=metrics)\n",
"vmg_metric.calculate()"
"hmg_metric = Metric(hmg, metrics=metrics)\n",
"hmg_metric.calculate()"
]
},
{
Expand All @@ -377,7 +374,7 @@
"metadata": {},
"outputs": [],
"source": [
"vmg_metric.names"
"hmg_metric.names"
]
},
{
Expand All @@ -386,7 +383,7 @@
"metadata": {},
"outputs": [],
"source": [
"vmg_metric.values"
"hmg_metric.values"
]
},
{
Expand All @@ -402,9 +399,9 @@
"metadata": {},
"outputs": [],
"source": [
"for n in vmg_metric.names:\n",
" abs_change = np.abs(vmg_metric.value(n) - rmg_metric.value(n))\n",
" pct_change = abs_change /( 2* (vmg_metric.value(n) + rmg_metric.value(n)))\n",
"for n in hmg_metric.names:\n",
" abs_change = np.abs(hmg_metric.value(n) - rmg_metric.value(n))\n",
" pct_change = abs_change /( (hmg_metric.value(n) + rmg_metric.value(n))/2)\n",
" print(n, \"\\n abs_change: \", abs_change, \"\\n pct_change: \", pct_change)"
]
},
Expand Down
10 changes: 5 additions & 5 deletions umami/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ def write_metrics_to_file(self, path, style, decimals=3):
>>> file_contents = out.getvalue().splitlines()
>>> for line in file_contents:
... print(line.strip())
9.0 # me
5.0 # ep10
5.0 # oid1_mean
8 # sn1
9.0 me
5.0 ep10
5.0 oid1_mean
8 sn1
Next we output in *yaml* style, in which each metric is serialized in
YAML format.
Expand All @@ -241,7 +241,7 @@ def write_metrics_to_file(self, path, style, decimals=3):
if style == "dakota":
stream = "\n".join(
[
str(np.round(val, decimals=decimals)) + " # " + str(key)
str(np.round(val, decimals=decimals)) + " " + str(key)
for key, val in self._values.items()
]
)
Expand Down
10 changes: 5 additions & 5 deletions umami/residual.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ def write_residuals_to_file(self, path, style, decimals=3):
>>> file_contents = out.getvalue().splitlines()
>>> for line in file_contents:
... print(line.strip())
17.533 # me
9.909 # ep10
9.813 # oid1_mean
-41 # sn1
17.533 me
9.909 ep10
9.813 oid1_mean
-41 sn1
Next we output in *yaml* style, in which each metric is serialized in
YAML format.
Expand All @@ -343,7 +343,7 @@ def write_residuals_to_file(self, path, style, decimals=3):
if style == "dakota":
stream = "\n".join(
[
str(np.round(val, decimals=decimals)) + " # " + str(key)
str(np.round(val, decimals=decimals)) + " " + str(key)
for key, val in self._values.items()
]
)
Expand Down

0 comments on commit 4005bb3

Please sign in to comment.