Skip to content

Commit 4906ef8

Browse files
committed
Delay checking of dimension consistency until file writing time.
(Initial template may be inconsistent with some variables yet to be defined)
1 parent 98066a8 commit 4906ef8

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

ncwriter/template.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ def __init__(self,
6262
self.variables = variables or OrderedDict()
6363
self.global_attributes = global_attributes or OrderedDict()
6464

65-
if not self.is_dim_consistent():
66-
raise TypeError("Correct the dimensions.")
67-
6865
self.check_var(self.variables)
6966
self.check_consistency(self.dimensions, self.variables)
7067

@@ -204,6 +201,8 @@ def __init__(self, *args, **kwargs):
204201
])
205202
self.fill_aliases = set(
206203
['fill_value', 'missing_value', 'FillValue', '_FillValue'])
204+
self.outfile = None
205+
self.ncobj = None
207206

208207
@classmethod
209208
def from_json(cls, path):
@@ -349,9 +348,12 @@ def to_netcdf(self, outfile, var_args={}, **kwargs):
349348
:return: None
350349
"""
351350
self.outfile = outfile
352-
self.ncobj = netCDF4.Dataset(self.outfile, mode='w', **kwargs)
353351

354352
self.update_dimensions()
353+
if not self.is_dim_consistent():
354+
raise ValueError("Dimensions.")
355+
356+
self.ncobj = netCDF4.Dataset(self.outfile, mode='w', **kwargs)
355357
self.create_dimensions()
356358
self.create_variables(**var_args)
357359
self.create_global_attributes()

0 commit comments

Comments
 (0)