read_mercury_cg Namespace Reference

Functions

def mercury_cg (name='Chain.stat', print_summary=True, row_major_index_order=False)
 This function reads a MercuryCG .stat file and returns a dictionary of the data. More...
 
def get_raw_data (name)
 This function reads raw data from a file. More...
 
def get_dimension (data, raw, row_major_index_order)
 This function determines the dimension of the data. More...
 
def get_coordinates (data, raw, dim, row_major_index_order)
 This function gets the spatial coordinates and time of the data. More...
 
def get_variables (data, raw, names, dim, row_major_index_order)
 This function gets the variables of the data from the .stat file. More...
 
def extend_variables (data)
 This function extends the variables of the data dictionary by computing several fields from the standard fields. More...
 
def read_header1 (header1)
 Parse the first header line of the input file. More...
 

Variables

string required_pandas_version = "1.2.0"
 
string required_numpy_version = "1.20.0"
 
 installed_pandas_version = pd.__version__
 
 installed_numpy_version = np.__version__
 

Function Documentation

◆ extend_variables()

def read_mercury_cg.extend_variables (   data)

This function extends the variables of the data dictionary by computing several fields from the standard fields.

Parameters
[in,out]dataThe data dictionary to extend the variables of.
Returns
data: A dictionary with the data with possible extended variables computed from the standard variables.
237 def extend_variables(data):
238  """!
239  @brief This function extends the variables of the data dictionary by computing several fields from the standard
240  fields.
241 
242  @param[in,out] data
243  The data dictionary to extend the variables of.
244 
245  @return data:
246  A dictionary with the data with possible extended variables computed from the standard variables.
247  """
248  if 'ParticleSize0' in data:
249  data['ParticleNumber'] = data['ParticleSize0']
250  mean = data['ParticleSize1'] / data['ParticleNumber']
251  mom2 = data['ParticleSize2'] / data['ParticleNumber']
252  mom3 = data['ParticleSize3'] / data['ParticleNumber']
253  mom4 = data['ParticleSize4'] / data['ParticleNumber']
254  mom5 = data['ParticleSize5'] / data['ParticleNumber']
255  mom5 = mom5 - 5 * mean * mom4 + 10 * mean ** 2 * mom3 - 10 * mean ** 3 * mom2 + 4 * mean ** 5
256  mom4 = mom4 - 4 * mean * mom3 + 6 * mean ** 2 * mom2 - 3 * mean ** 4
257  mom3 = mom3 - 3 * mean * mom2 + 2 * mean ** 3
258  mom2 = mom2 - mean ** 2
259  std = np.sqrt(mom2)
260  data['ParticleSize'] = {'Mean': mean, 'Variance': mom2, 'Skewness': mom3 / std ** 3,
261  'Kurtosis': mom4 / std ** 4, 'Hyperskewness': mom5 / std ** 5}
262 
263  if 'Density' in data:
264  data['VelocityX'] = data['MomentumX'] / data['Density']
265  data['VelocityY'] = data['MomentumY'] / data['Density']
266  data['VelocityZ'] = data['MomentumZ'] / data['Density']
267  data['VelocityX'][data['Density'] == 0] = 0
268  data['VelocityY'][data['Density'] == 0] = 0
269  data['VelocityZ'][data['Density'] == 0] = 0
270  data['KineticStressXX'] = data['MomentumFluxXX'] - data['MomentumX'] * data['VelocityX']
271  data['KineticStressXY'] = data['MomentumFluxXY'] - data['MomentumX'] * data['VelocityY']
272  data['KineticStressXZ'] = data['MomentumFluxXZ'] - data['MomentumX'] * data['VelocityZ']
273  data['KineticStressYY'] = data['MomentumFluxYY'] - data['MomentumY'] * data['VelocityY']
274  data['KineticStressYZ'] = data['MomentumFluxYZ'] - data['MomentumY'] * data['VelocityZ']
275  data['KineticStressZZ'] = data['MomentumFluxZZ'] - data['MomentumZ'] * data['VelocityZ']
276  data['StressXX'] = data['ContactStressXX'] + data['KineticStressXX']
277  data['StressXY'] = data['ContactStressXY'] + data['KineticStressXY']
278  data['StressXZ'] = data['ContactStressXZ'] + data['KineticStressXZ']
279  data['StressYX'] = data['ContactStressYX'] + data['KineticStressXY']
280  data['StressYY'] = data['ContactStressYY'] + data['KineticStressYY']
281  data['StressYZ'] = data['ContactStressYZ'] + data['KineticStressYZ']
282  data['StressZX'] = data['ContactStressZX'] + data['KineticStressXZ']
283  data['StressZY'] = data['ContactStressZY'] + data['KineticStressYZ']
284  data['StressZZ'] = data['ContactStressZZ'] + data['KineticStressZZ']
285  data['ContactPressure'] = (data['ContactStressXX'] + data['ContactStressYY'] + data['ContactStressZZ']) / 3
286  data['KineticPressure'] = (data['KineticStressXX'] + data['KineticStressYY'] + data['KineticStressZZ']) / 3
287  data['FluctuatingKineticEnergy'] = data['KineticStressXX'] + data['KineticStressYY'] + data['KineticStressZZ']
288  data['KineticEnergy'] = data['MomentumFluxXX'] + data['MomentumFluxYY'] + data['MomentumFluxZZ']
289  data['Pressure'] = (data['StressXX'] + data['StressYY'] + data['StressZZ']) / 3
290  data['Temperature'] = data['KineticPressure'] / data['Density']
291  return data
292 
293 
def extend_variables(data)
This function extends the variables of the data dictionary by computing several fields from the stand...
Definition: read_mercury_cg.py:237

