Commit e9657469 authored by Nicolas Vuaille's avatar Nicolas Vuaille Committed by Kitware Robot
Browse files

Merge topic 'UseCftimeModule'

0bfb8ea8 Enable NetCDF Time Annotation Plugin in CI
f28abb81

 Add check for cftime Python module in NetCDF Time Annotation plugin
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Mathieu Westphal's avatarMathieu Westphal <mathieu.westphal@kitware.com>
Acked-by: Thomas Galland's avatarThomas Galland <thomas.galland@kitware.com>
Merge-request: !5788
parents d30eb1a6 0bfb8ea8
Pipeline #288161 failed with stages
in 229 minutes and 51 seconds
# Enable default-off plugin with Python dependency
set(PARAVIEW_PLUGIN_ENABLE_NetCDFTimeAnnotationPlugin ON CACHE BOOL "")
include("${CMAKE_CURRENT_LIST_DIR}/configure_fedora_common.cmake")
# Enable default-off plugin with Python dependency
set(PARAVIEW_PLUGIN_ENABLE_NetCDFTimeAnnotationPlugin ON CACHE BOOL "")
include("${CMAKE_CURRENT_LIST_DIR}/configure_windows_vs2019.cmake")
......@@ -47,7 +47,7 @@ dnf install -y --setopt=install_weak_deps=False \
python3-pandas python3-pandas-datareader python3-sphinx python3-pip \
python3-mpi4py-mpich python3-mpi4py-openmpi python3-matplotlib
python3 -m pip install wslink
python3 -m pip install wslink cftime
# Plugin dependencies
dnf install -y --setopt=install_weak_deps=False \
......
# This file should always contain exact version references so that we know what
# we are actually testing at any given point.
# Needed for netcdftime.
Cython==0.29.21
......@@ -2,8 +2,7 @@
# we are actually testing at any given point.
# NetCDFTimeAnnotationPlugin
# Needs Cython installed before it can be `pip install`'d
netcdftime==1.0.0a2
cftime==1.6.0
# numpy
# Note that Linux will need 1.19.4
......
......@@ -22,7 +22,7 @@
.fedora35:
extends: .linux
image: "kitware/paraview:ci-fedora35-20220420"
image: "kitware/paraview:ci-fedora35-20220620"
.el8_icc:
extends: .linux
......
......@@ -99,8 +99,7 @@
# This may be necessary when running manually.
# Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
- . .\build\ci-venv\Scripts\Activate.ps1
- pip install -qq -r $pwdpath\.gitlab\ci\requirements-phase1.txt
- pip install -qq -r $pwdpath\.gitlab\ci\requirements-phase2.txt
- pip install -qq -r $pwdpath\.gitlab\ci\requirements.txt
- Set-Item -Force -Path "env:PATH" -Value "$env:PATH;$env:SCCACHE_PATH"
- Invoke-Expression -Command .gitlab/ci/vcvarsall.ps1
- sccache --start-server
......
......@@ -275,7 +275,6 @@ set(paraview_default_plugins
LegacyExodusReader
Moments
MooseXfemClip
NetCDFTimeAnnotationPlugin
NodeEditor
NonOrthogonalSource
PacMan
......
......@@ -4,14 +4,28 @@ paraview_add_plugin(NetCDFTimeAnnotationPlugin
VERSION "1.0"
SERVER_MANAGER_XML NetCDFTimeAnnotation.xml)
set_property(GLOBAL APPEND
PROPERTY
vtk_required_python_modules "netcdftime")
include(FindPythonModules)
if (BUILD_TESTING)
include(FindPythonModules)
find_python_module(netcdftime netcdftime_found)
if (netcdftime_found)
# First look for the module cftime
find_python_module(cftime module_found)
if (module_found)
set(module_name "cftime")
else ()
# If cftime is not found, search for netcdftime
find_python_module(netcdftime module_found)
if (module_found)
set(module_name "netcdftime")
endif ()
endif ()
if (module_found)
set_property(GLOBAL APPEND
PROPERTY
vtk_required_python_modules "${module_name}")
if (BUILD_TESTING)
add_subdirectory(Testing)
endif()
endif ()
else ()
message(FATAL_ERROR
"The Python module cftime (preferred) or netcdftime is required to build this plugin.")
endif ()
......@@ -33,7 +33,7 @@
<Element index="0" value=""/>
</Property>
<Property name="Script" id="6868.Script" number_of_elements="1">
<Element index="0" value="from netcdftime import utime&#xa;from netcdftime import datetime&#xa;&#xa;inp = self.GetInputDataObject(0,0)&#xa;outp = self.GetOutputDataObject(0)&#xa;&#xa;currentTime = inp.GetInformation().Get(vtk.vtkDataObject.DATA_TIME_STEP())&#xa;timeUnitsArray = inp.GetFieldData().GetAbstractArray(&#x22;time_units&#x22;)&#xa;if timeUnitsArray:&#xa; timeUnits = timeUnitsArray.GetValue(0)&#xa;&#xa; cdftime = utime(timeUnits)&#xa; t = cdftime.num2date(currentTime)&#xa;&#xa; fdate = vtk.vtkStringArray()&#xa; fdate.SetName(&#x22;FullDate&#x22;)&#xa; fdate.SetNumberOfValues(1)&#xa; fdate.SetValue(0, str(t))&#xa; outp.GetFieldData().AddArray(fdate)&#xa;&#xa; date = vtk.vtkIntArray()&#xa; date.SetName(&#x22;Date&#x22;)&#xa; date.SetNumberOfValues(6)&#xa; date.SetValue(0, t.year)&#xa; date.SetValue(1, t.month)&#xa; date.SetValue(2, t.day)&#xa; date.SetValue(3, t.hour)&#xa; date.SetValue(4, t.minute)&#xa; date.SetValue(5, t.second)&#xa; outp.GetFieldData().AddArray(date)&#xa;"/>
<Element index="0" value="try:&#xa; import cftime as ct&#xa; hasCftime = True&#xa;except:&#xa; try:&#xa; import netcdftime as ct&#xa; hasCftime = False&#xa; except:&#xa; print(&#x22;Need the python cftime (or the older netcdftime) module for the NetCDFTimeAnnotation plugin!&#x22;)&#xa;&#xa;&#xa;inp = self.GetInputDataObject(0,0)&#xa;outp = self.GetOutputDataObject(0)&#xa;&#xa;currentTime = inp.GetInformation().Get(vtk.vtkDataObject.DATA_TIME_STEP())&#xa;&#xa;sdate = vtk.vtkStringArray()&#xa;sdate.SetName(&#x22;RawDate&#x22;)&#xa;sdate.SetNumberOfValues(1)&#xa;sdate.SetValue(0,str(currentTime))&#xa;outp.GetFieldData().AddArray(sdate)&#xa;timeUnitsArray = inp.GetFieldData().GetAbstractArray(&#x22;time_units&#x22;)&#xa;&#xa;if timeUnitsArray:&#xa; timeUnits = timeUnitsArray.GetValue(0)&#xa;&#xa; if hasCftime:&#xa; t = ct.num2date(currentTime, timeUnits)&#xa; else:&#xa; cdftime = ct.utime(timeUnits)&#xa; t = cdftime.num2date(currentTime)&#xa;&#xa; fdate = vtk.vtkStringArray()&#xa; fdate.SetName(&#x22;FullDate&#x22;)&#xa; fdate.SetNumberOfValues(1)&#xa; fdate.SetValue(0, str(t))&#xa; outp.GetFieldData().AddArray(fdate)&#xa;&#xa; date = vtk.vtkIntArray()&#xa; date.SetName(&#x22;Date&#x22;)&#xa; date.SetNumberOfValues(6)&#xa; date.SetValue(0, t.year)&#xa; date.SetValue(1, t.month)&#xa; date.SetValue(2, t.day)&#xa; date.SetValue(3, t.hour)&#xa; date.SetValue(4, t.minute)&#xa; date.SetValue(5, t.second)&#xa; outp.GetFieldData().AddArray(date)&#xa;"/>
</Property>
<Property name="UpdateExtentScript" id="6868.UpdateExtentScript" number_of_elements="1">
<Element index="0" value=""/>
......
......@@ -34,9 +34,9 @@ you need to change the order of the Date array elements as in the following exam
## Important note
This plugin takes benefit from the third-party `netcdftime`
Python module, it is mandatory to have it installed in order to build
and use this filter.
This plugin takes benefit from the third-party `cftime` or `netcdftime`
Python modules (the former being preferred). It is mandatory to have
one of them installed in order to build and use this filter.
## Example
User can refer to this page
......
Supports Markdown
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