Wed, 22 Apr 2026 23:46:40 -0500
Add packaging script, remove alg_tools, measures, and pointsource_pde installation instruction from README.
| 12 | 1 | #!.venv/bin/python3 |
| 2 | import argparse | |
| 3 | import csv | |
| 4 | from pathlib import Path | |
| 5 | ||
| 6 | import numpy as np | |
| 7 | ||
| 8 | from plot import find_files | |
| 9 | ||
| 10 | ||
| 11 | def extract_aux(prefix): | |
| 12 | ||
| 13 | iter_files = find_files(prefix) | |
| 14 | ||
| 15 | init_filename = "%s/init_aux.csv" % Path(prefix).parent | |
| 16 | filename = "%s/res_aux.csv" % prefix | |
| 17 | ||
| 18 | # Do true and noisy values | |
| 19 | ||
| 20 | initdata = [ | |
| 21 | [ | |
| 22 | "k_true", | |
| 23 | "c1_true", | |
| 24 | "c2_true", | |
| 25 | "k_noisy", | |
| 26 | "c1_noisy", | |
| 27 | "c2_noisy", | |
| 28 | ] | |
| 29 | ] | |
| 30 | ||
| 31 | data0 = np.load("%s/omega_0.npz" % Path(prefix).parent) | |
| 32 | k_true = data0["k_true"] | |
| 33 | c1_true = data0["c1_true"] | |
| 34 | c2_true = data0["c2_true"] | |
| 35 | initdata.append( | |
| 36 | [ | |
| 37 | k_true, | |
| 38 | c1_true, | |
| 39 | c2_true, | |
| 40 | data0["k_noisy"], | |
| 41 | data0["c1_noisy"], | |
| 42 | data0["c2_noisy"], | |
| 43 | ] | |
| 44 | ) | |
| 45 | with open(init_filename, mode="w", newline="") as file: | |
| 46 | # Create a csv.writer object | |
| 47 | writer = csv.writer(file, delimiter="\t") | |
| 48 | # Write data to the CSV file | |
| 49 | writer.writerows(initdata) | |
| 50 | ||
| 51 | # Do reconstructed values | |
| 52 | ||
| 53 | auxdata = [ | |
| 54 | [ | |
| 55 | "iter", | |
| 56 | "k", | |
| 57 | "c1", | |
| 58 | "c2", | |
| 59 | "k_dist", | |
| 60 | "c_dist", | |
| 61 | ] | |
| 62 | ] | |
| 63 | ||
| 64 | for iter, file in iter_files: | |
| 65 | d = np.load(file) | |
| 66 | k = d["k"] | |
| 67 | c1 = d["c1"] | |
| 68 | c2 = d["c2"] | |
| 69 | k_dist = np.abs(k - k_true) | |
| 70 | c_dist = np.sqrt((c1 - c1_true) ** 2 + (c2 - c2_true) ** 2) | |
| 71 | auxdata.append([iter, k, c1, c2, k_dist, c_dist]) | |
| 72 | ||
| 73 | # Open the file in write mode | |
| 74 | with open(filename, mode="w", newline="") as file: | |
| 75 | # Create a csv.writer object | |
| 76 | writer = csv.writer(file, delimiter="\t") | |
| 77 | # Write data to the CSV file | |
| 78 | writer.writerows(auxdata) | |
| 79 | ||
| 80 | ||
| 81 | def main(): | |
| 82 | parser = argparse.ArgumentParser( | |
| 83 | prog="extract_aux.py", | |
| 84 | description="Extract auxiliary parameters from pointsource_pde", | |
| 85 | ) | |
| 86 | ||
| 87 | parser.add_argument("filename") | |
| 88 | ||
| 89 | args = parser.parse_args() | |
| 90 | ||
| 91 | extract_aux(args.filename) | |
| 92 | ||
| 93 | ||
| 94 | if __name__ == "__main__": | |
| 95 | main() |