Created
January 21, 2020 23:50
-
-
Save Kelvinrr/097f8c9c9c4eab2d5de546a4e0ce5efc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "import os \n", | |
| "from glob import glob\n", | |
| "\n", | |
| "\n", | |
| "os.environ[\"ISISROOT\"] = \"/usgs/cpkgs/anaconda3_linux/envs/isis3.9.0\"\n", | |
| "\n", | |
| "from pysis import isis\n", | |
| "from pysis.exceptions import ProcessError" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 55, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "def ingest_hirise(directory):\n", | |
| " l = glob(os.path.join(f\"{directory}, *RED*\"))\n", | |
| " l = [os.path.splitext(i)[0] for i in l]\n", | |
| " \n", | |
| " print(f\"Running hi2isis on {l}\")\n", | |
| " for i,cube in enumerate(l):\n", | |
| " print(f\"{i+1}/{len(l)}\")\n", | |
| " try:\n", | |
| " isis.hi2isis(from_=f'{cube}.IMG', to=f\"{cube}.cub\")\n", | |
| " print(f\"finished {cube}\")\n", | |
| " except ProcessError as e:\n", | |
| " print(e.stderr)\n", | |
| " \n", | |
| " print(f\"running spiceinit on {l}\")\n", | |
| " for i,cube in enumerate(l):\n", | |
| " print(f\"{i+1}/{len(l)}\")\n", | |
| " try:\n", | |
| " isis.spiceinit(from_=f'{cube}.cub')\n", | |
| " except ProcessError as e:\n", | |
| " print(e.stderr)\n", | |
| " \n", | |
| " print(f\"running hical on {l}\")\n", | |
| " for i,cube in enumerate(l):\n", | |
| " print(f\"{i}/{len(l)}\")\n", | |
| " try:\n", | |
| " isis.hical(from_=f'{cube}.cub', to=f'{cube}.cal.cub')\n", | |
| " except ProcessError as e:\n", | |
| " print(e.stderr)\n", | |
| " \n", | |
| " cal_list_0 = sorted(glob(os.path.join(directory, \"*0.cal*\")))\n", | |
| " cal_list_1 = sorted(glob(os.path.join(directory, \"*1.cal*\")))\n", | |
| " print(f\"Channel 0 images: {cal_list_0}\")\n", | |
| " print(f\"Channel 1 images: {cal_list_1}\")\n", | |
| " \n", | |
| " for i,cubes in enumerate(zip(cal_list_0, cal_list_1)):\n", | |
| " print(f\"{i}/{len(cal_list_0)}\")\n", | |
| " c0, c1 = cubes\n", | |
| " output =\"_\".join(c0.split(\"_\")[:-1])\n", | |
| " try:\n", | |
| " isis.histitch(from1=c0, from2=c1, to=f\"{output}.stitched.cub\")\n", | |
| " except ProcessError as e:\n", | |
| " print(e.stderr)\n", | |
| " \n", | |
| " stitch_list = glob(os.path.join(directory, \"*stitched*\"))\n", | |
| " \n", | |
| " print(f\"Normalizing: {stitch_list}\")\n", | |
| " for i,cube in enumerate(stitch_list):\n", | |
| " print(f\"{i+1}/{len(stitch_list)}\")\n", | |
| " output = os.path.splitext(cube)[0]+ \".norm.cub\"\n", | |
| " try:\n", | |
| " isis.cubenorm(from_=cube, to=output)\n", | |
| " except ProcessError as e:\n", | |
| " print(e.stderr)\n", | |
| " \n", | |
| " norm_list = glob(os.path.join(directory,\"*.norm*\"))\n", | |
| " with open(\"normalized.lis\", \"w\") as f:\n", | |
| " f.write(\"\\n\".join(norm_list))\n", | |
| "\n", | |
| " output = os.path.join(directory, \"ESP_026564_2405.cub\")\n", | |
| " \n", | |
| " print(f\"stitched file list: {norm_list}\")\n", | |
| " print(f\"Stitched output: {output}\")\n", | |
| " try:\n", | |
| " out = isis.hiccdstitch(from_=\"normalized.lis\", to=output)\n", | |
| " print(out)\n", | |
| " except ProcessError as e:\n", | |
| " print(e.stderr)\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 11, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED1_1\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED0_1\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED8_1\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED5_1\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED7_1\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED3_0\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED8_0\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED3_1\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED0_0\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED6_0\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED6_1\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED2_1\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED5_0\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED4_1\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED7_0\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED2_0\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED1_0\r\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED4_0" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "!cat ESP_026564_2405.lis" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 19, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "0/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED1_1\n", | |
| "1/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED0_1\n", | |
| "2/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED8_1\n", | |
| "3/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED5_1\n", | |
| "4/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED7_1\n", | |
| "5/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED3_0\n", | |
| "6/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED8_0\n", | |
| "7/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED3_1\n", | |
| "8/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED0_0\n", | |
| "9/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED6_0\n", | |
| "10/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED6_1\n", | |
| "11/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED2_1\n", | |
| "12/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED5_0\n", | |
| "13/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED4_1\n", | |
| "14/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED7_0\n", | |
| "15/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED2_0\n", | |
| "16/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED1_0\n", | |
| "17/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED4_0\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "# for i,cube in enumerate(l):\n", | |
| "# print(f\"{i+1}/{len(l)}\")\n", | |
| "# try:\n", | |
| "# isis.hi2isis(from_=f'{cube}.IMG', to=f\"{cube}.cub\")\n", | |
| "# print(f\"finished {cube}\")\n", | |
| "# except ProcessError as e:\n", | |
| "# print(e.stderr)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 20, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "0/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED1_1\n", | |
| "1/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED0_1\n", | |
| "2/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED8_1\n", | |
| "3/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED5_1\n", | |
| "4/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED7_1\n", | |
| "5/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED3_0\n", | |
| "6/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED8_0\n", | |
| "7/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED3_1\n", | |
| "8/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED0_0\n", | |
| "9/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED6_0\n", | |
| "10/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED6_1\n", | |
| "11/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED2_1\n", | |
| "12/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED5_0\n", | |
| "13/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED4_1\n", | |
| "14/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED7_0\n", | |
| "15/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED2_0\n", | |
| "16/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED1_0\n", | |
| "17/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED4_0\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "# for i,cube in enumerate(l):\n", | |
| "# print(f\"{i+1}/{len(l)}\")\n", | |
| "# try:\n", | |
| "# isis.spiceinit(from_=f'{cube}.cub')\n", | |
| "# print(f\"finished {cube}\")\n", | |
| "# except ProcessError as e:\n", | |
| "# print(e.stderr)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 21, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "0/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED1_1\n", | |
| "1/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED0_1\n", | |
| "2/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED8_1\n", | |
| "3/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED5_1\n", | |
| "4/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED7_1\n", | |
| "5/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED3_0\n", | |
| "6/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED8_0\n", | |
| "7/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED3_1\n", | |
| "8/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED0_0\n", | |
| "9/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED6_0\n", | |
| "10/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED6_1\n", | |
| "11/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED2_1\n", | |
| "12/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED5_0\n", | |
| "13/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED4_1\n", | |
| "14/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED7_0\n", | |
| "15/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED2_0\n", | |
| "16/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED1_0\n", | |
| "17/18\n", | |
| "finished /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED4_0\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "# for i,cube in enumerate(l):\n", | |
| "# print(f\"{i}/{len(l)}\")\n", | |
| "# try:\n", | |
| "# isis.hical(from_=f'{cube}.cub', to=f'{cube}.cal.cub')\n", | |
| "# print(f\"finished {cube}\")\n", | |
| "# except ProcessError as e:\n", | |
| "# print(e.stderr)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 41, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "0/18\n", | |
| "('/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED0_0.cal.cub', '/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED0_1.cal.cub')\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED0\n", | |
| "1/18\n", | |
| "('/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED1_0.cal.cub', '/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED1_1.cal.cub')\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED1\n", | |
| "2/18\n", | |
| "('/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED2_0.cal.cub', '/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED2_1.cal.cub')\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED2\n", | |
| "3/18\n", | |
| "('/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED3_0.cal.cub', '/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED3_1.cal.cub')\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED3\n", | |
| "4/18\n", | |
| "('/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED4_0.cal.cub', '/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED4_1.cal.cub')\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED4\n", | |
| "5/18\n", | |
| "('/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED5_0.cal.cub', '/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED5_1.cal.cub')\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED5\n", | |
| "6/18\n", | |
| "('/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED6_0.cal.cub', '/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED6_1.cal.cub')\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED6\n", | |
| "7/18\n", | |
| "('/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED7_0.cal.cub', '/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED7_1.cal.cub')\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED7\n", | |
| "8/18\n", | |
| "('/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED8_0.cal.cub', '/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED8_1.cal.cub')\n", | |
| "/scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED8\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "cal_list_0 = sorted(glob(\"/scratch/krodriguez/hirise/ESP_026564_2405/*0.cal*\"))\n", | |
| "cal_list_1 = sorted(glob(\"/scratch/krodriguez/hirise/ESP_026564_2405/*1.cal*\"))\n", | |
| "\n", | |
| "for i,cubes in enumerate(zip(cal_list_0, cal_list_1)):\n", | |
| " print(f\"{i}/{len(cal_list_0)}\")\n", | |
| " c0, c1 = cubes\n", | |
| " output =\"_\".join(c0.split(\"_\")[:-1])\n", | |
| " try:\n", | |
| " isis.histitch(from1=c0, from2=c1, to=f\"{output}.stitched.cub\")\n", | |
| " except ProcessError as e:\n", | |
| " print(e.stderr)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 50, | |
| "metadata": { | |
| "scrolled": true | |
| }, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "1/9\n", | |
| "output: /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED7.stitched.norm.cub\n", | |
| "2/9\n", | |
| "output: /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED5.stitched.norm.cub\n", | |
| "3/9\n", | |
| "output: /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED0.stitched.norm.cub\n", | |
| "4/9\n", | |
| "output: /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED1.stitched.norm.cub\n", | |
| "5/9\n", | |
| "output: /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED3.stitched.norm.cub\n", | |
| "6/9\n", | |
| "output: /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED6.stitched.norm.cub\n", | |
| "7/9\n", | |
| "output: /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED4.stitched.norm.cub\n", | |
| "8/9\n", | |
| "output: /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED8.stitched.norm.cub\n", | |
| "9/9\n", | |
| "output: /scratch/krodriguez/hirise/ESP_026564_2405/ESP_026564_2405_RED2.stitched.norm.cub\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "stitch_list = glob(\"/scratch/krodriguez/hirise/ESP_026564_2405/*stitched*\")\n", | |
| "\n", | |
| "for i,cube in enumerate(stitch_list):\n", | |
| " print(f\"{i+1}/{len(stitch_list)}\")\n", | |
| " output = os.path.splitext(cube)[0]+ \".norm.cub\"\n", | |
| " \n", | |
| " print(f\"output: {output}\")\n", | |
| " try:\n", | |
| " isis.cubenorm(from_=cube, to=output)\n", | |
| " except ProcessError as e:\n", | |
| " print(e.stderr)\n", | |
| " " | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "norm_list = glob(\"/scratch/krodriguez/hirise/ESP_026564_2405/*.norm*\")\n", | |
| "with open(\"normalized.lis\", \"w\") as f:\n", | |
| " f.write(\"\\n\".join(norm_list))\n", | |
| "\n", | |
| "try:\n", | |
| " out = isis.hiccdstitch(from_=\"normalized.lis\", to=\"ESP_026564_2405.cub\")\n", | |
| " print(out)\n", | |
| "except ProcessError as e:\n", | |
| " print(e.stderr)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true, | |
| "scrolled": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 56, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "\u001b[0m\u001b[01;32ma.out\u001b[0m* load_mongo.py To DataFrame.ipynb\r\n", | |
| "ESP_026564_2405.cub normalized.lis To DataFrame (PostGres Edition).ipynb\r\n", | |
| "ESP_026564_2405.lis print.prt Untitled.ipynb\r\n", | |
| "Hirise.ipynb SP_PostGreSQL.ipynb\r\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "ls" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "def match_pair(img1_path, img2_path, figpath=None):\n", | |
| " src_points = point_grid(GeoDataset(img1_path), step=50)\n", | |
| " f = open('temp.txt', 'w+')\n", | |
| " f.write('\\n'.join('{}, {}'.format(int(x),int(y)) for x,y in src_points))\n", | |
| " del f\n", | |
| "\n", | |
| " label = pvl.loads(campt(from_=img1_path, coordlist='temp.txt', coordtype='image'))\n", | |
| " points = []\n", | |
| " for group in label:\n", | |
| " try:\n", | |
| " lat = group[1]['PlanetocentricLatitude'].value\n", | |
| " lon = group[1]['PositiveEast360Longitude'].value\n", | |
| " points.append([lat, lon])\n", | |
| " except Exception as e:\n", | |
| " continue\n", | |
| "\n", | |
| " logger.info(\"{} points from image1 successfully reprojected to image2, rejected {}\".format(str(len(points)), str(len(src_points)-len(points))))\n", | |
| "\n", | |
| " if len(points) == 0:\n", | |
| " raise Exception(\"No valid points were found for pair {} {}\".format(img1_path, img2_path))\n", | |
| "\n", | |
| " f = open('temp.txt', 'w+')\n", | |
| " f.write('\\n'.join('{}, {}'.format(x,y) for x,y in points))\n", | |
| " del f\n", | |
| "\n", | |
| " img2label = pvl.loads(campt(from_=img2_path, coordlist='temp.txt', coordtype='ground', allowoutside=False))\n", | |
| " dst_lookup = {}\n", | |
| " for i,group in enumerate(img2label):\n", | |
| " if not group[1]['Error']:\n", | |
| " line = group[1]['Line']\n", | |
| " sample = group[1]['Sample']\n", | |
| " dst_lookup[i] = [sample, line]\n", | |
| "\n", | |
| " filelist = [img1_path, img2_path]\n", | |
| " cg = CandidateGraph.from_filelist(filelist)\n", | |
| "\n", | |
| " edge = cg[0][1]['data']\n", | |
| " img1 = GeoDataset(img1_path)\n", | |
| " img2 = GeoDataset(img2_path)\n", | |
| "\n", | |
| " src_keypoints = pd.DataFrame(data=src_points, columns=['x', 'y'])\n", | |
| " src_keypoints['response'] = 0\n", | |
| " src_keypoints['angle'] = 0\n", | |
| " src_keypoints['octave'] = 0\n", | |
| " src_keypoints['layer'] = 0\n", | |
| " src_keypoints\n", | |
| " edge.source._keypoints = src_keypoints\n", | |
| "\n", | |
| " results = []\n", | |
| " dst_keypoints = []\n", | |
| " dst_index = 0\n", | |
| " distances = []\n", | |
| "\n", | |
| " arr1 = img1.read_array()\n", | |
| " arr2 = img2.read_array()\n", | |
| " del img1\n", | |
| " del img2\n", | |
| "\n", | |
| " for keypoint in edge.source.keypoints.iterrows():\n", | |
| " index, row = keypoint\n", | |
| "\n", | |
| " sx, sy = row['x'], row['y']\n", | |
| "\n", | |
| " try:\n", | |
| " dx, dy = dst_lookup[index]\n", | |
| " except KeyError:\n", | |
| " continue\n", | |
| "\n", | |
| " try:\n", | |
| " ret = refine_subpixel(sx, sy, dx, dy, arr1, arr2, size=50, reduction=10, convergence_threshold=1)\n", | |
| " except Exception as ex:\n", | |
| " continue\n", | |
| "\n", | |
| " if ret is not None:\n", | |
| " x,y,metrics = ret\n", | |
| " else:\n", | |
| " continue\n", | |
| "\n", | |
| " dist = np.linalg.norm([x-dx, y-dy])\n", | |
| " results.append([0, index, 1, dst_index, dist])\n", | |
| " dst_keypoints.append([x,y, 0,0,0,0,0])\n", | |
| " dst_index += 1\n", | |
| "\n", | |
| "\n", | |
| " matches = pd.DataFrame(data=results, columns=['source_image', 'source_idx',\n", | |
| " 'destination_image', 'destination_idx',\n", | |
| " 'distance'])\n", | |
| "\n", | |
| " if matches.empty:\n", | |
| " logger.error(\"After matching points, matches dataframe returned empty.\")\n", | |
| "\n", | |
| " dst_keypoints = pd.DataFrame(data=dst_keypoints, columns=['x', 'y', 'response', 'size', 'angle', 'octave', 'layer'])\n", | |
| " edge.destination._keypoints = dst_keypoints\n", | |
| "\n", | |
| "\n", | |
| "\n", | |
| " edge._matches = matches\n", | |
| " edge.compute_fundamental_matrix()\n", | |
| " distance_check(edge, clean_keys=['fundamental'])\n", | |
| "\n", | |
| " if figpath:\n", | |
| " plt.figure(figsize=(10,25))\n", | |
| " cg[0][1]['data'].plot(clean_keys=['fundamental', 'distance'], nodata=-32768.0)\n", | |
| " plt.savefig(figpath)\n", | |
| " plt.close()\n", | |
| " return cg" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "autocnetdev", | |
| "language": "python", | |
| "name": "autocnetdev" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.6.7" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment