Skip to content

Commit

Permalink
Merge topic 'correct-tablefft-properties'
Browse files Browse the repository at this point in the history
8019104 TableFFT: add backward compatibility for new properties
edfe3c6 TableFFT: Update testing and baseline
4987d4e Make 'Frequency' a first-class citizen array for charts
76e28af TableFFT: expose correct API for proxy

Acked-by: Kitware Robot <[email protected]>
Acked-by: Mathieu Westphal <[email protected]>
Acked-by: Tiffany Chhim <[email protected]>
Merge-request: !6045
  • Loading branch information
Timothee Chabat authored and kwrobot committed Dec 13, 2022
2 parents af2fbde + 8019104 commit 6568ba9
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
183e7d3a8d12b137501347a604682898b8c702ee65f531bd309955eecee4715aebeca91c7dcf7b29c68804376187c2223b777c4c7e4a5f50676e57d5c2a5c356
19b1416d47a2e25c28e35e773f1b444dfd7763a2e16f287992383b3b657af89d74e67e750415217a6f713c343e0ec35a0e508691c58707d56645a4b42182632a
Original file line number Diff line number Diff line change
@@ -1 +1 @@
da0cc9e935afbea212c2795bcb7b292c77376b497edfd1ef335b480a42f755684ee7a8a11e9cf509a2045b37e499717482208916d37571145cee483a55f55c77
3c3b63fa16bad315c21d8a4d2d7aca11e13057752f3e35497db874533e185621a73b724f04957b990891b7a36aee69e4750160712707a0271ee706e6699d609f
5 changes: 3 additions & 2 deletions Clients/ParaView/Testing/XML/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,6 @@ if(PARAVIEW_USE_PYTHON)
SelectionLinkScripting.xml
SelectPointsTrace.xml
SplitViewTrace.xml
TestTableFFT.xml
TraceMultiViews.xml
)
set(SelectCellsTrace_DISABLE_CRS TRUE)
Expand Down Expand Up @@ -1525,7 +1524,9 @@ if(PARAVIEW_USE_PYTHON)

list(APPEND TESTS_WITH_INLINE_COMPARES
FindDataTrace.xml
FindDataQueries.xml)
FindDataQueries.xml
TestTableFFT.xml # needs programmable filter + numpy
)

