File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -132,13 +132,24 @@ def __init__(
132132 concat_dimension : str = "time" ,
133133 interp_dim : str = "range" ,
134134 ) -> None :
135- self .filenames = sorted (map (Path , filenames ), key = lambda f : f .name )
136135 self .concat_dimension = concat_dimension
137136 self .interp_dim = interp_dim
137+ self .filenames = sorted (
138+ [Path (filename ) for filename in filenames if self ._is_valid_file (filename )],
139+ key = lambda f : f .name ,
140+ )
138141 self .first_filename = self .filenames [0 ]
139142 self .first_file = netCDF4 .Dataset (self .first_filename )
140143 self .concatenated_file = self ._init_output_file (output_file )
141144
145+ def _is_valid_file (self , filename : str | PathLike ) -> bool :
146+ # Added to handle strange .znc files with no time and huge range
147+ # dimension resulting in large memory usage (e.g. Jülich 2019-05-18).
148+ with netCDF4 .Dataset (filename ) as nc :
149+ return (
150+ nc [self .concat_dimension ].size > 0 and nc [self .interp_dim ].size < 10_000
151+ )
152+
142153 def create_global_attributes (self , new_attributes : dict | None ) -> None :
143154 """Copies global attributes from one of the source files."""
144155 _copy_attributes (self .first_file , self .concatenated_file )
You can’t perform that action at this time.
0 commit comments