Skip to content

Commit 68661f2

Browse files
committed
rename DatasetTemplate.create() method to to_netcdf()
1 parent db5d0a2 commit 68661f2

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

ncwriter/template.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,18 @@ def createGlobalAttrs(self):
421421
for att in self.global_attributes.keys():
422422
self.ncobj.setncattr(att, self.global_attributes[att])
423423

424-
def create(self, outfile, mode='w', var_args={}, **kwargs):
425-
"""Create the file according to all the information in the template"""
424+
def to_netcdf(self, outfile, var_args={}, **kwargs):
425+
"""
426+
Create a netCDF file according to all the information in the template.
427+
See netCDF4 package documentation for additional arguments.
428+
429+
:param outfile: Path for the output file (clobbered by default if it already exists!)
430+
:param var_args: Additional arguments passed on to netCDF4.Dataset.createVariables()
431+
:param kwargs: Additional arguments for netCDF4.Dataset()
432+
:return: None
433+
"""
426434
self.outfile = outfile
427-
self.ncobj = netCDF4.Dataset(self.outfile, mode=mode, **kwargs)
435+
self.ncobj = netCDF4.Dataset(self.outfile, mode='w', **kwargs)
428436

429437
self.update_dimensinos()
430438
self.createDimensions()

test_ncwriter/test_template.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,15 @@ def test_set_variable_values(self):
137137

138138
def test_create_empty_file(self):
139139
template = DatasetTemplate()
140-
template.create(self.temp_nc_file)
140+
template.to_netcdf(self.temp_nc_file)
141141
dataset = Dataset(self.temp_nc_file)
142142

143143
def test_create_file(self):
144144
template = DatasetTemplate.from_json(TEMPLATE_JSON)
145145
template.variables['TIME']['values'] = self.values10
146146
template.variables['DEPTH']['values'] = self.values1
147147
template.variables['TEMP']['values'] = self.values10.reshape((10, 1))
148-
template.create(self.temp_nc_file)
149-
print("Created nc file '{}'".format(self.temp_nc_file))
148+
template.to_netcdf(self.temp_nc_file)
150149

151150
dataset = Dataset(self.temp_nc_file)
152151

0 commit comments

Comments
 (0)