# PythonAlgorithm plugin tests.
configure_file(
Expand Down
25 changes: 6 additions & 19 deletions Clients/ParaView/Testing/XML/TestTableFFT.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,14 @@
<pqevent object="pqClientMainWindow/menubar/menuSources/Alphabetical" command="activate" arguments="ProgrammableSource" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/OutputDataSetType/ComboBox" command="activated" arguments="vtkTable" />
<!-- Create a table. Script is :
obj = self.GetTableOutput()
time = vtk.vtkDoubleArray()
time.SetName("Time")
data = vtk.vtkDoubleArray()
data.SetName("Data")
obj.AddColumn(time)
obj.AddColumn(data)
gc = vtk.vtkMultiProcessController.GetGlobalController()
if gc.GetLocalProcessId() == 0:
time.InsertNextValue(0.0)
time.InsertNextValue(0.2)
time.InsertNextValue(0.4)
time.InsertNextValue(0.6)
data.InsertNextValue(1.0)
data.InsertNextValue(1.0)
data.InsertNextValue(1.0)
data.InsertNextValue(1.0)
time = numpy.linspace(0, 1, 10000, endpoint=False)
signal = numpy.sin(2 * numpy.pi * 1000 * time)
output.RowData.append(time, "Time")
output.RowData.append(signal, "Signal")
-->
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Script/Script"
command="set_string"
arguments="obj = self.GetTableOutput()&#xA;time = vtk.vtkDoubleArray()&#xA;time.SetName(&quot;Time&quot;)&#xA;data = vtk.vtkDoubleArray()&#xA;data.SetName(&quot;Data&quot;)&#xA;obj.AddColumn(time)&#xA;obj.AddColumn(data)&#xA;gc = vtk.vtkMultiProcessController.GetGlobalController()&#xA;if gc.GetLocalProcessId() == 0:&#xA; time.InsertNextValue(0.0)&#xA; time.InsertNextValue(0.2)&#xA; time.InsertNextValue(0.4)&#xA; time.InsertNextValue(0.6)&#xA; data.InsertNextValue(1.0)&#xA; data.InsertNextValue(1.0)&#xA; data.InsertNextValue(1.0)&#xA; data.InsertNextValue(1.0)"/>
arguments="time = numpy.linspace(0, 1, 10000, endpoint=False)&#xA;signal = numpy.sin(2 * numpy.pi * 1000 * time)&#xA;output.RowData.append(time, &quot;Time&quot;)&#xA;output.RowData.append(signal, &quot;Signal&quot;)"/>
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/Accept" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Container/Frame.1/Close" command="activate" arguments="" />

Expand All @@ -36,7 +23,7 @@ if gc.GetLocalProcessId() == 0:
<pqcompareview object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Container/Frame.2/CentralWidgetFrame/Viewport" baseline="$PARAVIEW_DATA_ROOT/Clients/ParaView/Testing/Data/Baseline/TableFFT1.png" width="400" height="400" />

<!-- Check optimize for real input otion -->
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/OptimizeForRealInput/CheckBox" command="set_boolean" arguments="true" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/OneSidedSpectrum/CheckBox" command="set_boolean" arguments="true" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/Accept" command="activate" arguments="" />
<pqcompareview object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Container/Frame.2/CentralWidgetFrame/Viewport" baseline="$PARAVIEW_DATA_ROOT/Clients/ParaView/Testing/Data/Baseline/TableFFT2.png" width="400" height="400" />
</pqevents>
101 changes: 72 additions & 29 deletions Remoting/Application/Resources/filters_filtersgeneral.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2647,8 +2647,19 @@
</Documentation>
</IntVectorProperty>

<DoubleVectorProperty name="DefaultSampleRate"
command="SetDefaultSampleRate"
number_of_elements="1"
default_values="10000">
<DoubleRangeDomain name="range" min="10" max="100000" />
<Documentation>
If the "Time" column is not found then this value will be used as the sample rate of the input.
</Documentation>
</DoubleVectorProperty>

<IntVectorProperty name="WindowingFunction"
command="SetWindowingFunction"
panel_visibility="advanced"
number_of_elements="1"
default_values="4">
<EnumerationDomain name="enum">
Expand All @@ -2660,14 +2671,13 @@
</EnumerationDomain>
<Documentation>
Specify the windowing function to apply on the input. This allows to better process
data that is not periodic. When NumberOfBlocks > 1, the windowing function is applied
to each block.
data that is not periodic. When Welch method is used, the window is applied to each frame.
</Documentation>
</IntVectorProperty>

<IntVectorProperty name="OptimizeForRealInput"
command="SetOptimizeForRealInput"
panel_visibility="advanced"
<IntVectorProperty name="OneSidedSpectrum"
command="SetReturnOnesided"
panel_visibility="default"
number_of_elements="1"
default_values="0">
<BooleanDomain name="bool" />
Expand All @@ -2684,59 +2694,92 @@
default_values="0">
<BooleanDomain name="bool" />
<Documentation>
Specify if the output should be normalized.
Specify if the output should be normalized. Only used if UseWelchMethod is false.
</Documentation>
<Hints>
<PropertyWidgetDecorator type="GenericDecorator"
mode="visibility"
property="AverageFft"
value="0" />
</Hints>
</IntVectorProperty>

<IntVectorProperty name="AverageFft"
<IntVectorProperty name="UseWelchMethod"
command="SetAverageFft"
label="Average FFT per block"
panel_visibility="advanced"
number_of_elements="1"
default_values="0">
<BooleanDomain name="bool" />
<Documentation>
Specify if the input should be split in multiple blocks to compute
an average fft across all blocks.
Specify if filter should use the Welch / periodogram method. If true the
input will be split in multiple segment to compute an average fft across
all segments / blocks. This can be faster for input with lots of samples
and also remove some noise.
</Documentation>
</IntVectorProperty>

<IntVectorProperty name="NumberOfBlock"
command="SetNumberOfBlock"
<IntVectorProperty name="BlockSize"
command="SetBlockSize"
panel_visibility="advanced"
number_of_elements="1"
default_values="2">
default_values="1024">
<Documentation>
Specify the number of blocks to use when computing the average fft over
the whole input sample array. If NumberOfBlock == 1, no average is done
and we only compute the fft on the first BlockSize samples of the input data.
Specify the number of samples to use for each block / segment in the Welch method.
This should be a power of 2 in order to achieve better performance.
</Documentation>
</IntVectorProperty>

<Hints>
<PropertyWidgetDecorator type="GenericDecorator"
mode="visibility"
property="AverageFft"
value="1" />
</Hints>
<IntVectorProperty name="BlockOverlap"
command="SetBlockOverlap"
panel_visibility="advanced"
number_of_elements="1"
default_values="-1">
<Documentation>
Specify the number of samples which will overlap between each block / segment.
If value is not in a valid range (ie inferior to 0 or superior to BlockSize) then the
value BlockSize / 2 will be used. Only used if UseWelchMethod is true.
</Documentation>
</IntVectorProperty>

<IntVectorProperty name="BlockSize"
command="SetBlockSize"
<IntVectorProperty name="ScalingMethod"
command="SetScalingMethod"
panel_visibility="advanced"
number_of_elements="1"
default_values="1024">
default_values="0">
<EnumerationDomain name="enum">
<Entry value="0" text="Density"/>
<Entry value="1" text="Spectrum"/>
</EnumerationDomain>
<Documentation>
Set what scaling should be used when applying the Welch method.
</Documentation>
</IntVectorProperty>

<IntVectorProperty name="Detrend"
command="SetDetrend"
panel_visibility="advanced"
number_of_elements="1"
default_values="0">
<BooleanDomain name="bool" />
<Documentation>
Specify the number of samples to use for each block. This should be a power of 2.
If not, the closest power of two will be used anyway.
Remove trend on each segment before applying the FFT. This is a constant
detrend where the mean of the signal is substracted to the signal.
Only used if UseWelchMethod is true.
</Documentation>
</IntVectorProperty>

<PropertyGroup label="Welch Method Parameters" panel_visibility="advanced" >
<Property name="BlockSize" />
<Property name="BlockOverlap" />
<Property name="ScalingMethod" />
<Property name="Detrend" />
<Hints>
<PropertyWidgetDecorator type="GenericDecorator"
mode="visibility"
property="AverageFft"
property="UseWelchMethod"
value="1" />
</Hints>
</IntVectorProperty>
</PropertyGroup>

<Hints>
<PipelineIcon name="XYChartView" />
Expand Down
40 changes: 40 additions & 0 deletions Remoting/ServerManager/vtkSMStateVersionController.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,39 @@ struct Process_5_10_to_5_11
}
};

