|
2 | 2 | import subprocess |
3 | 3 | import ruamel.yaml |
4 | 4 | import sys |
| 5 | +import os |
| 6 | +from tqdm import tqdm |
5 | 7 |
|
6 | 8 | sys.path.append("./") |
7 | 9 | sys.path.append("../") |
@@ -35,17 +37,32 @@ def path2ipfs(path): |
35 | 37 | product_path = config["OPTIONAL"]["product_dir"] |
36 | 38 | # %% |
37 | 39 |
|
38 | | -# add raw data to tree |
39 | | - |
40 | 40 | # Ensure the structure exists and initialize empty dicts if they don't exist |
41 | 41 | tree["products"]["HALO"].setdefault("dropsondes", {}) |
42 | | - |
43 | | - |
44 | 42 | if tree["products"]["HALO"]["dropsondes"] is None: |
45 | 43 | tree["products"]["HALO"]["dropsondes"] = {} |
46 | | -# add the hashes to the tree |
47 | | -product_sonde = path2ipfs(product_path) |
48 | | -tree["products"]["HALO"]["dropsondes"] = product_sonde |
| 44 | + |
| 45 | + |
| 46 | +# add product_data |
| 47 | +level_dirs = ["Level_1", "Level_2"] |
| 48 | +for level in level_dirs: |
| 49 | + print(level) |
| 50 | + tree["products"]["HALO"]["dropsondes"].setdefault(f"{level}", {}) |
| 51 | + if tree["products"]["HALO"]["dropsondes"][f"{level}"] is None: |
| 52 | + tree["products"]["HALO"]["dropsondes"][f"{level}"] = {} |
| 53 | + fl_path = os.path.join(product_path, level) |
| 54 | + flight_ids = [f for f in sorted(os.listdir(fl_path)) if "HALO-" in f] |
| 55 | + for flight in tqdm(flight_ids): |
| 56 | + path_to_flight = os.path.join(fl_path, flight) |
| 57 | + lev_sonde = path2ipfs(path_to_flight) |
| 58 | + |
| 59 | + tree["products"]["HALO"]["dropsondes"][f"{level}"][f"{flight}"] = lev_sonde |
| 60 | + |
| 61 | +level_dirs = ["Level_3", "Level_4"] |
| 62 | +for level in tqdm(level_dirs): |
| 63 | + path2lev = os.path.join(product_path, level) |
| 64 | + lev_sonde = path2ipfs(path2lev) |
| 65 | + tree["products"]["HALO"]["dropsondes"][f"{level}"] = lev_sonde |
49 | 66 |
|
50 | 67 | # Save the updated tree back to the YAML file |
51 | 68 | with open("../../ipfs_tools/tree.yaml", "w") as file: |
|
0 commit comments