Skip to content

Dar walczd3, Mineral classes/groups #170

Merged
merged 4 commits into from Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added StudentData/aqueous.Rds
Binary file not shown.
293 changes: 293 additions & 0 deletions StudentNotebooks/Assignment05/Aqueous.Rmd
@@ -0,0 +1,293 @@

---
title: "Aqueous SHERLOC minerals"
author: "Student Name"
date: "`r Sys.Date()`"
output:
html_document:
toc: yes
pdf_document:
toc: yes
subtitle: "MARs DAR-F24
---
## Weekly Work Summary
**NOTE:** Follow an outline format; use bullets to express individual points.
* RCS ID: **Always** include this!
* Project Name: **Always** include this!
* Summary of work since last week
* Describe the important aspects of what you worked on and accomplished
* NEW: Summary of github issues added and worked
* Issues that you've submitted
* Issues that you've self-assigned and addressed
* Summary of github commits
* Include branch name(s)
* Include filenames for any added or changed files on github
* Include links to shared Shiny apps
* List of presentations, papers, or other outputs
* Include browsable links (ie Google Slides, et.al.)
* List of references (if necessary)
* Indicate any use of group shared code base
* Indicate which parts of your described work were done by you or as part of joint efforts
* **Required:** Provide illustrating figures and/or tables
## Personal Contribution
* Clearly defined, unique contribution(s) done by you: code, ideas, writing...
* Include github issues you've addressed if any
## PACKAGES
```{r}
# Set the default CRAN repository
local({r <- getOption("repos")
r["CRAN"] <- "http://cran.r-project.org"
options(repos=r)
})

if (!require("pandoc")) {
install.packages("pandoc")
library(pandoc)
}

if (!require("ggplotify")) {
install.packages("ggplotify")
library(ggplotify)
}

if (!require("car")) {
install.packages("car")
library(car)
}
if (!require("ggbiplot")) {
install.packages("ggbiplot")
library(ggbiplot)
}

# Required packages for M20 LIBS analysis
if (!require("rmarkdown")) {
install.packages("rmarkdown")
library(rmarkdown)
}
if (!require("tidyverse")) {
install.packages("tidyverse")
library(tidyverse)
}
if (!require("stringr")) {
install.packages("stringr")
library(stringr)
}

if (!require("ggbiplot")) {
install.packages("ggbiplot")
library(ggbiplot)
}

if (!require("pheatmap")) {
install.packages("pheatmap")
library(pheatmap)
}
if (!require("ggtern")) {
install.packages("ggtern")
library(ggtern)
}

if (!require("gridExtra")) {
install.packages("gridExtra")
library(gridExtra)
}
if (!require("randomForest")) {
install.packages("randomForest")
library(randomForest)
}
```
```{r}
metadata_libs <- readRDS("~/DAR-Mars-F24/StudentData/v1_libs_to_sample.Rds") #metadata of libs. Unconnected with
libs <- readRDS("/academics/MATP-4910-F24/DAR-Mars-F24/StudentData/v1_libs.Rds")
lithology <- readRDS("/academics/MATP-4910-F24/DAR-Mars-F24/StudentData/v1_lithology.Rds")
sherloc <- readRDS("/academics/MATP-4910-F24/DAR-Mars-F24/StudentData/v1_sherloc.Rds")
pixl <- readRDS("/academics/MATP-4910-F24/DAR-Mars-F24/StudentData/v1_pixl.Rds")
metadata_pixl <- readRDS("/academics/MATP-4910-F24/DAR-Mars-F24/StudentData/v1_sample_meta.Rds")

oxide_elem <- 1 / c(2.1392, 1.6681, 1.8895, (1.2865 + 1.4297)/2, 1.6582, 1.3992, 1.3480, 1.2046, 2.2916, 2.4972, 1, 1.4615, 1.2912) #/2 is used to find average of FeO and Fe2O3
elem_pixl <- pixl[,2:ncol(pixl)]
for (i in seq(length(oxide_elem))) {
elem_pixl[,i] = elem_pixl[,i] * oxide_elem[i]
}

names(elem_pixl) <- c("Si", "Ti", "Al", "Fe", "Mg", "Ca", "Na", "K", "P", "S", "Cl", "Cr", "Mn")
elem_pixl["Total_Cation"] <- rowSums(elem_pixl)
elem_pixl["O"] <- 100 - elem_pixl$Total_Cation

```
## Analysis 1
### Creating Aqueous Dataframes based off of ChatBS
_Aqueous indicates whether a mineral has been chemically altered by an aqueous solvent or whether it precipiated out of ancient seas_
_For the aqueous dataframe, Dr. Rogers implied a few notable 'features' to add. (1) creation of group of feature (e.g: Ca, Mg, and Fe carbonates will all be placed with a Carbonates tag). (2) Is it aqueous or not (0 or 1). Quartz has altering forms of creation, but that will be identified as 1. Potentially we could add another feature that describes whether it partly is or not (but I think we will skip this for now). (3) Chemical Formula. Potentially apply NLP to process similarities._
```{r, result01_data}

#Dona created the same naming sequence for each sherloc and lithology dataframe so we can just use the names from one to identify aqueous and non-aqueous minerals
sample <- sherloc[,1]
sherloc <- sherloc[,-c(names(sherloc) == "Sample")]

#1 - feed into grepl
common_names <- c("Sulfate|sulfate" = "Sulfates", "Carbonate|carbonate" = "Carbonates", "Organic" = "Organic Matter", "Perchlorate|perchlorate" = "Perchlorate")

common_groups <- rep(NA, ncol(sherloc))
for (i in 1:length(common_names)) {
check <- grepl(names(common_names)[i], names(sherloc))
common_groups[check] = common_names[[i]]
}
common_groups[which(is.na(common_groups) == T)] = names(sherloc)[which(is.na(common_groups) == T)]

#2
#quartz is non-aq with correspondence to the note above
aqueous_total <- c(0,1,1,1,1,1,1,0,0,1,1,0,0,1,1,1,1,0,0,1,0,1,1,1,0,0,1,1,1,1,0,0,0,1,0)
aq <- sherloc[,aqueous_total == 1]
nonaq <- sherloc[,aqueous_total == 0]

#3 - formulas in order of common_groups
#formulas have | in them to separate between distinguishable types. e.g: ferrous and ferric oxide
formulas <- c("(Na,Cl)Al(Si,Al)Si2O8", "(Mg,Fe,Ca)SO4", "(Mg,Fe,Ca)SO4","(Mg,Fe,Ca)SO4","(Mg,Fe,Ca)SO4","(Mg,Fe,Ca)SO4",
"(Mg,Fe,Ca)SO4","(K,Na)ClO4|Mg(ClO4)2","(K,Na)ClO4|Mg(ClO4)2", "SiO4*nH2O", "PO4", "(Mg,Mn,Ca,Zn)(Fe,Al,Cr)Si2O6",
"(Mg,Fe)2SiO4","(Mg,Fe,Ca)CO3","(Mg,Fe,Ca)CO3","(Mg,Fe,Ca)CO3","(M2/M3)2-3 (Al, Fe, Mg)2-3 (Si, Al)4-5 O10-11", "(Na,C,K)Al(Si,Al)Si2O8","SiO2", "Ca5(PO4)3(F,Cl,OH)", "FeTiO3|Fe2TiO4", "NaCl", "Fe2O3|Fe3O4","Fe2O3|Fe3O4*nH2O",
NA,NA,NA,"(K,Ca,Mg,Fe,Al)4_6(Si,Al)8O20(OH,F)4","(Mg,Fe)6AlSi3O10(OH)8","Al2Si2O5(OH)4","(Fe,Mg)Cr2O4","FeTiO3","ZrSiO4",NA, "(Mg,Zn)Al2O4|Ca3Al2Si3O12")

aqueous.df <- data.frame(mineral = names(sherloc), common_mineral = common_groups, aqueous = aqueous_total, formula = formulas)


write_rds(aqueous.df, "~/DAR-Mars-F24/StudentData/aqueous.Rds")


```
### Analysis: Methods and results
_Describe in natural language a statement of the analysis you're trying to do_
_Provide clearly commented analysis code; include code for tables and figures!_
```{r, result01_analysis}
# Include all analysis code, clearly commented
# If not possible, screen shots are acceptable.
# If your contributions included things that are not done in an R-notebook,
# (e.g. researching, writing, and coding in Python), you still need to do
# this status notebook in R. Describe what you did here and put any products
# that you created in github. If you are writing online documents (e.g. overleaf
# or google docs), you can include links to the documents in this notebook
# instead of actual text.

```
### Discussion of results
_Provide in natural language a clear discussion of your observations._
## Analysis: Question 2 (Provide short name)
### Question being asked
_Provide in natural language a statement of what question you're trying to answer_
### Data Preparation
_Provide in natural language a description of the data you are using for this analysis_
_Include a step-by-step description of how you prepare your data for analysis_
_If you're re-using dataframes prepared in another section, simply re-state what data you're using_
```{r, result02_data}
# Include all data processing code (if necessary), clearly commented

```
### Analysis: Methods and Results
_Describe in natural language a statement of the analysis you're trying to do_
_Provide clearly commented analysis code; include code for tables and figures!_
```{r, result02_analysis}
# Include all analysis code, clearly commented
# If not possible, screen shots are acceptable.
# If your contributions included things that are not done in an R-notebook,
# (e.g. researching, writing, and coding in Python), you still need to do
# this status notebook in R. Describe what you did here and put any products
# that you created in github (documents, jupytor notebooks, etc). If you are writing online documents (e.g. overleaf
# or google docs), you can include links to the documents in this notebook
# instead of actual text.

```
### Discussion of results
_Provide in natural language a clear discussion of your observations._
## Analysis: Question 3 (Provide short name)
### Question being asked
_Provide in natural language a statement of what question you're trying to answer_
### Data Preparation
_Provide in natural language a description of the data you are using for this analysis_
_Include a step-by-step description of how you prepare your data for analysis_
_If you're re-using dataframes prepared in another section, re-state what data you're using_
```{r, result03_data}
# Include all data processing code (if necessary), clearly commented

```
### Analysis methods used
_Describe in natural language a statement of the analysis you're trying to do_
_Provide clearly commented analysis code; include code for tables and figures!_
```{r, result03_analysis}
# Include all analysis code, clearly commented
# If not possible, screen shots are acceptable.
# If your contributions included things that are not done in an R-notebook,
# (e.g. researching, writing, and coding in Python), you still need to do
# this status notebook in R. Describe what you did here and put any products
# that you created in github. If you are writing online documents (e.g. overleaf
# or google docs), you can include links to the documents in this notebook
# instead of actual text.

```
### Discussion of results
_Provide in natural language a clear discussion of your observations._
## Summary and next steps
_Provide in natural language a clear summary and your proposed next steps._