struct Process_5_11_to_5_12
{
bool operator()(xml_document& document) { return ConvertTableFFT(document); }

static bool ConvertTableFFT(xml_document& document)
{
pugi::xpath_node_set xpath_set =
document.select_nodes("//ServerManagerState/Proxy[@group='filters' and @type='TableFFT']");

for (auto xpath_node : xpath_set)
{
auto node = xpath_node.node();

if (auto averageNode = node.find_child_by_attribute("name", "AverageFft"))
{
averageNode.attribute("name").set_value("UseWelchMethod");
}

if (auto optimizeNode = node.find_child_by_attribute("name", "OptimizeForRealInput"))
{
optimizeNode.attribute("name").set_value("OneSidedSpectrum");
}

if (auto nblockNode = node.find_child_by_attribute("name", "NumberOfBlock"))
{
node.remove_child(nblockNode);
}
}

return true;
}
};

} // end of namespace

vtkStandardNewMacro(vtkSMStateVersionController);
Expand Down Expand Up @@ -1563,6 +1596,13 @@ bool vtkSMStateVersionController::Process(vtkPVXMLElement* parent, vtkSMSession*
version = vtkSMVersion(5, 11, 0);
}

if (status && (version < vtkSMVersion(5, 12, 0)))
{
Process_5_11_to_5_12 converter;
status = converter(document);
version = vtkSMVersion(5, 12, 0);
}

