NOAA-Buoy / buoy-python /ZScore2023.py
lukawskikacper's picture
First version of the dataset
8be024f
raw
history blame
1.76 kB
import csv
from pathlib import Path
import numpy as np
import pandas as pd
from collections import defaultdict
FULL_DATA_SET_STRING = "../full_2023_remove_flawed_rows.csv"
FULL_DATA_SET_PATH = Path(FULL_DATA_SET_STRING)
OUT_DATASET_STRING = "../zscore_2023.parquet"
OUT_DATASET_PATH = Path(OUT_DATASET_STRING)
OUT_FULL_DATASET_STRING = "../full_2023_remove_flawed.parquet"
OUT_FULL_DATASET_PATH = Path(OUT_FULL_DATASET_STRING)
NUMERIC_FIELDS = ["WSPD","GST","WVHT","DPD","APD","PRES","ATMP","WTMP"]
def load_data(data_path):
print("Loading data")
with open(data_path, newline='') as csv_file:
loaded_np_data = pd.read_csv(csv_file)
print("Writing out the full Parquet file")
loaded_np_data.to_parquet(OUT_FULL_DATASET_PATH)
print("Applying Sin() to the two degrees columns")
loaded_np_data["WDIR"] = np.sin(np.deg2rad(loaded_np_data["WDIR"]))
loaded_np_data["MWD"] = np.sin(np.deg2rad(loaded_np_data["MWD"]))
print("calculating z-scores")
for var in NUMERIC_FIELDS:
var_mean = np.mean(loaded_np_data[var])
var_std = np.std(loaded_np_data[var])
var_zscore = (loaded_np_data[var] - var_mean)/var_std
loaded_np_data[var] = var_zscore
print("exporting to parquet")
loaded_np_data.set_index("TSTMP")
loaded_np_data.to_parquet(OUT_DATASET_PATH)
if __name__ == '__main__':
print("Start")
# Load data
all_data = load_data(FULL_DATA_SET_PATH)
# Calculate mean and std dev for each non-date column
# Going to need to sin(X) for any circular numbers (WDIR & MWD)
# Write out data removing rows
# Probably want to write out the sin(X) for any circular numbers
print("finished")