@@ -53,10 +53,16 @@ def _fix_coordinates(cube: iris.cube.Cube, definition):
5353 time = coord .units .num2date (coord .points [0 ])
5454 # set time bounds to (year-01-01 00:00, year+1-01-01 00:00)
5555 start_date = datetime .datetime (
56- time .year , 1 , 1 , tzinfo = datetime .UTC
56+ time .year ,
57+ 1 ,
58+ 1 ,
59+ tzinfo = datetime .UTC ,
5760 )
5861 end_date = datetime .datetime (
59- time .year + 1 , 1 , 1 , tzinfo = datetime .UTC
62+ time .year + 1 ,
63+ 1 ,
64+ 1 ,
65+ tzinfo = datetime .UTC ,
6066 )
6167 if coord .bounds is not None :
6268 coord .bounds = None
@@ -95,7 +101,7 @@ def _regrid_infile(infile, outfile, weightsfile):
95101
96102 weightsfile_ok = False
97103
98- if os . path . isfile (weightsfile ):
104+ if Path (weightsfile ). exists ( ):
99105 weights = Dataset (weightsfile , "r" )
100106 # make sure dimensions of source and target grids match
101107 # expected values
@@ -122,8 +128,7 @@ def _regrid_infile(infile, outfile, weightsfile):
122128 )
123129 # check if path for weight files exists, if not create folder
124130 path = os .path .split (weightsfile )[0 ]
125- if not os .path .exists (path ):
126- os .makedirs (path )
131+ Path (path ).mkdir (parents = True , exist_ok = True )
127132 # generate weights
128133 cdo .genbil (
129134 f"{ target_grid } " ,
@@ -170,9 +175,9 @@ def _extract_variable(in_file, var, cfg, out_dir, year):
170175 # load input file (make sure only the variables specified in the config file
171176 # as "raw" are loaded)
172177 if type (var ["raw" ]) is list :
173- constraints = []
174- for rawname in var ["raw" ]:
175- constraints . append ( NameConstraint ( var_name = rawname ))
178+ constraints = [
179+ NameConstraint ( var_name = rawname ) for rawname in var ["raw" ]
180+ ]
176181 else :
177182 constraints = NameConstraint (var_name = var ["raw" ])
178183
@@ -290,7 +295,7 @@ def _extract_variable(in_file, var, cfg, out_dir, year):
290295 attributes ,
291296 unlimited_dimensions = ["time" ],
292297 )
293- os . remove (regridded_file ) # delete temporary file
298+ Path (regridded_file ). unlink ( ) # delete temporary file
294299 logger .info ("Finished CMORizing %s" , in_file )
295300
296301
0 commit comments