if (status)
{
std::ostringstream stream2;
Expand Down
2 changes: 1 addition & 1 deletion Remoting/Views/vtkSMChartSeriesListDomain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int vtkSMChartSeriesListDomain::ReadXMLAttributes(vtkSMProperty* prop, vtkPVXMLE
const char** vtkSMChartSeriesListDomain::GetKnownSeriesNames()
{
static const char* strings_to_check[] = { "bin_extents", "Time", "time", "arc_length", "XArray",
"x_array", nullptr };
"x_array", "Frequency", nullptr };
return strings_to_check;
}
//----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Remoting/Views/vtkSMChartSeriesSelectionDomain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static void InitSeriesVisibilityDefaults()
const char* defaults[] = { "^arc_length", "^bin_extents", "^FileId", "^GlobalElementId",
"^GlobalNodeId", "^ObjectId", "^object_id", "^Pedigree.*", "^Points_.*", "^Time",
"^vtkOriginal.*", "^ids$", "^ids .*", "^vtkValidPointMask", "^N .*", "^X$", "^X .*", "^Y$",
"^Y .*", "^Z$", "^Z .*", "^vtkGhostType$", nullptr };
"^Y .*", "^Z$", "^Z .*", "^vtkGhostType$", "^Frequency$", nullptr };
for (int cc = 0; defaults[cc] != nullptr; cc++)
{
SeriesVisibilityDefaults.push_back(
Expand Down
40 changes: 40 additions & 0 deletions Wrapping/Python/paraview/_backwardscompatibilityhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,27 @@ def setattr(proxy, pname, value):
raise NotSupportedException("'StaticMesh' is obsolete. Use 'MeshOverTime' property of " +
proxy.SMProxy.GetXMLName() + " filter instead.")

# 5.11 -> 5.12 breaking changes on "TableFFT" properties
# Renamed AverageFFTperblock into UseWelchMethod
# Renamed OptimizeForRealInput into OneSidedSpectrum
# Removed NumberOfBlock
if proxy.SMProxy and proxy.SMProxy.GetXMLName() == "TableFFT":
isOldVersion = paraview.compatibility.GetVersion() < (5, 12)
if pname == "AverageFFTperblock":
if isOldVersion:
proxy.GetProperty("UseWelchMethod").SetData(value)
raise Continue()
else:
raise NotSupportedException("'AverageFFTperblock' is obsolete. Use 'UseWelchMethod' property instead.")
elif pname == "OptimizeForRealInput":
if isOldVersion:
proxy.GetProperty("OneSidedSpectrum").SetData(value)
raise Continue()
else:
raise NotSupportedException("'OptimizeForRealInput' is obsolete. Use 'OneSidedSpectrum' property instead.")
elif pname == "NumberOfBlock" and not isOldVersion:
raise NotSupportedException("'NumberOfBlock' is obsolete. See 'BlockOverlap' property instead.")

if not hasattr(proxy, pname):
raise AttributeError()
proxy.__dict__[pname] = value
Expand Down Expand Up @@ -859,6 +880,25 @@ def getattr(proxy, pname):
raise NotSupportedException(
"Since ParaView 5.11, 'UseGeometryFilter' has been removed. ")

# 5.11 -> 5.12 breaking changes on "TableFFT" properties
# Renamed AverageFFTperblock into UseWelchMethod
# Renamed OptimizeForRealInput into OneSidedSpectrum
# Removed NumberOfBlock
if proxy.SMProxy and proxy.SMProxy.GetXMLName() == "TableFFT":
isOldVersion = paraview.compatibility.GetVersion() < (5, 12)
if pname == "AverageFFTperblock":
if isOldVersion:
return proxy.GetProperty("UseWelchMethod").GetData()
else:
raise NotSupportedException("'AverageFft' is obsolete. Use 'UseWelchMethod' property instead.")
elif pname == "OptimizeForRealInput":
if isOldVersion:
return proxy.GetProperty("OneSidedSpectrum").GetData()
else:
raise NotSupportedException("'OptimizeForRealInput' is obsolete. Use 'OneSidedSpectrum' property instead.")
elif pname == "NumberOfBlock" and not isOldVersion:
raise NotSupportedException("'NumberOfBlock' is obsolete. See 'BlockOverlap' property instead.")

raise Continue()

# Depending on the compatibility version that has been set, older functionalities
Expand Down

0 comments on commit 6568ba9

Please sign in to comment.