Commit 69379878 authored by Kristin's avatar Kristin
Browse files

:Merge branch 'master' of github.com:USGS-Astrogeology/knoten

parents 6ce49d6e 8492359a
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -3,15 +3,20 @@ channels:
  - conda-forge
  - usgs-astrogeology
dependencies:
  - python >= 3
  - coveralls
  - csmapi
  - gdal
  - jinja2
  - jupyter
  - matplotlib
  - numpy
  - pytest
  - plio
  - pvl
  - pyproj
  - pysis
  - pytest
  - python>=3
  - requests
  - scipy
  - matplotlib
  - shapely
  - usgscsm
+6 −6
Original line number Diff line number Diff line
%% Cell type:markdown id: tags:

# Comparing a USGSCSM and ISIS camera for Cassini ISS

%% Cell type:code id: tags:

``` python
import pvl
import numpy as np
import os
import pandas as pd
import knoten
import csmapi

os.environ['ISISROOT'] = '/usgs/pkgs/isis3.8.0_RC1/install'
from pysis import isis
from pysis.exceptions import ProcessError
```

%% Cell type:markdown id: tags:

## Make a CSM sensor model
Requires N1702360370_1.LBL and N1702360370_1.IMG in data directory

%% Cell type:code id: tags:

``` python
fileName = 'data/N1702360370_1.LBL'
camera = knoten.csm.create_csm(fileName)
```

%% Cell type:markdown id: tags:

## Ingest the image and spiceinit

%% Cell type:code id: tags:

``` python
# Set the output location of the resulting .cub
cub_loc = os.path.splitext(fileName)[0] + '.cub'

try:
    isis.ciss2isis(from_=fileName, to=cub_loc)
except ProcessError as e:
    print(e.stderr)

try:
    isis.spiceinit(from_=cub_loc, shape='ellipsoid')
except ProcessError as e:
    print(e.stderr)
```

%% Cell type:markdown id: tags:

## Define a function that compares ISIS and USGSCSM pixels

%% Cell type:code id: tags:

``` python
def check_pixel(camera, cub, line, sample):
    """Compares ISIS and USGSCSM pixel.

    Takes an image coordinate, projects it to a ground point using ISIS, then projects
    the result back into an image coordinate using USGSCSM and computes the difference
    between image coordinates.
    """
    output = isis.campt(from_=cub, line=line, sample=sample)
    pvl_output = pvl.loads(output)
    bodyfixed = pvl_output['GroundPoint']['BodyFixedCoordinate']
    bodyfixed = np.asarray(bodyfixed.value) * 1000
    image_coord = camera.groundToImage(csmapi.EcefCoord(*bodyfixed))
    # (.5,.5) in CSM == (1,1) in ISIS, so we have to subtract (.5,.5) from the ISIS pixels
    line_diff = line - image_coord.line - .5
    sample_diff = sample - image_coord.samp - .5
    return line_diff, sample_diff
```

%% Cell type:markdown id: tags:

## Get the total number of lines / samples

%% Cell type:code id: tags:

``` python
isis_label = pvl.load(cub_loc)
n_samples = isis_label['IsisCube']['Core']['Dimensions']['Samples']
n_lines = isis_label['IsisCube']['Core']['Dimensions']['Lines']
```

%% Cell type:markdown id: tags:

## Compare top left, top right, bottom left, bottom right, and center pixels using check_pixel

%% Cell type:code id: tags:

``` python
pixels_dict = {'line' : [1,1,n_lines, n_lines, n_lines/2],
               'sample' : [1, n_samples, 1, n_samples, n_samples/2]}

pixels_df = pd.DataFrame.from_dict(pixels_dict)
pixels_df['line_diff'] = np.NaN
pixels_df['sample_diff'] = np.NaN

for idx, row in pixels_df.iterrows():
    pixels_df.iloc[idx]['line_diff'], pixels_df.iloc[idx]['sample_diff'] = check_pixel(camera, cub_loc, row['line'], row['sample'])

pixels_df
```

%% Output

         line  sample    line_diff  sample_diff
    0     1.0     1.0 -1020.486363 -1024.409488
    1     1.0  1024.0 -1020.472731  1022.315882
    2  1024.0     1.0  1026.247265 -1024.418200
    3  1024.0  1024.0  1026.260599  1022.307325
    4   512.0   512.0     1.888677    -2.053929
         line  sample  line_diff  sample_diff
    0     1.0     1.0   0.153039     0.906085
    1     1.0  1024.0   0.142231     0.326977
    2  1024.0     1.0  -0.425122     0.915083
    3  1024.0  1024.0  -0.435769     0.335980
    4   512.0   512.0  -0.142021     0.620648
+1 −0
Original line number Diff line number Diff line
{"radii": {"semimajor": 482.1, "semiminor": 445.94, "unit": "km"}, "sensor_position": {"positions": [[258050.2687983894, 14326.958947727007, -4862493.832226484]], "velocities": [[-104.7145626143671, -85.03261098015915, -5.786975988636929]], "unit": "m"}, "sun_position": {"positions": [[360880681.08749247, 246471123.80357987, 30565891.31704259, 47397.508212291505]], "velocities": [[47397.508212291505, -69397.53747853675, 0.19335721325156585]], "unit": "m"}, "sensor_orientation": {"quaternions": [[0.001892487545803033, 0.021367862646678643, -0.2778085145572912, -0.9603969294912772]]}, "detector_sample_summing": 1, "detector_line_summing": 1, "focal_length_model": {"focal_length": 150.08}, "detector_center": {"line": 511.5, "sample": 511.5}, "starting_detector_line": 1, "starting_detector_sample": 1, "focal2pixel_lines": [0.0, 0.0, 71.40816909454442], "focal2pixel_samples": [0.0, 71.40816909454442, 0.0], "optical_distortion": {"dawnfc": {"coefficients": [9.2e-06]}}, "image_lines": 1024, "image_samples": 1024, "name_platform": "DAWN", "name_sensor": "FRAMING CAMERA 2", "reference_height": {"maxheight": 1000, "minheight": -1000, "unit": "m"}, "name_model": "USGS_ASTRO_FRAME_SENSOR_MODEL", "center_ephemeris_time": 488002614.62253857}
 No newline at end of file