// Auto calculate max_bin if set
if type(max_bin) is str and (max_bin.upper() == "AUTO"):
maxval = round(observed_max, 8) // Auto bins will detect maxval to use for calculating labels/bins
if type(min_bin) is str and (min_bin.upper() == "AUTO"):
b = round(observed_min, 8) // If bin_min is auto then overwrite starting value
// Print a warning if observed min/max outside user defined range
if observed_max > maxval or observed_min < b:
print("WARNING!!! The observed range of pixel values in your masked index provided is [" + str(observed_min) +
", " + str(observed_max) + "] but the user defined range of bins for pixel frequencies is [" + str(b) +
", " + str(maxval) + "]. Adjust min_bin and max_bin in order to avoid cutting off data being collected.")
// Calculate histogram
hist_val = [float(l[0]) for l in cv2.calcHist([masked_array.astype(np.float32)], [0], None, [bins], [b, maxval])]
bin_width = (maxval - b) / float(bins)
bin_labels = [float(b)]
plotting_labels = [float(b)]
for i in range(bins - 1):
b += bin_width
bin_labels.append(b)
plotting_labels.append(round(b, 2))
// Make hist percentage for plotting
pixels = cv2.countNonZero(mask)
hist_percent = [(p / float(pixels)) * 100 for p in hist_val]
params.debug = debug
if histplot is True:
dataset = pd.DataFrame({"Index Reflectance": bin_labels,
"Proportion of pixels (%)": hist_percent})
fig_hist = (ggplot(data=dataset,
mapping=aes(x="Index Reflectance",
y="Proportion of pixels (%)"))
+ geom_line(color="red")
+ scale_x_continuous(breaks=bin_labels, labels=plotting_labels))
analysis_image = fig_hist
if params.debug == "print":
fig_hist.save(os.path.join(params.debug_outdir, str(params.device) +
index_array.array_type + "hist.png"))
After Change
// Auto calculate max_bin if set
if type(max_bin) is str and (max_bin.upper() == "AUTO"):
maxval = float(round(observed_max, 8)) // Auto bins will detect maxval to use for calculating labels/bins
if type(min_bin) is str and (min_bin.upper() == "AUTO"):
b = float(round(observed_min, 8)) // If bin_min is auto then overwrite starting value
// Print a warning if observed min/max outside user defined range
if observed_max > maxval or observed_min < b:
print("WARNING!!! The observed range of pixel values in your masked index provided is [" + str(observed_min) +
", " + str(observed_max) + "] but the user defined range of bins for pixel frequencies is [" + str(b) +
", " + str(maxval) + "]. Adjust min_bin and max_bin in order to avoid cutting off data being collected.")
// Calculate histogram
hist_val = [float(l[0]) for l in cv2.calcHist([masked_array.astype(np.float32)], [0], None, [bins], [b, maxval])]
bin_width = (maxval - b) / float(bins)
bin_labels = [float(b)]
plotting_labels = [float(b)]
for i in range(bins - 1):
b += bin_width
bin_labels.append(b)
plotting_labels.append(round(b, 2))
// Make hist percentage for plotting
pixels = cv2.countNonZero(mask)
hist_percent = [(p / float(pixels)) * 100 for p in hist_val]
params.debug = debug
if histplot is True:
dataset = pd.DataFrame({"Index Reflectance": bin_labels,
"Proportion of pixels (%)": hist_percent})
fig_hist = (ggplot(data=dataset,
mapping=aes(x="Index Reflectance",
y="Proportion of pixels (%)"))
+ geom_line(color="red")
+ scale_x_continuous(breaks=bin_labels, labels=plotting_labels))
analysis_image = fig_hist
if params.debug == "print":
fig_hist.save(os.path.join(params.debug_outdir, str(params.device) +
index_array.array_type + "hist.png"))