From e41667428a39a87904d7bf7769d7cf437764b155 Mon Sep 17 00:00:00 2001 From: David Caron Date: Thu, 23 May 2019 16:30:28 -0400 Subject: [PATCH] don't add units to the header when there are none (some indices computation like frequency don't have any unit and having an empty pair of parenthesis is awkward) --- finch/processes/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/finch/processes/utils.py b/finch/processes/utils.py index eb09e143..53d0d06f 100644 --- a/finch/processes/utils.py +++ b/finch/processes/utils.py @@ -136,9 +136,13 @@ def netcdf_to_csv( for variable in ds.data_vars: model = ds.attrs["driving_model_id"] experiment = ds.attrs["driving_experiment_id"].replace(",", "_") + + output_variable = f"{variable}_{model}_{experiment}" + units = ds[variable].units + if units: + output_variable += f"_({units})" - output_variable = f"{variable}_{model}_{experiment}_({units})" ds = ds.rename({variable: output_variable}) df = ds.to_dataframe()[["lat", "lon", output_variable]]