-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from AhmedBasem20/optimize-bandwidth
Optimize bandwidth
- Loading branch information
Showing
4 changed files
with
72 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
import gzip | ||
import csv | ||
import sys | ||
|
||
def reduce_output_file_size(input_file:str, output_file:str): | ||
""" | ||
Simplify the data generated by the analysis pipeline by retaining only the essential information required for the frontend. | ||
""" | ||
if os.path.exists(input_file): | ||
# Open the input and output files | ||
with open(input_file, 'r') as infile, gzip.open(output_file, 'wt', newline='') as outfile: | ||
reader = csv.DictReader(infile) | ||
|
||
# Drop b_values columns | ||
fieldnames = [field for field in reader.fieldnames if not field.startswith('bval_')] | ||
writer = csv.DictWriter(outfile, fieldnames=fieldnames) | ||
writer.writeheader() | ||
|
||
columns_to_round = ['f', 'Dp', 'D', 'f_fitted', 'Dp_fitted', 'D_fitted'] | ||
|
||
for row in reader: | ||
#Delete columns starting with 'bval_' | ||
for key in list(row.keys()): | ||
if key.startswith('bval_'): | ||
del row[key] | ||
|
||
# Round values in the remaining relevant columns | ||
for column in columns_to_round: | ||
if column in row: | ||
row[column] = round(float(row[column]), 4) | ||
writer.writerow(row) | ||
else: | ||
print(f"File '{input_file}' not found.") | ||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) != 3: | ||
print("Usage: python reduce_output_size.py <input_file> <output_file>") | ||
sys.exit(1) | ||
|
||
input_file = sys.argv[1] | ||
output_file = sys.argv[2] | ||
reduce_output_file_size(input_file, output_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.7.1/jszip.min.js"></script> | ||
<script src="https://cdn.plot.ly/plotly-2.30.0.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/pako.min.js"></script> | ||
<script src="index.js"></script> | ||
<link rel="stylesheet" href="index.css"> | ||
</head> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters