@@ -972,53 +972,36 @@ def get_pandas_dataframe(self, data_size, stride, **kwargs):
972972 Returns
973973 -------
974974 pandas.DataFrame
975- A Pandas DataFrame with three columns describing the x,y,z mesh
976- cell indices corresponding to each filter bin. The number of rows
977- in the DataFrame is the same as the total number of bins in the
978- corresponding tally, with the filter bin appropriately tiled to map
979- to the corresponding tally bins.
975+ A Pandas DataFrame with columns describing the mesh cell indices
976+ corresponding to each filter bin. Column names depend on the mesh
977+ type (e.g., x/y/z for RegularMesh, r/phi/z for CylindricalMesh,
978+ r/theta/phi for SphericalMesh, or element index for
979+ UnstructuredMesh). The number of rows in the DataFrame is the same
980+ as the total number of bins in the corresponding tally, with the
981+ filter bin appropriately tiled to map to the corresponding tally
982+ bins.
980983
981984 See also
982985 --------
983986 Tally.get_pandas_dataframe(), CrossFilter.get_pandas_dataframe()
984987
985988 """
986- # Initialize Pandas DataFrame
987- df = pd .DataFrame ()
988-
989989 # Initialize dictionary to build Pandas Multi-index column
990990 filter_dict = {}
991991
992992 # Append mesh ID as outermost index of multi-index
993993 mesh_key = f'mesh { self .mesh .id } '
994994
995- # Find mesh dimensions - use 3D indices for simplicity
996- n_dim = len (self .mesh .dimension )
997- if n_dim == 3 :
998- nx , ny , nz = self .mesh .dimension
999- elif n_dim == 2 :
1000- nx , ny = self .mesh .dimension
1001- nz = 1
1002- else :
1003- nx = self .mesh .dimension
1004- ny = nz = 1
1005-
1006- # Generate multi-index sub-column for x-axis
1007- filter_dict [mesh_key , 'x' ] = _repeat_and_tile (
1008- np .arange (1 , nx + 1 ), stride , data_size )
1009-
1010- # Generate multi-index sub-column for y-axis
1011- filter_dict [mesh_key , 'y' ] = _repeat_and_tile (
1012- np .arange (1 , ny + 1 ), nx * stride , data_size )
1013-
1014- # Generate multi-index sub-column for z-axis
1015- filter_dict [mesh_key , 'z' ] = _repeat_and_tile (
1016- np .arange (1 , nz + 1 ), nx * ny * stride , data_size )
995+ # Determine index base (0-based for unstructured, 1-based otherwise)
996+ idx_start = 0 if isinstance (self .mesh , openmc .UnstructuredMesh ) else 1
1017997
1018- # Initialize a Pandas DataFrame from the mesh dictionary
1019- df = pd .concat ([df , pd .DataFrame (filter_dict )])
998+ # Generate a multi-index sub-column for each axis
999+ for label , dim_size in zip (self .mesh ._axis_labels , self .mesh .dimension ):
1000+ filter_dict [mesh_key , label ] = _repeat_and_tile (
1001+ np .arange (idx_start , idx_start + dim_size ), stride , data_size )
1002+ stride *= dim_size
10201003
1021- return df
1004+ return pd . DataFrame ( filter_dict )
10221005
10231006 def to_xml_element (self ):
10241007 """Return XML Element representing the Filter.
0 commit comments