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

Range history saver #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions flight/pygnc/configuration/pygnc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
import warnings

batch_sensor_gps_filepath = os.path.expanduser("~/sense.bin")
batch_range_filepath = os.path.expanduser("~/range.bin")
25 changes: 25 additions & 0 deletions flight/pygnc/tasks/range_history_saver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# from ..configuration.pygnc import batch_range_filepath

# print(f"Open {batch_range_filepath}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use this as the filepath to open

# read files from range filepath then read D bytes every S time steps
def read_and_save(input_file, output_file, D, S):
with open(input_file, 'rb') as infile, open(output_file, 'wb') as outfile:
print(f"Reading {input_file} and saving every {S}th measurement to {output_file}")
count = 0
while True:
data = infile.read(D)
if not data:
break # End of file
count += 1
if count % S == 0:
outfile.write(data)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a main() function that pulls in the correct constants and calls read_and_save().

if __name__ == "__main__":
# Replace 'input_file.bin' and 'output_file.bin' with your actual file names
input_file = 'range.txt'
output_file = 'sparse_measurements.bin'

# Replace 100 and 5 with your desired values for D and S
D = 120 # Number of bytes to read and save
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put these constants in ../configuration/range_history_saver.py

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also reference Py4Data/example_range_parse/dataparser_range.py to get the correct value for D (it's not 120).

S = 30 # Save every S instances
read_and_save(input_file, output_file, D, S)
Binary file not shown.