-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_report.py
More file actions
549 lines (452 loc) · 22.8 KB
/
create_report.py
File metadata and controls
549 lines (452 loc) · 22.8 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# python3.6 create_report.py orderName
# can you filter on how much image overlaps polygon?
# add line from csv to every line that is generated from create_report
# more data in ndvi/ecarr images
import os
import sys
import re
import pandas as pd
import json
import rasterio
import numpy as np
from xml.dom import minidom
import matplotlib.pyplot as plt
import matplotlib.colors as colors
#Import gdal
from osgeo import gdal
"""
The reflectance values will range from 0 to 1. You want to use a diverging color scheme to visualize the data,
and you want to center the colorbar at a defined midpoint. The class below allows you to normalize the colorbar.
"""
class MidpointNormalize(colors.Normalize):
"""
Normalise the colorbar so that diverging bars work there way either side from a prescribed midpoint value)
e.g. im=ax1.imshow(array, norm=MidpointNormalize(midpoint=0.,vmin=-100, vmax=100))
Credit: Joe Kington, http://chris35wills.github.io/matplotlib_diverging_colorbar/
"""
def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False):
self.midpoint = midpoint
colors.Normalize.__init__(self, vmin, vmax, clip)
def __call__(self, value, clip=None):
# I'm ignoring masked values and all kinds of edge cases to make a
# simple example...
x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1]
return np.ma.masked_array(np.interp(value, x, y), np.isnan(value))
# FRom: https://github.com/kscottz/PythonFromSpace/blob/master/TheBasics.ipynb
def load_image4(filename):
"""Return a 4D (r, g, b, nir) numpy array with the data in the specified TIFF filename."""
path = os.path.abspath(os.path.join('./', filename))
if os.path.exists(path):
with rasterio.open(path) as src:
b, g, r, nir = src.read()
return np.dstack([r, g, b, nir])
def load_image4_to_RGB(filename):
path = os.path.abspath(os.path.join('./', filename))
if os.path.exists(path):
with rasterio.open(path) as src:
b, g, r, nir = src.read()
img_4band = np.dstack([r, g, b, nir])
img_3band = img_4band[:,:,:3]
# Write an array as a raster band to a new 8-bit file. For
# the new file's profile, we start with the profile of the source
profile = src.profile
# And then change the band count to 1, set the
# dtype to uint8, and specify LZW compression.
profile.update(
dtype=rasterio.uint16,
count=3,
compress='lzw')
with rasterio.open(f"{filename}_example.tif", 'w', **profile) as dst:
dst.write(img_3band.astype(rasterio.uint16), 1)
def load_image3(filename,fndr):
"""Return a 3D (r, g, b) numpy array with the data in the specified TIFF filename."""
path = os.path.abspath(os.path.join('./', filename))
if os.path.exists(path):
with rasterio.open(path) as src:
b,g,r,mask = src.read()
img_3band = np.dstack([b, g, r])
profile = src.profile
# And then change the band count to 1, set the
# dtype to uint8, and specify LZW compression.
profile.update(
dtype=rasterio.uint16,
count=1,
compress='lzw')
with rasterio.open(f"{fndr}/example.tif", 'w', **profile) as dst:
dst.write(img_3band[:,:,1].astype(rasterio.uint16), 1)
def rgbir_to_rgb(img_4band):
"""Convert an RGBIR image to RGB"""
return img_4band[:,:,:3]
def getListOfFiles(dirName):
# create a list of file and sub directories
# names in the given directory
listOfFile = os.listdir(dirName)
allFiles = list()
# Iterate over all the entries
for entry in listOfFile:
# Create full path
fullPath = os.path.join(dirName, entry)
# If entry is a directory then get the list of files in this directory
if os.path.isdir(fullPath):
allFiles = allFiles + getListOfFiles(fullPath)
else:
allFiles.append(fullPath)
return allFiles
def getListOfMetadataFiles(dirName):
regex = re.compile(r'\(metadata.json\)$')
# create a list of file and sub directories
# names in the given directory
listOfFile = os.listdir(dirName)
allFiles = list()
# Iterate over all the entries
for entry in listOfFile:
# Create full path
fullPath = os.path.join(dirName, entry)
# If entry is a directory then get the list of files in this directory
if os.path.isdir(fullPath):
allFiles = allFiles + getListOfFiles(fullPath)
else:
if regex.match(fullPath):
allFiles.append(fullPath)
#filtered = [i for i in full if not regex.match(i)]
#return filtered
return allFiles
def main():
dirName = sys.argv[1]#os.getcwd()
# Get the list of all files in directory tree at given path
listOfFiles = getListOfFiles(dirName)
regex_tif = re.compile(r'MS_clip.tif')
filtered_tif = [i for i in listOfFiles if regex_tif.search(i)]
#filename = "20170623_180038_0f34_3B_AnalyticMS.tif"
#gdalinfo -mm 1155205_2017-03-31_RE3_3A_rgb.tif
#gdal_translate 1155205_2017-03-31_RE3_3A_rgb.tif 1155205_2017–03–31_RE3_3A_rgb_scaled.tif -scale 1422 49572 0 65535 -exponent 0.5 -co COMPRESS=DEFLATE -co PHOTOMETRIC=RGB
dateImageTuples = []
ndvistats = []
for filename in filtered_tif:
#print(filename)
fnbn = os.path.basename(filename)
fndn = os.path.dirname(filename)
#print(dirName)
#print(fndn)
rg = re.compile(r'' + dirName + '/(.+)/(.+)/files/')
xd = rg.search(filename)
#print(xd)
#print(xd[0])
#print(xd[1])
jsfn = re.sub('_3B_AnalyticMS_clip.tif','_metadata.json',filename)
js = json.load(open(jsfn))
pmid = js['id']
acqdate = js['properties']['acquired']
satid = js['properties']['satellite_id']
dateImageTuples.append((acqdate,fndn,xd[1]))
#dateImageTuples.sort()
#mnum = 1000
#for m in dateImageTuples:
# print(f"{m[0]} {m[1]}")
# mnum += 1
# os.system(f"cp {m[1]}/ndvi.png dt_ndvi_{mnum}.png")
#print(dateImageTuples)
#exit()
# first pass:
for filename in filtered_tif:
#print(filename)
# Load red and NIR bands - note all PlanetScope 4-band images have band order BGRN
with rasterio.open(filename) as src:
band_blue_radiance = src.read(1)
with rasterio.open(filename) as src:
band_green_radiance = src.read(2)
with rasterio.open(filename) as src:
band_red_radiance = src.read(3)
with rasterio.open(filename) as src:
band_nir_radiance = src.read(4)
fnbn = os.path.basename(filename)
fndn = os.path.dirname(filename)
#show(src.read())
rg = re.compile(r'' + dirName + '/(.+)/(.+)/files/')
xd = rg.search(filename)
jsfn = re.sub('_3B_AnalyticMS_clip.tif','_metadata.json',filename)
js = json.load(open(jsfn))
acqdate = js['properties']['acquired']
satid = js['properties']['satellite_id']
#dateImageTuples.append((acqdate,fndn))
xmlfn = re.sub('AnalyticMS_clip.tif','AnalyticMS_metadata_clip.xml',filename)
xmldoc = minidom.parse(xmlfn)
nodes = xmldoc.getElementsByTagName("ps:bandSpecificMetadata")
# XML parser refers to bands by numbers 1-4
coeffs = {}
for node in nodes:
bn = node.getElementsByTagName("ps:bandNumber")[0].firstChild.data
if bn in ['1', '2', '3', '4']:
i = int(bn)
value = node.getElementsByTagName("ps:reflectanceCoefficient")[0].firstChild.data
coeffs[i] = float(value)
#print("Conversion coefficients: {}".format(coeffs))
# Multiply the Digital Number (DN) values in each band by the TOA reflectance coefficients
band_blue_reflectance = band_blue_radiance * coeffs[1]
band_green_reflectance = band_green_radiance * coeffs[2]
band_red_reflectance = band_red_radiance * coeffs[3]
band_nir_reflectance = band_nir_radiance * coeffs[4]
print("Red band radiance is from {} to {}".format(np.amin(band_red_radiance), np.amax(band_red_radiance)))
print("Red band reflectance is from {} to {}".format(np.amin(band_red_reflectance), np.amax(band_red_reflectance)))
#Set spatial characteristics of the output object to mirror the input
kwargs = src.meta
kwargs.update(
dtype=rasterio.uint16,
count = 4)
print("Before Scaling, red band reflectance is from {} to {}".format(np.amin(band_red_reflectance),
np.amax(band_red_reflectance)))
# Here we include a fixed scaling factor. This is common practice.
scale = 10000
blue_ref_scaled = scale * band_blue_reflectance
green_ref_scaled = scale * band_green_reflectance
red_ref_scaled = scale * band_red_reflectance
nir_ref_scaled = scale * band_nir_reflectance
print("After Scaling, red band reflectance is from {} to {}".format(np.amin(red_ref_scaled),
np.amax(red_ref_scaled)))
# NDVI
band_nir = band_nir_reflectance
band_red = band_red_reflectance
#Allow division by zero
np.seterr(divide='ignore', invalid='ignore')
# Calculate NDVI
ndvi = (band_nir.astype(float) - band_red.astype(float)) / (band_nir + band_red)
# Set min/max values from reflectance range for image (excluding NAN)
min=np.nanmin(ndvi)
max=np.nanmax(ndvi)
mid=(max-min)/2.0# Could perhaps also be center of mass distribution?
#mid=0.20
ndvistats.append((min,max))
#.set_size_inches(float(H)/float(DPI),float(W)/float(DPI))
#fig = plt.figure(figsize=(20,10))
fig = plt.figure(figsize=(1600/200,1000/200))
ax = fig.add_subplot(111)
#ax.figtext(-1,-2,f"{max} {mid} {min}")
# diverging color scheme chosen from https://matplotlib.org/users/colormaps.html
# note that appending '_r' to the color scheme name reverses it!
#cmap = plt.cm.get_cmap('RdGy_r')
cmap = plt.cm.get_cmap('RdYlGn')
cax = ax.imshow(ndvi, cmap=cmap, clim=(min, max), norm=MidpointNormalize(midpoint=mid,vmin=min, vmax=max))
ax.axis('off')
ax.set_title(f"NDVI {acqdate} {satid}", fontsize=18, fontweight='bold')
cbar = fig.colorbar(cax, orientation='horizontal', shrink=0.65)#65
#fig.savefig(f"{fndn}/ndvi.png", dpi=200, bbox_inches='tight', pad_inches=0.7)
fig.savefig(f"{fndn}/ndvi.png", dpi=200, bbox_inches='tight', pad_inches=0.0)
os.system(f"cp {fndn}/ndvi.png dt_ndvi_{acqdate[0:10]}_{xd[1]}.png")
xmin = 0.0
xmax = 0.0
for s in ndvistats:
if xmax < s[1]:
xmax = s[1]
ndvi_stats_mid = (xmax-xmin)/2.0
# second pass:
nsc = 0
for filename in filtered_tif:
print(filename)
# Load red and NIR bands - note all PlanetScope 4-band images have band order BGRN
with rasterio.open(filename) as src:
band_blue_radiance = src.read(1)
with rasterio.open(filename) as src:
band_green_radiance = src.read(2)
with rasterio.open(filename) as src:
band_red_radiance = src.read(3)
with rasterio.open(filename) as src:
band_nir_radiance = src.read(4)
fnbn = os.path.basename(filename)
fndn = os.path.dirname(filename)
rg = re.compile(r'' + dirName + '/(.+)/(.+)/files/')
xd = rg.search(filename)
jsfn = re.sub('_3B_AnalyticMS_clip.tif','_metadata.json',filename)
js = json.load(open(jsfn))
acqdate = js['properties']['acquired']
satid = js['properties']['satellite_id']
#dateImageTuples.append((acqdate,fndn))
xmlfn = re.sub('AnalyticMS_clip.tif','AnalyticMS_metadata_clip.xml',filename)
xmldoc = minidom.parse(xmlfn)
nodes = xmldoc.getElementsByTagName("ps:bandSpecificMetadata")
# XML parser refers to bands by numbers 1-4
coeffs = {}
for node in nodes:
bn = node.getElementsByTagName("ps:bandNumber")[0].firstChild.data
if bn in ['1', '2', '3', '4']:
i = int(bn)
value = node.getElementsByTagName("ps:reflectanceCoefficient")[0].firstChild.data
coeffs[i] = float(value)
#print("Conversion coefficients: {}".format(coeffs))
# Multiply the Digital Number (DN) values in each band by the TOA reflectance coefficients
band_blue_reflectance = band_blue_radiance * coeffs[1]
band_green_reflectance = band_green_radiance * coeffs[2]
band_red_reflectance = band_red_radiance * coeffs[3]
band_nir_reflectance = band_nir_radiance * coeffs[4]
print("Red band radiance is from {} to {}".format(np.amin(band_red_radiance), np.amax(band_red_radiance)))
print("Red band reflectance is from {} to {}".format(np.amin(band_red_reflectance), np.amax(band_red_reflectance)))
#Set spatial characteristics of the output object to mirror the input
kwargs = src.meta
kwargs.update(
dtype=rasterio.uint16,
count = 4)
print("Before Scaling, red band reflectance is from {} to {}".format(np.amin(band_red_reflectance),
np.amax(band_red_reflectance)))
# Here we include a fixed scaling factor. This is common practice.
scale = 10000
blue_ref_scaled = scale * band_blue_reflectance
green_ref_scaled = scale * band_green_reflectance
red_ref_scaled = scale * band_red_reflectance
nir_ref_scaled = scale * band_nir_reflectance
print("After Scaling, red band reflectance is from {} to {}".format(np.amin(red_ref_scaled),
np.amax(red_ref_scaled)))
# NDVI
band_nir = band_nir_reflectance
band_red = band_red_reflectance
#Allow division by zero
np.seterr(divide='ignore', invalid='ignore')
# Calculate NDVI
ndvi = (band_nir.astype(float) - band_red.astype(float)) / (band_nir + band_red)
# Set min/max values from reflectance range for image (excluding NAN)
min=np.nanmin(xmin)
max=np.nanmax(xmax)
mid=ndvi_stats_mid
nsc += 1
#mid=0.20
print(nsc," ",xmin," ",xmax," ",mid)
#.set_size_inches(float(H)/float(DPI),float(W)/float(DPI))
#fig = plt.figure(figsize=(20,10))
fig = plt.figure(figsize=(1600/200,1000/200))
ax = fig.add_subplot(111)
#ax.figtext(-1,-2,f"{max} {mid} {min}")
# diverging color scheme chosen from https://matplotlib.org/users/colormaps.html
# note that appending '_r' to the color scheme name reverses it!
#cmap = plt.cm.get_cmap('RdGy_r')
cmap = plt.cm.get_cmap('RdYlGn')
cax = ax.imshow(ndvi, cmap=cmap, clim=(min, max), norm=MidpointNormalize(midpoint=mid,vmin=min, vmax=max))
ax.axis('off')
ax.set_title(f"NDVI {acqdate} {satid}", fontsize=18, fontweight='bold')
cbar = fig.colorbar(cax, orientation='horizontal', shrink=0.65)#65
#fig.savefig(f"{fndn}/ndvi.png", dpi=200, bbox_inches='tight', pad_inches=0.7)
fig.savefig(f"{fndn}/ndvi_post.png", dpi=200, bbox_inches='tight', pad_inches=0.0)
os.system(f"cp {fndn}/ndvi_post.png dt_ndvi_{acqdate[0:10]}_{xd[1]}.png")
os.system(f"convert dt_ndvi_{acqdate[0:10]}_{xd[1]}.png -gravity center -background white -extent 1200x1000 dt_m_ndvi_{acqdate[0:10]}_{xd[1]}.png")
## ECARR RED
#ecarrRed = 0.0161 * ((band_red_reflectance.astype(float) / (band_green_reflectance.astype(float) * band_red_reflectance.astype(float) ) ** 0.7784))
## Set min/max values from reflectance range for image (excluding NAN)
#min=np.nanmin(ecarrRed)
#max=np.nanmax(ecarrRed)
#mid=(max-min)/2.0# Could perhaps also be center of mass distribution?
#
#fig = plt.figure(figsize=(20,10))
#ax = fig.add_subplot(111)
#
## diverging color scheme chosen from https://matplotlib.org/users/colormaps.html
## note that appending '_r' to the color scheme name reverses it!
##cmap = plt.cm.get_cmap('RdGy_r')
#cax = ax.imshow(ecarrRed, cmap=cmap, clim=(min, max), norm=MidpointNormalize(midpoint=mid,vmin=min, vmax=max))
#ax.axis('off')
#ax.set_title(f"ECARR_red {acqdate} {satid}", fontsize=18, fontweight='bold')
#cbar = fig.colorbar(cax, orientation='horizontal', shrink=0.65)
#fig.savefig(f"{fndn}/ecarr_red.png", dpi=200, bbox_inches='tight', pad_inches=0.7)
## ECARR NIR
#ecarrnir = 0.0161 * ((band_nir_reflectance.astype(float) / (band_green_reflectance.astype(float) * band_nir_reflectance.astype(float) ) ** 0.7784))
## Set min/max values from reflectance range for image (excluding NAN)
#min=np.nanmin(ecarrnir)
#max=np.nanmax(ecarrnir)
#mid=(max-min)/2.0# Could perhaps also be center of mass distribution?
##mid=0.20
#
#fig = plt.figure(figsize=(20,10))
#ax = fig.add_subplot(111)
#
## diverging color scheme chosen from https://matplotlib.org/users/colormaps.html
## note that appending '_r' to the color scheme name reverses it!
##cmap = plt.cm.get_cmap('RdGy_r')
#cax = ax.imshow(ecarrnir, cmap=cmap, clim=(min, max), norm=MidpointNormalize(midpoint=mid,vmin=min, vmax=max))
#ax.axis('off')
#ax.set_title(f"ECARR_nir {acqdate} {satid}", fontsize=18, fontweight='bold')
#cbar = fig.colorbar(cax, orientation='horizontal', shrink=0.65)
#fig.savefig(f"{fndn}/ecarr_nir.png", dpi=200, bbox_inches='tight', pad_inches=0.7)
# Write band calculations to a new raster file
#print(f"in {fndn}:")
#print(f"about to write: {fndn}/rgb.png")
#with rasterio.open(f"{fndn}/rgb.png", 'w', **kwargs) as dst:
# #dst.write_band(1, band_red_reflectance.astype(rasterio.uint16))
# #dst.write_band(2, band_green_reflectance.astype(rasterio.uint16))
# #dst.write_band(3, band_blue_reflectance.astype(rasterio.uint16))
# dst.write_band(4, band_nir_reflectance.astype(rasterio.uint16))
# dst.write_band(3, band_red_reflectance.astype(rasterio.uint16))
# dst.write_band(2, band_green_reflectance.astype(rasterio.uint16))
# dst.write_band(1, band_blue_reflectance.astype(rasterio.uint16))
# ##dst.write_band(4, band_nir_reflectance.astype(rasterio.uint16))
## Set min/max values from reflectance range for image (excluding NAN)
min=np.nanmin(band_nir_reflectance)
max=np.nanmax(band_nir_reflectance)
mid=(max-min)/2.0# Could perhaps also be center of mass distribution?
#mid=0.20
fig = plt.figure(figsize=(20,10))
ax = fig.add_subplot(111)
# diverging color scheme chosen from https://matplotlib.org/users/colormaps.html
# note that appending '_r' to the color scheme name reverses it!
cmap = plt.cm.get_cmap('RdGy_r')
cax = ax.imshow(band_nir_reflectance, cmap=cmap, clim=(min, max), norm=MidpointNormalize(midpoint=mid,vmin=min, vmax=max))
ax.axis('off')
ax.set_title('NIR Reflectance', fontsize=18, fontweight='bold')
cbar = fig.colorbar(cax, orientation='horizontal', shrink=0.65)
fig.savefig(f"{fndn}/nir.png", dpi=200, bbox_inches='tight', pad_inches=0.7)
#from osgeo import gdal
print(f"About to open {filename}")
#load_image4_to_RGB(filename)
load_image3(filename,fndn)
#gtif = gdal.Open(filename)
#bmin = 0
#bmax = 1000000
#for band in range(1,4):
# print(band)
# srcband = gtif.GetRasterBand(band)
# #srcband.ComputeStatistics(0)
# bst = srcband.ComputeRasterMinMax()
# tbmin = bst[0]
# tbmax = bst[1]
# if tbmin < bmin:
# bmin = tbmin
# if tbmax > bmax:
# bmax = tbmax
#for band in range(1,4):
# print(band)
# srcband = gtif.GetRasterBand(band)
# sgtif = gdal.Translate(f"{fndn}/output{band}.tif", srcband, options = f"-scale {bmin} {bmax} 0 65535 -exponent 0.5 -co COMPRESS=DEFLATE -co PHOTOMETRIC=RGB")
# sgtif = None
#gtif = gdal.Translate(f"{fndn}/output.tif", gtif, scaleParams = [bmin,bmax,0,65535], exponents=[0.5])
#gtif = gdal.Translate(f"{fndn}/output.tif", gtif, scaleParams = [bmin,bmax,0,65535])
#gtif = gdal.Translate(f"{fndn}/output.tif", gtif, options = f"-scale {bmin} {bmax} 0 65535 -exponent 0.5 -co COMPRESS=DEFLATE -co PHOTOMETRIC=RGB")
#gtif = None
## Write band calculations to a new raster file
#print(f"in {fndn}:")
#print(f"about to write: {fndn}/rgb.png")
#with rasterio.open(f"{fndn}/rgb.png", 'w', **kwargs) as dst:
# #dst.write_band(1, band_red_reflectance.astype(rasterio.uint16))
# #dst.write_band(2, band_green_reflectance.astype(rasterio.uint16))
# #dst.write_band(3, band_blue_reflectance.astype(rasterio.uint16))
# dst.write_band(4, band_nir_reflectance.astype(rasterio.uint16))
# dst.write_band(3, band_red_reflectance.astype(rasterio.uint16))
# dst.write_band(2, band_green_reflectance.astype(rasterio.uint16))
# dst.write_band(1, band_blue_reflectance.astype(rasterio.uint16))
# ##dst.write_band(4, band_nir_reflectance.astype(rasterio.uint16))
regex = re.compile(r'_metadata.json')
filtered = [i for i in listOfFiles if regex.search(i)]
rowlist = []
# #print the files
for elem in filtered:
print(elem)
dict1 = json.load(open(elem))
dict1['filepath'] = elem
for p in dict1['properties']:
dict1[p] = dict1['properties'][p]
dict1.pop('properties',None)
rowlist.append(dict1)
df = pd.DataFrame(rowlist)
df.to_csv(f"{sys.argv[1]}.csv")
dateImageTuples.sort()
mnum = 1000
for m in dateImageTuples:
print(f"{m[0]} {m[1]}")
mnum += 1
os.system(f"cp {m[1]}/ndvi.png dt_{m[2]}_ndvi_{mnum}.png")
if __name__ == '__main__':
main()