From 50ecf064ac85f31b39dfdace50b92e1abec0165e Mon Sep 17 00:00:00 2001 From: Carlos Paniagua Date: Sat, 7 Dec 2024 17:51:19 -0500 Subject: [PATCH] refactor: update notebook to use long tracker --- notebooks/track-floes/track-floes.ipynb | 151 +++++++++++++++++++++--- 1 file changed, 136 insertions(+), 15 deletions(-) diff --git a/notebooks/track-floes/track-floes.ipynb b/notebooks/track-floes/track-floes.ipynb index a8c775c8..60239eea 100644 --- a/notebooks/track-floes/track-floes.ipynb +++ b/notebooks/track-floes/track-floes.ipynb @@ -27,9 +27,7 @@ "metadata": {}, "outputs": [], "source": [ - "using IceFloeTracker: pairfloes, deserialize, PaddedView, float64, mosaicview, Gray\n", - "using DataFrames\n", - "imshow(x) = Gray.(x);\n" + "using IceFloeTracker: deserialize, addfloemasks!, adduuid!, add_passtimes!, addψs!, long_tracker, imshow" ] }, { @@ -80,26 +78,133 @@ "metadata": {}, "outputs": [], "source": [ - "# Load data\n", - "pth = joinpath(HOME, \"test\", \"test_inputs\", \"tracker\")\n", - "floedata = deserialize(joinpath(pth,\"tracker_test_data.dat\"))\n", - "passtimes = deserialize(joinpath(pth,\"passtimes.dat\"))\n", + "begin # Load data\n", + " pth = joinpath(HOME, \"test\", \"test_inputs\", \"tracker\")\n", + " floedata = deserialize(joinpath(pth, \"tracker_test_data.dat\"))\n", + " # test/test_inputs/tracker/tracker_test_data.dat\n", + " passtimes = deserialize(joinpath(pth, \"passtimes.dat\"))\n", + " props, imgs = deepcopy.([floedata.props, floedata.imgs])\n", "\n", - "latlonimgpth = joinpath(HOME, \"test\", \"test_inputs\", \"NE_Greenland_truecolor.2020162.aqua.250m.tiff\")\n", + " # This order is important: masks, uuids, passtimes, ψs\n", + " addfloemasks!(props, imgs)\n", + " adduuid!(props)\n", + " add_passtimes!(props, passtimes)\n", + " addψs!(props)\n", + "end\n", "\n", - "props, imgs = deepcopy(floedata.props), deepcopy(floedata.imgs);\n", + "begin # Filter out floes with area less than `floe_area_threshold` pixels\n", + " floe_area_threshold = 400\n", + " for (i, prop) in enumerate(props)\n", + " props[i] = prop[prop[:, :area].>=floe_area_threshold, :];\n", + " sort!(props[i], :area, rev=true);\n", + " end\n", + "end\n", "\n", - "# Filter out floes with area less than 350 pixels\n", - "for (i, prop) in enumerate(props)\n", - " props[i] = prop[prop[:, :area].>=350, :]\n", - "end" + "# Delete some floes\n", + "deleteat!(props[1], 1); # delete the first floe in day 1 so it doesn't have a match in day 2\n", + "deleteat!(props[2], 5); # delete the fifth floe in day 2 so it doesn't have a match in day 1\n", + "\n", + "# All floes in days 1 and 2 have a match in day 3\n", + "# Expected: 5 trajectories, 3 of length 3 and 2 of length 2\n", + "nothing # suppress output -- not particularly informative. See the next block." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### 4. Pair and label floes" + "### 4. View floe data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Day 1\n", + "props[1][!, [:uuid, :passtime, :area]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "imshow(imgs[1])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "imshow(props[1][1, :mask])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Day 2\n", + "props[2][!, [:uuid, :passtime, :area]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "imshow(imgs[2]) # slightly rotated version of the image in day 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "imshow(props[2][1, :mask])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Day 3\n", + "props[3][!, [:uuid, :passtime, :area]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "imshow(props[3][1, :mask]) # missing in day 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "imshow(props[3][5, :mask]) # missing in day 2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 5. Pair and label floes" ] }, { @@ -109,7 +214,23 @@ "outputs": [], "source": [ "# Get paired floes with labels\n", - "pairs = pairfloes(imgs, props, passtimes, latlonimgpth, condition_thresholds, mc_thresholds)" + "trajectories = long_tracker(props, condition_thresholds, mc_thresholds);" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 6. View trajectories and _goodness_ of pairings" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "trajectories[!, [:uuid, :passtime, :area_mismatch, :corr]]" ] } ],