Commit 6cedabc1 authored by Daniel Scheffler's avatar Daniel Scheffler

Added GeoArray.show_histogram().

parent 7df1bd7c
Pipeline #493 passed with stages
in 44 seconds
......@@ -1213,6 +1213,43 @@ class GeoArray(object):
return m
def show_histogram(self, band=1, bins=200, normed=False, exclude_nodata=True, vmin=None, vmax=None, figsize=None):
# type: (int, int, bool, bool, float, float, tuple) -> None
"""Show a histogram of a given band.
:param band: the band to be used to plot the histogram
:param bins: number of bins to plot (default: 200)
:param normed: whether to normalize the y-axis or not (default: False)
:param exclude_nodata: whether tp exclude nodata value from the histogram
:param vmin: minimum value for the x-axis of the histogram
:param vmax: maximum value for the x-axis of the histogram
:param figsize: figure size (tuple)
"""
if self.nodata is not None and exclude_nodata:
data = np.ma.masked_equal(self[band], self.nodata)
data = data.compressed()
else:
data = self[band]
vmin = vmin if vmin is not None else np.percentile(data, 1)
vmax = vmax if vmax is not None else np.percentile(data, 99)
image2plot = data
plt.figure(figsize=figsize)
plt.hist(list(image2plot.flat), normed=normed, bins=bins, color='gray', range=[vmin, vmax])
plt.xlabel('Pixel value')
plt.ylabel('Probabilty' if normed else 'Count')
plt.show()
if not self.q:
print('STD:', np.std(data))
print('MEAN:', np.mean(data))
print('2 % percentile:', np.percentile(data, 2))
print('98 % percentile:', np.percentile(data, 98))
def get_mapPos(self, mapBounds, mapBounds_prj, band2get=None, out_prj=None, arr_gt=None, arr_prj=None, fillVal=None,
rspAlg='near', progress=None, v=False): # TODO implement slice for indexing bands
# type: (tuple, str, int, str, tuple, str, int, str, bool, bool) -> (np.ndarray, tuple, str)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment