Пример #1
0
def ss_crystal_dogbone(x,experiments,y_data):
    # x[0] = lnK_pm
    # x[1] = lnK_mw
    # x[2] = lnK_vw
    # x[3] = lnD
    # x[4] = phi

    K_pm = np.exp(x[0])
    #K_wm = np.exp(-x[1])
    #K_vw = np.exp(x[2])
    #K_vm = K_vw*K_wm
    #D = np.exp(x[3])
    #phi = x[4]
    D = np.exp(x[1])
    phi = x[2]
    K_vw = 10.
    K_wm = 0.0001
    K_vm = K_vw*K_wm

    uptake = []
    for exp in experiments:
        mass_dogbone = exp['mass_dogbone']
        rho_c = exp['rho_c']
        rho_a = exp['rho_a']
        A = exp['A']
        L = mass_dogbone/(rho_c+(rho_a-rho_c)*phi)/A

        V = exp['V']
        try:
            moles_t = exp['moles_t']
        except:
            moles_t = exp['mass_t']/exp['MW_t']
        c_in = moles_t/V

        phi_L = exp['phi_L']
        mass_surf = exp['mass_surf']
        density_mic = exp['density_mic']
        phi_M = (mass_surf/density_mic)/(V*phi_L)

        K = K_pm/(phi_L*phi_M + phi_L*(1-phi_M)*K_wm + (1-phi_L)*K_vm)

        nu = exp['nu']

        t_data = exp['times']

        # Run the diffusion code
        time, uptake_piece, _ = crystal_dogbone(V, A, K, c_in, D, L, phi, nu, 200, times_to_save=t_data)

        uptake += uptake_piece
    return np.sum((np.array(uptake)-np.array(y_data))**2)
Пример #2
0
    def uptake(lnK_mw=lnK_mw, lnK_vw=lnK_vw, lnK_pm=lnK_pm, lnD=lnD, phi=phi):
        """
            Return variable uptake given experimental input parameters and fluctuating model parameters.
        """
        # Convert stochastic variables into form more usable by diffusion code
        K_pm = np.exp(lnK_pm)
        K_wm = np.exp(-lnK_mw)
        K_vw = np.exp(lnK_vw)
        K_vm = K_vw*K_wm
        D = np.exp(lnD)

        # List of output data
        uptake = []

        for exp in experiments:
            # Set parameters and run dogbone for each experiment. Note this means that computational expense increases
            # as the number of experiments! If all parameters are identical except for the time, then use a single
            # experiment with ```times``` equal to a list or numpy array of the times to report.
            #
            # Make sure not to read from experimental parameters when you should be using the stochastic variable!
            mass_dogbone = exp['mass_dogbone']
            rho_c = exp['rho_c']
            rho_a = exp['rho_a']
            A = exp['A']
            L = mass_dogbone/(rho_c+(rho_a-rho_c)*phi)/A

            V = exp['V']
            try:
                moles_t = exp['moles_t']
            except:
                moles_t = exp['mass_t']/exp['MW_t']
            c_in = moles_t/V

            phi_L = exp['phi_L']
            mass_surf = exp['mass_surf']
            density_mic = exp['density_mic']
            phi_M = (mass_surf/density_mic)/(V*phi_L)

            K = K_pm/(phi_L*phi_M + phi_L*(1-phi_M)*K_wm + (1-phi_L)*K_vm)

            nu = exp['nu']

            t_data = exp['times']

            # Run the diffusion code
            time, uptake_piece, _ = crystal_dogbone(V, A, K, c_in, D, L, phi, nu, 200, times_to_save=t_data)

            # Note that order of data in uptake must be same as in y_data for comparison!
            uptake += uptake_piece
        return uptake
Пример #3
0
def fake_crystal_dogbone(experiments):
    times = []
    uptake = []
    masses = []
    for exp in experiments:
        # Look for unknown params in exp since we're generating fake data
        K_pm        = exp['K_pm']
        K_vw        = exp['K_vw']
        K_mw        = exp['K_mw']
        D           = exp['D']
        density_mic = exp['density_mic']

        # Calculate params that permeate.crystal_dogbone wants, same as in pymc model below
        K_wm = 1./K_mw
        K_vm = K_vw/K_mw

        mass_dogbone = exp['mass_dogbone']
        phi = exp['phi']
        nu = exp['nu']
        rho_c = exp['rho_c']
        rho_a = exp['rho_a']
        A = exp['A']
        L = mass_dogbone/(rho_c+(rho_a-rho_c)*phi)/A

        V = exp['V']
        moles_t = exp['moles_t']
        c_in = moles_t/V

        phi_L = exp['phi_L']
        mass_surf = exp['mass_surf']
        phi_M = (mass_surf/density_mic)/(V*phi_L)

        K = K_pm/(phi_L*phi_M + phi_L*(1-phi_M)*K_wm + (1-phi_L)*K_vm)

        t_data = exp['times']

        # Run the diffusion code
        time, uptake_piece, _, profile = crystal_dogbone(V, A, K, c_in, D, L, phi, nu, 200, times_to_save=t_data,\
                save_profile_flag=True)

        times  += time
        uptake += uptake_piece
        masses += [mass_dogbone]*len(time)

    # MAKE SOME NOISE
    exp_sigma = exp['exp_sigma']
    uptake = np.array(uptake) + np.random.normal(0.,exp_sigma,size=len(uptake))

    return times, uptake, masses, profile