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

Tetra Star-ID algorithm #91

Open
wants to merge 106 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
52fd2c5
Save
zeddie888 Aug 15, 2022
652c607
Cleanup starter tetra code
zeddie888 Aug 15, 2022
2d306b8
Implement Pattern construction
zeddie888 Aug 16, 2022
3259203
Stop before database work
zeddie888 Aug 16, 2022
3d350d8
Finish bad Tetra database reading code
zeddie888 Aug 16, 2022
2ad07f9
Continue with hashing code
zeddie888 Aug 16, 2022
39be1be
Finish bad database generation code, fix seg fault- allocate catalog …
zeddie888 Aug 16, 2022
e19a515
Save progress
zeddie888 Aug 16, 2022
f388785
Implement argsort- note that must define in .hpp
zeddie888 Aug 16, 2022
c5b44a2
Finish basic star ID working
zeddie888 Aug 16, 2022
b9f4528
Finish centroid matching, now just return catalog INDEX, not star ID
zeddie888 Aug 17, 2022
a728d5c
Add questionable catalog indexing for LOST attitude step to work
zeddie888 Aug 17, 2022
8412944
Update todos
zeddie888 Aug 17, 2022
302cae6
Continue documentation
zeddie888 Aug 17, 2022
5bb9ea9
Confirm our previous camera.CameraToSpatial does same thing
zeddie888 Aug 20, 2022
2c18c59
Test read from binary, default database
zeddie888 Sep 15, 2022
51b625a
Bug with generator function
zeddie888 Sep 15, 2022
c6fb96b
Bring back version of naive database loading
zeddie888 Sep 15, 2022
1bb5e5d
Fix false failure bug
zeddie888 Sep 15, 2022
ce775db
Test on database with fov=12, stable sort- success for now
zeddie888 Sep 15, 2022
f624299
Database generation working as of now!
zeddie888 Sep 15, 2022
bb4ff51
Use pair for range values in binning
zeddie888 Sep 20, 2022
9b035b9
Fix star ID inclusion issue for db
zeddie888 Sep 22, 2022
77286d0
Add final star table preprocessing step
zeddie888 Oct 21, 2022
927bdec
Continue Tetra db integration
zeddie888 Nov 9, 2022
cb3238a
Save progress on Serialization functions
zeddie888 Nov 25, 2022
0133514
Finish first draft of serialize Tetra db
zeddie888 Nov 25, 2022
d81e120
Remove outdated TetraDatabase from star-id
zeddie888 Nov 25, 2022
c6e6357
Add BuilderTetraDatabase code to io.cpp
zeddie888 Nov 25, 2022
00da9fe
Implement a hacky way to generate Tetra db
zeddie888 Nov 26, 2022
1468cb2
Save changes, bugs in pattern generation
zeddie888 Nov 29, 2022
26372bc
Debug Tetra db generation
zeddie888 Dec 24, 2022
eeaa255
Remove unecessary looping, db preprocessing is much faster now
zeddie888 Dec 24, 2022
8346734
Debug preprocessing, fixed now
zeddie888 Dec 24, 2022
f03d245
Use Vec3 for hashing
zeddie888 Dec 25, 2022
51a6a14
Redo coarse sky map parsing
zeddie888 Dec 25, 2022
c60945d
Review pattern generation for db
zeddie888 Dec 25, 2022
151db86
Implement TetraDatabase functions for parsing db from buffer
zeddie888 Dec 27, 2022
ffaa685
Restore working tetra version, reading from premade binary
zeddie888 Dec 27, 2022
47e31ff
Argsort for centroid indices, save a good bit of work
zeddie888 Dec 27, 2022
97d0960
Bug with Tetra db serialization - collision rate extremely high
zeddie888 Dec 27, 2022
5b5d541
Fix tetra serialization bug
zeddie888 Dec 27, 2022
c78ec82
First successful run with integrated Tetra db
zeddie888 Dec 27, 2022
acdec96
Integration for Tetra db generation
zeddie888 Dec 27, 2022
9720c73
Fix centroid selection bug
zeddie888 Dec 28, 2022
e406596
Save working version with full integration, work still todo
zeddie888 Dec 28, 2022
cddc040
Draft centroid combination generator function
zeddie888 Dec 29, 2022
16e8efa
Integrate centroid combination generator
zeddie888 Dec 29, 2022
e09aeaf
Remove hardcoded catalog length from tetra Go
zeddie888 Dec 29, 2022
2385761
Success on fake generated images!
zeddie888 Dec 29, 2022
491b3c9
Use CLI options for tetraMaxAngle in database
zeddie888 Jan 3, 2023
a008e02
Include maxAngle in tetra db
zeddie888 Jan 3, 2023
81e35a8
Prepare for pattern bin testing
zeddie888 Jan 4, 2023
9d94296
Test binning parameter values
zeddie888 Jan 14, 2023
7cdc236
Testing with database fov size, smaller is better
zeddie888 Feb 17, 2023
6ded84e
Add attitude testing script
zeddie888 Feb 19, 2023
ba2e2a7
Fix Tetra testing script
zeddie888 Feb 20, 2023
f7d9d75
Fix centroid-algo flag error
zeddie888 Feb 23, 2023
f50fb5f
Use normalized spatial vectors, surprisingly powerful improvements
zeddie888 Feb 27, 2023
1ea4f11
Factor out KeyToIndex function
zeddie888 Feb 28, 2023
7c6c5a7
Factor out more common functions- pattern construction, etc.
zeddie888 Mar 1, 2023
44cace3
Fix bug with testing script
zeddie888 Mar 1, 2023
5fab88c
Fix bug with pattern construction - ratios be sorted
zeddie888 Mar 1, 2023
0797b14
Enable other star ID algos, stopped overwriting original Catalog
zeddie888 Mar 1, 2023
65045ac
Enable old tests
zeddie888 Mar 5, 2023
07fe80f
Merge from master
zeddie888 Mar 5, 2023
d613ede
Get rid of static variables in generator function
zeddie888 Mar 5, 2023
e5b941b
Cleanup and documentation
zeddie888 Mar 5, 2023
3c79e84
More cleanup
zeddie888 Mar 5, 2023
7dbfbb7
Restore original tests
zeddie888 Mar 5, 2023
9fe67e7
Remove old db
zeddie888 Mar 5, 2023
7539bda
Indentation set to 4
zeddie888 Mar 8, 2023
ec96726
merge from master
zeddie888 Mar 15, 2023
4be5522
fixing pr
zeddie888 Mar 15, 2023
09a54a4
layout fixes, move preprocessing to databases.hpp
zeddie888 Mar 17, 2023
43306ac
get rid of shorts for db stuff, replaced with uint16_t
zeddie888 Mar 17, 2023
24f4fb5
replace dot product magic with intuitive angle comparisons
zeddie888 Mar 17, 2023
8a41648
split Tetra db serialization into two
zeddie888 Mar 17, 2023
f91beeb
clarity changes
zeddie888 Mar 17, 2023
0519d13
fix compiler warnings
zeddie888 Mar 17, 2023
8a2cb6f
smol comments
zeddie888 Mar 20, 2023
72b15a5
merge from master
zeddie888 Apr 3, 2023
286b29b
Merge branch 'master' of https://github.com/UWCubeSat/lost into ezhan…
zeddie888 Apr 3, 2023
2714892
merge master
zeddie888 Apr 4, 2023
c7231a6
smol comment
zeddie888 May 20, 2023
042f295
merge master
zeddie888 May 20, 2023
4f59c67
move GetPatternMatches functionality to TetraDatabase
zeddie888 May 29, 2023
62212e9
get rid of linear catalog search
zeddie888 May 29, 2023
4bc1fc4
add iterator class for centroid combo, Tetra
zeddie888 May 29, 2023
461f018
change debug output to cerr, man page documentation updated
zeddie888 May 29, 2023
3d41e5b
smol comment
zeddie888 May 29, 2023
a45eed6
hyperparam tuning, interesting results
zeddie888 May 30, 2023
882322e
Merge remote-tracking branch 'origin/master' into ezhang8-tetra2
zeddie888 May 30, 2023
15bc5f1
smol cleanup
zeddie888 May 30, 2023
9e8d031
get rid of special Vec3 comparison function:
zeddie888 May 31, 2023
e592d3d
revert formatting changes to otherwise unmodified code (tetra)
markasoftware Jun 2, 2023
2f6c369
refactor Tetra serialization to use new serdes
zeddie888 Nov 5, 2023
35e2f84
finish tetra serialization
zeddie888 Nov 5, 2023
ac37fef
add extremely simple regression testing script
zeddie888 Nov 13, 2023
3834a3a
Merge remote-tracking branch 'origin/master' into ezhang8-tetra2
zeddie888 Nov 14, 2023
bdcc396
refactoring for tetra stuff
zeddie888 Nov 14, 2023
2cddbcf
line refactoring
zeddie888 Nov 14, 2023
0d284cd
update reg test test to recursively look at subdirectories
zeddie888 Nov 15, 2023
e4e94c8
enable catalog minsep narrowing
zeddie888 Nov 16, 2023
1fa7f28
Merge branch 'master' into ezhang8-tetra2
zeddie888 Nov 16, 2023
917e19a
disable camera printing for testing
zeddie888 Dec 4, 2023
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*.out.*
*.lisp
*.org
*.py
# *.py
*.json
/.gdb_history

Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Copyright (c) 2020 Mark Polyakov, Karen Haining (If you edit the file, add your name here!)
#
# Copyright (c) 2020 Mark Polyakov, Karen Haining, Edward Zhang
# (If you edit the file, add your name here!)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -85,6 +86,7 @@ test: $(BIN) $(BSC) $(TEST_BIN)
# bash ./test/scripts/pyramid-incorrect.sh
bash ./test/scripts/readme-examples-test.sh
bash ./test/scripts/random-crap.sh
# bash ./test/scripts/tetra.sh

