From 69cb28e03f16d89d19cbdc0a6f30b4ebd3eca33f Mon Sep 17 00:00:00 2001 From: David Shean Date: Mon, 18 Sep 2023 23:55:43 -0700 Subject: [PATCH] bundle_adjust_plots, corr_and_dem_plots, WIP reorg --- bundle_adjust_plots.ipynb | 108 +++++++++-------- corr_and_dem_plots.ipynb | 244 ++++++++++++++------------------------ 2 files changed, 143 insertions(+), 209 deletions(-) diff --git a/bundle_adjust_plots.ipynb b/bundle_adjust_plots.ipynb index 7dab796..2b90a27 100644 --- a/bundle_adjust_plots.ipynb +++ b/bundle_adjust_plots.ipynb @@ -69,6 +69,16 @@ "topdir = '/Users/dshean/scr/BlackSky/Utqiagvik_20220425_stereo/BSG-STEREO-102-20220425-215106-22900060-stereo_reorder_20230119/'" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "efcef52d-4f58-4a39-b0f3-e6b86657b335", + "metadata": {}, + "outputs": [], + "source": [ + "topdir = '/Users/dshean/scr/hma_glof_samples_for_asp_plot'" + ] + }, { "cell_type": "code", "execution_count": null, @@ -130,6 +140,16 @@ "#ba_brefix=\"ba/ba_ip2k_nadirpinhole\"" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "0661c87b-6c1a-4761-b967-13b485051854", + "metadata": {}, + "outputs": [], + "source": [ + "ba_prefix = 'ba/ba_csm'" + ] + }, { "cell_type": "code", "execution_count": null, @@ -141,6 +161,17 @@ "#map_crs = 'EPSG:32604'" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "4959cb3a-16f0-4bb5-a350-caff336756d0", + "metadata": {}, + "outputs": [], + "source": [ + "map_crs = 'EPSG:32645'\n", + "#map_crs = 'EPSG:32604'" + ] + }, { "cell_type": "code", "execution_count": null, @@ -153,6 +184,16 @@ "#refdem = 'COP30_lzw-adj_proj_ref.tif'" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "09dad1c1-be21-4de7-a792-deae88438c45", + "metadata": {}, + "outputs": [], + "source": [ + "refdem = 'GongbatongshaTsho_COP30_lzw-adj_proj.tif'" + ] + }, { "cell_type": "code", "execution_count": null, @@ -435,38 +476,12 @@ "metadata": {}, "outputs": [], "source": [ - "geodiff_init = read_geodiff(geodiff_init_csv)\n", - "geodiff_final = read_geodiff(geodiff_final_csv)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "062012ed-68db-410d-b61f-3cf221971140", - "metadata": {}, - "outputs": [], - "source": [ - "geodiff_init.describe()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e2b41b9a-1b91-48ab-8bd6-5ee95e095162", - "metadata": {}, - "outputs": [], - "source": [ - "geodiff_final.describe()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "0bdbd967-a0e1-41dd-9343-a83a1d2aac13", - "metadata": {}, - "outputs": [], - "source": [ - "resid_plot(geodiff_init, geodiff_final, col='diff', clim=(-15, 15), cmap='RdYlBu')" + "if os.path.exists(geodiff_init_csv) and os.path.exists(geodiff_final_csv):\n", + " geodiff_init = read_geodiff(geodiff_init_csv)\n", + " geodiff_final = read_geodiff(geodiff_final_csv)\n", + " geodiff_init.describe() \n", + " geodiff_final.describe()\n", + " resid_plot(geodiff_init, geodiff_final, col='diff', clim=(-15, 15), cmap='RdYlBu')" ] }, { @@ -504,31 +519,14 @@ { "cell_type": "code", "execution_count": null, - "id": "508c1374-e1f3-4593-b18e-f56160808769", - "metadata": {}, - "outputs": [], - "source": [ - "mapproj_match_offset = read_mapproj_match_offset(mapproj_match_offset_txt)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a3fc0938-ca16-46cc-8464-fdc04cb590e9", - "metadata": {}, - "outputs": [], - "source": [ - "mapproj_match_offset.describe()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "361b42b9-9cc0-480d-b8ce-c01fdea062e7", + "id": "f33d7a44-743f-4577-abad-cb36ab700cd1", "metadata": {}, "outputs": [], "source": [ - "col='mapproj_ip_dist_meters'" + "if os.path.exists(mapproj_match_offset_txt):\n", + " mapproj_match_offset = read_mapproj_match_offset(mapproj_match_offset_txt)\n", + " mapproj_match_offset.describe()\n", + " col='mapproj_ip_dist_meters'\n" ] }, { @@ -1353,7 +1351,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/corr_and_dem_plots.ipynb b/corr_and_dem_plots.ipynb index 0fd5fa1..5c25284 100644 --- a/corr_and_dem_plots.ipynb +++ b/corr_and_dem_plots.ipynb @@ -6,7 +6,6 @@ "metadata": {}, "source": [ "# ASP Stereo Output Plotting\n", - "### Examples for BlackSky Easton Glacier test case (n=20)\n", "\n", "David Shean \n", "1/2/23" @@ -17,8 +16,8 @@ "id": "db995225-27fb-48fe-98ec-c4dac4601f8e", "metadata": {}, "source": [ - "### To do:\n", - "* Integrate the disparity plot notebook - remove x and y bias, show total magnitude" + "## To do:\n", + "* Integrate with the disparity plot notebook - remove x and y bias, show total magnitude" ] }, { @@ -70,87 +69,13 @@ " ax.set_yticks([])" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "9f80fb99-a48a-442f-a305-b1f00e94285d", - "metadata": {}, - "outputs": [], - "source": [ - "#topdir = '/Users/dshean/scr/BlackSky/DAN_TUM_multiple_opportunities/Dana/stereo_nadirpinhole/'\n", - "topdir = '/Users/dshean/scr/BlackSky/DAN_TUM_multiple_opportunities/Dana/stereo_rpc/'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e9e7fc0a-afa0-4d05-a667-fc6c2c533c9b", - "metadata": {}, - "outputs": [], - "source": [ - "topdir = '/Users/dshean/scr/BlackSky/GM_SnowOff_202208/stereo_nadirpinhole/'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a040f989-f2e0-4a2e-a450-1e009efd75c2", - "metadata": {}, - "outputs": [], - "source": [ - "topdir = '/Users/dshean/scr/BlackSky/GM_SnowOff_202208/stereo_rpc/'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "fc28fb94-4faf-4689-97b4-c1f350780e8a", - "metadata": {}, - "outputs": [], - "source": [ - "#topdir = '/Users/dshean/scr/BlackSky/EastonGlacier_20220918-20221012/non-ortho_20230102/stereo_ba_all_maskref_tri_weight_pc_align'\n", - "topdir = '/Users/dshean/scr/BlackSky/EastonGlacier_20220918-20221012/non-ortho_20230102/stereo_rpc/'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "748c0572-b9e5-40f4-8c8d-d989c5402111", - "metadata": {}, - "outputs": [], - "source": [ - "topdir = '/Users/dshean/scr/BlackSky/Utqiagvik_20220425_stereo/BSG-STEREO-102-20220425-215106-22900060-stereo_reorder_20230119/stereo_rpc/'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7b72196a-90fc-4492-a7f1-4db7ca8e9b98", - "metadata": {}, - "outputs": [], - "source": [ - "cd $topdir" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3825e99e-c099-4757-b9d2-7e499ed48cf0", - "metadata": {}, - "outputs": [], - "source": [ - "outdir_list = glob.glob('BSG*__BSG*/*DEM.tif')\n", - "outdir_list = [os.path.split(p)[0] for p in outdir_list]\n", - "outdir_list.sort()" - ] - }, { "cell_type": "markdown", "id": "335d680c-e0f2-4652-bdfd-caf2ffc3f2de", "metadata": {}, "source": [ "### WIP: read match files to plot on orthoimages\n", - "Modified from `bare`" + "Modified from `bare`: https://github.com/friedrichknuth/bare" ] }, { @@ -214,72 +139,8 @@ "metadata": {}, "outputs": [], "source": [ - "read_match(match_fn)" - ] - }, - { - "cell_type": "markdown", - "id": "68bc86d3-edf1-482e-aa58-e2b083bb2761", - "metadata": {}, - "source": [ - "## Stereo correlation plots" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d2f44bd6-5e75-48fb-a8e6-e9c4dce5e9b7", - "metadata": {}, - "outputs": [], - "source": [ - "def plot_corr_results(outdir):\n", - " f, axa = plt.subplots(3, 2, figsize=(7.5,10), dpi=220)\n", - " axa = axa.ravel()\n", - " \n", - " l_img_fn = glob.glob(os.path.join(outdir, '*-L.tif'))[0]\n", - " l_img_ma = read_array(l_img_fn)\n", - " \n", - " r_img_fn = glob.glob(os.path.join(outdir, '*-R.tif'))[0]\n", - " r_img_ma = read_array(r_img_fn)\n", - " \n", - " disp_fn = glob.glob(os.path.join(outdir, '*-F.tif'))[0]\n", - " dx_ma = read_array(disp_fn, 1)\n", - " dy_ma = read_array(disp_fn, 2)\n", - " disp_clim = find_common_clim(dx_ma, dy_ma, symm=True)\n", - " \n", - " l_stddev_fn = glob.glob(os.path.join(outdir, '*-L_stddev_filter_output.tif'))\n", - " if l_stddev_fn:\n", - " l_stddev_fn = l_stddev_fn[0]\n", - " l_stddev_ma = read_array(l_stddev_fn)\n", - " r_stddev_fn = glob.glob(os.path.join(outdir, '*-R_stddev_filter_output.tif'))[0]\n", - " r_stddev_ma = read_array(r_stddev_fn)\n", - " stddev_clim = list(find_common_clim(l_stddev_ma, r_stddev_ma))\n", - " stddev_clim[0] = 0\n", - " plot_ar(l_stddev_ma, ax=axa[2], clim=stddev_clim, cmap='inferno', label='std filter (px)')\n", - " plot_ar(r_stddev_ma, ax=axa[3], clim=stddev_clim, cmap='inferno', label='std filter (px)')\n", - " \n", - " plot_ar(l_img_ma, ax=axa[0], cmap='gray', clim_perc=(0,100))\n", - " plot_ar(r_img_ma, ax=axa[1], cmap='gray', clim_perc=(0,100))\n", - " \n", - " plot_ar(dx_ma, ax=axa[4], clim=disp_clim, cmap='RdBu', label='x disparity (px)')\n", - " plot_ar(dy_ma, ax=axa[5], clim=disp_clim, cmap='RdBu', label='y disparity (px)')\n", - " \n", - " plt.suptitle(os.path.split(outdir)[-1])\n", - " plt.tight_layout()\n", - " out_fn = l_img_fn.split('-L.tif')[0]+'-corr_report.png'\n", - " plt.savefig(out_fn)\n", - " plt.close(f)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f83eac62-dc42-45fa-bd08-8892ed98031b", - "metadata": {}, - "outputs": [], - "source": [ - "#outdir = '/Users/dshean/scr/BlackSky/EastonGlacier_20220918-20221012/non-ortho/stereo_ba_all_tri_weight/BSG-112-20220918-173557-38516577__BSG-113-20220918-175217-38567076'\n", - "#outdir = '/Users/dshean/scr/BlackSky/EastonGlacier_20220918-20221012/non-ortho/stereo_ba_all_tri_weight/BSG-108-20221005-191015-40132991__BSG-118-20221012-202648-41004143'" + "#read_match(match_fn)\n", + "#Plot ip and matches over L_sub and R_sub" ] }, { @@ -301,15 +162,17 @@ " f, axa = plt.subplots(1, 5, figsize=(10,3), dpi=220)\n", " axa = axa.ravel()\n", "\n", - " ortho_fn = glob.glob(os.path.join(outdir, '*-L_ortho.tif'))\n", + " ortho_fn = glob.glob(os.path.join(outdir, '*-L_sub.tif'))\n", + " #ortho_fn = glob.glob(os.path.join(outdir, '*-L_ortho.tif'))\n", " if ortho_fn:\n", " ortho_fn = ortho_fn[0]\n", " ortho_ma = read_array(ortho_fn)\n", " plot_ar(ortho_ma, ax=axa[0], cmap='gray')\n", " else:\n", " axa[0].axis('off')\n", - " \n", - " ortho_fn = glob.glob(os.path.join(outdir, '*-R_ortho.tif'))\n", + "\n", + " ortho_fn = glob.glob(os.path.join(outdir, '*-R_sub.tif'))\n", + " #ortho_fn = glob.glob(os.path.join(outdir, '*-R_ortho.tif'))\n", " if ortho_fn:\n", " ortho_fn = ortho_fn[0]\n", " ortho_ma = read_array(ortho_fn)\n", @@ -348,7 +211,7 @@ " else:\n", " axa[3].axis('off')\n", " \n", - " #This is not generated by default (requires point2dem --errorimage)\n", + " #This is not generated by default (requires compute_diff.py $dem_fn $refdem)\n", " diff_fn = glob.glob(os.path.join(outdir, '*-DEM*diff.tif'))\n", " if diff_fn:\n", " diff_fn = diff_fn[0]\n", @@ -365,17 +228,90 @@ " plt.close(f)" ] }, + { + "cell_type": "markdown", + "id": "bf471b03-76ff-48e9-af9a-5af8c5ce0242", + "metadata": {}, + "source": [ + "## Stereo correlation plots" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d2f44bd6-5e75-48fb-a8e6-e9c4dce5e9b7", + "metadata": {}, + "outputs": [], + "source": [ + "def plot_corr_results(outdir):\n", + " f, axa = plt.subplots(3, 2, figsize=(7.5,10), dpi=220)\n", + " axa = axa.ravel()\n", + "\n", + " l_img_fn = glob.glob(os.path.join(outdir, '*-L_sub.tif'))[0]\n", + " #l_img_fn = glob.glob(os.path.join(outdir, '*-L.tif'))[0]\n", + " l_img_ma = read_array(l_img_fn)\n", + "\n", + " r_img_fn = glob.glob(os.path.join(outdir, '*-R_sub.tif'))[0]\n", + " #r_img_fn = glob.glob(os.path.join(outdir, '*-R.tif'))[0]\n", + " r_img_ma = read_array(r_img_fn)\n", + " \n", + " disp_fn = glob.glob(os.path.join(outdir, '*-RD.tif'))[0]\n", + " #disp_fn = glob.glob(os.path.join(outdir, '*-F.tif'))[0]\n", + " dx_ma = read_array(disp_fn, 1)\n", + " dy_ma = read_array(disp_fn, 2)\n", + " disp_clim = find_common_clim(dx_ma, dy_ma, symm=True)\n", + " \n", + " l_stddev_fn = glob.glob(os.path.join(outdir, '*-L_stddev_filter_output.tif'))\n", + " if l_stddev_fn:\n", + " l_stddev_fn = l_stddev_fn[0]\n", + " l_stddev_ma = read_array(l_stddev_fn)\n", + " r_stddev_fn = glob.glob(os.path.join(outdir, '*-R_stddev_filter_output.tif'))[0]\n", + " r_stddev_ma = read_array(r_stddev_fn)\n", + " stddev_clim = list(find_common_clim(l_stddev_ma, r_stddev_ma))\n", + " stddev_clim[0] = 0\n", + " plot_ar(l_stddev_ma, ax=axa[2], clim=stddev_clim, cmap='inferno', label='std filter (px)')\n", + " plot_ar(r_stddev_ma, ax=axa[3], clim=stddev_clim, cmap='inferno', label='std filter (px)')\n", + " \n", + " plot_ar(l_img_ma, ax=axa[0], cmap='gray', clim_perc=(0,100))\n", + " plot_ar(r_img_ma, ax=axa[1], cmap='gray', clim_perc=(0,100))\n", + " \n", + " plot_ar(dx_ma, ax=axa[4], clim=disp_clim, cmap='RdBu', label='x disparity (px)')\n", + " plot_ar(dy_ma, ax=axa[5], clim=disp_clim, cmap='RdBu', label='y disparity (px)')\n", + " \n", + " plt.suptitle(os.path.split(outdir)[-1])\n", + " plt.tight_layout()\n", + " out_fn = l_img_fn.split('-L.tif')[0]+'-corr_report.png'\n", + " plt.savefig(out_fn)\n", + " plt.close(f)" + ] + }, + { + "cell_type": "markdown", + "id": "0cedf4f8-ca7b-4d45-89ee-02d204d134f7", + "metadata": {}, + "source": [ + "## Testing" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c6162f76-55e7-4ce5-bbc7-b68cb12331f0", + "metadata": {}, + "outputs": [], + "source": [ + "outdir = '/Users/dshean/scr/utqiagvik/WV02_20220411_10300100D102A400_10300100D1B7D600/ncc_dgmaprpc/'" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "b6873f66-eb1e-42da-94c5-c65d159acb83", + "id": "cf76b056-5e07-477c-b95c-6de7bacf7f6c", "metadata": {}, "outputs": [], "source": [ - "for outdir in outdir_list:\n", - " print(outdir)\n", - " plot_corr_results(outdir)\n", - " plot_dem(outdir)" + "plot_dem(outdir)\n", + "#plot_corr_results(outdir)" ] } ], @@ -395,7 +331,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.10.12" } }, "nbformat": 4,