Referenced by mercury_cg().

◆ get_coordinates()

def read_mercury_cg.get_coordinates (   data,
  raw,
  dim,
  row_major_index_order 
)

This function gets the spatial coordinates and time of the data.

This function extracts the spatial coordinates and time from the raw data and adds them to the data dictionary.

Parameters
[in,out]dataA dictionary where the keys are the variable names and the values are numpy arrays of the data.
[in]rawA pandas DataFrame containing the raw data.
[in]dimA list representing the dimension of the data for spatial coordinates and time if applicable.
[in]row_major_index_orderA boolean value indicating whether the index order is row major. If True, the index order is xyz, otherwise it is zyx.
Returns
data: The data dictionary updated with the spatial coordinates and time if applicable.
136 def get_coordinates(data, raw, dim, row_major_index_order):
137  """!
138  @brief This function gets the spatial coordinates and time of the data.
139  @details This function extracts the spatial coordinates and time from the raw data and adds them to the data
140  dictionary.
141 
142  @param[in,out] data
143  A dictionary where the keys are the variable names and the values are numpy arrays of the data.
144 
145  @param[in] raw
146  A pandas DataFrame containing the raw data.
147 
148  @param[in] dim
149  A list representing the dimension of the data for spatial coordinates and time if applicable.
150 
151  @param[in] row_major_index_order
152  A boolean value indicating whether the index order is row major. If True, the index order is xyz, otherwise it is
153  zyx.
154 
155  @return data:
156  The data dictionary updated with the spatial coordinates and time if applicable.
157  """
158 
159  order = "C" if row_major_index_order else "F"
160  data['t'] = np.reshape(raw.values[:, 0], dim, order=order)
161  coord = 'xyz'
162  coord = ''.join(c for c, n in zip(coord, data['n']) if n != 1)
163  for i in range(len(coord)):
164  data[coord[i]] = np.reshape(raw.values[:, i + 1], dim, order=order)
165  return data
166 
167 
def get_coordinates(data, raw, dim, row_major_index_order)
This function gets the spatial coordinates and time of the data.
Definition: read_mercury_cg.py:136

Referenced by mercury_cg().

◆ get_dimension()

def read_mercury_cg.get_dimension (   data,
  raw,
  row_major_index_order 
)

This function determines the dimension of the data.

This function calculates the dimension of the data based on the number of data points and the row major index order.

