From 03b3ef31b1c78f3ae14bac9182f38452a1b9e405 Mon Sep 17 00:00:00 2001 From: Lalit Rajendran Date: Tue, 6 Apr 2021 17:14:02 -0400 Subject: [PATCH] added lines to handle tracking displacements --- sample_script.py | 167 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 153 insertions(+), 14 deletions(-) diff --git a/sample_script.py b/sample_script.py index 5164d82..ae6324c 100755 --- a/sample_script.py +++ b/sample_script.py @@ -5,8 +5,6 @@ import matplotlib # matplotlib.use('Agg') import matplotlib.pyplot as plt -import sys -import os from scipy.io import savemat from scipy.io import loadmat import timeit @@ -15,7 +13,6 @@ from DensityIntegrationUncertaintyQuantification import Density_integration_Poisson_uncertainty from DensityIntegrationUncertaintyQuantification import Density_integration_WLS_uncertainty -# import helper functions import loadmat_functions def plot_figures(X, Y, rho_x, rho_y, rho, sigma_rho): @@ -211,7 +208,7 @@ def create_mask(nr, nc, Eval): return mask -def load_displacements(filename, displacement_uncertainty_method): +def load_displacements_correlation(filename, displacement_uncertainty_method): """ Function to load the displacements from Prana processing @@ -252,17 +249,151 @@ def load_displacements(filename, displacement_uncertainty_method): return X_pix, Y_pix, U, V, sigma_U, sigma_V, Eval +def grid_PTV_velocity_uncertainty_2D(Xn, Yn, fluid_mask, xp, yp, up, vp, up_unc, vp_unc, N_avg=3, dist_epsilon=1e-6): + # This function maps the velocity and its uncertainty from PTV data (on unstructured particle locations) to + # a predefined Cartesian grid using inverse-distance based weighted average. + # Inputs: + # Xn, Yn: 2d array specifying the Cartesian grid. + # fluid_mask: 2d array of a binary mask specifying the flow region. The particle data will be interpolated only onto the grid points with fluid_mask==True + # xp, yp: 1d array of particle locations. + # up, vp: 1d array of particle velocity values. + # up_unc, vp_unc: 1d array of paticle velocity uncertainty (std). + # N_avg: the number of particle data points used to determine the velocity for each grid point. + # dist_epsilon: the minimum distance allowed for setting up the weights (to avoid signularity). + # Outputs: + # Un, Vn: the 3d arrays of velocity on grid. + # Un_unc, Vn_unc: 3d arrays of velocity uncertainty on grid. + # Cov_u, Cov_v: the sparse matrices of covariance matrices of interpolated velocity. + + Ny,Nx = np.shape(Xn) + + j,i = np.where(fluid_mask==True) + Npts = len(j) + Np = len(xp) + + # Setup the linear operator to map the p velocity to grid using inverse distance based average + Map_M = scysparse.csr_matrix((Npts,Np),dtype=np.float) + for ct_pt in range(Npts): + x_grid = Xn[j[ct_pt],i[ct_pt]] + y_grid = Yn[j[ct_pt],i[ct_pt]] + # find closest particles for linear interpolation. + dist = ((xp - x_grid)**2 + (yp - y_grid)**2)**0.5 + dist[dist