fsleyes.plotting.histogramseries
- This module provides the
HistogramSeries
, ImageHistogramSeries
,ComplexHistogramSeries
, andMeshHistogramSeries
classes, used by theHistogramPanel
for plotting histogram data.
Two standalone functions are also defined in this module:
- class fsleyes.plotting.histogramseries.HistogramSeries(overlay, overlayList, displayCtx, plotCanvas)[source]
Bases:
fsleyes.plotting.dataseries.DataSeries
A
HistogramSeries
generates histogram data from an overlay. It is the base class for theImageHistogramSeriess
andMeshHistogramSeries
classes.- nbins = <MagicMock name='mock.Int()' id='140112348001424'>
Number of bins to use in the histogram. This value is overridden by the
autoBin
setting.
- autoBin = <MagicMock name='mock.Boolean()' id='140112348499920'>
If
True
, the number of bins used for eachHistogramSeries
is calculated automatically. Otherwise,HistogramSeries.nbins
bins are used.
- ignoreZeros = <MagicMock name='mock.Boolean()' id='140112348499920'>
If
True
, zeros are excluded from the calculated histogram.
- includeOutliers = <MagicMock name='mock.Boolean()' id='140112348499920'>
If
True
, values which are outside of thedataRange
are included in the histogram end bins.
- dataRange = <MagicMock name='mock.Bounds()' id='140112347388352'>
Specifies the range of data which should be included in the histogram. See the
includeOutliers
property.
- __init__(overlay, overlayList, displayCtx, plotCanvas)[source]
Create a
HistogramSeries
.- Parameters
overlay – The overlay from which the data to be plotted is retrieved.
overlayList – The
OverlayList
instance.displayCtx – The
DisplayContext
instance.plotCanvas – The
HistogramPanel
that owns thisHistogramSeries
.
- destroy()[source]
This needs to be called when this
HistogramSeries
instance is no longer being used.
- setHistogramData(data, key)[source]
Must be called by sub-classes whenever the underlying histogram data changes.
- Parameters
data – A
numpy
array containing the data that the histogram is to be calculated on. Pass inNone
to indicate that there is currently no histogram data.key – Something which identifies the
data
, and can be used as adict
key.
- onDataRangeChange()[source]
May be implemented by sub-classes. Is called when the
dataRange
changes.
- getData()[source]
Overrides
DataSeries.getData()
.Returns a tuple containing the
(x, y)
histogram data.
- property binWidth
Returns the width of one bin for this
HistogramSeries
.
- getVertexData()[source]
Returns a
numpy
array of shape(N, 2)
, which contains a set of “vertices” which can be used to display the histogram data as a filled polygon.
- property numHistogramValues
Returns the number of values which were used in calculating the histogram.
- __dataRangeChanged(*args, **kwargs)
Called when the
dataRange
property changes, and also by the__initProperties()
and__volumeChanged()
methods.
- __histPropsChanged(*a)
Called internally, and when any histogram settings change. Re-calculates the histogram data.
- __annotations__ = {}
- __module__ = 'fsleyes.plotting.histogramseries'
- class fsleyes.plotting.histogramseries.ImageHistogramSeries(*args, **kwargs)[source]
Bases:
fsleyes.plotting.histogramseries.HistogramSeries
An
ImageHistogramSeries
instance manages generation of histogram data for anImage
overlay.- showOverlay = <MagicMock name='mock.Boolean()' id='140112348499920'>
If
True
, a maskProxyImage
overlay is added to theOverlayList
, which highlights the voxels that have been included in the histogram. The mask image is managed by theHistogramProfile
instance, which manages histogram plot interaction.
- showOverlayRange = <MagicMock name='mock.Bounds()' id='140112347388352'>
Data range to display with the
showOverlay
mask.
- __init__(*args, **kwargs)[source]
Create an
ImageHistogramSeries
. All arguments are passed through toHistogramSeries.__init__()
.
- destroy()[source]
Must be called when this
ImageHistogramSeries
is no longer needed. Removes some property listeners, and callsHistogramSeries.destroy()
.
- redrawProperties()[source]
Overrides
DataSeries.redrawProperties()
. TheHistogramSeries
data does not need to be re-plotted when theshowOverlay
orshowOverlayRange
properties change.
- onDataRangeChange()[source]
Overrides
HistogramSeries.onDataRangeChange()
. Makes sure that theshowOverlayRange
limits are synced to theHistogramSeries.dataRange
.
- __volumeChanged(*args, **kwargs)
Called when the
volume
property changes, and also by the__init__()
method.Passes the data to the
HistogramSeries.setHistogramData()
method.
- __overlayTypeChanged(*a)
Called when the
Display.overlayType
changes. When this happens, theDisplayOpts
instance associated with the overlay gets destroyed and recreated. This method de-registers and re-registers property listeners as needed.
- __annotations__ = {}
- __module__ = 'fsleyes.plotting.histogramseries'
- class fsleyes.plotting.histogramseries.ComplexHistogramSeries(*args, **kwargs)[source]
Bases:
fsleyes.plotting.histogramseries.ImageHistogramSeries
Thre
ComplexHistogramSeries
class is a specialisation of theImageHistogramSeries
for images with a complex data type.See also the
ComplexTimeSeries
andComplexPowerSpectrumSeries
classes.- plotReal = <MagicMock name='mock.Boolean()' id='140112348499920'>
- plotImaginary = <MagicMock name='mock.Boolean()' id='140112348499920'>
- plotMagnitude = <MagicMock name='mock.Boolean()' id='140112348499920'>
- plotPhase = <MagicMock name='mock.Boolean()' id='140112348499920'>
- __init__(*args, **kwargs)[source]
Create a
ComplexHistogramSeries
. All arguments are passed through to theImageHistogramSeries
constructor.
- extraSeries()[source]
Returns a list containing an
ImaginaryHistogramSeries
,MagnitudeHistogramSeries
, and/orPhaseHistogramSeries
, depending on the values of theplotImaginary
,plotMagnitude
, andplotPhase
properties.
- getData()[source]
Overrides
HistogramSeries.setHistogramData()
. IfplotReal
isFalse
, returns(None, None)
. Otherwise returns the parent class implementation.
- setHistogramData(data, key)[source]
Overrides
HistogramSeries.setHistogramData()
. The real component of the data is passed to the parent class implementation.
- __annotations__ = {}
- __module__ = 'fsleyes.plotting.histogramseries'
- class fsleyes.plotting.histogramseries.ImaginaryHistogramSeries(*args, **kwargs)[source]
Bases:
fsleyes.plotting.histogramseries.ImageHistogramSeries
Class which plots the histogram of the imaginary component of a complex-valued image.
- setHistogramData(data, key)[source]
Must be called by sub-classes whenever the underlying histogram data changes.
- Parameters
data – A
numpy
array containing the data that the histogram is to be calculated on. Pass inNone
to indicate that there is currently no histogram data.key – Something which identifies the
data
, and can be used as adict
key.
- __annotations__ = {}
- __module__ = 'fsleyes.plotting.histogramseries'
- class fsleyes.plotting.histogramseries.MagnitudeHistogramSeries(*args, **kwargs)[source]
Bases:
fsleyes.plotting.histogramseries.ImageHistogramSeries
Class which plots the histogram of the magnitude of a complex-valued image.
- setHistogramData(data, key)[source]
Must be called by sub-classes whenever the underlying histogram data changes.
- Parameters
data – A
numpy
array containing the data that the histogram is to be calculated on. Pass inNone
to indicate that there is currently no histogram data.key – Something which identifies the
data
, and can be used as adict
key.
- __annotations__ = {}
- __module__ = 'fsleyes.plotting.histogramseries'
- class fsleyes.plotting.histogramseries.PhaseHistogramSeries(*args, **kwargs)[source]
Bases:
fsleyes.plotting.histogramseries.ImageHistogramSeries
Class which plots the histogram of the phase of a complex-valued image.
- setHistogramData(data, key)[source]
Must be called by sub-classes whenever the underlying histogram data changes.
- Parameters
data – A
numpy
array containing the data that the histogram is to be calculated on. Pass inNone
to indicate that there is currently no histogram data.key – Something which identifies the
data
, and can be used as adict
key.
- __annotations__ = {}
- __module__ = 'fsleyes.plotting.histogramseries'
- class fsleyes.plotting.histogramseries.MeshHistogramSeries(*args, **kwargs)[source]
Bases:
fsleyes.plotting.histogramseries.HistogramSeries
A
MeshHistogramSeries
instance manages generation of histogram data for aMesh
overlay.- __annotations__ = {}
- __module__ = 'fsleyes.plotting.histogramseries'
- __init__(*args, **kwargs)[source]
Create a
MeshHistogramSeries
. All arguments are passed through toHistogramSeries.__init__()
.
- destroy()[source]
Must be called when this
MeshHistogramSeries
is no longer needed. CallsHistogramSeries.destroy()
and removes some property listeners.
- __vertexDataChanged(*a)
Called when the
MeshOpts.vertexData
orMeshOpts.vertexDataIndex
properties change. Updates the histogram data viaHistogramSeries.setHistogramData()
.
- fsleyes.plotting.histogramseries.histogram(data, nbins, histRange, dataRange, includeOutliers=False, count=True)[source]
Calculates a histogram of the given
data
.- Parameters
data – The data to calculate a histogram foe
nbins – Number of bins to use
histRange – Tuple containing the
(low, high)
data range that the histogram is to be calculated on.dataRange – Tuple containing the
(min, max)
range of values in the dataincludeOutliers – If
True
, the outermost bins will contain counts for values which are outside thehistRange
. Defaults toFalse
.count – If
True
(the default), the raw histogram counts are returned. Otherwise they are converted into probabilities.
- Returns
A tuple containing:
The
x
histogram data (bin edges)The
y
histogram dataThe total number of values that were used in the histogram calculation
- fsleyes.plotting.histogramseries.autoBin(data, dataRange)[source]
Calculates the number of bins which should be used for a histogram of the given data. The calculation is identical to that implemented in the original FSLView.
- Parameters
data – The data that the histogram is to be calculated on.
dataRange – A tuple containing the
(min, max)
histogram range.