Parameters
[in]dataA dictionary where the keys are the variable names and the values are numpy arrays of the data.
[in]rawA pandas DataFrame containing the raw data.
[in]row_major_index_orderA boolean value indicating whether the index order is row major. If True, the index order is xyz, otherwise it is zyx.
Returns
dim: A list representing the dimension of the data for spatial coordinates and time if applicable.
107 def get_dimension(data, raw, row_major_index_order):
108  """!
109  @brief This function determines the dimension of the data.
110  @details This function calculates the dimension of the data based on the number of data points and the row major
111  index order.
112 
113  @param[in] data
114  A dictionary where the keys are the variable names and the values are numpy arrays of the data.
115 
116  @param[in] raw
117  A pandas DataFrame containing the raw data.
118 
119  @param[in] row_major_index_order
120  A boolean value indicating whether the index order is row major. If True, the index order is xyz, otherwise it is
121  zyx.
122 
123  @return dim:
124  A list representing the dimension of the data for spatial coordinates and time if applicable.
125  """
126 
127  if row_major_index_order:
128  dim = data['n'] + [int(len(raw) / np.prod(data['n']))]
129  else:
130  dim = list(reversed(data['n'])) + [int(len(raw) / np.prod(data['n']))]
131  dim = [d for d in dim if d != 1]
132  dim.append(1) if not dim else None
133  return dim
134 
135 
return int(ret)+1
def get_dimension(data, raw, row_major_index_order)
This function determines the dimension of the data.
Definition: read_mercury_cg.py:107

References int().

Referenced by mercury_cg().

◆ get_raw_data()

def read_mercury_cg.get_raw_data (   name)

This function reads raw data from a file.

This function reads raw data from a file and returns the raw data and the headers.

Parameters
[in]nameThe name of the file to read from.
Returns
raw, header1, header2: The raw data of the .stat file, first header with the MercuryCG parameters, and second header with field names.
78 def get_raw_data(name):
79  """!
80  @brief This function reads raw data from a file.
81  @details This function reads raw data from a file and returns the raw data and the headers.
82 
83  @param[in] name
84  The name of the file to read from.
85 
86  @return raw, header1, header2:
87  The raw data of the .stat file, first header with the MercuryCG parameters, and second header with field names.
88  """
89 
90  with open(name, 'r') as file:
91  lines = file.readlines()
92 
93  # Extract headers
94  header1 = lines[0].strip()
95  if len(lines) > 1:
96  header2 = lines[1].strip().split()
97  else:
98  header2 = None
99 
100  # Read data
101  data_lines = lines[2:]
102  raw = pd.DataFrame([(float(x) for x in line.strip().split()) for line in data_lines])
103 
104  return raw, header1, header2
105 
106 
void split(const DoubleVector &in_vector, Vector< DoubleVector * > &out_vector_pt)
Definition: double_vector.cc:1413
def get_raw_data(name)
This function reads raw data from a file.
Definition: read_mercury_cg.py:78

References oomph::DoubleVectorHelpers.split().

Referenced by mercury_cg().

◆ get_variables()

def read_mercury_cg.get_variables (   data,
  raw,
  names,
  dim,
  row_major_index_order 
)

This function gets the variables of the data from the .stat file.

This function extracts the variables from the raw data and adds them to the data dictionary.

