Править страницу Ссылки сюда Px: Normalization.Minerals Calculation form Excel table. To 4 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, Na2O_wtp Output Si_pfu, Ti_pfu, Al_pfu, Cr_pfu, Fe_pfu, Fe_p2_wtp, Fe_p3_wtp, Mn_pfu, Mg_pfu, Ca_pfu, Na_pfu Использовать Проверить заголовок краткое описание статья ссылка карточка подробное описание код тест Source recalc.px_nm <- function (wtp_data, ...) { #Names preparation ox_tnames <- c('SiO2', 'TiO2', 'Al2O3', 'Cr2O3', 'Fe2O3', 'FeO', 'MnO', 'MgO' ,'CaO', 'Na2O'); ox_names <- c('SiO2_wtp','TiO2_wtp', 'Al2O3_wtp', 'Cr2O3_wtp', 'Fe2O3_wtp', 'FeO_wtp', 'MnO_wtp', 'MgO_wtp','CaO_wtp','Na2O_wtp'); pfu_names <- c('Si_pfu', 'Ti_pfu', 'Al_pfu', 'Cr_pfu', 'Fe_p3_pfu', 'Fe_p2_pfu', 'Mn_pfu', 'Mg_pfu' ,'Ca_pfu', 'Na_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,] * 6/rowSums(mole_oxigen)[i]; } else { norm_cations[i,] = norm_cations[i,] * 4/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(12-charge>0,12-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<- 12-endcharge; rownames <- data.frame(Name = wtp_data$Name); qcheck <- data.frame(ChargeDisbalance = endcharge); return (cbind(rownames, pfu_units, qcheck)); } recalc.px_nm.test <- function () { test <- data.frame(Name=c("Sp1","Sp2"), SiO2_wtp=c(63.338,63.338), Al2O3_wtp=c(3.231,3.231), FeO_wtp=c(12.339,12.339), Fe2O3_wtp=c(1, 0),MgO_wtp=c(19.823, 19.823), CaO_wtp=c(1.269, 1.269)); result <- recalc.px_nm(test); expect_equal(object = result[1,]$Fe_p2_pfu, 0.354, tolerance = 0.005); expect_equal(object = result[2,]$Si_pfu, 2.338, tolerance = 0.005); } recalc/px_nm.txt Последние изменения: 2018/11/12 15:08(внешнее изменение) Войти