From 1fca12227604c7765caa2754b98c84ea87c746a9 Mon Sep 17 00:00:00 2001 From: Chris Leaman Date: Wed, 6 Mar 2019 15:34:32 +1100 Subject: [PATCH] Ensure float precision is limited when outputting csv Without this change, interim .csv files were being recorded with 9 decimal places, greatly increasing the file size. This keeps the number of decimals limited to a practical amount. --- src/analysis/forecast_twl.py | 2 +- src/analysis/forecasted_storm_impacts.py | 2 +- src/data/parse_mat.py | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/analysis/forecast_twl.py b/src/analysis/forecast_twl.py index c4c84bf..cd02071 100644 --- a/src/analysis/forecast_twl.py +++ b/src/analysis/forecast_twl.py @@ -422,6 +422,6 @@ def create_twl_forecast( profile_type=profile_type, ) - df_twl.to_csv(output_file) + df_twl.to_csv(output_file, float_format="%.4f") logger.info("Saved to %s", output_file) logger.info("Done!") diff --git a/src/analysis/forecasted_storm_impacts.py b/src/analysis/forecasted_storm_impacts.py index d992c5f..6ce742f 100644 --- a/src/analysis/forecasted_storm_impacts.py +++ b/src/analysis/forecasted_storm_impacts.py @@ -140,6 +140,6 @@ def create_forecasted_impacts(profile_features_csv, forecasted_twl_csv, output_f right_on=["site_id"], ) - df_forecasted_impacts.to_csv(output_file) + df_forecasted_impacts.to_csv(output_file, float_format="%.4f") logger.info("Saved to %s", output_file) logger.info("Done!") diff --git a/src/data/parse_mat.py b/src/data/parse_mat.py index 855479b..437a29b 100644 --- a/src/data/parse_mat.py +++ b/src/data/parse_mat.py @@ -467,8 +467,8 @@ def create_waves_csv(waves_mat, sites_csv, waves_output_file, sites_waves_output df_waves.set_index(["site_id", "datetime"], inplace=True) df_waves.sort_index(inplace=True) df_waves, df_sites_waves = split_site_wave_params(df_waves) - df_waves.to_csv(waves_output_file) - df_sites_waves.to_csv(sites_waves_output_file) + df_waves.to_csv(waves_output_file, float_format="%.4f") + df_sites_waves.to_csv(sites_waves_output_file, float_format="%.4f") logger.info("Created %s", waves_output_file) logger.info("Created %s", sites_waves_output_file) @@ -523,9 +523,9 @@ def create_sites_and_profiles_csv( df_sites.set_index(["site_id"], inplace=True) df_sites.sort_index(inplace=True) - df_profiles.to_csv(profiles_output_file) + df_profiles.to_csv(profiles_output_file, float_format="%.8f") logger.info("Created %s", profiles_output_file) - df_sites.to_csv(sites_output_file, float_format="%.3f") + df_sites.to_csv(sites_output_file, float_format="%.8f") logger.info("Created %s", sites_output_file) @@ -542,7 +542,7 @@ def create_tides_csv(tides_mat, sites_csv, output_file): df_tides = replace_unique_sites(df_tides, df_sites) df_tides.set_index(["site_id", "datetime"], inplace=True) df_tides.sort_index(inplace=True) - df_tides.to_csv(output_file) + df_tides.to_csv(output_file, float_format="%.4f") logger.info("Created %s", output_file)