$(TEST_BIN): $(TEST_OBJS)
$(CXX) $(LDFLAGS) -o $(TEST_BIN) $(TEST_OBJS) $(LIBS)
Expand Down
13 changes: 13 additions & 0 deletions documentation/database.man
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ Sets the maximum distance \fImax\fP (degrees). Defaults to 15 if option is not s
\fB--kvector-distance-bins\fP \fInum-bins\fP
Sets the number of distance bins in the kvector building method to \fInum-bins\fP. Defaults to 10000 if option is not selected, which is pretty reasonable for most cases.

.SH TETRA DATABASE OPTIONS

The Tetra database is needed for the Tetra star identification algorithm. Its primary payload is
a pattern catalog , essentially a large hash table that stores 4-star patterns

.TP
\fB--tetra\fP
Generate a Tetra database

.TP
\fB--tetra-max-angle \fImax\fP
Sets the maximum allowable angle between stars in a Tetra pattern to \fImax\fP (degrees). Defaults to 12 if option is not selected.

.SH OTHER OPTIONS

.TP
Expand Down
2 changes: 1 addition & 1 deletion documentation/pipeline.man
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Runs the dummy centroiding algorithm (random centroid algorithm) with \fInum-sta

.TP
\fB--star-id-algo\fP \fIalgo\fP
Runs the \fIalgo\fP star identification algorithm. Current options are "dummy", "gv", and "pyramid". Defaults to "dummy" if option is not selected.
Runs the \fIalgo\fP star identification algorithm. Current options are "dummy", "gv", "tetra", and "pyramid". Defaults to "dummy" if option is not selected.

