{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fileName = '/osirisrex/tsts/mapcam/truth/20190303T100344S990_map_iofL2pan_V001-spiceinit.cub'\n",
    "\n",
    "import os\n",
    "os.environ[\"ISISDATA\"] = \"/isis3/isis_data\"\n",
    "os.environ[\"ISISTESTDATA\"] = \"/pkgs/isis_testData\"\n",
    "os.environ[\"ISISROOT\"] = \"/isis/ISIS3/build\"\n",
    "\n",
    "import ale \n",
    "from ale.drivers.osirisrex_drivers import OsirisRexCameraIsisLabelNaifSpiceDriver\n",
    "from ale.formatters.formatter import to_isd\n",
    "import spiceypy as spice\n",
    "from ale.drivers import AleJsonEncoder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ale.util import generate_kernels_from_cube\n",
    "kernels = generate_kernels_from_cube(fileName, expand=True, format_as='list')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "with OsirisRexCameraIsisLabelNaifSpiceDriver(fileName, props = {\"kernels\": kernels}) as driver:\n",
    "    isisString = to_isd(driver)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "isisString"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "isis_dict = isisString\n",
    "\n",
    "json_file = os.path.splitext(fileName)[0] + '.json'\n",
    "\n",
    "with open(json_file, 'w') as fp:\n",
    "    json.dump(isis_dict, fp, cls = AleJsonEncoder)\n",
    "    \n",
    "with open(json_file, 'r') as fp:\n",
    "    isis_dict = json.load(fp)\n",
    "    \n",
    "isis_dict.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "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.10.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
