Loading examples/cassini_isis_cmp.ipynb +5 −10 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 -0.197283 4.530243 1 1.0 1024.0 -0.213690 3.837590 2 1024.0 1.0 -0.898897 4.538942 3 1024.0 1024.0 -0.914839 3.846119 4 512.0 512.0 -0.558596 4.191232 %% Cell type:code id: tags: ``` python ``` 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 Loading
examples/cassini_isis_cmp.ipynb +5 −10 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 -0.197283 4.530243 1 1.0 1024.0 -0.213690 3.837590 2 1024.0 1.0 -0.898897 4.538942 3 1024.0 1024.0 -0.914839 3.846119 4 512.0 512.0 -0.558596 4.191232 %% Cell type:code id: tags: ``` python ``` 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