Loading py/cso_gridded.py +42 −38 Original line number Diff line number Diff line Loading @@ -30,6 +30,9 @@ # 2024-01, Arjo Segers # Check if source files are actually present when creating gridded averages. # # 2024-08, Arjo Segers # Updated message on missing source file. # ######################################################################## Loading Loading @@ -246,9 +249,9 @@ class CSO_GriddedAverage(utopya.UtopyaRc): utopya.UtopyaRc.__init__(self, rcfile, rcbase=rcbase, env=env) # info ... logging.info(indent + "") logging.info(indent + "** Gridded CSO data") logging.info(indent + "") logging.info(f"{indent}") logging.info(f"{indent}** Gridded CSO data") logging.info(f"{indent}") # time range: t1 = self.GetSetting("timerange.start", totype="datetime") Loading @@ -257,7 +260,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # info ... tfmt = "%Y-%m-%d %H:%M" logging.info( indent + "timerange: [%s,%s] by %s" % (t1.strftime(tfmt), t2.strftime(tfmt), tstep) f"{indent}timerange: [%s,%s] by %s" % (t1.strftime(tfmt), t2.strftime(tfmt), tstep) ) # renew? Loading @@ -281,12 +284,12 @@ class CSO_GriddedAverage(utopya.UtopyaRc): nlon = int(numpy.round((east - west) / dlon)) nlat = int(numpy.round((north - south) / dlat)) # info ... logging.info(indent + "define regular grid ...") logging.info(f"{indent}define regular grid ...") logging.info( indent + " domain : [%7.2f,%7.2f] x [%7.2f,%7.2f]" % (west, east, south, north) f"{indent} domain : [%7.2f,%7.2f] x [%7.2f,%7.2f]" % (west, east, south, north) ) logging.info(indent + " resolution : %5.2f x %5.2f" % (dlon, dlat)) logging.info(indent + " resolution : %5i x %5i" % (nlon, nlat)) logging.info(f"{indent} resolution : %5.2f x %5.2f" % (dlon, dlat)) logging.info(f"{indent} resolution : %5i x %5i" % (nlon, nlat)) # centers: da_lons = xarray.DataArray( Loading @@ -304,7 +307,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): grid_coords = {"longitude": da_lons, "latitude": da_lats} # info ... logging.info(indent + "compute cell_area ...") logging.info(f"{indent}compute cell_area ...") # corners of first column: # 3 o---o 2 # | | Loading Loading @@ -402,12 +405,12 @@ class CSO_GriddedAverage(utopya.UtopyaRc): dt = None # info .. logging.info(indent + "time loop ...") logging.info(f"{indent}time loop ...") # time loop: t = t1 while t < t2: # info .. logging.info(indent + " %s ..." % t.strftime("%Y-%m-%d %H:%M")) logging.info(f"{indent} %s ..." % t.strftime("%Y-%m-%d %H:%M")) # not first? if dt is not None: Loading Loading @@ -474,7 +477,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # renew? if (not os.path.isfile(outfile)) or renew: # info ... logging.info(indent + " create %s ..." % outfile) logging.info(f"{indent} create %s ..." % outfile) # init storage for output arrays: das_out = {} Loading @@ -489,7 +492,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # new file? if listing_curr != listing_latest: # read listing: listing = cso_file.CSO_Listing(listing_curr, indent=indent + " ") listing = cso_file.CSO_Listing(listing_curr, indent=f"{indent} ") # store name: listing_latest = listing_curr # endif Loading @@ -499,7 +502,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # empty? then leave: if len(xdf) == 0: # info .. logging.info(indent + " no source file(s) found for this time ...") logging.info(f"{indent} no source file(s) found for this time ...") # next time step: continue # endif Loading @@ -510,7 +513,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): datafiles.append(os.path.join(listing.dirname, fname)) # endfor # info .. logging.info(indent + " found %i file(s) in listing .." % (len(datafiles))) logging.info(f"{indent} found %i file(s) in listing .." % (len(datafiles))) else: # filename pattern specified Loading @@ -530,7 +533,8 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # empty? then leave: if len(datafiles) == 0: # info .. logging.info(indent + " no source file(s) found for this time ...") logging.info(f"{indent} no source file(s) found for time {t} matching:") logging.info(f"{indent} {infile_curr}") # next time step: continue # endif Loading @@ -550,7 +554,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): for datafile in datafiles: # info ... logging.info(indent + " read input file: %s" % datafile) logging.info(f"{indent} read input file: %s" % datafile) # check .. if datafile in processed_files: Loading Loading @@ -578,17 +582,17 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # filter: selected, history = sources[stype0]["file"].SelectPixels( self.rcf, rcbase, indent=indent + " " self.rcf, rcbase, indent=f"{indent} " ) # info .. logging.info( indent + " selected %i / %i pixels .." % (selected.sum(), selected.size) f"{indent} selected %i / %i pixels .." % (selected.sum(), selected.size) ) # selected indices: (iipix,) = numpy.where(selected) # info ... logging.info(indent + " distribute points over footprints ...") logging.info(f"{indent} distribute points over footprints ...") # center points or footprings? if mapping_levels == 0: # centers, just copy: Loading Loading @@ -677,7 +681,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # endfor # output variables # info ... logging.info(indent + " average %i pixels over grid cells ..." % len(iipix)) logging.info(f"{indent} average %i pixels over grid cells ..." % len(iipix)) # group per target grid cell, sum over weights: df2 = df.groupby(["jj", "ii"]).sum() Loading Loading @@ -847,11 +851,11 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # endfor # time loop # info ... logging.info(indent + "") logging.info(indent + "processed %i files" % len(processed_files)) logging.info(indent + "") logging.info(indent + "** end") logging.info(indent + "") logging.info(f"{indent}") logging.info(f"{indent}processed %i files" % len(processed_files)) logging.info(f"{indent}") logging.info(f"{indent}** end") logging.info(f"{indent}") # enddef __init__ Loading Loading @@ -958,16 +962,16 @@ class CSO_GriddedAverageMeans(utopya.UtopyaRc): utopya.UtopyaRc.__init__(self, rcfile, rcbase=rcbase, env=env) # info ... logging.info(indent + "") logging.info(indent + "** Temperoal means over gridded CSO data") logging.info(indent + "") logging.info(f"{indent}") logging.info(f"{indent}** Temperoal means over gridded CSO data") logging.info(f"{indent}") # time range: t1 = self.GetSetting("timerange.start", totype="datetime") t2 = self.GetSetting("timerange.end", totype="datetime") # info ... tfmt = "%Y-%m-%d %H:%M" logging.info(indent + "timerange: [%s,%s]" % (t1.strftime(tfmt), t2.strftime(tfmt))) logging.info(f"{indent}timerange: [%s,%s]" % (t1.strftime(tfmt), t2.strftime(tfmt))) # time units to be used: tunits = "seconds since %s" % t1.strftime("%Y-01-01 00:00:00") Loading Loading @@ -1009,11 +1013,11 @@ class CSO_GriddedAverageMeans(utopya.UtopyaRc): output_file = self.GetSetting("resolution.%s.output.file" % resolution) # info .. logging.info(indent + "time loop ...") logging.info(f"{indent}time loop ...") # loop: for t in tt: # info .. logging.info(indent + " %s .." % t.strftime(tfmt)) logging.info(f"{indent} %s .." % t.strftime(tfmt)) # target file: outfile = t.strftime(output_file) Loading @@ -1021,7 +1025,7 @@ class CSO_GriddedAverageMeans(utopya.UtopyaRc): if (not os.path.isfile(outfile)) or renew: # info ... logging.info(indent + " create %s ..." % outfile) logging.info(f"{indent} create %s ..." % outfile) # search pattern for input files: fpattern = t.strftime(input_files) Loading @@ -1029,8 +1033,8 @@ class CSO_GriddedAverageMeans(utopya.UtopyaRc): fnames = glob.glob(fpattern) # check ... if len(fnames) == 0: logging.warning(indent + "no files found matching input pattern:") logging.warning(indent + " " + fpattern) logging.warning(f"{indent}no files found matching input pattern:") logging.warning(f"{indent} " + fpattern) continue # endif # open input: Loading Loading @@ -1179,9 +1183,9 @@ class CSO_GriddedAverageMeans(utopya.UtopyaRc): # endfor # resolution # info ... logging.info(indent + "") logging.info(indent + "** end") logging.info(indent + "") logging.info(f"{indent}") logging.info(f"{indent}** end") logging.info(f"{indent}") # enddef __init__ Loading Loading
py/cso_gridded.py +42 −38 Original line number Diff line number Diff line Loading @@ -30,6 +30,9 @@ # 2024-01, Arjo Segers # Check if source files are actually present when creating gridded averages. # # 2024-08, Arjo Segers # Updated message on missing source file. # ######################################################################## Loading Loading @@ -246,9 +249,9 @@ class CSO_GriddedAverage(utopya.UtopyaRc): utopya.UtopyaRc.__init__(self, rcfile, rcbase=rcbase, env=env) # info ... logging.info(indent + "") logging.info(indent + "** Gridded CSO data") logging.info(indent + "") logging.info(f"{indent}") logging.info(f"{indent}** Gridded CSO data") logging.info(f"{indent}") # time range: t1 = self.GetSetting("timerange.start", totype="datetime") Loading @@ -257,7 +260,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # info ... tfmt = "%Y-%m-%d %H:%M" logging.info( indent + "timerange: [%s,%s] by %s" % (t1.strftime(tfmt), t2.strftime(tfmt), tstep) f"{indent}timerange: [%s,%s] by %s" % (t1.strftime(tfmt), t2.strftime(tfmt), tstep) ) # renew? Loading @@ -281,12 +284,12 @@ class CSO_GriddedAverage(utopya.UtopyaRc): nlon = int(numpy.round((east - west) / dlon)) nlat = int(numpy.round((north - south) / dlat)) # info ... logging.info(indent + "define regular grid ...") logging.info(f"{indent}define regular grid ...") logging.info( indent + " domain : [%7.2f,%7.2f] x [%7.2f,%7.2f]" % (west, east, south, north) f"{indent} domain : [%7.2f,%7.2f] x [%7.2f,%7.2f]" % (west, east, south, north) ) logging.info(indent + " resolution : %5.2f x %5.2f" % (dlon, dlat)) logging.info(indent + " resolution : %5i x %5i" % (nlon, nlat)) logging.info(f"{indent} resolution : %5.2f x %5.2f" % (dlon, dlat)) logging.info(f"{indent} resolution : %5i x %5i" % (nlon, nlat)) # centers: da_lons = xarray.DataArray( Loading @@ -304,7 +307,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): grid_coords = {"longitude": da_lons, "latitude": da_lats} # info ... logging.info(indent + "compute cell_area ...") logging.info(f"{indent}compute cell_area ...") # corners of first column: # 3 o---o 2 # | | Loading Loading @@ -402,12 +405,12 @@ class CSO_GriddedAverage(utopya.UtopyaRc): dt = None # info .. logging.info(indent + "time loop ...") logging.info(f"{indent}time loop ...") # time loop: t = t1 while t < t2: # info .. logging.info(indent + " %s ..." % t.strftime("%Y-%m-%d %H:%M")) logging.info(f"{indent} %s ..." % t.strftime("%Y-%m-%d %H:%M")) # not first? if dt is not None: Loading Loading @@ -474,7 +477,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # renew? if (not os.path.isfile(outfile)) or renew: # info ... logging.info(indent + " create %s ..." % outfile) logging.info(f"{indent} create %s ..." % outfile) # init storage for output arrays: das_out = {} Loading @@ -489,7 +492,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # new file? if listing_curr != listing_latest: # read listing: listing = cso_file.CSO_Listing(listing_curr, indent=indent + " ") listing = cso_file.CSO_Listing(listing_curr, indent=f"{indent} ") # store name: listing_latest = listing_curr # endif Loading @@ -499,7 +502,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # empty? then leave: if len(xdf) == 0: # info .. logging.info(indent + " no source file(s) found for this time ...") logging.info(f"{indent} no source file(s) found for this time ...") # next time step: continue # endif Loading @@ -510,7 +513,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): datafiles.append(os.path.join(listing.dirname, fname)) # endfor # info .. logging.info(indent + " found %i file(s) in listing .." % (len(datafiles))) logging.info(f"{indent} found %i file(s) in listing .." % (len(datafiles))) else: # filename pattern specified Loading @@ -530,7 +533,8 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # empty? then leave: if len(datafiles) == 0: # info .. logging.info(indent + " no source file(s) found for this time ...") logging.info(f"{indent} no source file(s) found for time {t} matching:") logging.info(f"{indent} {infile_curr}") # next time step: continue # endif Loading @@ -550,7 +554,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): for datafile in datafiles: # info ... logging.info(indent + " read input file: %s" % datafile) logging.info(f"{indent} read input file: %s" % datafile) # check .. if datafile in processed_files: Loading Loading @@ -578,17 +582,17 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # filter: selected, history = sources[stype0]["file"].SelectPixels( self.rcf, rcbase, indent=indent + " " self.rcf, rcbase, indent=f"{indent} " ) # info .. logging.info( indent + " selected %i / %i pixels .." % (selected.sum(), selected.size) f"{indent} selected %i / %i pixels .." % (selected.sum(), selected.size) ) # selected indices: (iipix,) = numpy.where(selected) # info ... logging.info(indent + " distribute points over footprints ...") logging.info(f"{indent} distribute points over footprints ...") # center points or footprings? if mapping_levels == 0: # centers, just copy: Loading Loading @@ -677,7 +681,7 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # endfor # output variables # info ... logging.info(indent + " average %i pixels over grid cells ..." % len(iipix)) logging.info(f"{indent} average %i pixels over grid cells ..." % len(iipix)) # group per target grid cell, sum over weights: df2 = df.groupby(["jj", "ii"]).sum() Loading Loading @@ -847,11 +851,11 @@ class CSO_GriddedAverage(utopya.UtopyaRc): # endfor # time loop # info ... logging.info(indent + "") logging.info(indent + "processed %i files" % len(processed_files)) logging.info(indent + "") logging.info(indent + "** end") logging.info(indent + "") logging.info(f"{indent}") logging.info(f"{indent}processed %i files" % len(processed_files)) logging.info(f"{indent}") logging.info(f"{indent}** end") logging.info(f"{indent}") # enddef __init__ Loading Loading @@ -958,16 +962,16 @@ class CSO_GriddedAverageMeans(utopya.UtopyaRc): utopya.UtopyaRc.__init__(self, rcfile, rcbase=rcbase, env=env) # info ... logging.info(indent + "") logging.info(indent + "** Temperoal means over gridded CSO data") logging.info(indent + "") logging.info(f"{indent}") logging.info(f"{indent}** Temperoal means over gridded CSO data") logging.info(f"{indent}") # time range: t1 = self.GetSetting("timerange.start", totype="datetime") t2 = self.GetSetting("timerange.end", totype="datetime") # info ... tfmt = "%Y-%m-%d %H:%M" logging.info(indent + "timerange: [%s,%s]" % (t1.strftime(tfmt), t2.strftime(tfmt))) logging.info(f"{indent}timerange: [%s,%s]" % (t1.strftime(tfmt), t2.strftime(tfmt))) # time units to be used: tunits = "seconds since %s" % t1.strftime("%Y-01-01 00:00:00") Loading Loading @@ -1009,11 +1013,11 @@ class CSO_GriddedAverageMeans(utopya.UtopyaRc): output_file = self.GetSetting("resolution.%s.output.file" % resolution) # info .. logging.info(indent + "time loop ...") logging.info(f"{indent}time loop ...") # loop: for t in tt: # info .. logging.info(indent + " %s .." % t.strftime(tfmt)) logging.info(f"{indent} %s .." % t.strftime(tfmt)) # target file: outfile = t.strftime(output_file) Loading @@ -1021,7 +1025,7 @@ class CSO_GriddedAverageMeans(utopya.UtopyaRc): if (not os.path.isfile(outfile)) or renew: # info ... logging.info(indent + " create %s ..." % outfile) logging.info(f"{indent} create %s ..." % outfile) # search pattern for input files: fpattern = t.strftime(input_files) Loading @@ -1029,8 +1033,8 @@ class CSO_GriddedAverageMeans(utopya.UtopyaRc): fnames = glob.glob(fpattern) # check ... if len(fnames) == 0: logging.warning(indent + "no files found matching input pattern:") logging.warning(indent + " " + fpattern) logging.warning(f"{indent}no files found matching input pattern:") logging.warning(f"{indent} " + fpattern) continue # endif # open input: Loading Loading @@ -1179,9 +1183,9 @@ class CSO_GriddedAverageMeans(utopya.UtopyaRc): # endfor # resolution # info ... logging.info(indent + "") logging.info(indent + "** end") logging.info(indent + "") logging.info(f"{indent}") logging.info(f"{indent}** end") logging.info(f"{indent}") # enddef __init__ Loading