def mrtm_k2p(tac, dt, inputf1, k2p, linear_phase_start, linear_phase_end, fig, fig_name): if linear_phase_start is None: linear_phase_start = 0 if linear_phase_end is None: linear_phase_end = np.amax(dt) mft = kt.dt2mft(dt) mft = np.append(0, mft) dt_new = np.array([mft[:-1], mft[1:]]) tdur = kt.dt2tdur(dt_new) input_dt = kt.int2dt(inputf1,dt) tac = np.append(0, tac) input_dt = np.append(0, input_dt) tac_cum = np.cumsum((tac[:-1] + tac[1:]) / 2 * tdur) input_cum = np.cumsum((input_dt[:-1] + input_dt[1:]) / 2 * tdur) tac = tac[1:] input_dt = input_dt[1:] yy = tac xx = np.column_stack((input_cum + 1 / k2p * input_dt, tac_cum)) tt = np.logical_and(mft > linear_phase_start, mft < linear_phase_end) tt = tt[1:] mft = mft[1:] reg = LinearRegression(fit_intercept=False).fit(xx[tt, ], yy[tt]) bp = - reg.coef_[0]/reg.coef_[1] - 1 yyf = reg.predict(xx) if fig: plt.cla() plt.plot(mft, yy, '.') plt.plot(mft, yyf, 'r') if fig_name is not None: plt.savefig(fig_name) plt.show() kps = {'bp': bp} return kps
def mrtm(tac, dt, inputf1, linear_phase_start, linear_phase_end, fig): if linear_phase_start is None: linear_phase_start = 0 if linear_phase_end is None: linear_phase_end = np.amax(dt) mft = kt.dt2mft(dt) mft = np.append(0, mft) dt_new = np.array([mft[:-1], mft[1:]]) tdur = kt.dt2tdur(dt_new) input_dt = kt.int2dt(inputf1, dt) tac = np.append(0, tac) input_dt = np.append(0, input_dt) tac_cum = np.cumsum((tac[:-1] + tac[1:]) / 2 * tdur) input_cum = np.cumsum((input_dt[:-1] + input_dt[1:]) / 2 * tdur) tac = tac[1:] input_dt = input_dt[1:] yy = tac xx = np.column_stack((input_cum, tac_cum, input_dt)) tt = np.logical_and(mft > linear_phase_start, mft < linear_phase_end) tt = tt[1:] mft = mft[1:] reg = LinearRegression(fit_intercept=False).fit(xx[tt, ], yy[tt]) bp = -reg.coef_[0] / reg.coef_[1] - 1 k2p = reg.coef_[0] / reg.coef_[2] # for 1 TC r1 = reg.coef_[2] k2 = -reg.coef_[1] yyf = reg.predict(xx) if fig: plt.plot(mft, yy, '.') plt.plot(mft, yyf, 'r') plt.show() kps = {'bp': bp, 'k2p': k2p, 'r1': r1, 'k2': k2} return kps
def logan_ref_k2p(tac, dt, inputf1, k2p, linear_phase_start, linear_phase_end, fig): if linear_phase_start is None: linear_phase_start = 0 if linear_phase_end is None: linear_phase_end = np.amax(dt) mft = kt.dt2mft(dt) mft = np.append(0, mft) dt_new = np.array([mft[:-1], mft[1:]]) tdur = kt.dt2tdur(dt_new) input_dt = kt.int2dt(inputf1, dt) tac = np.append(0, tac) input_dt = np.append(0, input_dt) tac_cum = np.cumsum((tac[:-1] + tac[1:]) / 2 * tdur) input_cum = np.cumsum((input_dt[:-1] + input_dt[1:]) / 2 * tdur) tac = tac[1:] input_dt = input_dt[1:] yy = np.zeros(tac.shape) xx = np.zeros(tac.shape) mask = tac.nonzero() yy[mask] = tac_cum[mask] / tac[mask] xx[mask] = (input_cum[mask] + input_dt[mask] / k2p) / tac[mask] tt = np.logical_and(mft > linear_phase_start, mft < linear_phase_end) tt = tt[1:] dvr, inter, _, _, _ = linregress(xx[tt], yy[tt]) bp = dvr - 1 yyf = dvr * xx + inter if fig: plt.plot(xx, yy, '.') plt.plot(xx[tt], yyf[tt], 'r') plt.show() kps = {'bp': bp} return kps
def srtm_fun(inputf1_dt, r1, k2, bp): inputf1, dt = inputf1_dt t1 = np.arange(np.amax(dt)) theta = kp.srtm_kp2theta(r1, k2, bp) tac1 = theta[0]*inputf1 tac1 += theta[1]*np.convolve(inputf1, np.exp(-theta[2]*t1))[0:tac1.size] tac = kt.int2dt(tac1, dt) return tac
def mrtm(tac, dt, inputf1, linear_phase_start, linear_phase_end, fig): if linear_phase_start is None: linear_phase_start = 0 if linear_phase_end is None: linear_phase_end = np.amax(dt) # fill the coffee break gap if kt.dt_has_gaps(dt): tac, dt = kt.tac_dt_fill_coffee_break(tac, dt) mft = kt.dt2mft(dt) mft = np.append(0, mft) dt_new = np.array([mft[:-1], mft[1:]]) tdur = kt.dt2tdur(dt_new) input_dt = kt.int2dt(inputf1, dt) tac = np.append(0, tac) input_dt = np.append(0, input_dt) # set negative values to zero tac[tac < 0] = 0.0 input_dt[input_dt < 0] = 0.0 tac_cum = np.cumsum((tac[:-1] + tac[1:]) / 2 * tdur) input_cum = np.cumsum((input_dt[:-1] + input_dt[1:]) / 2 * tdur) tac = tac[1:] input_dt = input_dt[1:] yy = tac xx = np.column_stack((input_cum, tac_cum, input_dt)) # find tt for the linear phase tt = np.logical_and(mft >= linear_phase_start, mft <= linear_phase_end) tt = tt[1:] # select tt for tac > 0 tt = np.logical_and(tt, tac > 0) # select tt for xx < inf, yy < inf infinf = 1e10 tt = np.logical_and(tt, np.all(xx < infinf, axis=-1)) tt = np.logical_and(tt, yy < infinf) mft = mft[1:] reg = LinearRegression(fit_intercept=False).fit(xx[tt, ], yy[tt]) bp = -reg.coef_[0] / reg.coef_[1] - 1 k2p = reg.coef_[0] / reg.coef_[2] # for 1 TC r1 = reg.coef_[2] k2 = -reg.coef_[1] yyf = reg.predict(xx) if fig: plt.plot(mft, yy, '.') plt.plot(mft, yyf, 'r') plt.show() kps = {'bp': bp, 'k2p': k2p, 'r1': r1, 'k2': k2} return kps
def logan_ref_k2p(tac, dt, inputf1, k2p, linear_phase_start, linear_phase_end, fig): if linear_phase_start is None: linear_phase_start = 0 if linear_phase_end is None: linear_phase_end = np.amax(dt) # fill the coffee break gap if kt.dt_has_gaps(dt): tac, dt = kt.tac_dt_fill_coffee_break(tac, dt) mft = kt.dt2mft(dt) mft = np.append(0, mft) dt_new = np.array([mft[:-1], mft[1:]]) tdur = kt.dt2tdur(dt_new) input_dt = kt.int2dt(inputf1, dt) tac = np.append(0, tac) input_dt = np.append(0, input_dt) # set negative values to zero tac[tac < 0] = 0.0 input_dt[input_dt < 0] = 0.0 tac_cum = np.cumsum((tac[:-1] + tac[1:]) / 2 * tdur) input_cum = np.cumsum((input_dt[:-1] + input_dt[1:]) / 2 * tdur) tac = tac[1:] input_dt = input_dt[1:] yy = tac_cum / (tac + 0.0000000000000001) xx = (input_cum + input_dt / k2p) / (tac + 0.0000000000000001) # find tt for the linear phase tt = np.logical_and(mft >= linear_phase_start, mft <= linear_phase_end) tt = tt[1:] # select tt for tac > 0 tt = np.logical_and(tt, tac > 0) # select tt for xx < inf, yy < inf infinf = 1e10 tt = np.logical_and(tt, xx < infinf) tt = np.logical_and(tt, yy < infinf) # do linear regression with selected tt xx = xx[tt] yy = yy[tt] dvr, inter, _, _, _ = linregress(xx, yy) bp = dvr - 1 yyf = dvr * xx + inter if fig: plt.plot(xx, yy, '.') plt.plot(xx[tt], yyf[tt], 'r') plt.show() kps = {'bp': bp} return kps
def logan_ref(tac, dt, inputf1, linear_phase_start, linear_phase_end, fig): if linear_phase_start is None: linear_phase_start = 0 if linear_phase_end is None: linear_phase_end = np.amax(dt) # fill the coffee break gap if kt.dt_has_gaps(dt): tac, dt = kt.tac_dt_fill_coffee_break(tac, dt) mft = kt.dt2mft(dt) mft = np.append(0, mft) dt_new = np.array([mft[:-1], mft[1:]]) tdur = kt.dt2tdur(dt_new) input_dt = kt.int2dt(inputf1, dt) tac = np.append(0, tac) input_dt = np.append(0, input_dt) # set negative values to zero tac[tac < 0] = 0.0 input_dt[input_dt < 0] = 0.0 # calculate integration tac_cum = np.cumsum((tac[:-1] + tac[1:]) / 2 * tdur) input_cum = np.cumsum((input_dt[:-1] + input_dt[1:]) / 2 * tdur) # tac_cum and input_cum are calculated in such a way to match tac # # # debug # file_path = '/Users/Himiko/data/amsterdam_data_pib/transfer_162391_files_89f2cba1/' # savetxt(file_path + 'tac_cum.csv', tac_cum) # savetxt(file_path + 'input_cum.csv', input_cum) # # tac1 = kt.interpt1(mft, tac, dt) # input1 = kt.interpt1(mft, input_dt, dt) # tac_cum1 = np.cumsum(tac1) # input_cum1 = np.cumsum(input1) # tac_cum1_mft = tac_cum1[mft.astype(int)] # input_cum1_mft = input_cum1[mft.astype(int)] # savetxt(file_path + 'tac_cum1_mft.csv', tac_cum1_mft) # savetxt(file_path + 'input_cum1_mft.csv', input_cum1_mft) # # # debug tac = tac[1:] input_dt = input_dt[1:] # yy = np.zeros(tac.shape) # xx = np.zeros(tac.shape) # mask = tac.nonzero() # yy[mask] = tac_cum[mask] / tac[mask] # xx[mask] = input_cum[mask] / tac[mask] yy = tac_cum / (tac + 0.0000000000000001) # ADDED BY MY 20210616 xx = input_cum / (tac + 0.0000000000000001) # ADDED BY MY 20210616 # find tt for the linear phase tt = np.logical_and(mft >= linear_phase_start, mft <= linear_phase_end) tt = tt[1:] # select tt for tac > 0 tt = np.logical_and(tt, tac > 0) # select tt for xx < inf, yy < inf infinf = 1e10 tt = np.logical_and(tt, xx < infinf) tt = np.logical_and(tt, yy < infinf) # do linear regression with selected tt xx = xx[tt] yy = yy[tt] dvr, inter, _, _, _ = linregress(xx, yy) bp = dvr - 1 yyf = dvr * xx + inter if fig: plt.plot(xx, yy, '.') plt.plot(xx, yyf, 'r') plt.show() kps = {'bp': bp} return kps