Skip to content

Commit

Permalink
Merge topic 'UseCftimeModule'
Browse files Browse the repository at this point in the history
0bfb8ea Enable NetCDF Time Annotation Plugin in CI
f28abb8 Add check for cftime Python module in NetCDF Time Annotation plugin

Acked-by: Kitware Robot <[email protected]>
Acked-by: Mathieu Westphal <[email protected]>
Acked-by: Thomas Galland <[email protected]>
Merge-request: !5788
  • Loading branch information
NicolasVuaille authored and kwrobot committed Jun 29, 2022
2 parents d30eb1a + 0bfb8ea commit e965746
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 24 deletions.
4 changes: 4 additions & 0 deletions .gitlab/ci/configure_fedora35.cmake
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@

# Enable default-off plugin with Python dependency
set(PARAVIEW_PLUGIN_ENABLE_NetCDFTimeAnnotationPlugin ON CACHE BOOL "")

include("${CMAKE_CURRENT_LIST_DIR}/configure_fedora_common.cmake")
3 changes: 3 additions & 0 deletions .gitlab/ci/configure_windows_vs2019_kits_mpi_python_qt.cmake
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Enable default-off plugin with Python dependency
set(PARAVIEW_PLUGIN_ENABLE_NetCDFTimeAnnotationPlugin ON CACHE BOOL "")

include("${CMAKE_CURRENT_LIST_DIR}/configure_windows_vs2019.cmake")
2 changes: 1 addition & 1 deletion .gitlab/ci/docker/fedora35/install_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
5 changes: 0 additions & 5 deletions .gitlab/ci/requirements-phase1.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .gitlab/os-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

.fedora35:
extends: .linux
image: "kitware/paraview:ci-fedora35-20220420"
image: "kitware/paraview:ci-fedora35-20220620"

.el8_icc:
extends: .linux
Expand Down
3 changes: 1 addition & 2 deletions .gitlab/os-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ set(paraview_default_plugins
LegacyExodusReader
Moments
MooseXfemClip
NetCDFTimeAnnotationPlugin
NodeEditor
NonOrthogonalSource
PacMan
Expand Down
30 changes: 22 additions & 8 deletions Plugins/NetCDFTimeAnnotationPlugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Original file line number Diff line number Diff line change
Expand Up @@ -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=""/>
Expand Down
6 changes: 3 additions & 3 deletions Plugins/NetCDFTimeAnnotationPlugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e965746

Please sign in to comment.