Править страницу Ссылки сюда Pl: Normalization.Minerals Calculation form Excel table. To 5 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, BaO_wtp, K2O_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, BaO_wtp, K2O_wtp, Na_pfu Использовать Проверить заголовок краткое описание статья ссылка карточка подробное описание код тест Source recalc.pl_nm <- function (wtp_data, ...) { #Names preparation ox_tnames <- c('SiO2', 'TiO2', 'Al2O3', 'Cr2O3', 'Fe2O3', 'FeO', 'MnO', 'MgO' ,'CaO', 'BaO', 'Na2O', 'K2O'); ox_names <- c('SiO2_wtp','TiO2_wtp', 'Al2O3_wtp', 'Cr2O3_wtp', 'Fe2O3_wtp', 'FeO_wtp', 'MnO_wtp', 'MgO_wtp','CaO_wtp', 'BaO_wtp','Na2O_wtp','K2O_wtp'); pfu_names <- c('Si_pfu', 'Ti_pfu', 'Al_pfu', 'Cr_pfu', 'Fe_p3_pfu', 'Fe_p2_pfu', 'Mn_pfu', 'Mg_pfu' ,'Ca_pfu','Ba_pfu', 'Na_pfu', 'K_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,] * 8/rowSums(mole_oxigen)[i]; } else { norm_cations[i,] = norm_cations[i,] * 5/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(16-charge>0,16-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<- 16-endcharge; rownames <- data.frame(Name = wtp_data$Name); qcheck <- data.frame(ChargeDisbalance = endcharge); return (cbind(rownames, pfu_units, qcheck)); } recalc.pl_nm.test <- function () { test <- data.frame(Name=c("Sp1","Sp2"), SiO2_wtp=c(38.03,38.03), Al2O3_wtp=c(12.91,12.91), FeO_wtp=c(5,0), Fe2O3_wtp=c(0,30.32), CaO_wtp=c(17.75, 17.75)); result <- recalc.pl_nm(test); print(result); expect_equal(object = result[1,]$Fe_p2_pfu, 0.244, tolerance = 0.005); expect_equal(object = result[2,]$Al_pfu, 0.8, tolerance = 0.005); } recalc/pl_nm.txt Последние изменения: 2018/11/12 15:08(внешнее изменение) Войти