Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Sensor Util Functions #130

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
316 changes: 316 additions & 0 deletions examples/sensor_utils.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
{
amystamile-usgs marked this conversation as resolved.
Show resolved Hide resolved
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Sensor Utils\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"from csmapi import csmapi\n",
"from knoten import csm, sensor_utils\n",
"\n",
"import ale\n",
"import json"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create a usgscsm sensor model"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/astamile/opt/anaconda3/envs/knoten/lib/python3.9/site-packages/osgeo/gdal.py:312: FutureWarning: Neither gdal.UseExceptions() nor gdal.DontUseExceptions() has been explicitly called. In GDAL 4.0, exceptions will be enabled by default.\n",
" warnings.warn(\n"
]
}
],
"source": [
"fileName = \"data/N1573082850_1.cub\"\n",
"\n",
"kernels = ale.util.generate_kernels_from_cube(fileName, expand=True)\n",
"isd_string = ale.loads(fileName, props={'kernels': kernels})\n",
"csm_isd = os.path.splitext(fileName)[0] + '.json'\n",
"\n",
"with open(csm_isd, 'w') as isd_file:\n",
" isd_file.write(isd_string)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Run Sensor Utils with usgscsm sensor model and image point"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"camera = csm.create_csm(csm_isd)\n",
"image_pt = csmapi.ImageCoord(511.5, 511.5)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"38.87212509629893"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"phaseAngle = sensor_utils.phase_angle(image_pt, camera)\n",
"\n",
"phaseAngle"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"49.60309924896046"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"emissionAngle = sensor_utils.emission_angle(image_pt, camera)\n",
"\n",
"emissionAngle"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2903512972.146144"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"slantDistance = sensor_utils.slant_distance(image_pt, camera)\n",
"\n",
"slantDistance"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2943536048.858226"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"targetCenterDistance = sensor_utils.target_center_distance(image_pt, camera)\n",
"\n",
"targetCenterDistance"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"LatLon(lat=3.2229625890973583, lon=258.6197326526089)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"subSpacecraftPoint = sensor_utils.sub_spacecraft_point(image_pt, camera)\n",
"\n",
"subSpacecraftPoint"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"59096282.02424558"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"localRadius = sensor_utils.local_radius(image_pt, camera)\n",
"\n",
"localRadius"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(79.34815579474038, -2.7790780986459485)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rightAscDec = sensor_utils.right_ascension_declination(image_pt, camera)\n",
"\n",
"rightAscDec"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"17397.960941876583"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lineResolution = sensor_utils.line_resolution(image_pt, camera)\n",
"\n",
"lineResolution"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"17397.933700407997"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sampleResolution = sensor_utils.sample_resolution(image_pt, camera)\n",
"\n",
"sampleResolution"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"17397.94732114229"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pixelResolution = sensor_utils.pixel_resolution(image_pt, camera)\n",
"\n",
"pixelResolution"
]
}
],
"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.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
29 changes: 29 additions & 0 deletions knoten/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,35 @@ def compute_ground_partials(sensor, ground_pt):
partials = np.array(sensor.computeGroundPartials(csm_ground))
return np.reshape(partials, (2, 3))

def compute_image_partials(sensor, ground_pt):
"""
Compute the partial derivatives of the ground point with respect to
the line and sample at a ground point.

These are not normally available from the CSM model, so we use
csm::RasterGM::computeGroundPartials to get the Jacobian of the ground to
image transformation. Then we use the pseudoinverse of that to get the
Jacobian of the image to ground transformation.

Parameters
----------
sensor : CSM sensor
The CSM sensor model
ground_pt : array
The (x, y, z) ground point to compute the partial derivatives W.R.T.

Returns
-------
: array
The partial derivatives of the image to ground transformation
"""
if isinstance(ground_pt, csmapi.EcefCoord):
ground_pt = [ground_pt.x, ground_pt.y, ground_pt.z]
ground_matrix = compute_ground_partials(sensor, ground_pt)
image_matrix = np.linalg.pinv(ground_matrix)

return image_matrix.flatten()

def compute_coefficient_columns(network, sensors, parameters):
"""
Compute the columns for different coefficients
Expand Down
Loading
Loading