Skip to content

Commit

Permalink
fix to write single variables with POD naming convention in write_dat…
Browse files Browse the repository at this point in the history
…aset (#584)
  • Loading branch information
jtmims authored Jun 4, 2024
1 parent 341b882 commit c87746c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -1153,15 +1153,15 @@ def write_dataset(self, var, ds):
<https://xarray.pydata.org/en/stable/generated/xarray.Dataset.to_netcdf.html>`__.
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,
Expand Down

0 comments on commit c87746c

Please sign in to comment.