Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Plio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aflab
astrogeology
Plio
Commits
44acc278
Commit
44acc278
authored
6 years ago
by
acpaquette
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #46 from tthatcher95/master
Updated Notebook / io_controlnetwork
parents
dbc1207a
f55cbbfd
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
notebooks/Socet2ISIS.ipynb
+162
-58
162 additions, 58 deletions
notebooks/Socet2ISIS.ipynb
plio/io/io_controlnetwork.py
+9
-9
9 additions, 9 deletions
plio/io/io_controlnetwork.py
with
171 additions
and
67 deletions
notebooks/Socet2ISIS.ipynb
+
162
−
58
View file @
44acc278
...
@@ -16,10 +16,9 @@
...
@@ -16,10 +16,9 @@
"import math\n",
"import math\n",
"import pyproj\n",
"import pyproj\n",
"\n",
"\n",
"# sys.path.insert(0, \"/home/tthatcher/Desktop/Projects/Plio/plio\")\n",
"\n",
"from plio.examples import get_path\n",
"from plio.examples import get_path\n",
"from plio.io.io_bae import read_gpf, read_ipf\n",
"from plio.io.io_bae import read_gpf, read_ipf\n",
"from collections import defaultdict\n",
"import plio.io.io_controlnetwork as cn\n",
"import plio.io.io_controlnetwork as cn\n",
"import plio.io.isis_serial_number as sn"
"import plio.io.isis_serial_number as sn"
]
]
...
@@ -35,45 +34,50 @@
...
@@ -35,45 +34,50 @@
"# .apf file (should be the same as all others) \n",
"# .apf file (should be the same as all others) \n",
"def read_atf(atf_file):\n",
"def read_atf(atf_file):\n",
" with open(atf_file) as f:\n",
" with open(atf_file) as f:\n",
"\n",
" files = []\n",
" ipf = []\n",
" sup = []\n",
" files_dict = []\n",
" \n",
" \n",
" # Grabs every PRJ, GPF, SUP, and IPF image from the ATF file\n",
" # Extensions of files we want\n",
" files_ext = ['.prj', '.sup', '.ipf', '.gpf']\n",
" files_dict = []\n",
" files = defaultdict(list)\n",
"\n",
" for line in f:\n",
" for line in f:\n",
" if line[-4:-1] == 'prj' or line[-4:-1] == 'gpf' or line[-4:-1] == 'sup' or line[-4:-1] == 'ipf' or line[-4:-1] == 'atf':\n",
" ext = os.path.splitext(line)[-1].strip()\n",
" files.append(line)\n",
" \n",
" # Check is needed for split as all do not have a space\n",
" if ext in files_ext:\n",
" \n",
" # If it is the .prj file, it strips the directory away and grabs file name\n",
" if ext == '.prj':\n",
" files[ext].append(line.strip().split(' ')[1].split('\\\\')[-1])\n",
" \n",
" # If the ext is in the list of files we care about, it addes to the dict\n",
" files[ext].append(line.strip().split(' ')[-1])\n",
" \n",
" else:\n",
" \n",
" # Adds to the dict even if not in files we care about\n",
" files[ext.strip()].append(line)\n",
" \n",
" \n",
" files = np.array(files)\n",
" # Gets the base filepath\n",
" files['basepath'] = os.path.dirname(os.path.abspath(atf_file))\n",
" \n",
" \n",
" # Creates appropriate arrays for certain files in the right format\n",
" for file in files:\n",
" file = file.strip()\n",
" file = file.split(' ')\n",
"\n",
" # Grabs all the IPF files\n",
" if file[1].endswith('.ipf'):\n",
" ipf.append(file[1])\n",
"\n",
" # Grabs all the SUP files\n",
" if file[1].endswith('.sup'):\n",
" sup.append(file[1])\n",
"\n",
" files_dict.append(file)\n",
"\n",
" # Creates a dict out of file lists for GPF, PRJ, IPF, and ATF\n",
" # Creates a dict out of file lists for GPF, PRJ, IPF, and ATF\n",
" files_dict = (dict(files_dict))\n",
" files_dict = (dict(files_dict))\n",
" \n",
" \n",
" # Sets the value of IMAGE_IPF to all IPF images\n",
" # Sets the value of IMAGE_IPF to all IPF images\n",
" files_dict['IMAGE_IPF'] = ipf\n",
" files_dict['IMAGE_IPF'] =
files['.
ipf
']
\n",
" \n",
" \n",
" # Sets the value of IMAGE_SUP to all SUP images\n",
" # Sets the value of IMAGE_SUP to all SUP images\n",
" files_dict['IMAGE_SUP'] = sup\n",
" files_dict['IMAGE_SUP'] = files['.sup']\n",
" \n",
" # Sets value for GPF file\n",
" files_dict['GP_FILE'] = files['.gpf'][0]\n",
" \n",
" # Sets value for PRJ file\n",
" files_dict['PROJECT'] = files['.prj'][0]\n",
" \n",
" \n",
" # Sets the value of PATH to the path of the ATF file\n",
" # Sets the value of PATH to the path of the ATF file\n",
" files_dict['PATH'] =
os.path.dirname(os.path.abspath(atf_file))
\n",
" files_dict['PATH'] =
files['basepath']
\n",
" \n",
" \n",
" return files_dict\n",
" return files_dict\n",
"\n",
"\n",
...
@@ -163,25 +167,126 @@
...
@@ -163,25 +167,126 @@
" coord_360 = to_360(ocentric_coord)\n",
" coord_360 = to_360(ocentric_coord)\n",
" return coord_360\n",
" return coord_360\n",
"\n",
"\n",
"def body_fix(record, semi_major, semi_minor):\n",
"def body_fix(record, semi_major, semi_minor, inverse=False):\n",
" \"\"\"\n",
" Parameters\n",
" ----------\n",
" record : ndarray\n",
" (n,3) where columns are x, y, height or lon, lat, alt\n",
" \"\"\"\n",
" \n",
" ecef = pyproj.Proj(proj='geocent', a=semi_major, b=semi_minor)\n",
" ecef = pyproj.Proj(proj='geocent', a=semi_major, b=semi_minor)\n",
" lla = pyproj.Proj(proj='latlon', a=semi_major, b=semi_minor)\n",
" lla = pyproj.Proj(proj='latlon', a=semi_major, b=semi_minor)\n",
" lon, lat, height = pyproj.transform(lla, ecef, record['long_X_East'], record['lat_Y_North'], record['ht'])\n",
" return lon, lat, height\n",
" \n",
" \n",
" if inverse:\n",
" lon, lat, height = pyproj.transform(ecef, lla, record[0], record[1], record[2])\n",
" return lon, lat, height\n",
" else:\n",
" y, x, z = pyproj.transform(lla, ecef, record[0], record[1], record[2])\n",
" return y, x, z\n",
"\n",
"def ignore_toggle(record):\n",
" if record['stat'] == 0:\n",
" return True\n",
" else:\n",
" return False\n",
"\n",
"# TODO: Does isis cnet need a convariance matrix for sigmas? Even with a static matrix of 1,1,1,1 \n",
"def compute_sigma_covariance_matrix(lat, lon, rad, latsigma, lonsigma, radsigma, semimajor_axis):\n",
" \n",
" \"\"\"\n",
" Given geospatial coordinates, desired accuracy sigmas, and an equitorial radius, compute a 2x3\n",
" sigma covariange matrix.\n",
" Parameters\n",
" ----------\n",
" lat : float\n",
" A point's latitude in degrees\n",
" lon : float\n",
" A point's longitude in degrees\n",
" rad : float\n",
" The radius (z-value) of the point in meters\n",
" latsigma : float\n",
" The desired latitude accuracy in meters (Default 10.0)\n",
" lonsigma : float\n",
" The desired longitude accuracy in meters (Default 10.0)\n",
" radsigma : float\n",
" The desired radius accuracy in meters (Defualt: 15.0)\n",
" semimajor_axis : float\n",
" The semi-major or equitorial radius in meters (Default: 1737400.0 - Moon)\n",
" Returns\n",
" -------\n",
" rectcov : ndarray\n",
" (2,3) covariance matrix\n",
" \"\"\"\n",
" \n",
" lat = math.radians(lat)\n",
" lon = math.radians(lon)\n",
" \n",
" # SetSphericalSigmasDistance\n",
" scaled_lat_sigma = latsigma / semimajor_axis\n",
"\n",
" # This is specific to each lon.\n",
" scaled_lon_sigma = lonsigma * math.cos(lat) / semimajor_axis\n",
" \n",
" # SetSphericalSigmas\n",
" cov = np.eye(3,3)\n",
" cov[0,0] = scaled_lat_sigma ** 2\n",
" cov[1,1] = scaled_lon_sigma ** 2\n",
" cov[2,2] = radsigma ** 2\n",
" \n",
" # Approximate the Jacobian\n",
" j = np.zeros((3,3))\n",
" cosphi = math.cos(lat)\n",
" sinphi = math.sin(lat)\n",
" coslambda = math.cos(lon)\n",
" sinlambda = math.sin(lon)\n",
" rcosphi = rad * cosphi\n",
" rsinphi = rad * sinphi\n",
" j[0,0] = -rsinphi * coslambda\n",
" j[0,1] = -rcosphi * sinlambda\n",
" j[0,2] = cosphi * coslambda\n",
" j[1,0] = -rsinphi * sinlambda\n",
" j[1,1] = rcosphi * coslambda\n",
" j[1,2] = cosphi * sinlambda\n",
" j[2,0] = rcosphi\n",
" j[2,1] = 0.\n",
" j[2,2] = sinphi\n",
" mat = j.dot(cov)\n",
" mat = mat.dot(j.T)\n",
" rectcov = np.zeros((2,3))\n",
" rectcov[0,0] = mat[0,0]\n",
" rectcov[0,1] = mat[0,1]\n",
" rectcov[0,2] = mat[0,2]\n",
" rectcov[1,0] = mat[1,1]\n",
" rectcov[1,1] = mat[1,2]\n",
" rectcov[1,2] = mat[2,2]\n",
" \n",
" return rectcov\n",
"# return np.array([[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]])\n",
"\n",
"\n",
"def compute_cov_matrix(record, semimajor_axis):\n",
" cov_matrix = compute_sigma_covariance_matrix(record['lat_Y_North'], record['long_X_East'], record['ht'], record['sig0'], record['sig1'], record['sig2'], semimajor_axis)\n",
" return cov_matrix.ravel().tolist()\n",
"\n",
"\n",
"# applys transformations to columns\n",
"# applys transformations to columns\n",
"def apply_transformations(atf_dict, df):\n",
"def apply_transformations(atf_dict, df):\n",
" prj_file = os.path.join(atf_dict['PATH'], atf_dict['PROJECT']
.split('\\\\')[-1]
)\n",
" prj_file = os.path.join(atf_dict['PATH'], atf_dict['PROJECT'])\n",
" \n",
" \n",
" eRadius, pRadius = get_axis(prj_file)\n",
" eRadius, pRadius = get_axis(prj_file)\n",
" \n",
" \n",
" lla = np.array([[df['long_X_East']], [df['lat_Y_North']], [df['ht']]])\n",
" \n",
" ecef = body_fix(lla, semi_major = eRadius, semi_minor = pRadius, inverse=False)\n",
" \n",
" df['s.'], df['l.'], df['image_index'] = (zip(*df.apply(line_sample_size, path = atf_dict['PATH'], axis=1)))\n",
" df['s.'], df['l.'], df['image_index'] = (zip(*df.apply(line_sample_size, path = atf_dict['PATH'], axis=1)))\n",
" df['known'] = df.apply(known, axis=1)\n",
" df['known'] = df.apply(known, axis=1)\n",
" df['lat_Y_North'] = df.apply(lat_ISIS_coord, semi_major = eRadius, semi_minor = pRadius, axis=1)\n",
" df['long_X_East'] = ecef[0][0]\n",
" df['long_X_East'] = df.apply(lon_ISIS_coord, semi_major = eRadius, semi_minor = pRadius, axis=1)\n",
" df['lat_Y_North'] = ecef[1][0]\n",
" df['long_X_East'], df['lat_Y_North'], df['ht'] = zip(*df.apply(body_fix, semi_major = eRadius, semi_minor = pRadius, axis = 1))\n",
" df['ht'] = ecef[2][0] \n",
" \n",
" df['aprioriCovar'] = df.apply(compute_cov_matrix, semimajor_axis = eRadius, axis=1)\n",
" df['ignore'] = df.apply(ignore_toggle, axis=1)\n",
" \n",
"def socet2isis(prj_file):\n",
"def socet2isis(prj_file):\n",
" # Read in and setup the atf dict of information\n",
" # Read in and setup the atf dict of information\n",
" atf_dict = read_atf(prj_file)\n",
" atf_dict = read_atf(prj_file)\n",
...
@@ -213,9 +318,10 @@
...
@@ -213,9 +318,10 @@
" \n",
" \n",
" # Define column remap for socet dataframe\n",
" # Define column remap for socet dataframe\n",
" column_remap = {'l.': 'y', 's.': 'x',\n",
" column_remap = {'l.': 'y', 's.': 'x',\n",
" 'res_l': '
L
ineResidual', 'res_s': '
S
ampleResidual', 'known': 'Type',\n",
" 'res_l': '
l
ineResidual', 'res_s': '
s
ampleResidual', 'known': 'Type',\n",
" 'lat_Y_North': 'AprioriY', 'long_X_East': 'AprioriX', 'ht': 'AprioriZ',\n",
" 'lat_Y_North': 'AprioriY', 'long_X_East': 'AprioriX', 'ht': 'AprioriZ',\n",
" 'sig0': 'AprioriLatitudeSigma', 'sig1': 'AprioriLongitudeSigma', 'sig2': 'AprioriRadiusSigma'}\n",
" 'sig0': 'AprioriLatitudeSigma', 'sig1': 'AprioriLongitudeSigma', 'sig2': 'AprioriRadiusSigma',\n",
" 'sig_l': 'linesigma', 'sig_s': 'samplesigma'}\n",
" \n",
" \n",
" # Rename the columns using the column remap above\n",
" # Rename the columns using the column remap above\n",
" socet_df.rename(columns = column_remap, inplace=True)\n",
" socet_df.rename(columns = column_remap, inplace=True)\n",
...
@@ -224,44 +330,42 @@
...
@@ -224,44 +330,42 @@
" return socet_df\n",
" return socet_df\n",
"\n",
"\n",
"# creates a dict of serial numbers with the cub being the key\n",
"# creates a dict of serial numbers with the cub being the key\n",
"def serial_numbers(image
_dict
, path):\n",
"def serial_numbers(image
s
, path
, extension
):\n",
" serial_dict = dict()\n",
" serial_dict = dict()\n",
"\n",
"
\n",
" for
key
in image
_dict
:\n",
" for
image
in image
s
:\n",
" snum = sn.generate_serial_number(os.path.join(path, image
_dict[key]
))\n",
" snum = sn.generate_serial_number(os.path.join(path, image
+ extension
))\n",
" snum = snum.replace('Mars_Reconnaissance_Orbiter', 'MRO')\n",
" snum = snum.replace('Mars_Reconnaissance_Orbiter', 'MRO')\n",
" serial_dict[key] = snum\n",
" serial_dict[image] = snum\n",
" return serial_dict"
" return serial_dict\n",
"\n"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
"metadata": {
"metadata": {
"scrolled":
fals
e
"scrolled":
tru
e
},
},
"outputs": [],
"outputs": [],
"source": [
"source": [
"# Setup stuffs for the cub information namely the path and extension\n",
"# Setup stuffs for the cub information namely the path and extension\n",
"path = '/Volumes/Blueman/'\n",
"path = '/path/where/cub/files/are/'\n",
"atf_file = get_path('CTX_Athabasca_Middle_step0.atf')\n",
"\n",
"# Extension of your cub files\n",
"extension = '.something.cub'\n",
"\n",
"\n",
"image_dict = {'P01_001540_1889_XI_08N204W' : 'P01_001540_1889_XI_08N204W.lev1.cub',\n",
"# Path to atf file\n",
" 'P01_001606_1897_XI_09N203W' : 'P01_001606_1897_XI_09N203W.lev1.cub',\n",
"atf_file = ('/path/to/atf/file')\n",
" 'P02_001804_1889_XI_08N204W' : 'P02_001804_1889_XI_08N204W.lev1.cub',\n",
" 'P03_002226_1895_XI_09N203W' : 'P03_002226_1895_XI_09N203W.lev1.cub',\n",
" 'P03_002371_1888_XI_08N204W' : 'P03_002371_1888_XI_08N204W.lev1.cub',\n",
" 'P19_008344_1894_XN_09N203W' : 'P19_008344_1894_XN_09N203W.lev1.cub',\n",
" 'P20_008845_1894_XN_09N203W' : 'P20_008845_1894_XN_09N203W.lev1.cub'}\n",
"\n",
"\n",
"socet_df = socet2isis(atf_file)\n",
"socet_df = socet2isis(atf_file)\n",
"\n",
"\n",
"images = pd.unique(socet_df['ipf_file'])\n",
"images = pd.unique(socet_df['ipf_file'])\n",
"\n",
"\n",
"serial_dict = serial_numbers(image
_dict
, path)\n",
"serial_dict = serial_numbers(image
s
, path
, extension
)\n",
"\n",
"\n",
"# creates the control network\n",
"# creates the control network\n",
"cn.to_isis('/
Volumes/Blueman/banana
.net', socet_df, serial_dict)"
"cn.to_isis('/
path/you/want/the/cnet/to/be/in/cn
.net', socet_df, serial_dict)"
]
]
},
},
{
{
...
@@ -288,7 +392,7 @@
...
@@ -288,7 +392,7 @@
"name": "python",
"name": "python",
"nbconvert_exporter": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"pygments_lexer": "ipython3",
"version": "3.6.
3
"
"version": "3.6.
4
"
}
}
},
},
"nbformat": 4,
"nbformat": 4,
...
...
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
import
os
import
os
import
sys
import
sys
from
functools
import
singledispatch
from
functools
import
singledispatch
import
warnings
import
warnings
import
pandas
as
pd
import
pandas
as
pd
import
numpy
as
np
import
numpy
as
np
import
math
import
math
import
pyproj
import
pyproj
# sys.path.insert(0, "/home/tthatcher/Desktop/Projects/Plio/plio")
from
plio.examples
import
get_path
from
plio.examples
import
get_path
from
plio.io.io_bae
import
read_gpf
,
read_ipf
from
plio.io.io_bae
import
read_gpf
,
read_ipf
from
collections
import
defaultdict
import
plio.io.io_controlnetwork
as
cn
import
plio.io.io_controlnetwork
as
cn
import
plio.io.isis_serial_number
as
sn
import
plio.io.isis_serial_number
as
sn
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Reads a .atf file and outputs all of the
# Reads a .atf file and outputs all of the
# .ipf, .gpf, .sup, .prj, and path to locate the
# .ipf, .gpf, .sup, .prj, and path to locate the
# .apf file (should be the same as all others)
# .apf file (should be the same as all others)
def
read_atf
(
atf_file
):
def
read_atf
(
atf_file
):
with
open
(
atf_file
)
as
f
:
with
open
(
atf_file
)
as
f
:
files
=
[]
# Extensions of files we want
ipf
=
[]
files_ext
=
[
'
.prj
'
,
'
.sup
'
,
'
.ipf
'
,
'
.gpf
'
]
sup
=
[]
files_dict
=
[]
files_dict
=
[]
files
=
defaultdict
(
list
)
# Grabs every PRJ, GPF, SUP, and IPF image from the ATF file
for
line
in
f
:
for
line
in
f
:
if
line
[
-
4
:
-
1
]
==
'
prj
'
or
line
[
-
4
:
-
1
]
==
'
gpf
'
or
line
[
-
4
:
-
1
]
==
'
sup
'
or
line
[
-
4
:
-
1
]
==
'
ipf
'
or
line
[
-
4
:
-
1
]
==
'
atf
'
:
ext
=
os
.
path
.
splitext
(
line
)[
-
1
].
strip
()
files
.
append
(
line
)
# Check is needed for split as all do not have a space
if
ext
in
files_ext
:
files
=
np
.
array
(
files
)
# If it is the .prj file, it strips the directory away and grabs file name
if
ext
==
'
.prj
'
:
files
[
ext
].
append
(
line
.
strip
().
split
(
'
'
)[
1
].
split
(
'
\\
'
)[
-
1
])
# Creates appropriate arrays for certain files in the right format
# If the ext is in the list of files we care about, it addes to the dict
for
file
in
files
:
files
[
ext
].
append
(
line
.
strip
().
split
(
'
'
)[
-
1
])
file
=
file
.
strip
()
file
=
file
.
split
(
'
'
)
# Grabs all the IPF files
else
:
if
file
[
1
].
endswith
(
'
.ipf
'
):
ipf
.
append
(
file
[
1
])
# Grabs all the SUP files
# Adds to the dict even if not in files we care about
if
file
[
1
].
endswith
(
'
.sup
'
):
files
[
ext
.
strip
()].
append
(
line
)
sup
.
append
(
file
[
1
])
files_dict
.
append
(
file
)
# Gets the base filepath
files
[
'
basepath
'
]
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
atf_file
))
# Creates a dict out of file lists for GPF, PRJ, IPF, and ATF
# Creates a dict out of file lists for GPF, PRJ, IPF, and ATF
files_dict
=
(
dict
(
files_dict
))
files_dict
=
(
dict
(
files_dict
))
# Sets the value of IMAGE_IPF to all IPF images
# Sets the value of IMAGE_IPF to all IPF images
files_dict
[
'
IMAGE_IPF
'
]
=
ipf
files_dict
[
'
IMAGE_IPF
'
]
=
files
[
'
.
ipf
'
]
# Sets the value of IMAGE_SUP to all SUP images
# Sets the value of IMAGE_SUP to all SUP images
files_dict
[
'
IMAGE_SUP
'
]
=
sup
files_dict
[
'
IMAGE_SUP
'
]
=
files
[
'
.sup
'
]
# Sets value for GPF file
files_dict
[
'
GP_FILE
'
]
=
files
[
'
.gpf
'
][
0
]
# Sets value for PRJ file
files_dict
[
'
PROJECT
'
]
=
files
[
'
.prj
'
][
0
]
# Sets the value of PATH to the path of the ATF file
# Sets the value of PATH to the path of the ATF file
files_dict
[
'
PATH
'
]
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
atf_file
))
files_dict
[
'
PATH
'
]
=
files
[
'
basepath
'
]
return
files_dict
return
files_dict
# converts columns l. and s. to isis
# converts columns l. and s. to isis
def
line_sample_size
(
record
,
path
):
def
line_sample_size
(
record
,
path
):
with
open
(
os
.
path
.
join
(
path
,
record
[
'
ipf_file
'
]
+
'
.sup
'
))
as
f
:
with
open
(
os
.
path
.
join
(
path
,
record
[
'
ipf_file
'
]
+
'
.sup
'
))
as
f
:
for
i
,
line
in
enumerate
(
f
):
for
i
,
line
in
enumerate
(
f
):
if
i
==
2
:
if
i
==
2
:
img_index
=
line
.
split
(
'
\\
'
)
img_index
=
line
.
split
(
'
\\
'
)
img_index
=
img_index
[
-
1
].
strip
()
img_index
=
img_index
[
-
1
].
strip
()
img_index
=
img_index
.
split
(
'
.
'
)[
0
]
img_index
=
img_index
.
split
(
'
.
'
)[
0
]
if
i
==
3
:
if
i
==
3
:
line_size
=
line
.
split
(
'
'
)
line_size
=
line
.
split
(
'
'
)
line_size
=
line_size
[
-
1
].
strip
()
line_size
=
line_size
[
-
1
].
strip
()
assert
int
(
line_size
)
>
0
,
"
Line number {} from {} is a negative number: Invalid Data
"
.
format
(
line_size
,
record
[
'
ipf_file
'
])
assert
int
(
line_size
)
>
0
,
"
Line number {} from {} is a negative number: Invalid Data
"
.
format
(
line_size
,
record
[
'
ipf_file
'
])
if
i
==
4
:
if
i
==
4
:
sample_size
=
line
.
split
(
'
'
)
sample_size
=
line
.
split
(
'
'
)
sample_size
=
sample_size
[
-
1
].
strip
()
sample_size
=
sample_size
[
-
1
].
strip
()
assert
int
(
sample_size
)
>
0
,
"
Sample number {} from {} is a negative number: Invalid Data
"
.
format
(
sample_size
,
record
[
'
ipf_file
'
])
assert
int
(
sample_size
)
>
0
,
"
Sample number {} from {} is a negative number: Invalid Data
"
.
format
(
sample_size
,
record
[
'
ipf_file
'
])
break
break
line_size
=
int
(
line_size
)
/
2.0
+
record
[
'
l.
'
]
+
1
line_size
=
int
(
line_size
)
/
2.0
+
record
[
'
l.
'
]
+
1
sample_size
=
int
(
sample_size
)
/
2.0
+
record
[
'
s.
'
]
+
1
sample_size
=
int
(
sample_size
)
/
2.0
+
record
[
'
s.
'
]
+
1
return
sample_size
,
line_size
,
img_index
return
sample_size
,
line_size
,
img_index
# converts known to ISIS keywords
# converts known to ISIS keywords
def
known
(
record
):
def
known
(
record
):
if
record
[
'
known
'
]
==
0
:
if
record
[
'
known
'
]
==
0
:
return
'
Free
'
return
'
Free
'
elif
record
[
'
known
'
]
==
1
or
record
[
'
known
'
]
==
2
or
record
[
'
known
'
]
==
3
:
elif
record
[
'
known
'
]
==
1
or
record
[
'
known
'
]
==
2
or
record
[
'
known
'
]
==
3
:
return
'
Constrained
'
return
'
Constrained
'
# converts +/- 180 system to 0 - 360 system
# converts +/- 180 system to 0 - 360 system
def
to_360
(
num
):
def
to_360
(
num
):
return
num
%
360
return
num
%
360
# ocentric to ographic latitudes
# ocentric to ographic latitudes
def
oc2og
(
dlat
,
dMajorRadius
,
dMinorRadius
):
def
oc2og
(
dlat
,
dMajorRadius
,
dMinorRadius
):
try
:
try
:
dlat
=
math
.
radians
(
dlat
)
dlat
=
math
.
radians
(
dlat
)
dlat
=
math
.
atan
(((
dMajorRadius
/
dMinorRadius
)
**
2
)
*
(
math
.
tan
(
dlat
)))
dlat
=
math
.
atan
(((
dMajorRadius
/
dMinorRadius
)
**
2
)
*
(
math
.
tan
(
dlat
)))
dlat
=
math
.
degrees
(
dlat
)
dlat
=
math
.
degrees
(
dlat
)
except
:
except
:
print
(
"
Error in oc2og conversion
"
)
print
(
"
Error in oc2og conversion
"
)
return
dlat
return
dlat
# ographic to ocentric latitudes
# ographic to ocentric latitudes
def
og2oc
(
dlat
,
dMajorRadius
,
dMinorRadius
):
def
og2oc
(
dlat
,
dMajorRadius
,
dMinorRadius
):
try
:
try
:
dlat
=
math
.
radians
(
dlat
)
dlat
=
math
.
radians
(
dlat
)
dlat
=
math
.
atan
((
math
.
tan
(
dlat
)
/
((
dMajorRadius
/
dMinorRadius
)
**
2
)))
dlat
=
math
.
atan
((
math
.
tan
(
dlat
)
/
((
dMajorRadius
/
dMinorRadius
)
**
2
)))
dlat
=
math
.
degrees
(
dlat
)
dlat
=
math
.
degrees
(
dlat
)
except
:
except
:
print
(
"
Error in og2oc conversion
"
)
print
(
"
Error in og2oc conversion
"
)
return
dlat
return
dlat
# gets eRadius and pRadius from a .prj file
# gets eRadius and pRadius from a .prj file
def
get_axis
(
file
):
def
get_axis
(
file
):
with
open
(
file
)
as
f
:
with
open
(
file
)
as
f
:
from
collections
import
defaultdict
from
collections
import
defaultdict
files
=
defaultdict
(
list
)
files
=
defaultdict
(
list
)
for
line
in
f
:
for
line
in
f
:
ext
=
line
.
strip
().
split
(
'
'
)
ext
=
line
.
strip
().
split
(
'
'
)
files
[
ext
[
0
]].
append
(
ext
[
-
1
])
files
[
ext
[
0
]].
append
(
ext
[
-
1
])
eRadius
=
float
(
files
[
'
A_EARTH
'
][
0
])
eRadius
=
float
(
files
[
'
A_EARTH
'
][
0
])
pRadius
=
eRadius
*
(
1
-
float
(
files
[
'
E_EARTH
'
][
0
]))
pRadius
=
eRadius
*
(
1
-
float
(
files
[
'
E_EARTH
'
][
0
]))
return
eRadius
,
pRadius
return
eRadius
,
pRadius
# function to convert lat_Y_North to ISIS_lat
# function to convert lat_Y_North to ISIS_lat
def
lat_ISIS_coord
(
record
,
semi_major
,
semi_minor
):
def
lat_ISIS_coord
(
record
,
semi_major
,
semi_minor
):
ocentric_coord
=
og2oc
(
record
[
'
lat_Y_North
'
],
semi_major
,
semi_minor
)
ocentric_coord
=
og2oc
(
record
[
'
lat_Y_North
'
],
semi_major
,
semi_minor
)
coord_360
=
to_360
(
ocentric_coord
)
coord_360
=
to_360
(
ocentric_coord
)
return
coord_360
return
coord_360
# function to convert long_X_East to ISIS_lon
# function to convert long_X_East to ISIS_lon
def
lon_ISIS_coord
(
record
,
semi_major
,
semi_minor
):
def
lon_ISIS_coord
(
record
,
semi_major
,
semi_minor
):
ocentric_coord
=
og2oc
(
record
[
'
long_X_East
'
],
semi_major
,
semi_minor
)
ocentric_coord
=
og2oc
(
record
[
'
long_X_East
'
],
semi_major
,
semi_minor
)
coord_360
=
to_360
(
ocentric_coord
)
coord_360
=
to_360
(
ocentric_coord
)
return
coord_360
return
coord_360
def
body_fix
(
record
,
semi_major
,
semi_minor
):
def
body_fix
(
record
,
semi_major
,
semi_minor
,
inverse
=
False
):
"""
Parameters
----------
record : ndarray
(n,3) where columns are x, y, height or lon, lat, alt
"""
ecef
=
pyproj
.
Proj
(
proj
=
'
geocent
'
,
a
=
semi_major
,
b
=
semi_minor
)
ecef
=
pyproj
.
Proj
(
proj
=
'
geocent
'
,
a
=
semi_major
,
b
=
semi_minor
)
lla
=
pyproj
.
Proj
(
proj
=
'
latlon
'
,
a
=
semi_major
,
b
=
semi_minor
)
lla
=
pyproj
.
Proj
(
proj
=
'
latlon
'
,
a
=
semi_major
,
b
=
semi_minor
)
lon
,
lat
,
height
=
pyproj
.
transform
(
lla
,
ecef
,
record
[
'
long_X_East
'
],
record
[
'
lat_Y_North
'
],
record
[
'
ht
'
])
return
lon
,
lat
,
height
if
inverse
:
lon
,
lat
,
height
=
pyproj
.
transform
(
ecef
,
lla
,
record
[
0
],
record
[
1
],
record
[
2
])
return
lon
,
lat
,
height
else
:
y
,
x
,
z
=
pyproj
.
transform
(
lla
,
ecef
,
record
[
0
],
record
[
1
],
record
[
2
])
return
y
,
x
,
z
def
ignore_toggle
(
record
):
if
record
[
'
stat
'
]
==
0
:
return
True
else
:
return
False
# TODO: Does isis cnet need a convariance matrix for sigmas? Even with a static matrix of 1,1,1,1
def
compute_sigma_covariance_matrix
(
lat
,
lon
,
rad
,
latsigma
,
lonsigma
,
radsigma
,
semimajor_axis
):
"""
Given geospatial coordinates, desired accuracy sigmas, and an equitorial radius, compute a 2x3
sigma covariange matrix.
Parameters
----------
lat : float
A point
'
s latitude in degrees
lon : float
A point
'
s longitude in degrees
rad : float
The radius (z-value) of the point in meters
latsigma : float
The desired latitude accuracy in meters (Default 10.0)
lonsigma : float
The desired longitude accuracy in meters (Default 10.0)
radsigma : float
The desired radius accuracy in meters (Defualt: 15.0)
semimajor_axis : float
The semi-major or equitorial radius in meters (Default: 1737400.0 - Moon)
Returns
-------
rectcov : ndarray
(2,3) covariance matrix
"""
lat
=
math
.
radians
(
lat
)
lon
=
math
.
radians
(
lon
)
# SetSphericalSigmasDistance
scaled_lat_sigma
=
latsigma
/
semimajor_axis
# This is specific to each lon.
scaled_lon_sigma
=
lonsigma
*
math
.
cos
(
lat
)
/
semimajor_axis
# SetSphericalSigmas
cov
=
np
.
eye
(
3
,
3
)
cov
[
0
,
0
]
=
scaled_lat_sigma
**
2
cov
[
1
,
1
]
=
scaled_lon_sigma
**
2
cov
[
2
,
2
]
=
radsigma
**
2
# Approximate the Jacobian
j
=
np
.
zeros
((
3
,
3
))
cosphi
=
math
.
cos
(
lat
)
sinphi
=
math
.
sin
(
lat
)
coslambda
=
math
.
cos
(
lon
)
sinlambda
=
math
.
sin
(
lon
)
rcosphi
=
rad
*
cosphi
rsinphi
=
rad
*
sinphi
j
[
0
,
0
]
=
-
rsinphi
*
coslambda
j
[
0
,
1
]
=
-
rcosphi
*
sinlambda
j
[
0
,
2
]
=
cosphi
*
coslambda
j
[
1
,
0
]
=
-
rsinphi
*
sinlambda
j
[
1
,
1
]
=
rcosphi
*
coslambda
j
[
1
,
2
]
=
cosphi
*
sinlambda
j
[
2
,
0
]
=
rcosphi
j
[
2
,
1
]
=
0.
j
[
2
,
2
]
=
sinphi
mat
=
j
.
dot
(
cov
)
mat
=
mat
.
dot
(
j
.
T
)
rectcov
=
np
.
zeros
((
2
,
3
))
rectcov
[
0
,
0
]
=
mat
[
0
,
0
]
rectcov
[
0
,
1
]
=
mat
[
0
,
1
]
rectcov
[
0
,
2
]
=
mat
[
0
,
2
]
rectcov
[
1
,
0
]
=
mat
[
1
,
1
]
rectcov
[
1
,
1
]
=
mat
[
1
,
2
]
rectcov
[
1
,
2
]
=
mat
[
2
,
2
]
return
rectcov
# return np.array([[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]])
def
compute_cov_matrix
(
record
,
semimajor_axis
):
cov_matrix
=
compute_sigma_covariance_matrix
(
record
[
'
lat_Y_North
'
],
record
[
'
long_X_East
'
],
record
[
'
ht
'
],
record
[
'
sig0
'
],
record
[
'
sig1
'
],
record
[
'
sig2
'
],
semimajor_axis
)
return
cov_matrix
.
ravel
().
tolist
()
# applys transformations to columns
# applys transformations to columns
def
apply_transformations
(
atf_dict
,
df
):
def
apply_transformations
(
atf_dict
,
df
):
prj_file
=
os
.
path
.
join
(
atf_dict
[
'
PATH
'
],
atf_dict
[
'
PROJECT
'
]
.
split
(
'
\\
'
)[
-
1
]
)
prj_file
=
os
.
path
.
join
(
atf_dict
[
'
PATH
'
],
atf_dict
[
'
PROJECT
'
])
eRadius
,
pRadius
=
get_axis
(
prj_file
)
eRadius
,
pRadius
=
get_axis
(
prj_file
)
lla
=
np
.
array
([[
df
[
'
long_X_East
'
]],
[
df
[
'
lat_Y_North
'
]],
[
df
[
'
ht
'
]]])
ecef
=
body_fix
(
lla
,
semi_major
=
eRadius
,
semi_minor
=
pRadius
,
inverse
=
False
)
df
[
'
s.
'
],
df
[
'
l.
'
],
df
[
'
image_index
'
]
=
(
zip
(
*
df
.
apply
(
line_sample_size
,
path
=
atf_dict
[
'
PATH
'
],
axis
=
1
)))
df
[
'
s.
'
],
df
[
'
l.
'
],
df
[
'
image_index
'
]
=
(
zip
(
*
df
.
apply
(
line_sample_size
,
path
=
atf_dict
[
'
PATH
'
],
axis
=
1
)))
df
[
'
known
'
]
=
df
.
apply
(
known
,
axis
=
1
)
df
[
'
known
'
]
=
df
.
apply
(
known
,
axis
=
1
)
df
[
'
lat_Y_North
'
]
=
df
.
apply
(
lat_ISIS_coord
,
semi_major
=
eRadius
,
semi_minor
=
pRadius
,
axis
=
1
)
df
[
'
long_X_East
'
]
=
ecef
[
0
][
0
]
df
[
'
long_X_East
'
]
=
df
.
apply
(
lon_ISIS_coord
,
semi_major
=
eRadius
,
semi_minor
=
pRadius
,
axis
=
1
)
df
[
'
lat_Y_North
'
]
=
ecef
[
1
][
0
]
df
[
'
long_X_East
'
],
df
[
'
lat_Y_North
'
],
df
[
'
ht
'
]
=
zip
(
*
df
.
apply
(
body_fix
,
semi_major
=
eRadius
,
semi_minor
=
pRadius
,
axis
=
1
))
df
[
'
ht
'
]
=
ecef
[
2
][
0
]
df
[
'
aprioriCovar
'
]
=
df
.
apply
(
compute_cov_matrix
,
semimajor_axis
=
eRadius
,
axis
=
1
)
df
[
'
ignore
'
]
=
df
.
apply
(
ignore_toggle
,
axis
=
1
)
def
socet2isis
(
prj_file
):
def
socet2isis
(
prj_file
):
# Read in and setup the atf dict of information
# Read in and setup the atf dict of information
atf_dict
=
read_atf
(
prj_file
)
atf_dict
=
read_atf
(
prj_file
)
# Get the gpf and ipf files using atf dict
# Get the gpf and ipf files using atf dict
gpf_file
=
os
.
path
.
join
(
atf_dict
[
'
PATH
'
],
atf_dict
[
'
GP_FILE
'
]);
gpf_file
=
os
.
path
.
join
(
atf_dict
[
'
PATH
'
],
atf_dict
[
'
GP_FILE
'
]);
ipf_list
=
[
os
.
path
.
join
(
atf_dict
[
'
PATH
'
],
i
)
for
i
in
atf_dict
[
'
IMAGE_IPF
'
]]
ipf_list
=
[
os
.
path
.
join
(
atf_dict
[
'
PATH
'
],
i
)
for
i
in
atf_dict
[
'
IMAGE_IPF
'
]]
# Read in the gpf file and ipf file(s) into seperate dataframes
# Read in the gpf file and ipf file(s) into seperate dataframes
gpf_df
=
read_gpf
(
gpf_file
)
gpf_df
=
read_gpf
(
gpf_file
)
ipf_df
=
read_ipf
(
ipf_list
)
ipf_df
=
read_ipf
(
ipf_list
)
# Check for differences between point ids using each dataframes
# Check for differences between point ids using each dataframes
# point ids as a reference
# point ids as a reference
gpf_pt_idx
=
pd
.
Index
(
pd
.
unique
(
gpf_df
[
'
point_id
'
]))
gpf_pt_idx
=
pd
.
Index
(
pd
.
unique
(
gpf_df
[
'
point_id
'
]))
ipf_pt_idx
=
pd
.
Index
(
pd
.
unique
(
ipf_df
[
'
pt_id
'
]))
ipf_pt_idx
=
pd
.
Index
(
pd
.
unique
(
ipf_df
[
'
pt_id
'
]))
point_diff
=
ipf_pt_idx
.
difference
(
gpf_pt_idx
)
point_diff
=
ipf_pt_idx
.
difference
(
gpf_pt_idx
)
if
len
(
point_diff
)
!=
0
:
if
len
(
point_diff
)
!=
0
:
warnings
.
warn
(
"
The following points found in ipf files missing from gpf file:
\n\n
{}.
\
warnings
.
warn
(
"
The following points found in ipf files missing from gpf file:
\n\n
{}.
\
\n\n
Continuing, but these points will be missing from the control network
"
.
format
(
list
(
point_diff
)))
\n\n
Continuing, but these points will be missing from the control network
"
.
format
(
list
(
point_diff
)))
# Merge the two dataframes on their point id columns
# Merge the two dataframes on their point id columns
socet_df
=
ipf_df
.
merge
(
gpf_df
,
left_on
=
'
pt_id
'
,
right_on
=
'
point_id
'
)
socet_df
=
ipf_df
.
merge
(
gpf_df
,
left_on
=
'
pt_id
'
,
right_on
=
'
point_id
'
)
# Apply the transformations
# Apply the transformations
apply_transformations
(
atf_dict
,
socet_df
)
apply_transformations
(
atf_dict
,
socet_df
)
# Define column remap for socet dataframe
# Define column remap for socet dataframe
column_remap
=
{
'
l.
'
:
'
y
'
,
'
s.
'
:
'
x
'
,
column_remap
=
{
'
l.
'
:
'
y
'
,
'
s.
'
:
'
x
'
,
'
res_l
'
:
'
L
ineResidual
'
,
'
res_s
'
:
'
S
ampleResidual
'
,
'
known
'
:
'
Type
'
,
'
res_l
'
:
'
l
ineResidual
'
,
'
res_s
'
:
'
s
ampleResidual
'
,
'
known
'
:
'
Type
'
,
'
lat_Y_North
'
:
'
AprioriY
'
,
'
long_X_East
'
:
'
AprioriX
'
,
'
ht
'
:
'
AprioriZ
'
,
'
lat_Y_North
'
:
'
AprioriY
'
,
'
long_X_East
'
:
'
AprioriX
'
,
'
ht
'
:
'
AprioriZ
'
,
'
sig0
'
:
'
AprioriLatitudeSigma
'
,
'
sig1
'
:
'
AprioriLongitudeSigma
'
,
'
sig2
'
:
'
AprioriRadiusSigma
'
}
'
sig0
'
:
'
AprioriLatitudeSigma
'
,
'
sig1
'
:
'
AprioriLongitudeSigma
'
,
'
sig2
'
:
'
AprioriRadiusSigma
'
,
'
sig_l
'
:
'
linesigma
'
,
'
sig_s
'
:
'
samplesigma
'
}
# Rename the columns using the column remap above
# Rename the columns using the column remap above
socet_df
.
rename
(
columns
=
column_remap
,
inplace
=
True
)
socet_df
.
rename
(
columns
=
column_remap
,
inplace
=
True
)
# Return the socet dataframe to be converted to a control net
# Return the socet dataframe to be converted to a control net
return
socet_df
return
socet_df
# creates a dict of serial numbers with the cub being the key
# creates a dict of serial numbers with the cub being the key
def
serial_numbers
(
image
_dict
,
path
):
def
serial_numbers
(
image
s
,
path
,
extension
):
serial_dict
=
dict
()
serial_dict
=
dict
()
for
key
in
image
_dict
:
for
image
in
image
s
:
snum
=
sn
.
generate_serial_number
(
os
.
path
.
join
(
path
,
image
_dict
[
key
]
))
snum
=
sn
.
generate_serial_number
(
os
.
path
.
join
(
path
,
image
+
extension
))
snum
=
snum
.
replace
(
'
Mars_Reconnaissance_Orbiter
'
,
'
MRO
'
)
snum
=
snum
.
replace
(
'
Mars_Reconnaissance_Orbiter
'
,
'
MRO
'
)
serial_dict
[
key
]
=
snum
serial_dict
[
image
]
=
snum
return
serial_dict
return
serial_dict
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Setup stuffs for the cub information namely the path and extension
# Setup stuffs for the cub information namely the path and extension
path
=
'
/Volumes/Blueman/
'
path
=
'
/path/where/cub/files/are/
'
atf_file
=
get_path
(
'
CTX_Athabasca_Middle_step0.atf
'
)
# Extension of your cub files
extension
=
'
.something.cub
'
image_dict
=
{
'
P01_001540_1889_XI_08N204W
'
:
'
P01_001540_1889_XI_08N204W.lev1.cub
'
,
# Path to atf file
'
P01_001606_1897_XI_09N203W
'
:
'
P01_001606_1897_XI_09N203W.lev1.cub
'
,
atf_file
=
(
'
/path/to/atf/file
'
)
'
P02_001804_1889_XI_08N204W
'
:
'
P02_001804_1889_XI_08N204W.lev1.cub
'
,
'
P03_002226_1895_XI_09N203W
'
:
'
P03_002226_1895_XI_09N203W.lev1.cub
'
,
'
P03_002371_1888_XI_08N204W
'
:
'
P03_002371_1888_XI_08N204W.lev1.cub
'
,
'
P19_008344_1894_XN_09N203W
'
:
'
P19_008344_1894_XN_09N203W.lev1.cub
'
,
'
P20_008845_1894_XN_09N203W
'
:
'
P20_008845_1894_XN_09N203W.lev1.cub
'
}
socet_df
=
socet2isis
(
atf_file
)
socet_df
=
socet2isis
(
atf_file
)
images
=
pd
.
unique
(
socet_df
[
'
ipf_file
'
])
images
=
pd
.
unique
(
socet_df
[
'
ipf_file
'
])
serial_dict
=
serial_numbers
(
image
_dict
,
path
)
serial_dict
=
serial_numbers
(
image
s
,
path
,
extension
)
# creates the control network
# creates the control network
cn
.
to_isis
(
'
/
Volumes/Blueman/banana
.net
'
,
socet_df
,
serial_dict
)
cn
.
to_isis
(
'
/
path/you/want/the/cnet/to/be/in/cn
.net
'
,
socet_df
,
serial_dict
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
```
```
...
...
This diff is collapsed.
Click to expand it.
plio/io/io_controlnetwork.py
+
9
−
9
View file @
44acc278
from
time
import
gmtime
,
strftime
from
time
import
gmtime
,
strftime
import
pandas
as
pd
import
pandas
as
pd
import
numpy
as
np
import
pvl
import
pvl
from
plio.io
import
ControlNetFileV0002_pb2
as
cnf
from
plio.io
import
ControlNetFileV0002_pb2
as
cnf
...
@@ -189,19 +190,19 @@ class IsisStore(object):
...
@@ -189,19 +190,19 @@ class IsisStore(object):
if
version
==
2
:
if
version
==
2
:
point_attrs
=
[
i
for
i
in
cnf
.
_CONTROLPOINTFILEENTRYV0002
.
fields_by_name
if
i
!=
'
measures
'
]
point_attrs
=
[
i
for
i
in
cnf
.
_CONTROLPOINTFILEENTRYV0002
.
fields_by_name
if
i
!=
'
measures
'
]
measure_attrs
=
[
i
for
i
in
cnf
.
_CONTROLPOINTFILEENTRYV0002_MEASURE
.
fields_by_name
]
measure_attrs
=
[
i
for
i
in
cnf
.
_CONTROLPOINTFILEENTRYV0002_MEASURE
.
fields_by_name
]
cols
=
point_attrs
+
measure_attrs
cols
=
point_attrs
+
measure_attrs
cp
=
cnf
.
ControlPointFileEntryV0002
()
cp
=
cnf
.
ControlPointFileEntryV0002
()
self
.
_handle
.
seek
(
header_start_byte
)
self
.
_handle
.
seek
(
header_start_byte
)
pbuf_header
=
cnf
.
ControlNetFileHeaderV0002
()
pbuf_header
=
cnf
.
ControlNetFileHeaderV0002
()
pbuf_header
.
ParseFromString
(
self
.
_handle
.
read
(
header_bytes
))
pbuf_header
.
ParseFromString
(
self
.
_handle
.
read
(
header_bytes
))
self
.
_handle
.
seek
(
point_start_byte
)
self
.
_handle
.
seek
(
point_start_byte
)
cp
=
cnf
.
ControlPointFileEntryV0002
()
cp
=
cnf
.
ControlPointFileEntryV0002
()
pts
=
[]
pts
=
[]
for
s
in
pbuf_header
.
pointMessageSizes
:
for
s
in
pbuf_header
.
pointMessageSizes
:
cp
.
ParseFromString
(
self
.
_handle
.
read
(
s
))
cp
.
ParseFromString
(
self
.
_handle
.
read
(
s
))
pt
=
[
getattr
(
cp
,
i
)
for
i
in
point_attrs
if
i
!=
'
measures
'
]
pt
=
[
getattr
(
cp
,
i
)
for
i
in
point_attrs
if
i
!=
'
measures
'
]
for
measure
in
cp
.
measures
:
for
measure
in
cp
.
measures
:
...
@@ -267,24 +268,24 @@ class IsisStore(object):
...
@@ -267,24 +268,24 @@ class IsisStore(object):
# As per protobuf docs for assigning to a repeated field.
# As per protobuf docs for assigning to a repeated field.
if
attr
==
'
aprioriCovar
'
:
if
attr
==
'
aprioriCovar
'
:
arr
=
g
.
iloc
[
0
][
'
aprioriCovar
'
]
arr
=
g
.
iloc
[
0
][
'
aprioriCovar
'
]
point_spec
.
aprioriCovar
.
extend
(
arr
.
ravel
().
tolist
())
if
isinstance
(
arr
,
np
.
ndarray
):
arr
=
arr
.
ravel
().
tolist
()
point_spec
.
aprioriCovar
.
extend
(
arr
)
else
:
else
:
setattr
(
point_spec
,
attr
,
attrtype
(
g
.
iloc
[
0
][
attr
]))
setattr
(
point_spec
,
attr
,
attrtype
(
g
.
iloc
[
0
][
attr
]))
point_spec
.
type
=
2
# Hardcoded to free
point_spec
.
type
=
2
# Hardcoded to free
this is bad
# The reference index should always be the image with the lowest index
# The reference index should always be the image with the lowest index
point_spec
.
referenceIndex
=
0
point_spec
.
referenceIndex
=
0
# A single extend call is cheaper than many add calls to pack points
# A single extend call is cheaper than many add calls to pack points
measure_iterable
=
[]
measure_iterable
=
[]
for
node_id
,
m
in
g
.
iterrows
():
for
node_id
,
m
in
g
.
iterrows
():
measure_spec
=
point_spec
.
Measure
()
measure_spec
=
point_spec
.
Measure
()
# For all of the attributes, set if they are an dict accessible attr of the obj.
# For all of the attributes, set if they are an dict accessible attr of the obj.
for
attr
,
attrtype
in
self
.
measure_attrs
:
for
attr
,
attrtype
in
self
.
measure_attrs
:
if
attr
in
g
.
columns
:
if
attr
in
g
.
columns
:
setattr
(
measure_spec
,
attr
,
attrtype
(
m
[
attr
]))
setattr
(
measure_spec
,
attr
,
attrtype
(
m
[
attr
]))
measure_spec
.
serialnumber
=
serials
[
m
.
image_index
]
measure_spec
.
serialnumber
=
serials
[
m
.
image_index
]
measure_spec
.
sample
=
m
.
x
measure_spec
.
sample
=
m
.
x
measure_spec
.
line
=
m
.
y
measure_spec
.
line
=
m
.
y
...
@@ -298,7 +299,6 @@ class IsisStore(object):
...
@@ -298,7 +299,6 @@ class IsisStore(object):
point_message
=
point_spec
.
SerializeToString
()
point_message
=
point_spec
.
SerializeToString
()
point_sizes
.
append
(
point_spec
.
ByteSize
())
point_sizes
.
append
(
point_spec
.
ByteSize
())
point_messages
.
append
(
point_message
)
point_messages
.
append
(
point_message
)
return
point_messages
,
point_sizes
return
point_messages
,
point_sizes
def
create_buffer_header
(
self
,
networkid
,
targetname
,
def
create_buffer_header
(
self
,
networkid
,
targetname
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment