Skip to main content

Chagne filename of downloaded planet data into aquisition date

  • 26 April 2024
  • 0 replies
  • 0 views

I have downloaded some planet data using the Example-8-:-Multiple-timestamps-data script (link) and that works fine. However, as I plan to download the last 7 days of images, every week, it would be useful to know what date the image was taken.


There is a simlar question here however it uses WmsRequest() and with that solution I am able to open the url in the json that the function (see below) looks at, however the json file that I have does not contain a date aspect in the url. It contains a timestamp, but that is when I created it, not when the image was taken.
image


How can I adjust this script to change the filename to the acquisition date (or a similar script)?


import pandas as pd
import glob
import json
import datetime as dt
from urllib.parse import unquote

def get_request_dt(request_file):
with open(request_file, 'r') as req:
request = json.load(req)
url = unquote(request['url'])
time_parameter = [t for t in url.split('&') if t.startswith('TIME=')][0]
time = time_parameter.split('TIME=')[1].split('/')[0]
return dt.datetime.strptime(time, "%Y-%m-%dT%H:%M:%S")

if __name__ == "__main__":
folders = glob.glob('./data/*')
dates = [get_request_dt(f'{folder}/request.json') for folder in folders]
df = pd.DataFrame(zip(folders, dates), columns=['folder', 'datetime'])
df.sort_values(by='datetime', ascending=True, inplace=True)
print(df.head().to_markdown())

0 replies

Be the first to reply!

Reply