diff --git a/notebooks/KernelSlice.ipynb b/notebooks/KernelSlice.ipynb index ebb896367c91de8cf3528b6ffe0ae8735a660e2a..e16f8112b42715c62c55177086797753d1fc57c1 100644 --- a/notebooks/KernelSlice.ipynb +++ b/notebooks/KernelSlice.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -15,12 +15,14 @@ "from itertools import chain\n", "import io\n", "import networkx as nx\n", + "import tempfile\n", "\n", "\n", "# These should be provided when running this script. \n", "cube = \"/work/users/sgstapleton/kernel_split/EN1072174528M.cub\"\n", "output_dir = \"/work/users/sgstapleton/kernel_split/\" # Output dir for created kernel files\n", "data_dir = \"/usgs/cpkgs/isis3/data/\" # Dir of where to pull original kernels from\n", + "ckslicer_loc = \"/work/users/sgstapleton/kernel_split/ckslicer\"\n", "\n", " \n", "def get_reference_id(bc_filename):\n", @@ -35,9 +37,7 @@ " return reference\n", "\n", "\n", - "def add_light_time_correction(cube_info, kernels):\n", - " \n", - " furnished_kerns = spice.furnsh(kernels)\n", + "def add_light_time_correction(cube_info):\n", " \n", " image_start_et = spice.scs2e(cube_info['SpacecraftID'], cube_info['SpacecraftClockCount'])\n", " image_end_et = image_start_et + cube_info['ExposureDuration']\n", @@ -123,7 +123,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -131,7 +131,7 @@ "# more manageable kernel files for ale testing purposes. This currently only handles ck and spk files.\n", "\n", "# Get dictionary of kernel lists from cube\n", - "cube_info = util.generate_kernels_from_cube(cube, 'dict')\n", + "cube_info = util.generate_kernels_from_cube(cube, format_as = 'dict')\n", "\n", "# Replace path variables with absolute paths for kernels\n", "for kernel_list in cube_info:\n", @@ -141,6 +141,7 @@ " \n", "# Create ordered list of kernels for furnishing\n", "kernels = [kernel for kernel in chain.from_iterable(cube_info.values()) if isinstance(kernel, str)]\n", + "spice.furnsh(kernels)\n", " \n", "# Loads cube as pvl to extract rest of data\n", "cube_pvl = pvl.load(cube)\n", @@ -152,7 +153,7 @@ "cube_info.update(SpacecraftID = spice.bods2c(cube_pvl['IsisCube']['Instrument']['SpacecraftName']))\n", "\n", "# Add lighttime-corrected SCLK values to cube_info\n", - "add_light_time_correction(cube_info, kernels)\n", + "add_light_time_correction(cube_info)\n", "\n", "# For each binary ck kernel specified in cube, run the ckslicer, comment and to-transfer commands\n", "for ck in cube_info['InstrumentPointing']:\n", @@ -166,7 +167,7 @@ " output_kern = output_dir + ck_filename + '_sliced' + ck_file_extension\n", " \n", " # Create new sliced ck kernel\n", - " ckslicer_command = [\"./ckslicer\", \n", + " ckslicer_command = [ckslicer_loc, \n", " '-LSK {}'.format(cube_info['LeapSecond'][0]), \n", " '-SCLK {}'.format(cube_info['SpacecraftClock'][0]), \n", " '-INPUTCK {}'.format(ck), \n", @@ -182,7 +183,7 @@ " subprocess.call(commnt_command)\n", " \n", " # Makes a new txt file for the only comments that should be stored in the new ck file\n", - " with open(\"temp_commnts.txt\",\"w+\") as f:\n", + " with open(output_dir + \"temp_commnts.txt\",\"w+\") as f:\n", " f.write(\"This CK is for testing with the image: {}\\n\".format(cube))\n", " f.write(\"\\nThis CK was generated using the following command: {}\\n\".format(\" \".join(ckslicer_command)))\n", " \n", @@ -190,6 +191,9 @@ " new_commnts_command = [\"commnt\", \"-a {}\".format(output_kern), \"temp_commnts.txt\"]\n", " subprocess.call(new_commnts_command)\n", " \n", + " # Clean up temp comment file\n", + " os.remove(output_dir + \"temp_commnts.txt\")\n", + " \n", " # Create the transfer file of the new ck kernel\n", " subprocess.call([\"toxfr\", output_kern])\n", "\n", @@ -198,10 +202,7 @@ "\n", "# Run the spkmerge command\n", "spkmerge_command = [\"spkmerge\", output_dir + \"spk.config\"]\n", - "subprocess.call(spkmerge_command)\n", - "\n", - "# Clean up temp config file\n", - "os.remove(output_dir + \"spk.config\")" + "subprocess.call(spkmerge_command)\n" ] }, {