TNO Intern

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

Added `method` argument to listing file selection.

parent afd64eb8
Loading
Loading
Loading
Loading
+40 −19
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@
# 2022-09, Arjo Segers, Met-Norway
#   Fixed computation of packing parameters for array with constant value.
#
# 2023-08, Arjo Segers
#   Added "method" argument to CSO_Listing.Select().
#

########################################################################
###
@@ -1328,14 +1331,19 @@ class CSO_Listing( object ) :
    
    # *

    def Select( self, tr=None ) :
    def Select(self, tr=None, method="overlap"):

        """
        Return dataframe with selected records.

        Optional arguments:

        * ``tr=(t1,t2)`` : select records that overlap with this timerange.
        * ``tr=(t1,t2)`` : select records that could be assigned to this timerange;
          requires the ``method`` keyword:
          
          * ``method='overlap'`` (default) : select records that have pixels overlapping with interval
          * ``method='middle'`` : select pixels with the middle of ``start_time`` and ``end_time``
            within the inerval ``(t1,t2]``
        """

        # modules:
@@ -1348,8 +1356,21 @@ class CSO_Listing( object ) :
        if tr is not None:
            # convert if needed:
            t1, t2 = pandas.Timestamp(tr[0]), pandas.Timestamp(tr[1])
            # switch:
            if method == "overlap":
                # select:
                df = df[(df["start_time"] <= t2) & (df["end_time"] >= t1)]
            #
            elif method == "middle":
                # mid times:
                mid_time = df["start_time"] + (df["end_time"] - df["start_time"]) / 2
                # select:
            df = df[ (df['start_time'] <= t2) & (df['end_time'] >= t1) ]
                df = df[(mid_time > t1) & (mid_time <= t2)]
            #
            else:
                logging.error('unsupported method "%s" with argument ``tr``' % method)
                raise Exception
            # endif
        # endif

        # ok