toughanimator 0.1.2__tar.gz → 0.1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {toughanimator-0.1.2 → toughanimator-0.1.4}/PKG-INFO +1 -1
- {toughanimator-0.1.2 → toughanimator-0.1.4}/setup.py +1 -1
- {toughanimator-0.1.2 → toughanimator-0.1.4}/toughanimator/tough_classes.py +91 -83
- {toughanimator-0.1.2 → toughanimator-0.1.4}/toughanimator.egg-info/PKG-INFO +1 -1
- {toughanimator-0.1.2 → toughanimator-0.1.4}/README.md +0 -0
- {toughanimator-0.1.2 → toughanimator-0.1.4}/pyproject.toml +0 -0
- {toughanimator-0.1.2 → toughanimator-0.1.4}/setup.cfg +0 -0
- {toughanimator-0.1.2 → toughanimator-0.1.4}/tests/test_all_cases.py +0 -0
- {toughanimator-0.1.2 → toughanimator-0.1.4}/toughanimator/__init__.py +0 -0
- {toughanimator-0.1.2 → toughanimator-0.1.4}/toughanimator/run.py +0 -0
- {toughanimator-0.1.2 → toughanimator-0.1.4}/toughanimator.egg-info/SOURCES.txt +0 -0
- {toughanimator-0.1.2 → toughanimator-0.1.4}/toughanimator.egg-info/dependency_links.txt +0 -0
- {toughanimator-0.1.2 → toughanimator-0.1.4}/toughanimator.egg-info/requires.txt +0 -0
- {toughanimator-0.1.2 → toughanimator-0.1.4}/toughanimator.egg-info/top_level.txt +0 -0
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name='toughanimator', # Package name on PyPI
|
|
5
|
-
version='0.1.
|
|
5
|
+
version='0.1.4',
|
|
6
6
|
description='A tool for visualizing TOUGH simulation outputs.',
|
|
7
7
|
long_description=open('README.md').read(),
|
|
8
8
|
long_description_content_type='text/markdown',
|
|
@@ -7,8 +7,8 @@ import numpy as np
|
|
|
7
7
|
import pandas as pd
|
|
8
8
|
from vtkmodules.all import *
|
|
9
9
|
import pathlib
|
|
10
|
-
import pyvista as pv
|
|
11
10
|
import json
|
|
11
|
+
|
|
12
12
|
from enum import Enum
|
|
13
13
|
|
|
14
14
|
class MeshType(Enum):
|
|
@@ -69,7 +69,7 @@ class VisVariable:
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
class VisSetting:
|
|
72
|
-
def __init__(self, input_file_paths, out_file_paths, vis_dir, corners_file="unkown", out_format_type=OutType.Unknown, tough_version = ToughVersion.Unknown, vis_types=[VisType.ParaView, VisType.Tecplot], mesh_type=MeshType.RegularGrid, debug=False, eos="ECO2N"):
|
|
72
|
+
def __init__(self, input_file_paths, out_file_paths, vis_dir, corners_file="unkown", out_format_type=OutType.Unknown, tough_version = ToughVersion.Unknown, vis_types=[VisType.ParaView, VisType.Tecplot], mesh_type=MeshType.RegularGrid, debug=False, eos="ECO2N", minc=False):
|
|
73
73
|
self.mesh_type = mesh_type
|
|
74
74
|
self.out_format_type = out_format_type
|
|
75
75
|
self.vis_types = vis_types
|
|
@@ -84,7 +84,7 @@ class VisSetting:
|
|
|
84
84
|
self.corners_file = corners_file
|
|
85
85
|
self.debug = debug
|
|
86
86
|
self.eos = eos
|
|
87
|
-
self.minc =
|
|
87
|
+
self.minc = minc
|
|
88
88
|
|
|
89
89
|
|
|
90
90
|
def setBounds(self, x_bounds, y_bounds, z_bounds):
|
|
@@ -129,16 +129,21 @@ class vis_reader:
|
|
|
129
129
|
corners_file = os.path.join(case_dir, config["corners_file"] if "corners_file" in config else "None"),
|
|
130
130
|
debug = config['debug'] if 'debug' in config else False,
|
|
131
131
|
eos = config['EOS'] if 'EOS' in config else "ECO2N",
|
|
132
|
-
|
|
132
|
+
minc = config['MINC'] if 'MINC' in config else False,
|
|
133
133
|
)
|
|
134
134
|
|
|
135
|
+
# check if the project is using MINC
|
|
136
|
+
minc_file = os.path.join(case_dir, 'MINC')
|
|
137
|
+
if os.path.exists(minc_file):
|
|
138
|
+
setting.minc = True
|
|
139
|
+
if minc_file in setting.input_file_paths:
|
|
140
|
+
setting.input_file_paths.remove(minc_file)
|
|
141
|
+
|
|
135
142
|
for input_file_path in setting.input_file_paths:
|
|
136
143
|
if not os.path.exists(input_file_path):
|
|
137
144
|
print(f'Can\'t find input file: ({input_file_path}). please check the path or remove it from the config.json.')
|
|
138
145
|
sys.exit(1)
|
|
139
|
-
|
|
140
|
-
elif input_file_path.endswith('MINC'):
|
|
141
|
-
setting.minc = True
|
|
146
|
+
|
|
142
147
|
for out_file_path in setting.out_file_paths:
|
|
143
148
|
if not os.path.exists(input_file_path):
|
|
144
149
|
print(f'Can\'t find output file: ({out_file_path}). please check the path or remove it from the config.json.')
|
|
@@ -429,92 +434,77 @@ class vis_reader:
|
|
|
429
434
|
self.__write_vtk_file(self.incon_vtk, self.incon_path)
|
|
430
435
|
print(f' ✓ Initial condition file created: {self.incon_path}')
|
|
431
436
|
|
|
437
|
+
|
|
438
|
+
|
|
432
439
|
def __read_TOUGH2_CSV_outfile(self):
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
440
|
+
self.time_steps_list = []
|
|
441
|
+
value_type = ValueType.Unknown
|
|
442
|
+
current_time = None
|
|
443
|
+
buffer = io.StringIO()
|
|
436
444
|
csv_headers = []
|
|
437
445
|
line_number = -1
|
|
438
|
-
reading_number = 0
|
|
439
|
-
value_type = ValueType.Unknown
|
|
440
446
|
start_index = -1
|
|
441
|
-
|
|
447
|
+
def process_chunk():
|
|
448
|
+
"""Define what to do with each flushed chunk."""
|
|
449
|
+
buffer.seek(0)
|
|
450
|
+
df = pd.read_csv(buffer)
|
|
451
|
+
#print(f"Processing time group:\n{df.head()}")
|
|
452
|
+
time_step = VisTimeStep(
|
|
453
|
+
time=float(current_time),
|
|
454
|
+
time_step=len(self.time_steps_list)+1,
|
|
455
|
+
iteration=1
|
|
456
|
+
)
|
|
457
|
+
self.time_steps_list.append(time_step)
|
|
458
|
+
if value_type == ValueType.Scalar:
|
|
459
|
+
self.__write_scalar_result(time_step, df, csv_headers)
|
|
460
|
+
elif value_type == ValueType.Vector:
|
|
461
|
+
self.__write_vector_result(time_step, df, csv_headers)
|
|
462
|
+
|
|
463
|
+
buffer.close()
|
|
464
|
+
|
|
442
465
|
with open(self.current_out_file) as f:
|
|
443
466
|
for line in f:
|
|
444
467
|
line_number = line_number + 1
|
|
445
468
|
values = line.strip().split(',')
|
|
469
|
+
|
|
446
470
|
if line_number == 0:
|
|
447
471
|
csv_headers = [x.strip() for x in values]
|
|
448
472
|
if 'ELEM' in csv_headers and 'INDEX' in csv_headers:
|
|
449
473
|
value_type = ValueType.Scalar
|
|
450
|
-
start_index =
|
|
451
|
-
|
|
474
|
+
start_index = 1 # remove the first item
|
|
475
|
+
|
|
452
476
|
elif 'ELEM1' in csv_headers and 'ELEM2' in csv_headers:
|
|
453
477
|
value_type = ValueType.Vector
|
|
454
478
|
start_index = 4
|
|
455
|
-
|
|
479
|
+
|
|
480
|
+
# remove the first "TIME" header (to reduce the number of columns)
|
|
456
481
|
csv_headers = csv_headers[start_index:]
|
|
457
|
-
|
|
482
|
+
|
|
483
|
+
# Write header once
|
|
484
|
+
buffer.write(','.join(csv_headers) + '\n')
|
|
458
485
|
continue
|
|
459
486
|
|
|
460
|
-
|
|
487
|
+
row_time = self.__parse_float(values[0].strip())
|
|
461
488
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
# when all items in this timestep have been read
|
|
466
|
-
if value_type == ValueType.Scalar and reading_number == self.number_of_elements:
|
|
467
|
-
output_buffer.seek(0)
|
|
468
|
-
df = pd.read_csv(output_buffer, sep=',', header=0)
|
|
469
|
-
|
|
470
|
-
self.__write_scalar_result(
|
|
471
|
-
current_time_step, df, csv_headers)
|
|
472
|
-
output_buffer.flush()
|
|
473
|
-
output_buffer.close()
|
|
474
|
-
output_buffer = io.StringIO()
|
|
475
|
-
reading_number = 0
|
|
476
|
-
if value_type == ValueType.Vector and reading_number == self.number_of_connections:
|
|
477
|
-
output_buffer.seek(0)
|
|
478
|
-
df = pd.read_csv(output_buffer, sep=',', header=0)
|
|
479
|
-
#df.to_csv(os.path.join(self.setting.vis_dir, "timestep.csv"), index=False)
|
|
480
|
-
self.__write_vector_result(
|
|
481
|
-
current_time_step, df, csv_headers)
|
|
482
|
-
output_buffer.flush()
|
|
483
|
-
output_buffer.close()
|
|
484
|
-
output_buffer = io.StringIO()
|
|
485
|
-
reading_number = 0
|
|
489
|
+
if current_time is None:
|
|
490
|
+
current_time = row_time
|
|
486
491
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
)
|
|
492
|
-
|
|
492
|
+
if row_time != current_time:
|
|
493
|
+
# Time changed → flush and reset
|
|
494
|
+
process_chunk()
|
|
495
|
+
buffer = io.StringIO()
|
|
496
|
+
buffer.write(','.join(csv_headers) + '\n') # Write header
|
|
497
|
+
current_time = row_time
|
|
498
|
+
|
|
499
|
+
# Write current row
|
|
500
|
+
buffer.write(','.join(values[start_index:]) + '\n')
|
|
501
|
+
|
|
502
|
+
# Flush the last group
|
|
503
|
+
if buffer.tell() > 0:
|
|
504
|
+
process_chunk()
|
|
505
|
+
|
|
493
506
|
|
|
494
|
-
# Initialize buffer
|
|
495
|
-
header_string = ','.join(csv_headers)
|
|
496
|
-
output_buffer.write(header_string + '\n')
|
|
497
|
-
self.time_steps_list.append(current_time_step)
|
|
498
|
-
tim_step_counter = tim_step_counter + 1
|
|
499
|
-
|
|
500
|
-
output_buffer.write(','.join(values[start_index:]) + '\n')
|
|
501
|
-
reading_number = reading_number + 1
|
|
502
|
-
else:
|
|
503
|
-
output_buffer.write(','.join(values[start_index:]) + '\n')
|
|
504
|
-
reading_number = reading_number + 1
|
|
505
|
-
else:
|
|
506
|
-
# write the last time step
|
|
507
|
-
if value_type == ValueType.Scalar:
|
|
508
|
-
output_buffer.seek(0)
|
|
509
|
-
df = pd.read_csv(output_buffer, sep=',', header=0)
|
|
510
|
-
self.__write_scalar_result(current_time_step, df, csv_headers)
|
|
511
|
-
if value_type == ValueType.Vector:
|
|
512
|
-
output_buffer.seek(0)
|
|
513
|
-
df = pd.read_csv(output_buffer, sep=',', header=0)
|
|
514
|
-
self.__write_vector_result(current_time_step, df, csv_headers)
|
|
515
|
-
output_buffer.close()
|
|
516
507
|
|
|
517
|
-
# TODO: find whick case is TOUGH3
|
|
518
508
|
def __read_TOUGH3_CSV_outfile(self):
|
|
519
509
|
scalar_buffer = io.StringIO()
|
|
520
510
|
current_time_step = None
|
|
@@ -801,7 +791,8 @@ class vis_reader:
|
|
|
801
791
|
|
|
802
792
|
|
|
803
793
|
def __write_scalar_result(self, vis_time_step, dataframe, headers):
|
|
804
|
-
|
|
794
|
+
|
|
795
|
+
|
|
805
796
|
index = self.time_steps_list.index(vis_time_step)
|
|
806
797
|
#vtr_path = os.path.join(self.setting.vis_dir, 'paraview', f'time_step_{vis_time_step.time_step}.vtr')
|
|
807
798
|
|
|
@@ -811,10 +802,6 @@ class vis_reader:
|
|
|
811
802
|
#scalar_vtr = vtkRectilinearGrid()
|
|
812
803
|
|
|
813
804
|
if not os.path.exists(vtr_path):
|
|
814
|
-
#vtr_reader = vtkXMLRectilinearGridReader()
|
|
815
|
-
#vtr_reader.SetFileName(self.main_geometry)
|
|
816
|
-
#vtr_reader.Update()
|
|
817
|
-
#scalar_vtr = vtr_reader.GetOutput()
|
|
818
805
|
scalar_vtr = self.__read_vtk_file(self.main_geometry)
|
|
819
806
|
|
|
820
807
|
# add time step data
|
|
@@ -833,6 +820,17 @@ class vis_reader:
|
|
|
833
820
|
vtr = scalar_vtr
|
|
834
821
|
|
|
835
822
|
variable_list = []
|
|
823
|
+
|
|
824
|
+
# make sure to drop TIME and INDEX columns if they exist
|
|
825
|
+
if 'INDEX' in dataframe.columns:
|
|
826
|
+
dataframe = dataframe.drop(columns=['INDEX'])
|
|
827
|
+
headers.remove('INDEX')
|
|
828
|
+
if 'ELEM' in dataframe.columns:
|
|
829
|
+
# remove leading spaces from ELEM column
|
|
830
|
+
dataframe['ELEM'] = dataframe['ELEM'].str.lstrip()
|
|
831
|
+
headers.remove('ELEM')
|
|
832
|
+
|
|
833
|
+
# create vtkDoubleArray for each header
|
|
836
834
|
for header in headers:
|
|
837
835
|
array = vtkDoubleArray()
|
|
838
836
|
array.SetName(header)
|
|
@@ -840,13 +838,20 @@ class vis_reader:
|
|
|
840
838
|
variable_list.append(VisVariable(header, ValueType.Scalar, 1))
|
|
841
839
|
|
|
842
840
|
|
|
841
|
+
#if self.setting.minc:
|
|
842
|
+
#print(f' MinC is enabled. Adding MinC values to the result.')
|
|
843
|
+
|
|
843
844
|
for i in range(0, vtr.GetNumberOfCells()):
|
|
845
|
+
elemID = self.elemIDArray.GetValue(i)
|
|
844
846
|
index = self.sequence_dist[i]
|
|
847
|
+
if 'ELEM' in dataframe.columns:
|
|
848
|
+
index = dataframe['ELEM'].tolist().index(elemID)
|
|
845
849
|
for header in headers:
|
|
846
|
-
value = float(self.__parse_float(dataframe[header][index]))
|
|
850
|
+
value = float(self.__parse_float(dataframe[header].iloc[index]))
|
|
847
851
|
vtr.GetCellData().GetArray(header).InsertNextValue(value)
|
|
848
852
|
|
|
849
853
|
|
|
854
|
+
|
|
850
855
|
# update the variable list
|
|
851
856
|
if self.current_out_file not in self.variable_list:
|
|
852
857
|
self.variable_list[self.current_out_file] = variable_list
|
|
@@ -910,6 +915,7 @@ class vis_reader:
|
|
|
910
915
|
# Other data
|
|
911
916
|
for header in headers:
|
|
912
917
|
array = vtr.GetCellData().GetArray(header)
|
|
918
|
+
|
|
913
919
|
for e in range(0, vtr.GetNumberOfCells()):
|
|
914
920
|
file.write(str(array.GetValue(e)) + " ")
|
|
915
921
|
file.write(" \n")
|
|
@@ -1152,6 +1158,8 @@ class vis_reader:
|
|
|
1152
1158
|
matArray.InsertNextValue(elem_df['MA12'][i])
|
|
1153
1159
|
matIDArray.InsertNextValue(mat_mapping[elem_df['MA12'][i]])
|
|
1154
1160
|
pmxArray.InsertNextValue(self.__parse_float(elem_df['PMX'][i]))
|
|
1161
|
+
|
|
1162
|
+
self.elemIDArray = elemIDArray
|
|
1155
1163
|
|
|
1156
1164
|
'''
|
|
1157
1165
|
compute permeability
|
|
@@ -1275,7 +1283,7 @@ class vis_reader:
|
|
|
1275
1283
|
|
|
1276
1284
|
d1_array = elem_conne_vtu.GetCellData().GetArray('D1')
|
|
1277
1285
|
d2_array = elem_conne_vtu.GetCellData().GetArray('D2')
|
|
1278
|
-
elemIDArray = elem_conne_vtu.GetPointData().GetArray('ELEME')
|
|
1286
|
+
#elemIDArray = elem_conne_vtu.GetPointData().GetArray('ELEME')
|
|
1279
1287
|
volxArray = elem_conne_vtu.GetPointData().GetArray('VOLX')
|
|
1280
1288
|
matArray = elem_conne_vtu.GetPointData().GetArray('Material')
|
|
1281
1289
|
matIDArray = elem_conne_vtu.GetPointData().GetArray('Material_ID')
|
|
@@ -1496,7 +1504,7 @@ class vis_reader:
|
|
|
1496
1504
|
rGrid.SetXCoordinates(xyz_coords_array[0])
|
|
1497
1505
|
rGrid.SetYCoordinates(xyz_coords_array[1])
|
|
1498
1506
|
rGrid.SetZCoordinates(xyz_coords_array[2])
|
|
1499
|
-
rGrid.GetCellData().AddArray(elemIDArray)
|
|
1507
|
+
rGrid.GetCellData().AddArray(self.elemIDArray)
|
|
1500
1508
|
rGrid.GetCellData().AddArray(volxArray)
|
|
1501
1509
|
rGrid.GetCellData().AddArray(matArray)
|
|
1502
1510
|
|
|
@@ -1535,7 +1543,7 @@ class vis_reader:
|
|
|
1535
1543
|
vts_points.InsertNextPoint(x, y, z_value)
|
|
1536
1544
|
|
|
1537
1545
|
vts.SetPoints(vts_points)
|
|
1538
|
-
vts.GetCellData().AddArray(elemIDArray)
|
|
1546
|
+
vts.GetCellData().AddArray(self.elemIDArray)
|
|
1539
1547
|
vts.GetCellData().AddArray(volxArray)
|
|
1540
1548
|
vts.GetCellData().AddArray(matArray)
|
|
1541
1549
|
|
|
@@ -1584,7 +1592,7 @@ class vis_reader:
|
|
|
1584
1592
|
# TODO: compute mesh quality and fix bad cells
|
|
1585
1593
|
|
|
1586
1594
|
|
|
1587
|
-
auto_corner_vtu.GetCellData().AddArray(elemIDArray)
|
|
1595
|
+
auto_corner_vtu.GetCellData().AddArray(self.elemIDArray)
|
|
1588
1596
|
auto_corner_vtu.GetCellData().AddArray(volxArray)
|
|
1589
1597
|
auto_corner_vtu.GetCellData().AddArray(matArray)
|
|
1590
1598
|
if self.rock_dict is not None:
|
|
@@ -1923,13 +1931,13 @@ class vis_reader:
|
|
|
1923
1931
|
main_geometray.InsertNextCell(VTK_POLYHEDRON, polyhedron_faces_idlist)
|
|
1924
1932
|
|
|
1925
1933
|
|
|
1926
|
-
main_geometray.GetCellData().AddArray(elemIDArray)
|
|
1934
|
+
main_geometray.GetCellData().AddArray(self.elemIDArray)
|
|
1927
1935
|
main_geometray.GetCellData().AddArray(volxArray)
|
|
1928
1936
|
main_geometray.GetCellData().AddArray(matArray)
|
|
1929
1937
|
if self.rock_dict is not None:
|
|
1930
1938
|
main_geometray.GetCellData().AddArray(per_array)
|
|
1931
1939
|
main_geometray.GetCellData().AddArray(sgr_array)
|
|
1932
|
-
|
|
1940
|
+
|
|
1933
1941
|
main_geometray.GetCellData().AddArray(matIDArray)
|
|
1934
1942
|
main_geometray.GetCellData().AddArray(horizon_id_array)
|
|
1935
1943
|
self.main_geometry = os.path.join(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|