Skip to content

Commit

Permalink
👌 Exact grid spacing, broaden mask and refactor tilling function
Browse files Browse the repository at this point in the history
Final part of #52! Increasing number of training image tiles from 2111 to 2480! Couple of changes for that to work. The grid spacing -I flag in GMT now uses 250+e instead of 250 so that output cell size is precisely 250 metres. Mask_cell_radius was increased from 2 to 3 (i.e. 7x7 pixel neighbourhood mask) to get more tiles along the Siple Coast area.

Tiling functions refactored for speed, fixing rounding errors, and linted using black. Note that we are still using the default gridline registration https://gmt.soest.hawaii.edu/doc/latest/GMT_Docs.html#gridline-registration when doing interpolation. Unit tests added for get_window_bounds and selective_tile functions!!
  • Loading branch information
weiji14 committed Nov 24, 2018
1 parent 8706302 commit ab0295e
Show file tree
Hide file tree
Showing 2 changed files with 224 additions and 105 deletions.
257 changes: 163 additions & 94 deletions data_prep.ipynb

Large diffs are not rendered by default.

72 changes: 61 additions & 11 deletions test_ipynb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,56 @@
" '0.05808/0.83244/0.02058/0.95071'\n",
"ok\n",
"Trying:\n",
" xr.DataArray(\n",
" data=np.zeros(shape=(36, 32)),\n",
" coords={\"x\": np.arange(1, 37), \"y\": np.arange(1, 33)},\n",
" dims=[\"x\", \"y\"],\n",
" ).to_netcdf(path=\"/tmp/tmp_wb.nc\")\n",
"Expecting nothing\n",
"ok\n",
"Trying:\n",
" get_window_bounds(filepath=\"/tmp/tmp_wb.nc\")\n",
"Expecting:\n",
" Tiling: /tmp/tmp_wb.nc ... 2\n",
" [(0.5, 4.5, 32.5, 36.5), (0.5, 0.5, 32.5, 32.5)]\n",
"ok\n",
"Trying:\n",
" os.remove(\"/tmp/tmp_wb.nc\")\n",
"Expecting nothing\n",
"ok\n",
"Trying:\n",
" xr.DataArray(\n",
" data=np.random.RandomState(seed=42).rand(64).reshape(8, 8),\n",
" coords={\"x\": np.arange(8), \"y\": np.arange(8)},\n",
" dims=[\"x\", \"y\"],\n",
" ).to_netcdf(path=\"/tmp/tmp_st.nc\", mode=\"w\")\n",
"Expecting nothing\n",
"ok\n",
"Trying:\n",
" selective_tile(\n",
" filepath=\"/tmp/tmp_st.nc\",\n",
" window_bounds=[(1.0, 4.0, 3.0, 6.0), (2.0, 5.0, 4.0, 7.0)],\n",
" )\n",
"Expecting:\n",
" Tiling: /tmp/tmp_st.nc\n",
" array([[[[0.18485446],\n",
" [0.96958464]],\n",
" <BLANKLINE>\n",
" [[0.4951769 ],\n",
" [0.03438852]]],\n",
" <BLANKLINE>\n",
" <BLANKLINE>\n",
" [[[0.04522729],\n",
" [0.32533032]],\n",
" <BLANKLINE>\n",
" [[0.96958464],\n",
" [0.77513283]]]], dtype=float32)\n",
"ok\n",
"Trying:\n",
" os.remove(\"/tmp/tmp_st.nc\")\n",
"Expecting nothing\n",
"ok\n",
"Trying:\n",
" xyz_data = 1000*pd.DataFrame(np.random.RandomState(seed=42).rand(60).reshape(20, 3))\n",
"Expecting nothing\n",
"ok\n",
Expand All @@ -166,26 +216,26 @@
"Trying:\n",
" grid.to_array().values\n",
"Expecting:\n",
" array([[[388.9193 , 542.3901 , 711.7681 , 964.1099 , 798.63763],\n",
" [361.2711 , 503.67337, 461.1001 , 207.78824, 272.23367],\n",
" [358.95032, 346.20276, 130.3158 , 127.49137, 219.36589],\n",
" [426.14886, 444.0474 , 185.34523, 382.60327, 479.42456],\n",
" [495.67093, 731.8629 , 231.33981, 787.7948 , 808.39734]]],\n",
" array([[[403.17618 , 544.92535 , 670.7824 , 980.75055 , 961.47723 ],\n",
" [379.0757 , 459.26407 , 314.38297 , 377.78555 , 546.0469 ],\n",
" [450.67664 , 343.26 , 88.391594, 260.10492 , 452.3337 ],\n",
" [586.09906 , 469.74008 , 216.8168 , 486.9802 , 642.2116 ],\n",
" [451.4794 , 652.7244 , 325.77896 , 879.8973 , 916.7921 ]]],\n",
" dtype=float32)\n",
"ok\n",
"4 items had no tests:\n",
"2 items had no tests:\n",
" data_prep\n",
" data_prep.get_window_bounds\n",
" data_prep.parse_datalist\n",
" data_prep.selective_tile\n",
"5 items passed all tests:\n",
"7 items passed all tests:\n",
" 6 tests in data_prep.ascii_to_xyz\n",
" 3 tests in data_prep.check_sha256\n",
" 3 tests in data_prep.download_to_path\n",
" 2 tests in data_prep.get_region\n",
" 3 tests in data_prep.get_window_bounds\n",
" 3 tests in data_prep.selective_tile\n",
" 5 tests in data_prep.xyz_to_grid\n",
"19 tests in 9 items.\n",
"19 passed and 0 failed.\n",
"25 tests in 9 items.\n",
"25 passed and 0 failed.\n",
"Test passed.\n"
]
}
Expand Down

0 comments on commit ab0295e

Please sign in to comment.