TNO Intern

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

Updated ItemSearch following deprication warning.

parent 450dff0b
Loading
Loading
Loading
Loading
+18 −15
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@
#   Added 'CSO_PAL_Downloader' class.
#   Updated catalogue url in description.
#
# 2024-09, Arjo Segers
#   Updated ItemSearch following deprication warning.
#

########################################################################
###
@@ -137,9 +140,9 @@ class CSO_PAL_Inquire(utopya.UtopyaRc):
        import pandas

        # info ...
        logging.info(indent + "")
        logging.info(indent + "** Inquire files available on PAL")
        logging.info(indent + "")
        logging.info(f"{indent}")
        logging.info(f"{indent}** Inquire files available on PAL")
        logging.info(f"{indent}")

        # init base object:
        utopya.UtopyaRc.__init__(self, rcfile=rcfile, rcbase=rcbase, env=env)
@@ -147,20 +150,20 @@ class CSO_PAL_Inquire(utopya.UtopyaRc):
        # domain:
        url = self.GetSetting("url")
        # info ...
        logging.info(indent + "url          : %s" % url)
        logging.info(f"{indent}url          : %s" % url)

        # 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)))

        # product type (always 10 characters!):
        #    L2__NO2___
        producttype = self.GetSetting("producttype")
        # filter for ItemSearch:
        sfilter = "s5p:file_type='%s'" % producttype
        sfilter = f"s5p:file_type='{producttype}'"

        # area of interest: west,south:east,north
        area = self.GetSetting("area")
@@ -183,7 +186,7 @@ class CSO_PAL_Inquire(utopya.UtopyaRc):
            }
        else:
            # info ...
            logging.info(indent + "area         : no")
            logging.info(f"{indent}area         : no")
            # no intersection:
            intersects = None
        # endif
@@ -197,7 +200,7 @@ class CSO_PAL_Inquire(utopya.UtopyaRc):
        output_df = pandas.DataFrame()

        # info ...
        logging.info(indent + "search all items in timerange ...")
        logging.info(f"{indent}search all items in timerange ...")

        # loop over months to follow progress ..
        xt2 = t1
@@ -210,7 +213,7 @@ class CSO_PAL_Inquire(utopya.UtopyaRc):
            # limit:
            xt2 = min(xt2, t2)
            # info ..
            logging.info(indent + "  %s .." % xt1.strftime("%Y-%m"))
            logging.info(f"{indent}  %s .." % xt1.strftime("%Y-%m"))

            # collection:
            collection = pystac.Collection.from_file(url)
@@ -219,9 +222,9 @@ class CSO_PAL_Inquire(utopya.UtopyaRc):
            # search:
            item_collection = pystac_client.ItemSearch(
                endpoint_url, datetime=(xt1, xt2), intersects=intersects, filter=sfilter
            ).get_all_items()
            ).item_collection()
            # info ..
            logging.info(indent + "    found %i items" % len(item_collection))
            logging.info(f"{indent}    found {len(item_collection)} items")

            # testing ..
            for item in item_collection:
@@ -277,7 +280,7 @@ class CSO_PAL_Inquire(utopya.UtopyaRc):
        # endwhile  # months

        # info ..
        logging.info("save to: %s ..." % output_file)
        logging.info(f"save to: {output_file} ...")
        # create directory:
        dirname = os.path.dirname(output_file)
        if len(dirname) > 0:
@@ -288,9 +291,9 @@ class CSO_PAL_Inquire(utopya.UtopyaRc):
        output_df.to_csv(output_file, sep=";", index=False)

        # info ...
        logging.info(indent + "")
        logging.info(indent + "** end inquire")
        logging.info(indent + "")
        logging.info(f"{indent}")
        logging.info(f"{indent}** end inquire")
        logging.info(f"{indent}")

    # enddef __init__