-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyfrac.py
60 lines (50 loc) · 2.05 KB
/
pyfrac.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
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 17 19:30:27 2019
@author: Matthew
PyFRAC runtime script. Run from terminal using "python pyfrac.py"
"""
import time, datetime, csv
import numpy as np
import os
from image import image
import calibration
def stats(image):
dust_pixels = image[image < 0]
return {'total_dust_pixels' : dust_pixels.size,
'mean_dust_pixel_value' : np.mean(dust_pixels),
'std_dust_pixel_value' : np.std(dust_pixels),
'percent_dust_pixels' : dust_pixels.size/image.size}
start = time.time()
np.seterr(all='ignore')
path, dirs, files = next(os.walk("PATH_TO_DIRECTORY_OF_IMAGES"))
print(f"Found {len(files)} files.")
a = []
for i, j in enumerate(files):
print(f"Processing file: {i+1} of {len(files)} - {j}", end="\r")
filedata = image(path+"\\"+j)
metadata= filedata.get_metadata()
quality = filedata.get_quality_indicators()
c4_cal_quality = quality['calibration_quality_flags'][:,1]
c5_cal_quality = quality['calibration_quality_flags'][:,2]
rad_to_temp_coeffs4 = [metadata['ch_4_central_wavenumber']/(10**3),
metadata['ch_4_constant_1']/(10**5),
metadata['ch_4_constant_2']/(10**6)]
rad_to_temp_coeffs5 = [metadata['ch_5_central_wavenumber']/(10**3),
metadata['ch_5_constant_1']/(10**5),
metadata['ch_5_constant_2']/(10**6)]
cal_coeffs = filedata.get_coefficients()
try:
data_counts = filedata.get_data_counts()
except AttributeError:
continue #skip this file
data_counts = calibration.calibrate_image(rad_to_temp_coeffs4, rad_to_temp_coeffs5, cal_coeffs, data_counts, c4_cal_quality, c5_cal_quality)
subtracted = data_counts['b4_counts'] - data_counts['b5_counts']
s = stats(subtracted)
a.append([j,metadata['start_of_data_set_year'],metadata['start_of_data_set_day_of_year'],
metadata["start_of_data_set_utc_time_of_day"],
subtracted.size,s['total_dust_pixels'],s['mean_dust_pixel_value'],s['std_dust_pixel_value']])
with open('OUTFILE', 'w', newline='') as outfile:
wr = csv.writer(outfile)
wr.writerows(a)
print(f"\nTotal time elapsed for {len(files)} files: {datetime.timedelta(seconds=time.time() - start)}s")