"ALE drivers are objects that define how to acquire common ISD keys from an input image format, in this case we are reading in a PDS3 image using NAIF SPICE kernels for exterior orientation data. If the driver utilizes NAIF SPICE kernels, it is implemented as a [context manager](https://docs.python.org/3/reference/datamodel.html#context-managers) and will furnish metakernels when entering the context (i.e. when entering the `with` block) and free the metakernels on exit. This maintains the integrity of spicelib's internal data structures. These driver objects are short-lived and are input to a formatter function that consumes the API to create a serializable file format. `ale.formatters` contains available formatter functions. \n",
"\n",
"The default config file is located at `ale/config.yml` and is copied into your home directory at `.ale/config.yml` on first use of the library. The config file can be modified using a text editor. `ale.config` is loaded into memory as a dictionary. It is used to find metakernels for different missions. For example, there is an entry for MRO that points to `/usgs/cpkgs/isis3/data/mro/kernels/mk/` by default. If you want to use your own metakernels, you will need to udpate this path. For example, if the metakernels are located in `/data/ctxmro/mk/` the MRO entry should be updated with this path. If you are using the default metakernels, then you do not need to update the path.\n",
"\n",
"ALE has a two step process for writing out an ISD: 1. Instantiate your driver (in this case `MroCtxPds3LabelNaifSpiceDriver`) within a context and 2. pass the driver object into a formatter (in this case, `to_usgscsm`). \n",
"\n",
"Requirements:\n",
" * A PDS3 CTX MRO image\n",
" * NAIF metakernels installed\n",
" * Config file path for MRO (ale.config.mro) pointing to MRO NAIF metakernel directory \n",
" * A conda environment with ALE installed into it usisng the `conda install` command or created using the environment.yml file at the base of ALE."
"# metakernels are furnsh-ed when entering the context (with block) with a driver instance\n",
"# most driver constructors simply accept an image path \n",
"with MroCtxPds3LabelNaifSpiceDriver(file_name) as driver:\n",
" # pass driver instance into formatter function\n",
" usgscsmString = to_usgscsm(driver)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Write ISD to disk \n",
"\n",
"ALE formatter functions generally return bytes or a string that can be written out to disk. ALE's USGSCSM formatter function returns a JSON encoded string that can be written out using any JSON library. \n",
"\n",
"USGSCSM requires the ISD to be colocated with the image file with a `.json` extension in place of the image extension."
ALE drivers are objects that define how to acquire common ISD keys from an input image format, in this case we are reading in a PDS3 image using NAIF SPICE kernels for exterior orientation data. If the driver utilizes NAIF SPICE kernels, it is implemented as a [context manager](https://docs.python.org/3/reference/datamodel.html#context-managers) and will furnish metakernels when entering the context (i.e. when entering the `with` block) and free the metakernels on exit. This maintains the integrity of spicelib's internal data structures. These driver objects are short-lived and are input to a formatter function that consumes the API to create a serializable file format. `ale.formatters` contains available formatter functions.
The default config file is located at `ale/config.yml` and is copied into your home directory at `.ale/config.yml` on first use of the library. The config file can be modified using a text editor. `ale.config` is loaded into memory as a dictionary. It is used to find metakernels for different missions. For example, there is an entry for MRO that points to `/usgs/cpkgs/isis3/data/mro/kernels/mk/` by default. If you want to use your own metakernels, you will need to udpate this path. For example, if the metakernels are located in `/data/ctxmro/mk/` the MRO entry should be updated with this path. If you are using the default metakernels, then you do not need to update the path.
ALE has a two step process for writing out an ISD: 1. Instantiate your driver (in this case `MroCtxPds3LabelNaifSpiceDriver`) within a context and 2. pass the driver object into a formatter (in this case, `to_usgscsm`).
Requirements:
* A PDS3 CTX MRO image
* NAIF metakernels installed
* Config file path for MRO (ale.config.mro) pointing to MRO NAIF metakernel directory
* A conda environment with ALE installed into it usisng the `conda install` command or created using the environment.yml file at the base of ALE.
%% Cell type:code id: tags:
``` python
# printing config displays the yaml formatted string
print(ale.config)
# config object is a dictionary so it has the same access patterns
print('MRO spice directory:',ale.config['mro'])
# updating config for new LRO path in this notebook
# Note: this will not change the path in `.ale/config.yml`. This change only lives in the notebook.
ALE formatter functions generally return bytes or a string that can be written out to disk. ALE's USGSCSM formatter function returns a JSON encoded string that can be written out using any JSON library.
USGSCSM requires the ISD to be colocated with the image file with a `.json` extension in place of the image extension.
%% Cell type:code id: tags:
``` python
# Load the json string into a dict
usgscsm_dict=json.loads(usgscsmString)
# Write the dict out to the associated file
json_file=os.path.splitext(file_name)[0]+'.json'
# Save off the json and read it back in to check if