pyvista / pyvista

3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK)
https://docs.pyvista.org
MIT License
2.76k stars 509 forks source link

`MultiBlock` repr does not format bounds using scientific notation #6438

Closed user27182 closed 3 weeks ago

user27182 commented 4 months ago

Describe the bug, what's wrong, and what you expected.

The repr for a dataset like PolyData, UnstructuredGrid, etc uses scientific notation to format the bounds. But MultiBlock does not. This is made abundantly clear in the example below where 300+ digits are shown for each multiblock bound. The bounds formatting in the MultiBlock bounds repr is expected to match the non-multiblock formatting.

Steps to reproduce the bug.

import pyvista as pv 
empty_mesh = pv.PolyData().extract_cells(0)
print(empty_mesh)
# UnstructuredGrid (0x12a3161c0)
#   N Cells:    0
#   N Points:   0
#   X Bounds:   1.000e+299, -1.000e+299
#   Y Bounds:   1.000e+299, -1.000e+299
#   Z Bounds:   1.000e+299, -1.000e+299
#   N Arrays:   0

blocks = pv.MultiBlock([empty_mesh])
print(blocks)
# MultiBlock (0x12a0f52e0)
#   N Blocks    1
#   X Bounds    100000000000000005250476025520442024870446858110815915491585411551180245798890819578637137508044786404370444383288387817694252323536043057564479218478670698284838720092657580373783023379478809005936895323497079994508111903896764088007465274278014249457925878882005684283811566947219638686545940054016.000, -100000000000000005250476025520442024870446858110815915491585411551180245798890819578637137508044786404370444383288387817694252323536043057564479218478670698284838720092657580373783023379478809005936895323497079994508111903896764088007465274278014249457925878882005684283811566947219638686545940054016.000
#   Y Bounds    100000000000000005250476025520442024870446858110815915491585411551180245798890819578637137508044786404370444383288387817694252323536043057564479218478670698284838720092657580373783023379478809005936895323497079994508111903896764088007465274278014249457925878882005684283811566947219638686545940054016.000, -100000000000000005250476025520442024870446858110815915491585411551180245798890819578637137508044786404370444383288387817694252323536043057564479218478670698284838720092657580373783023379478809005936895323497079994508111903896764088007465274278014249457925878882005684283811566947219638686545940054016.000
#   Z Bounds    100000000000000005250476025520442024870446858110815915491585411551180245798890819578637137508044786404370444383288387817694252323536043057564479218478670698284838720092657580373783023379478809005936895323497079994508111903896764088007465274278014249457925878882005684283811566947219638686545940054016.000, -100000000000000005250476025520442024870446858110815915491585411551180245798890819578637137508044786404370444383288387817694252323536043057564479218478670698284838720092657580373783023379478809005936895323497079994508111903896764088007465274278014249457925878882005684283811566947219638686545940054016.000

EDIT: This bug is not specific to empty meshes. It applies generally to any multiblock bounds.

System Information

OS : Darwin (macOS 14.4.1)
            CPU(s) : 8
           Machine : arm64
      Architecture : 64bit
       Environment : Python
        GPU Vendor : Apple
      GPU Renderer : Apple M2
       GPU Version : 4.1 Metal - 88
  MathText Support : True

  Python 3.9.13 (v3.9.13:6de2ca5339, May 17 2022, 11:37:23)  [Clang 13.0.0
  (clang-1300.0.29.30)]

           pyvista : 0.45.dev0
               vtk : 9.3.1
             numpy : 2.0.0
        matplotlib : 3.9.0
            scooby : 0.10.0
             pooch : 1.8.2
            pillow : 10.4.0
           IPython : 8.18.1
          colorcet : 3.1.0
             scipy : 1.13.1
    pytest_pyvista : 0.1.9

Screenshots

No response

TimeTravelerFromNow commented 1 month ago

Found a solution to this, should I open a pull request although it's a small change?

Forked repository commit

It changes the format for bounds attributes in the MultiBlock class attrs.append(('X Bounds', (bds[0], bds[1]), '{:.3f}, {:.3f}')) becomes attrs.append(('X Bounds', (bds[0], bds[1]), '{:.3E}, {:.3E}'))

And example output:

Python 3.12.6 (main, Sep 30 2024, 18:04:18) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvista
>>> empty_mesh = pyvista.PolyData().extract_cells(0)
>>> blocks = pyvista.MultiBlock([empty_mesh])
>>> print(blocks)
MultiBlock (0x11b77b100)
  N Blocks    1
  X Bounds    1.000E+299, -1.000E+299
  Y Bounds    1.000E+299, -1.000E+299
  Z Bounds    1.000E+299, -1.000E+299
>>> 
tkoyama010 commented 1 month ago

@TimeTravelerFromNow We are happy to have your contribution!