-
Notifications
You must be signed in to change notification settings - Fork 0
/
blacksky_metadata_archiver.py
108 lines (95 loc) · 7.05 KB
/
blacksky_metadata_archiver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os
import shutil
from tkinter import filedialog as fd
import tkinter as tk
import json
import csv
# Get rid of tkinter root window
root = tk.Tk()
root.withdraw()
# Ask which folder needs to be processed
directoryname = fd.askdirectory()
os.chdir(directoryname)
print('')
with open('metadata.csv', 'w', newline='') as metaFile:
writer = csv.writer(metaFile)
writer.writerow(['Image ID', 'Acquisition Date/Time', 'Region', 'Site', 'Tasked By', 'Product Type', 'Sensor Name', 'Sensor Angle', 'Integration Time', 'Reported Saturation Percentage'])
with os.scandir(os.getcwd()) as directory:
for file in directory:
if file.is_dir():
os.chdir(file) # Enter year folder
with os.scandir(os.getcwd()) as directory2:
for file2 in directory2:
if file2.is_dir():
os.chdir(file2) # Enter date folder
with os.scandir(os.getcwd()) as directory3:
for file3 in directory3:
# Area Coverage images
if file3.name.endswith('AREA'):
print('Area coverage: ' + os.getcwd())
os.chdir(file3) # Enter Area Coverage folder
os.chdir('Anthro') # Enter Anthro folder
with os.scandir(os.getcwd()) as directory4:
for file4 in directory4:
if file4.name.endswith('.json') and file4.name.startswith('BSG'):
with open(file4) as f:
data = f.read()
parsed_json = json.loads(data)
id = parsed_json['id'][29:38]
acquisitionDate = parsed_json['acquisitionDate'][0:10]+' '+parsed_json['acquisitionDate'][11:19]+' UTC'
region = ''
site = ''
taskedBy = ''
productType = 'Area Coverage'
sensorName = parsed_json['sensorName']
offNadirAngle = ''
integrationTime = ''
fractionSaturated = str(parsed_json['fractionSaturated'])
writer.writerow([id, acquisitionDate, region, site, taskedBy, productType, sensorName, offNadirAngle, integrationTime, fractionSaturated])
print('Image ID: ' + id)
print('Acquisition Date/Time: ' + acquisitionDate)
print('Product Type: ' + productType)
print('Sensor Name: ' + sensorName)
print('Sensor Angle: ' + offNadirAngle)
print('Integration Time: ' + integrationTime)
print('Reported Saturation Percentage: ' + fractionSaturated)
print('')
os.chdir('../..')
# Either Standard or Frame images
if file3.is_dir and not file3.name.endswith('AREA') and not file3.name.endswith('Store') and not file3.name.startswith('.'):
print('Standard or frame: ' + os.getcwd())
os.chdir(file3) # Enter standard or frame folder
os.chdir('Anthro') # Enter Anthro folder
with os.scandir(os.getcwd()) as directory4:
for file4 in directory4:
if file4.name.endswith('.json') and file4.name.startswith('BSG'):
with open(file4) as f:
data = f.read()
parsed_json = json.loads(data)
id = parsed_json['id'][24:33]
acquisitionDate = parsed_json['acquisitionDate'][0:10]+' '+parsed_json['acquisitionDate'][11:19]+' UTC'
region = ''
site = ''
taskedBy = ''
if 'multiImage' in parsed_json:
productType = 'Frame'
else:
productType = 'Standard'
sensorName = parsed_json['sensorName']
offNadirAngle = str(parsed_json['offNadirAngle'])
if 'integrationTime' in parsed_json:
integrationTime = str(parsed_json['integrationTime'])
else:
integrationTime = ''
fractionSaturated = str(parsed_json['fractionSaturated'])
writer.writerow([id, acquisitionDate, region, site, taskedBy, productType, sensorName, offNadirAngle, integrationTime, fractionSaturated])
print('Image ID: ' + id)
print('Acquisition Date/Time: ' + acquisitionDate)
print('Product Type: ' + productType)
print('Sensor Name: ' + sensorName)
print('Sensor Angle: ' + offNadirAngle)
print('Integration Time: ' + integrationTime)
print('Reported Saturation Percentage: ' + fractionSaturated)
print('')
os.chdir('../..')
os.chdir('..')