Skip to content
Snippets Groups Projects
Commit f77a70b8 authored by Ray Garcia's avatar Ray Garcia :scream_cat:
Browse files

failed experiment adding BT colors

parent ada75c9e
No related branches found
No related tags found
No related merge requests found
...@@ -9,15 +9,19 @@ Recommended runtime: Python 3.6 with netCDF4, numba, numpy, e.g. Continuum.IO An ...@@ -9,15 +9,19 @@ Recommended runtime: Python 3.6 with netCDF4, numba, numpy, e.g. Continuum.IO An
import netCDF4 as nc4 import netCDF4 as nc4
import numpy as np import numpy as np
import numba import numba
try:
import goesr.l1b as pug
except:
pug = None
def load(ncfilename, varname): def load(nc, varname):
nc = nc4.Dataset(ncfilename)
nc.set_auto_scale(False) nc.set_auto_scale(False)
ncv = nc[varname] ncv = nc[varname]
counts = ncv[:] counts = ncv[:]
bit_depth = ncv.sensor_band_bit_depth bit_depth = ncv.sensor_band_bit_depth
print("{}: bit depth {}, ")
splat = counts.ravel() splat = counts.ravel()
return splat, bit_depth return splat, bit_depth, ncv.scale_factor, ncv.add_offset
@numba.jit((numba.int16[:], numba.int32)) @numba.jit((numba.int16[:], numba.int32))
def dist(splat, bit_depth): def dist(splat, bit_depth):
...@@ -26,7 +30,7 @@ def dist(splat, bit_depth): ...@@ -26,7 +30,7 @@ def dist(splat, bit_depth):
z[v] += 1 z[v] += 1
return z return z
def hist(pngname, filename, distribution, extra=''): def hist(pngname, filename, distribution, bt=None, extra=''):
import matplotlib import matplotlib
matplotlib.use('Agg') matplotlib.use('Agg')
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
...@@ -34,7 +38,11 @@ def hist(pngname, filename, distribution, extra=''): ...@@ -34,7 +38,11 @@ def hist(pngname, filename, distribution, extra=''):
ax = fig.add_subplot(111) #, axisbg='#EEEEEE') ax = fig.add_subplot(111) #, axisbg='#EEEEEE')
# ax.grid(color='white', linestyle='solid') # ax.grid(color='white', linestyle='solid')
ax.grid() ax.grid()
ax.plot(np.log(distribution+1), '.') if bt is None:
ax.plot(np.log(distribution+1), '.')
else:
sc = ax.scatter(np.arange(len(distribution.squeeze())), distribution, c=bt)
plt.colorbar(sc)
ax.set_xlabel('unscaled pixel value') ax.set_xlabel('unscaled pixel value')
ax.set_ylabel('log(occurrences+1)') ax.set_ylabel('log(occurrences+1)')
ax.set_title('log(n+1) {} value distribution'.format(filename) + extra) ax.set_title('log(n+1) {} value distribution'.format(filename) + extra)
...@@ -45,9 +53,11 @@ if __name__=='__main__': ...@@ -45,9 +53,11 @@ if __name__=='__main__':
if len(sys.argv)==1: if len(sys.argv)==1:
print("parameters: netcdf-filename counts-variable-name optional-histogram optional-histogram-bins") print("parameters: netcdf-filename counts-variable-name optional-histogram optional-histogram-bins")
ncfilename, varname = sys.argv[1:3] ncfilename, varname = sys.argv[1:3]
splat, bit_depth = load(ncfilename, varname) nc = nc4.Dataset(ncfilename)
splat, bit_depth, sf, ao = load(nc, varname)
distribution = dist(splat, bit_depth) distribution = dist(splat, bit_depth)
uniq = np.argwhere(distribution != 0).squeeze() uniq = np.argwhere(distribution != 0).squeeze()
minv, maxv = np.min(uniq), np.max(uniq)
fn = os.path.split(ncfilename)[-1] fn = os.path.split(ncfilename)[-1]
nvals = len(uniq) nvals = len(uniq)
print("{} of {} unique values in {}".format(nvals, 2**bit_depth, fn)) print("{} of {} unique values in {}".format(nvals, 2**bit_depth, fn))
...@@ -55,4 +65,12 @@ if __name__=='__main__': ...@@ -55,4 +65,12 @@ if __name__=='__main__':
stem = sys.argv[3] stem = sys.argv[3]
with open(stem + '.tsv', 'wt') as fp: with open(stem + '.tsv', 'wt') as fp:
fp.write('\n'.join(['{}\t{}'.format(i,x) for i,x in enumerate(distribution)]) + '\n') fp.write('\n'.join(['{}\t{}'.format(i,x) for i,x in enumerate(distribution)]) + '\n')
hist(stem + '.png', fn, distribution, ' {} unique values of {}'.format(nvals, 2**bit_depth)) if pug is None:
bt = None
else:
l1b = pug.PugL1bTools(nc)
# radiance range
r = np.arange(2**bit_depth, dtype=np.float32).reshape((1,2**bit_depth)) * sf + ao
bt = pug.calc_bt(r, **l1b.cal)
bt = bt.squeeze()
hist(stem + '.png', fn, distribution, bt, ' {} unique values of {} range {} {}'.format(nvals, 2**bit_depth, minv, maxv))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment