From c87746c7e19870806b025c79c90f96cc33c1d173 Mon Sep 17 00:00:00 2001 From: Jacob Mims <122570226+jtmims@users.noreply.github.com> Date: Tue, 4 Jun 2024 17:58:23 -0500 Subject: [PATCH] fix to write single variables with POD naming convention in write_dataset (#584) --- src/preprocessor.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/preprocessor.py b/src/preprocessor.py index b558e25ad..4e534c43a 100644 --- a/src/preprocessor.py +++ b/src/preprocessor.py @@ -406,13 +406,13 @@ def execute(self, var, ds, **kwargs): tv = var.translation # abbreviate rename_d = dict() # rename var - if tv.name != var.name: - var.log.debug("Rename '%s' variable in %s to '%s'.", - tv.name, var.full_name, var.name, - tags=util.ObjectLogTag.NC_HISTORY - ) - rename_d[tv.name] = var.name - tv.name = var.name + #if tv.name != var.name: + # var.log.debug("Rename '%s' variable in %s to '%s'.", + # tv.name, var.full_name, var.name, + # tags=util.ObjectLogTag.NC_HISTORY + # ) + # rename_d[tv.name] = var.name + # tv.name = var.name # rename coords for c in tv.dim_axes.values(): @@ -1153,15 +1153,15 @@ def write_dataset(self, var, ds): `__. May be overwritten by child classes. """ - # TODO: remove any netCDF Variables that were present in the input file - # (and ds) but not needed for PODs' data request os.makedirs(os.path.dirname(var.dest_path), exist_ok=True) + var_ds = ds[var.translation.name].to_dataset() + var_ds = var_ds.rename_vars(name_dict={var.translation.name:var.name}) # var.log.info("Writing '%s'.", var.dest_path, tags=util.ObjectLogTag.OUT_FILE) if var.is_static: unlimited_dims = [] else: unlimited_dims = [var.T.name] - ds.to_netcdf( + var_ds.to_netcdf( path=var.dest_path, mode='w', **self.save_dataset_kwargs,