Skip to content

Commit

Permalink
fixed index search for new PGC files
Browse files Browse the repository at this point in the history
  • Loading branch information
trchudley committed Jul 22, 2024
1 parent 0e6749a commit 788e53c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/pdemtools/_index_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,25 @@ def search(
gdf["year"] = gdf.time_mean.dt.year
gdf["month"] = gdf.time_mean.dt.month

# Filter according to date (acqdate)
# Filter according to date (acqdate)
if dates != None:
if dates[0] != None:
datetime1 = pd.to_datetime(dates[0])
gdf = gdf[gdf["time1"] > datetime1]
try:
gdf = gdf[gdf["time1"] > datetime1]
except: # account for UTC-aware datetime storage in newer PGC index files.
datetime1 = pd.to_datetime(dates[0], utc=True)
gdf = gdf[gdf["time1"] > datetime1]

if dates[1] != None:
datetime2 = pd.to_datetime(dates[1])
gdf = gdf[gdf["time2"] < datetime2]
try:
gdf = gdf[gdf["time2"] < datetime2]
except: # account for UTC-aware datetime storage in newer PGC index files.
datetime2 = pd.to_datetime(dates[1], utc=True)
gdf = gdf[gdf["time2"] < datetime2]
# can probably make this more efficient than just try-except - e.g. check if
# date column is utc-aware and if so, make datetime utc-aware too.

# Filter to months
if months != None:
Expand Down

0 comments on commit 788e53c

Please sign in to comment.