diff --git a/.travis.yml b/.travis.yml index 2e13b43..f21adeb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/appveyor.yml b/appveyor.yml index ba554a9..56d4c64 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,46 +4,41 @@ 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-x64" - TARGET_ARCH: x64 - CONDA_NPY: 111 - CONDA_INSTALL_LOCN: C:\\Miniconda36-x64 - CONDA_PY: 3.7 + PYTHON: "C:\\Python37-x64" + MINICONDA: "C:\\Miniconda3-x64" - TARGET_ARCH: x64 - CONDA_NPY: 111 - CONDA_INSTALL_LOCN: C:\\Miniconda37-x64 - CONDA_PY: 3.8 + PYTHON: "C:\\Python36-x64" + MINICONDA: "C:\\Miniconda3-x64" 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 + - 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 config --add channels conda-forge + - cmd: conda info + - cmd: conda list + - cmd: conda search landlab + - cmd: conda env create -f environment-dev.yml + - cmd: conda activate umami-dev - cmd: conda info - cmd: conda list build: false test_script: - - pip install numpy - pip install -e . - pytest -vvv diff --git a/notebooks/OtherIO_options.ipynb b/notebooks/OtherIO_options.ipynb index 92bfc27..9938e99 100644 --- a/notebooks/OtherIO_options.ipynb +++ b/notebooks/OtherIO_options.ipynb @@ -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" ] @@ -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. " ] @@ -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)" ] }, { @@ -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)" ] @@ -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. " ] @@ -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\")" ] }, { @@ -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()" ] }, { @@ -377,7 +374,7 @@ "metadata": {}, "outputs": [], "source": [ - "vmg_metric.names" + "hmg_metric.names" ] }, { @@ -386,7 +383,7 @@ "metadata": {}, "outputs": [], "source": [ - "vmg_metric.values" + "hmg_metric.values" ] }, { @@ -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)" ] }, diff --git a/umami/metric.py b/umami/metric.py index 2798ac6..aeb10a0 100755 --- a/umami/metric.py +++ b/umami/metric.py @@ -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. @@ -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() ] ) diff --git a/umami/residual.py b/umami/residual.py index 2880ad2..65620fa 100644 --- a/umami/residual.py +++ b/umami/residual.py @@ -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. @@ -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() ] )