Grt: Normalization.Minerals

Calculation form Excel table. To 8 cations with optional Fe_p3_pfu calculation from charge balance.

Details

Reference
Input SiO2_wtp, TiO2_wtp, Al2O3_wtp, Cr2O3_wtp, Fe2O3_wtp, FeO_wtp, MnO_wtp, MgO_wtp, CaO_wtp
Output Si_pfu, Ti_pfu, Al_pfu, Cr_pfu, Fe_pfu, Fe_p2_wtp, Fe_p3_wtp, Mn_pfu, Mg_pfu, Ca_pfu

Использовать Проверить

  • заголовок
  • краткое описание
  • статья
  • ссылка
  • карточка
  • подробное описание
  • код
  • тест

Source

recalc.grt_nm <- function (wtp_data, ...) {

    #Names preparation
    ox_tnames <- c('SiO2',    'TiO2',     'Al2O3',     'Cr2O3',     'Fe2O3',     'FeO',       'MnO',     'MgO'    ,'CaO');
    ox_names <-  c('SiO2_wtp','TiO2_wtp', 'Al2O3_wtp', 'Cr2O3_wtp', 'Fe2O3_wtp', 'FeO_wtp',   'MnO_wtp', 'MgO_wtp','CaO_wtp');
    pfu_names <- c('Si_pfu',  'Ti_pfu',   'Al_pfu',    'Cr_pfu',    'Fe_p3_pfu', 'Fe_p2_pfu', 'Mn_pfu',  'Mg_pfu' ,'Ca_pfu');

    #Periodic table load
    elem <- read.csv("constants_nmperiodic.csv",stringsAsFactors=F, dec = ".");
    tmelem <- data.frame(t(elem), stringsAsFactors = F);
    names(tmelem) <- elem$oxide;
    telem  <- selectNames(tmelem,ox_tnames);
    names(telem) <- ox_names;

    #Select columns
    wtp_group <- selectNames(wtp_data,ox_names);

    mole_cations <- rowApply('*', wtp_group, as.numeric(telem['ncations',]));
    mole_cations <- rowApply('/', mole_cations, as.numeric(telem['mole_wt',]));

    mole_oxigen <- rowApply('*', wtp_group, as.numeric(telem['noxygen',]));
    mole_oxigen <- rowApply('/', mole_oxigen, as.numeric(telem['mole_wt',]));

    norm_cations <- mole_cations;

    for(i in 1:nrow(norm_cations)) {
        if(norm_cations[i,]$Fe2O3_wtp>0) {
            norm_cations[i,] = norm_cations[i,] * 12/rowSums(mole_oxigen)[i];
        } else {
            norm_cations[i,] = norm_cations[i,] * 8/rowSums(mole_cations)[i];        
        }
    }
    
    norm_oxygens <- norm_cations;
    norm_oxygens <- rowApply('*', norm_oxygens, as.numeric(telem['noxygen',]));
    norm_oxygens <- rowApply('/', norm_oxygens, as.numeric(telem['ncations',]));

    names(norm_cations) <- pfu_names;
    charge <- 4*(norm_cations$Si_pfu+norm_cations$Ti_pfu)+
              3*(norm_cations$Al_pfu+norm_cations$Cr_pfu+norm_cations$Fe_p3_pfu)+
              2*(norm_cations$Fe_p2_pfu+norm_cations$Mn_pfu+norm_cations$Mg_pfu+norm_cations$Ca_pfu);
              
    pfu_units <- norm_cations;

    fecharge <- ifelse(24-charge>0,24-charge,0);
    pfu_units$Fe_p3_pfu <- ifelse(pfu_units$Fe_p3_pfu > 0, pfu_units$Fe_p3_pfu, fecharge);
    pfu_units$Fe_p2_pfu <- ifelse(norm_cations$Fe_p3_pfu > 0, pfu_units$Fe_p2_pfu, norm_cations$Fe_p2_pfu - pfu_units$Fe_p3_pfu);

    endcharge <- 4*(pfu_units$Si_pfu+pfu_units$Ti_pfu)+
                 3*(pfu_units$Al_pfu+pfu_units$Cr_pfu+pfu_units$Fe_p3_pfu)+
                 2*(pfu_units$Fe_p2_pfu+pfu_units$Mn_pfu+pfu_units$Mg_pfu+pfu_units$Ca_pfu);

    endcharge<- 24-endcharge;

    rownames <- data.frame(Name = wtp_data$Name);
    qcheck <- data.frame(ChargeDisbalance = endcharge);
 
    return (cbind(rownames, pfu_units, qcheck));
}

recalc.grt_nm.test <- function () {
    test <- data.frame(Name=c("Sp1","Sp2"), SiO2_wtp=c(37.39,37.39), TiO2_wtp=c(0.28, 0.28), Al2O3_wtp=c(10.08,10.08), FeO_wtp=c(19.35, 19.35), Fe2O3_wtp=c(1, 0), MnO_wtp=c(0.14, 0.14), MgO_wtp=c(1.55, 1.55), CaO_wtp=c(29.63, 29.63));
    result <- recalc.grt_nm(test);

    expect_equal(object = result[1,]$Fe_p2_pfu, 1.344, tolerance = 0.005);
    expect_equal(object = result[2,]$Si_pfu, 2.996, tolerance = 0.005);
}
  • recalc/grt_nm.txt
  • Последние изменения: 2018/11/12 15:08
  • (внешнее изменение)