.TP
\fB--angular-tolerance\fP [\fItolerance\fP] Sets the estimated angular centroiding error tolerance,
Expand Down
65 changes: 65 additions & 0 deletions reg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Script to check performance on images in given folder and prevent regression testing
# Go over all images in some folder and check performance, log it to stdout (for now)
# TODO: figure out some storage plan

# CLI:
# test directory name, output log name
# (optional) attitude estimator
# Example usage: python reg.py samples/ log.txt -att_estimator quest

import subprocess
import argparse

# import os
import glob
import datetime

parser = argparse.ArgumentParser()
parser.add_argument("test_dir", type=str)
parser.add_argument("log", type=str, default="log.txt")
parser.add_argument("-att_estimator", type=str, nargs="?", default="dqm")
args = parser.parse_args()

print(f"Testing images in {args.test_dir}")
print(f"attitude estimator: {args.att_estimator}")
print(f"Logging outputs to {args.log}")


def get_diff(expected, actual):
"""Get element-wise angle difference between expected and actual (what we got)"""
return [expected[i] - actual[i] for i in range(len(actual))]


output_log = open(args.log, "a+") # append to end of log, don't overwrite
for img_name in glob.glob(args.test_dir + "**/*.png", recursive=True):
print(f"===================={img_name}====================")
cmd = (
f"./lost pipeline \
--png {img_name} \
--fov 17 \
--centroid-algo cog \
--centroid-filter-brightest 8 \
--star-id-algo tetra \
--database tetra-algo-12.dat \
--false-stars 0 \
--attitude-algo {args.att_estimator} \
--print-attitude attitude.txt \
--plot-output annotated-res.png",
)
subprocess.call(cmd, shell=True)
# log attitude.txt
# Log:
# which image was tested
# Output from attitude.txt
dt = datetime.datetime.now().isoformat()
output_log.write("----------------------------\n")
output_log.write(f"{img_name}-{dt}-{args.att_estimator}\n")
output_log.write("----------------------------\n")
with open("attitude.txt") as att_log:
targets = ["attitude_ra", "attitude_de", "attitude_roll"]
for line in att_log:
line = line.split(" ")
if line[0] in targets:
output_log.write(line[1])

