case = SliceProperties(time=time, casedir=casedir, casename=casename, rot_z=rot_z, result_folder=result_folder) # Read slices and store them in case.slice_* dict case.readSlices(properties=property, slicenames=slicenames, slicenames_sub=slicenames_sub) # Initialize lists to store multiple slices coor and value data list_x, list_y, list_z = [], [], [] list_rgb, list_bij, list_rij = [], [], [] # Go through specified slices for i, slicename in enumerate(case.slicenames): """ Process Uninterpolated Anisotropy Tensor """ # Retrieve Rij of this slice rij = case.slices_val[slicename] rij = expandSymmetricTensor(rij).reshape((-1, 3, 3)) # Rotate Rij if requested, rotateData only accept full matrix form if rotate_data: rij = rotateData(rij, anglez=rot_z) rij = contractSymmetricTensor(rij) rij_tmp = rij.copy() # Get bij from Rij and its corresponding eigenval and eigenvec bij, eig_val, eig_vec = processReynoldsStress(rij_tmp, realization_iter=0, make_anisotropic=make_anisotropic, to_old_grid_shape=False) # bij was (n_samples, 3, 3) contract it bij = contractSymmetricTensor(bij) # Get barycentric map coor and normalized RGB xy_bary, rgb = getBarycentricMapData(eig_val, c_offset=c_offset, c_exp=c_exp) """ Interpolation """ # 1st coor is always x not matter vertical or horizontal slice # 2nd coor is y if horizontal slice otherwise z, take appropriate confinebox limit
# Remove NaN predictions if bij_novelty == 'excl': print( "Since bij_novelty is 'excl', removing NaN and making y_pred_test realizable..." ) nan_mask = np.isnan(y_pred_test).any(axis=1) ccx_test = ccx_test[~nan_mask] ccy_test = ccy_test[~nan_mask] ccz_test = ccz_test[~nan_mask] y_pred_test = y_pred_test[~nan_mask] for _ in range(2): y_pred_test = makeRealizable(y_pred_test) # Rotate field y_pred_test = expandSymmetricTensor(y_pred_test).reshape((-1, 3, 3)) y_pred_test = rotateData(y_pred_test, anglez=fieldrot) y_pred_test = contractSymmetricTensor(y_pred_test) t1 = t.time() print('\nFinished bij prediction in {:.4f} s'.format(t1 - t0)) """ Postprocess Machine Learning Predictions """ # Filter the result if requested. # This requires: # 1. Remove any component outside bound and set to NaN # 2. Interpolate to 2D slice mesh grid with nearest method # 3. Use 2D Gaussian filter to smooth the mesh grid while ignoring NaN, for every component # 4. Make whatever between bound and limits realizable if filter: cc2_test = ccz_test if slicedir == 'vertical' else ccy_test ccx_test_mesh, cc2_test_mesh, _, y_predtest_mesh = fieldSpatialSmoothing(
# Remove NaN predictions if bij_novelty == 'excl': print( "Since bij_novelty is 'excl', removing NaN and making y_pred realizable..." ) nan_mask = np.isnan(y_pred).any(axis=1) ccx_test = ccx_test[~nan_mask] ccy_test = ccy_test[~nan_mask] ccz_test = ccz_test[~nan_mask] y_pred = y_pred[~nan_mask] for _ in range(2): y_pred = makeRealizable(y_pred) # Rotate field y_pred = expandSymmetricTensor(y_pred).reshape((-1, 3, 3)) y_pred = rotateData(y_pred, anglez=fieldrot) y_pred = contractSymmetricTensor(y_pred) t1 = t.time() print('\nFinished bij prediction in {:.4f} s'.format(t1 - t0)) """ Postprocess Machine Learning Predictions """ # Filter the result if requested. # This requires: # 1. Remove any component outside bound and set to NaN # 2. Interpolate to 2D slice mesh grid with nearest method # 3. Use 2D Gaussian filter to smooth the mesh grid while ignoring NaN, for every component # 4. Make whatever between bound and limits realizable if filter: cc2_test = ccz_test if slicedir == 'vertical' else ccy_test ccx_test_mesh, cc2_test_mesh, _, y_pred_mesh = fieldSpatialSmoothing(