Parameters
[in]dataA dictionary where the keys are the variable names and the values are numpy arrays of the data.
[in]rawA pandas DataFrame containing the raw data.
[in]namesA list of strings representing the field names of the input from a MercuryCG .stat file.
[in]dimA list representing the dimension of the data for spatial coordinates and time if applicable.
[in]row_major_index_orderA boolean value indicating whether the index order is row major. If True, the index order is xyz, otherwise it is zyx.
Returns
data: The data dictionary updated with the variables as new keys of the dictionary.
168 def get_variables(data, raw, names, dim, row_major_index_order):
169  """!
170  @brief This function gets the variables of the data from the .stat file.
171  @details This function extracts the variables from the raw data and adds them to the data dictionary.
172 
173  @param[in] data
174  A dictionary where the keys are the variable names and the values are numpy arrays of the data.
175 
176  @param[in] raw
177  A pandas DataFrame containing the raw data.
178 
179  @param[in] names
180  A list of strings representing the field names of the input from a MercuryCG .stat file.
181 
182  @param[in] dim
183  A list representing the dimension of the data for spatial coordinates and time if applicable.
184 
185  @param[in] row_major_index_order
186  A boolean value indicating whether the index order is row major. If True, the index order is xyz, otherwise it is
187  zyx.
188 
189  @return data:
190  The data dictionary updated with the variables as new keys of the dictionary.
191  """
192 
193  order = "C" if row_major_index_order else "F"
194  is_variable = [':' in name for name in names]
195  for i in range(len(names)):
196  if is_variable[i]:
197  colon = names[i].find(':')
198  hyphen = names[i].find('-')
199  # if no hyphen is found
200  if hyphen == -1:
201  a = np.NaN
202  b = np.NaN
203  else:
204  a = int(names[i][:hyphen])
205  b = int(names[i][hyphen + 1:colon])
206  n = names[i][colon + 1:]
207  if hyphen == -1:
208  a = int(names[i][:colon])
209  data[n] = np.reshape(raw.values[:, a - 1], dim, order=order)
210  elif b - a == 2:
211  data[n + 'X'] = np.reshape(raw.values[:, a - 1], dim, order=order)
212  data[n + 'Y'] = np.reshape(raw.values[:, a], dim, order=order)
213  data[n + 'Z'] = np.reshape(raw.values[:, a + 1], dim, order=order)
214  elif b - a == 5 and n != 'ParticleSize':
215  data[n + 'XX'] = np.reshape(raw.values[:, a - 1], dim, order=order)
216  data[n + 'XY'] = np.reshape(raw.values[:, a], dim, order=order)
217  data[n + 'XZ'] = np.reshape(raw.values[:, a + 1], dim, order=order)
218  data[n + 'YY'] = np.reshape(raw.values[:, a + 2], dim, order=order)
219  data[n + 'YZ'] = np.reshape(raw.values[:, a + 3], dim, order=order)
220  data[n + 'ZZ'] = np.reshape(raw.values[:, a + 4], dim, order=order)
221  elif b - a == 8:
222  data[n + 'XX'] = np.reshape(raw.values[:, a - 1], dim, order=order)
223  data[n + 'XY'] = np.reshape(raw.values[:, a], dim, order=order)
224  data[n + 'XZ'] = np.reshape(raw.values[:, a + 1], dim, order=order)
225  data[n + 'YX'] = np.reshape(raw.values[:, a + 2], dim, order=order)
226  data[n + 'YY'] = np.reshape(raw.values[:, a + 3], dim, order=order)
227  data[n + 'YZ'] = np.reshape(raw.values[:, a + 4], dim, order=order)
228  data[n + 'ZX'] = np.reshape(raw.values[:, a + 5], dim, order=order)
229  data[n + 'ZY'] = np.reshape(raw.values[:, a + 6], dim, order=order)
230  data[n + 'ZZ'] = np.reshape(raw.values[:, a + 7], dim, order=order)
231  else:
232  for j in range(a, b + 1):
233  data[n + str(j - a)] = np.reshape(raw.values[:, j - 1], dim, order=order)
234  return data
235 
236 
str
Definition: compute_granudrum_aor.py:141
def get_variables(data, raw, names, dim, row_major_index_order)
This function gets the variables of the data from the .stat file.
Definition: read_mercury_cg.py:168

References int(), and compute_granudrum_aor.str.

Referenced by mercury_cg().

◆ mercury_cg()

def read_mercury_cg.mercury_cg (   name = 'Chain.stat',
  print_summary = True,
  row_major_index_order = False 
)

This function reads a MercuryCG .stat file and returns a dictionary of the data.

This function reads a MercuryCG .stat file, processes the data, and returns a dictionary of the data. The dictionary keys are the variable names and the values are numpy arrays of the data.

