TNO Intern

Commit b7bad691 authored by Arjo Segers's avatar Arjo Segers
Browse files

Support defined creation mode for listing files. Explicitly set units of...

Support defined creation mode for listing files. Explicitly set units of ouptut time variable to `seconds since ...` to ensure correct parsing by ncdump and other tools.
parent 1d6a48ad
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -62,6 +62,9 @@
#
# 2025-02, Arjo Segers
#   Fixed type conversion of "dmode" setting.
#   Ensure that "dmode" is used when creating listing file.
#   Explicitly set units of ouptut time variable to `seconds since ...`
#   to ensure correct parsing by ncdump and other tools.
#


@@ -690,7 +693,7 @@ class CSO_S5p_File(cso_file.CSO_File):

    def AddSelection(self, sfile, selected, rcf, rcbase, indent=""):
        """
        Add selected OMI to satellite extract file.
        Add selected S5p pixels to satellite extract file.

        Arguments:

@@ -1387,8 +1390,8 @@ class CSO_S5p_File(cso_file.CSO_File):
                    values = tref + dts
                # endif

                ## base time for units "seconds since ..." as start of year:
                # tref = pandas.Timestamp( year=values[0].year, month=1, day=1, tz=0 )
                # base time for units "seconds since ..." as start of year:
                t0 = pandas.to_datetime( tref ).to_pydatetime()

                # create variable:
                da = xarray.DataArray(values, dims=vdims, coords={"pixel": pixel}, attrs=oda.attrs)
@@ -1396,6 +1399,7 @@ class CSO_S5p_File(cso_file.CSO_File):
                da.attrs["standard_name"] = "time"
                da.attrs["long_name"] = "time"
                da.encoding["calendar"] = "standard"
                da.encoding["units"] = f"seconds since {t0.year}-01-01 00:00:000"

            # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            # pixel corners: for longitudes, need to ensure that also near dateline
@@ -2880,11 +2884,7 @@ class CSO_S5p_Convert(utopya.UtopyaRc):
            # endif

            # output dir:
            dname = os.path.dirname(output_filename)
            if len(dname) > 0:
                if not os.path.isdir(dname):
                    os.makedirs(dname)
            # endif
            cso_file.CheckDir( output_filename, dmode=dmode )

            # split filename at extension:
            fname, ext = os.path.splitext(output_filename)
@@ -3829,7 +3829,7 @@ class CSO_S5p_Download_Listing(utopya.UtopyaRc):
            logging.info(f"{indent}  base directory: %s ..." % bdir)

            # initiallize for (re)creation:
            listing = cso_file.CSO_Listing(lst_file, indent=f"{indent}    ")
            listing = cso_file.CSO_Listing(indent=f"{indent}    ")

            # info ...
            logging.info(f"{indent}  cleanup records if necessary ...")
@@ -3957,7 +3957,7 @@ class CSO_S5p_Download_Listing(utopya.UtopyaRc):
            # endwhile

            # save:
            listing.Close(indent=f"{indent}  ")
            listing.Save(lst_file, dmode=dmode, indent=f"{indent}  ")

        else:
            # info ..