output_log.close()
2 changes: 1 addition & 1 deletion src/attitude-estimators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ float QuestCharPoly(float x, float a, float b, float c, float d, float s) {retur
float QuestCharPolyPrime(float x, float a, float b, float c) {return 4*pow(x,3) - 2*(a+b)*x - c;}

/**
* Approximates roots of a real function using the Newton-Raphson algorithm
* Approximates roots of a real function using the Newton-Raphson algorithm
* @see https://www.geeksforgeeks.org/program-for-newton-raphson-method/
*/
float QuestEigenvalueEstimator(float guess, float a, float b, float c, float d, float s) {
Expand Down
18 changes: 16 additions & 2 deletions src/attitude-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ float FloatModulo(float x, float mod) {
return result >= 0 ? result : result + mod;
}

std::ostream &operator<<(std::ostream &output, const Vec2 &vec) {
output << "Vec2(x: " << vec.x << ", y: " << vec.y << ")";
return output;
}

std::ostream &operator<<(std::ostream &output, const Vec3 &vec) {
output << "Vec3(x: " << vec.x << ", y: " << vec.y << ", z: " << vec.z << ")";
return output;
}

/// The square of the magnitude
float Vec3::MagnitudeSq() const {
return fma(x,x,fma(y,y, z*z));
Expand Down Expand Up @@ -200,12 +210,12 @@ float Vec3::operator*(const Vec3 &other) const {
return fma(x,other.x, fma(y,other.y, z*other.z));
}

/// Dot product
/// Vector-scalar multiplication
Vec2 Vec2::operator*(const float &other) const {
return { x*other, y*other };
}

/// Vector-Scalar multiplication
/// Vector-scalar multiplication
Vec3 Vec3::operator*(const float &other) const {
return { x*other, y*other, z*other };
}
Expand All @@ -225,6 +235,10 @@ Vec3 Vec3::operator-(const Vec3 &other) const {
return { x - other.x, y - other.y, z - other.z };
}

Vec3 Vec3::operator+(const Vec3 &other) const {
return {x + other.x, y + other.y, z + other.z};
}

/// Usual vector cross product
Vec3 Vec3::CrossProduct(const Vec3 &other) const {
return {
Expand Down
29 changes: 28 additions & 1 deletion src/attitude-utils.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#ifndef ATTITUDE_UTILS_H
#define ATTITUDE_UTILS_H

#include <algorithm>
#include <fstream>
#include <memory>
#include <numeric> // iota
#include <vector>

#include "serialize-helpers.hpp"
Expand All @@ -26,6 +29,8 @@ struct Vec2 {
Vec2 operator*(const float &) const;
Vec2 operator-(const Vec2 &) const;
Vec2 operator+(const Vec2 &) const;

friend std::ostream &operator<<(std::ostream &output, const Vec2 &vec);
};

class Mat3; // define above so we can use in Vec3 class
Expand All @@ -37,6 +42,9 @@ class Vec3 {
float y;
float z;

Vec3(){};
Vec3(float x, float y, float z) : x(x), y(y), z(z){};

float Magnitude() const;
float MagnitudeSq() const;
Vec3 Normalize() const;
Expand All @@ -45,8 +53,11 @@ class Vec3 {
Vec3 operator*(const float &) const;
Vec3 operator*(const Mat3 &) const;
Vec3 operator-(const Vec3 &) const;
Vec3 operator+(const Vec3 &) const;
Vec3 CrossProduct(const Vec3 &) const;
Mat3 OuterProduct(const Vec3 &) const;

friend std::ostream &operator<<(std::ostream &output, const Vec3 &vec);
};

/// 3x3 vector with floating point components
Expand Down Expand Up @@ -183,8 +194,24 @@ float ArcSecToRad(float);
/// Always returns something in [0,mod) Eg -0.8 mod 0.6 = 0.4
float FloatModulo(float x, float mod);

// Argsort function - Tetra
// Sort first vector based on values of second vector (asc)
template <class T, class U>
std::vector<T> ArgsortVector(std::vector<T> arr, std::vector<U> cmp) {
std::vector<T> res;
std::vector<int> indices(arr.size());
std::iota(indices.begin(), indices.end(), 0);
std::sort(indices.begin(), indices.end(),
[&](int a, int b) -> bool { return cmp[a] < cmp[b]; });

for (int ind : indices) {
res.push_back(arr[ind]);
}
return res;
}

// TODO: quaternion and euler angle conversion, conversion between ascension/declination to rec9tu

}
} // namespace lost

#endif
2 changes: 1 addition & 1 deletion src/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Camera {
/// Focal length in pixels
float FocalLength() const { return focalLength; };
/// Horizontal field of view in radians
float Fov() const;
float Fov() const; // in radians

void SetFocalLength(float focalLength) { this->focalLength = focalLength; }

Expand Down
2 changes: 2 additions & 0 deletions src/database-options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ LOST_CLI_OPTION("kvector-max-distance" , float , kvectorMaxDistance ,
LOST_CLI_OPTION("kvector-distance-bins" , long , kvectorNumDistanceBins, 10000 , atol(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("swap-integer-endianness", bool , swapIntegerEndianness , false , atobool(optarg), true)
LOST_CLI_OPTION("swap-float-endianness" , bool , swapFloatEndianness , false , atobool(optarg), true)
LOST_CLI_OPTION("tetra" , bool , tetra , false , atobool(optarg), true)
LOST_CLI_OPTION("tetra-max-angle" , float , tetraMaxAngle , 12 , atof(optarg) , kNoDefaultArgument)
LOST_CLI_OPTION("output" , std::string, outputPath , "-" , optarg , kNoDefaultArgument)
Loading