Parameters
[in]nameThe name of the .stat file created by MercuryCG to read from. Default is 'Chain.stat'.
[in]print_summaryIf True, print a summary of the data key shapes. Default is True.
[in]row_major_index_orderIf True, the index order for spatial coordinates is xyz, otherwise it is zyx. Default is False.
Returns
data: A dictionary where the keys are the variable names and the values are numpy arrays of the data.
40 def mercury_cg(name='Chain.stat', print_summary=True, row_major_index_order=False):
41  """!
42  @brief This function reads a MercuryCG .stat file and returns a dictionary of the data.
43  @details This function reads a MercuryCG .stat file, processes the data, and returns a dictionary of the data.
44  The dictionary keys are the variable names and the values are numpy arrays of the data.
45 
46  @param[in] name
47  The name of the .stat file created by MercuryCG to read from. Default is 'Chain.stat'.
48 
49  @param[in] print_summary
50  If True, print a summary of the data key shapes. Default is True.
51 
52  @param[in] row_major_index_order
53  If True, the index order for spatial coordinates is xyz, otherwise it is zyx. Default is False.
54 
55  @return data:
56  A dictionary where the keys are the variable names and the values are numpy arrays of the data.
57  """
58 
59  # ignore division by zero errors. Division by zero values will be set to NaN.
60  # This line is just to suppress the error in the terminal
61  np.seterr(divide='ignore', invalid='ignore')
62 
63  raw, header1, header2 = get_raw_data(name)
64  data = read_header1(header1)
65  data['name'] = name
66  print(name)
67  print(header1)
68  dim = get_dimension(data, raw, row_major_index_order)
69  data = get_coordinates(data, raw, dim, row_major_index_order)
70  data = get_variables(data, raw, header2, dim, row_major_index_order)
71  data = extend_variables(data)
72  if print_summary:
73  for key, value in data.items():
74  print(f"{key}: {np.array(value).shape}")
75  return data
76 
77 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet print(const Packet &a)
Definition: GenericPacketMath.h:1166
def read_header1(header1)
Parse the first header line of the input file.
Definition: read_mercury_cg.py:294
def mercury_cg(name='Chain.stat', print_summary=True, row_major_index_order=False)
This function reads a MercuryCG .stat file and returns a dictionary of the data.
Definition: read_mercury_cg.py:40

References extend_variables(), get_coordinates(), get_dimension(), get_raw_data(), get_variables(), Eigen::internal.print(), and read_header1().

Referenced by compute_granudrum_aor.compute_granudrum_aor().

◆ read_header1()

def read_mercury_cg.read_header1 (   header1)

Parse the first header line of the input file.

This function takes the first header line of the input file, splits it into separate words, and extracts the values associated with certain keys. The keys it looks for are 'n', 'width', 'timeMin', 'min', and 'max'. The values associated with these keys are then converted to floats and stored in a dictionary.

Parameters
[in]header1A string of the first header line of the input file.
Returns
data: A dictionary where the keys are the keys found in the header line and the values are lists of floats associated with these keys. If a key is not found in the header line, its value in the dictionary is an empty list.
294 def read_header1(header1):
295  """!
296  @brief Parse the first header line of the input file.
297  @details This function takes the first header line of the input file, splits it into
298  separate words, and extracts the values associated with certain keys. The keys
299  it looks for are 'n', 'width', 'timeMin', 'min', and 'max'. The values associated
300  with these keys are then converted to floats and stored in a dictionary.
301 
302  @param[in] header1
303  A string of the first header line of the input file.
304 
305  @return data:
306  A dictionary where the keys are the keys found in the header line and the
307  values are lists of floats associated with these keys. If a key is not found
308  in the header line, its value in the dictionary is an empty list.
309  """
310 
311  opt = header1.split()
312  keys = ['n', 'width', 'timeMin', 'min', 'max']
313  key_to_num_values = {'n': 3, 'width': 1, 'timeMin': 1, 'min': 3, 'max': 3}
314  # List comprehension to get all the values that exist in the header
315  values = [[float(opt[opt.index(key) + i]) for i in range(1, key_to_num_values[key] + 1)] if
316  key in opt else [] for key in keys]
317 
318  data = {key: value if key in opt else [] for key, value in zip(keys, values)}
319  data['n'] = [int(n) for n in data['n']]
320  return data

References int().

Referenced by mercury_cg().

Variable Documentation

◆ installed_numpy_version

read_mercury_cg.installed_numpy_version = np.__version__

◆ installed_pandas_version

read_mercury_cg.installed_pandas_version = pd.__version__

◆ required_numpy_version

string read_mercury_cg.required_numpy_version = "1.20.0"

◆ required_pandas_version

string read_mercury_cg.required_pandas_version = "1.2.0"