Commit 1c216579 authored by Rodriguez, Kelvin's avatar Rodriguez, Kelvin
Browse files

Merge branch 'image-to-ground-tutorial' into 'main'

CSM Stack - Image to ground tutorial

See merge request astrogeology/asc-public-docs!6
parents 1d620e4f 61cd3915
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -138,6 +138,15 @@
    {{ super() }}
    {% endblock %}

{% block content %}
{% if page.nb_url %}
    <a href="{{ page.nb_url }}" title="Download Notebook" class="md-content__button md-icon">
        {% include ".icons/material/download.svg" %}
    </a>
{% endif %}

{{ super() }}
{% endblock content %}

{% block footer %}

@@ -211,7 +220,6 @@
      
</footer>


{% endblock %}

    {% block styles %}
+119 −0
Original line number Diff line number Diff line
%% Cell type:markdown id:a117baed-ab98-4499-832c-8c73a8606cc0 tags:

# Getting Started: Instantiating a CSM Camera Model from Image

%% Cell type:markdown id:3602c014-53bc-4330-a9b0-0848d4927458 tags:

### 1. Install dependencies
The `knoten` installation may take a little longer than usual due to the many dependencies (including ALE) involved.

%% Cell type:markdown id:ffeccab3-0d5d-4609-9c7f-871bdb69f17a tags:

```
conda install -c conda-forge knoten=0.2.1
```

%% Cell type:markdown id:faed4a43-cd06-45c7-bfa1-793978d41486 tags:

### 2. Generate an ISD from a Cube
We will use MRO data located in the `data/image_to_ground` folder containing a cube and necessary kernels for ISD (Image Support Data) generation.
*Note*: If your cube already has attached spice data, do you not have to specify kernels in the `props` param and can pass in an empty dict `{}` instead.

%% Cell type:code id:7f58cb34-d27f-456d-bfb5-f9075ca575b3 tags:

``` python
import ale
import json
import knoten
import os

# Set local data directory and paths
data_dir = '../data/image_to_ground'
cube_file = os.path.join(data_dir, 'B10_013341_1010_XN_79S172W.cub')
isd_file = os.path.join(data_dir, 'isd_file.json')

# Set local kernel paths
props = {
    'kernels': [
        os.path.join(data_dir, 'B10_013341_1010_XN_79S172W_0.bsp'),
        os.path.join(data_dir, 'B10_013341_1010_XN_79S172W_1.bsp'),
        os.path.join(data_dir, 'mro_ctx_v11.ti'),
        os.path.join(data_dir, 'mro_sc_psp_090526_090601_0_sliced_-74000.bc'),
        os.path.join(data_dir, 'mro_sc_psp_090526_090601_1_sliced_-74000.bc'),
        os.path.join(data_dir, 'mro_sclkscet_00082_65536.tsc'),
        os.path.join(data_dir, 'mro_v16.tf'),
        os.path.join(data_dir, 'naif0012.tls'),
        os.path.join(data_dir, 'pck00008.tpc')
    ]
}

# Generate the ISD string from the cube's label
isd_str = ale.loads(
    label=cube_file,
    formatter="ale",
    props=props,
    indent=2,
    verbose=False,
    only_isis_spice=False,
    only_naif_spice=False
)

# Write the ISD string to file 'isd_file.json'
with open(isd_file, "w") as file:
    file.write(isd_str)
```

%% Output

    /Users/chkim/mambaforge3/envs/test/lib/python3.12/site-packages/osgeo/gdal.py:287: FutureWarning: Neither gdal.UseExceptions() nor gdal.DontUseExceptions() has been explicitly called. In GDAL 4.0, exceptions will be enabled by default.
      warnings.warn(

%% Cell type:markdown id:4ed327aa-bffc-4316-b42f-496d9e07465e tags:

### 3. Create a Community Sensor Model
We will use Knoten's implementation of CSM as the library supports line scanner types of sensor models in the usgscsm library.

%% Cell type:code id:0c4dbf84-2986-495b-9e4a-da4c77059e7e tags:

``` python
sensor_model = knoten.csm.create_csm(isd_file, verbose=False)
```

%% Cell type:markdown id:d6973fe3-9d4a-4408-9310-50334a52ff58 tags:

### 4. Convert image coordinates into ground coordinates

%% Cell type:code id:d8f2b155-9803-4a6b-a967-bca1ef35860f tags:

``` python
# Create an image coordinate at line = 206 and sample = 206
image_coord = knoten.csmapi.ImageCoord(206, 206)

# Convert the image coordinates to ground coordinates with desired precision of 0.0
ground_coord = sensor_model.imageToGround(image_coord, 0.0)

# Output the ground coordinates
ground_coord.x, ground_coord.y, ground_coord.z
```

%% Output

    (-572485.2147483829, -79884.88742005036, -3326939.6184008163)

%% Cell type:markdown id:bf87c5a5-b26c-4168-9324-ce5b0004cc7c tags:

### 5. Convert ground coordinates into image coordinates

%% Cell type:code id:0edc0b6d-cdbe-46a8-9fdc-4ebdc4570f1a tags:

``` python
# Convert the image coordinates to ground coordinates with desired precision of 0.0
image_coord = sensor_model.groundToImage(ground_coord, 0.0)

# Output the image coordinates
image_coord.line, image_coord.samp
```

%% Output

    (205.99991086761267, 206.00000010379927)
+66 KiB

File added.

No diff preview for this file type.

+6 KiB

File added.

No diff preview for this file type.

+6 KiB

File added.

No diff preview for this file type.

Loading