Ol: Normalization.Minerals

Calculation form Excel table. To 3 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, CaO_pfu

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

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

Source

recalc.ol_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,] * 4/rowSums(mole_oxigen)[i];
        } else {
            norm_cations[i,] = norm_cations[i,] * 3/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(8-charge>0,8-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<- 8-endcharge;

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

recalc.ol_nm.test <- function () {
    test <- data.frame(Name=c("Sp1","Sp2"), SiO2_wtp=c(38.48,38.48), TiO2_wtp=c(0.1, 0.1), Al2O3_wtp=c(0.13,0.13), FeO_wtp=c(20.99, 20.99), Fe2O3_wtp=c(0, 1), MnO_wtp=c(0.33, 0.33), MgO_wtp=c(40.45, 40.45), CaO_wtp=c(0.02, 0.02));
    result <- recalc.ol_nm(test);

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