forked from acannistra/planet-snowcover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
raster_average.py
45 lines (35 loc) · 1.13 KB
/
raster_average.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
import click
import numpy as np
import rasterio as rio
import seaborn as sns
import matplotlib.pyplot as plt
@click.command()
@click.argument("file")
@click.option("--dark", "-d", is_flag=True)
def average_file(file, dark):
f = rio.open(file)
data = f.read(masked=True) * 100
mean, std = np.ma.mean(data), np.ma.std(data)
print(mean, std)
if dark:
plt.style.use("dark_background")
plt.rcParams['text.color'] = 'white'
plt.rcParams['axes.labelcolor'] = 'white'
plt.rcParams['xtick.color'] = 'white'
plt.rcParams['ytick.color'] = 'white'
nonmasked_vals = data[~data.mask]
plt.rcParams.update({'font.size': 22})
log = False
if len(nonmasked_vals) > 10000:
log = True
plt.hist(nonmasked_vals, bins = 100, log=log)
plt.axvline(x = mean, color = 'red', linestyle = '--')
plt.xlim(-100, 100)
sns.despine()
plt.ylabel("# pixels")
plt.xlabel("Difference [% points]")
plt.tight_layout()
print(len(nonmasked_vals))
plt.savefig(file+"_dist.png", dpi=300, transparent=True, layout="bbox_inches")
if __name__ == "__main__":
average_file()