1+ """Dat file visualization."""
2+
13import lnmmeshio
24import numpy as np
35import os
1214
1315
1416def convert_to_vtu (dat_file_path , temp_dir ):
15- # This function converts a given dat file into a corresponding vtu file
16- # Input:
17- # dat_file_path: string: full path to the dat file to be converted
18- # Output:
19- # vtu_file_path: full path of the converted file
17+ """Convert dat file to vtu.
18+
19+ Args:
20+ dat_file_path (str, Path): Path to dat file
21+ temp_dir (str, Path): Temp directory
2022
23+ Returns:
24+ str: Path to vtu file
25+ """
2126 # define the vtu_file_path to have the same name as the dat file, but the its directory is in './temp_files'
2227 vtu_file_path = str (
2328 Path (temp_dir ) / f"{ os .path .splitext (os .path .basename (dat_file_path ))[0 ]} .vtu"
@@ -36,6 +41,14 @@ def convert_to_vtu(dat_file_path, temp_dir):
3641
3742
3843def function_plot_figure (state_data ):
44+ """Get function plot figure.
45+
46+ Args:
47+ state_data (trame_server.core.Server): Trame server state
48+
49+ Returns:
50+ plotly.graph_objects._figure.Figure: Figure to be plotted
51+ """
3952 num_of_time_points = 1000 # number of discrete time points used for plotting
4053 data = {
4154 "t" : np .linspace (0 , state_data .MAX_TIME , num_of_time_points ),
@@ -66,11 +79,14 @@ def function_plot_figure(state_data):
6679
6780
6881def return_function_from_funct_string (funct_string ):
69- # The function takes in the value of the funct string coming from a function and returns the parsed function
70- # Input:
71- # funct_string: string of the function, containing the variables t, x, y, z
72- # Output:
73- # return_funct: function of the mentioned arguments
82+ """Create function from funct string.
83+
84+ Args:
85+ funct_string (str): Funct definition
86+
87+ Returns:
88+ callable: callable function of x, y, z, t
89+ """
7490
7591 def funct_using_eval (x , y , z , t ):
7692 # defined functions to be replaced: <def_funct> becomes <np.funct>
@@ -101,7 +117,14 @@ def funct_using_eval(x, y, z, t):
101117 return np .frompyfunc (funct_using_eval , 4 , 1 )
102118
103119
104- def to_vtu (dis , vtu_file : str , override = True , ascii = False ):
120+ def to_vtu (dis , vtu_file : str , override = True ):
121+ """Discretization to vtu.
122+
123+ Args:
124+ dis (lnmmeshio.Discretization): Discretization object
125+ vtu_file (str): Path to vtu file
126+ override (bool, optional): Overwrite existing file. Defaults to True
127+ """
105128 add_dat_file_data_to_dis (dis )
106129
107130 # write case file
@@ -111,12 +134,3 @@ def to_vtu(dis, vtu_file: str, override=True, ascii=False):
111134 file_format = "vtu" ,
112135 override = override ,
113136 )
114-
115-
116- def validate_vtu_file_path (vtu_file_path ):
117- # Validate the file path: file has to exist and end with ".vtu"
118- if not vtu_file_path .endswith (".dat" ):
119- raise Exception ("Provided file does not end with .dat!" )
120-
121- if not os .path .exists (vtu_file_path ):
122- raise Exception ("Provided file does not exist!" )
0 commit comments