Skip to content

Commit

Permalink
Merge pull request #105 from mao-wfs/#104-Add-script-for-merge
Browse files Browse the repository at this point in the history
Add script for merge
  • Loading branch information
kiwakami authored Dec 5, 2023
2 parents 38cfe05 + 63f555c commit 6f884ba
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions scripts/merge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# standard library
from datetime import datetime
from pathlib import Path
from re import compile


# dependencies
from mao_merge_45m import correlator, merge


# constants
DATA = Path.home() / "Data" / "2022"
DT_FMT_CORR = "%Y%j%H%M%S"
DT_FMT_ISO8601 = "%Y%m%dT%H%M%SZ"
NAME_FMT_CORR = compile(r"^(\S+?)_(\d{13})_5.dist.zarr$")


def to_iso8601(dt: str) -> str:
"""Convert the datetime format used for correlators to ISO 8601."""
return datetime.strptime(dt, DT_FMT_CORR).strftime(DT_FMT_ISO8601)


def main() -> None:
for corr in (DATA / "correlator").glob("*.dist.zarr"):
if (match := NAME_FMT_CORR.search(corr.name)) is None:
continue

try:
print(f"Start merging {corr}:")

merged = f"mao45_{to_iso8601(match.group(2))}_if12.zarr.zip"
merge.merge(
corr,
DATA / "merged_20231201" / merged,
path_accelerometer_zarr=DATA / "accelerometer" / "2022-05.zarr",
path_weather_zarr=DATA / "weather" / "2022-05.zarr",
path_antenna_zarr=DATA / "antenna" / "2022-05.zarr",
path_thermometer_zarr=DATA / "thermometer" / "2022-05.zarr",
path_power_meter_zarr=DATA / "power_meter" / "2022-05.zarr",
time_offset=1000,
)

print("Done")
except Exception as error:
print(f"Failed to merge {corr}: {error}")


if __name__ == "__main__":
main()

0 comments on commit 6f884ba

Please sign in to comment.