Skip to content

Commit

Permalink
Add acquisition date to subsetted granules
Browse files Browse the repository at this point in the history
  • Loading branch information
leonelluiscorado committed Mar 7, 2024
1 parent 6ad64a7 commit 0c708ac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pipeline/subsetter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import warnings
warnings.filterwarnings("ignore")

from utils.utils import get_date_from_gedi_fn

# Default layers to be subset and exported, see README for information on how to add additional layers
l1b_subset = ['/geolocation/latitude_bin0', '/geolocation/longitude_bin0', '/channel', '/shot_number',
'/rxwaveform','/rx_sample_count', '/stale_return_flag', '/tx_sample_count', '/txwaveform',
Expand Down Expand Up @@ -306,6 +308,9 @@ def subset(self, granule):
out_df = out_df.dropna(subset=['geometry'])
out_df = out_df[out_df['geometry'].is_valid]
out_df = out_df[~out_df['geometry'].is_empty]

# Write date column to subsetted file
out_df['date'] = get_date_from_gedi_fn(granule_name)

## TODO: Implement the saving to file module as optional
try:
Expand Down
Empty file added utils/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions utils/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from datetime import datetime

def get_date_from_gedi_fn(granule_name):
"""
Transforms Julian Date present in the GEDI Filenames by default into
a date string with format YYYY/mm/dd (e.g. 2024/03/06)
Args -
granule_name: str
Returns -
date_sec (date_section) str in format YYYY/mm/dd
"""
filename = granule_name.split("/")[-1]
julian_date = filename.split("_")[2][0:7]
date_sec = datetime.strptime(julian_date, "%Y%j").date()
date_sec = date_sec.strftime("%Y/%m/%d")
return date_sec

0 comments on commit 0c708ac

Please sign in to comment.