Loading py/cso_file.py +40 −19 Original line number Diff line number Diff line Loading @@ -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(). # ######################################################################## ### Loading Loading @@ -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: Loading @@ -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 Loading Loading
py/cso_file.py +40 −19 Original line number Diff line number Diff line Loading @@ -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(). # ######################################################################## ### Loading Loading @@ -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: Loading @@ -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 Loading