QF-Error-Tracking / QFVD5

0 stars 0 forks source link

PyVistaQF.py updates and bug fixes #22

Closed ntutland closed 10 months ago

ntutland commented 1 year ago

Describe the bug This is a continuation of Issue #18 submitted by @mathfire, which was caused by the PyVistaQF script requiring an old version of pyVista. As per @amarcozzi, these issues can be resolved by using the conda/pip requirements in the QF distribution (found in dep/python3_requirements), but those requirements will only work in a narrow range of Python versions (e.g. 3.8.16). However, I found that a relatively limited number of changes can be made to the code so that the script will work with newer versions of Python and pyVista, which may eliminate the need for a separate environment just to run the script.

Relevant package versions in requirements: pyvista==0.31.3 numpy==1.18.1 (Python==3.8.16)

Package version in my current evironment: pyvista==0.41.1 numpy==1.23.5 (Python==3.10.9)

My goal is to document the changes I made so that the PyVistaQF.py script is compatible with these newer versions to hopefully take away some versioning headaches. I will group the "bugs" into 3 categories: pyvista updates, numpy updates, and true bugs in the code. If I find any more I will add to this issue.

To Reproduce Run PyVistaQF.py with PyVistaQF_example.inp. Both can be found in QF_5.2.3/scripts/postprocessing/python3. The QF run I am using can be found here (request access if outside NMC).

Desktop

Updates and fixes

PyVista Updates

  1. Issue: point_arrays is no longer an attribute of a pyvista.StructuredGrid object

    • Fix: Replace point_arrays with point_data
    • Line 297: terrain_top.point_arrays['heights'] = terrain_top.points[:, 2] --> terrain_top.point_data['heights'] = terrain_top.points[:, 2]
  2. Issue: cell_arrays is no longer an attribute of a pyvista.UnstructuredGridobject

    • Fix: Replace cell_arrays with cell_data
    • Example: fuel_dens["CANOPY_GRID"].cell_arrays['Fuel Density'] = ftemp[1:, :, :].flatten(order='F') --> fuel_dens["CANOPY_GRID"].cell_data['Fuel Density'] = ftemp[1:, :, :].flatten(order='F')
    • Lines: 394, 413, 425, 429, 431, 435, 489, 504, 535, 537, 539, 646, 670
  3. Issue: xlabel, ylabel, and zlabel are deprecated (throws a warning, not an error)

    • Fix: replace with xtitle, ytitle, and ztitle, respectively
    • Example: plotter.show_grid(font_size=fontsize, xlabel='X [m]', ylabel='Y [m]', zlabel='Z [m]') --> plotter.show_grid(font_size=fontsize, xtitle='X [m]', ytitle='Y [m]', ztitle='Z [m]')
    • Lines: 318, 388, 475, 691

Numpy updates

The following do not result in errors, but are deprecated and result in lots of annoying warnings

  1. Issue: np.int and np.float are deprecated
    • Fix: Replace with built-in functions int and float, respectively. (OR replace with np.int64/np.float64 or np.int32/np.float32 if desired)
    • Example: nslices = np.int(plot_params['NSLICES']) --> nslices = int(plot_params['NSLICES'])
    • Lines: Not going to list them all out here, a find-replace all should be ok for this one.

True bug fixes

I noticed these when I changed the fireTracking flag in the input file to 1.

  1. Issue: fuel_dens dictionary has no key 'VAL'.

    • Fix: Replace 'VAL' with 'DATA'
    • Example: if fuel_dens['VAL'][it][kk, jj, ii] > 0.0: --> if fuel_dens['DATA'][it][kk, jj, ii] > 0.0:
    • Lines: 626, 627
  2. Issue: trackingOffset expects values in input string to be separated by spaces

    • Fix: Remove space after comma in the string split separator argument
    • Line 752: tracking_offset = tracking_offset.split(", ", 2) --> tracking_offset = tracking_offset.split(",", 2)

Updated Script

I will keep an up-to-date version of the script with my fixes here (request permission if outside NMC).

sbrambilla commented 10 months ago

@ntutland thank you for the detailed explanations. All of your comments have been included into the new PyVista with the option of using python 3.8 or 3.10.