diff --git a/StudentNotebooks/Assignment01/quintd-assignment1-f24.Rmd b/StudentNotebooks/Assignment01/quintd-assignment1-f24.Rmd new file mode 100644 index 0000000..04c3c3a --- /dev/null +++ b/StudentNotebooks/Assignment01/quintd-assignment1-f24.Rmd @@ -0,0 +1,407 @@ +--- +title: "RPI github and Mars 2020 PIXL Example Notebook:" +subtitle: "DAR Assignment 1 (Fall 2024)" +author: "David Quintero" +date: "`r format(Sys.time(), '%d %B %Y')`" +output: + html_document: + toc: true + number_sections: true + df_print: paged + pdf_document: default +--- +```{r setup, include=FALSE} +# REQUIRE R PACKAGE INSTALLATIONS +# This section installs packages if they are not already installed. +# This block will not be shown in the knitted file. + +# RUN THIS BLOCK BEFORE ATTEMPTING TO KNIT THIS NOTEBOOK!!! + +# 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("knitr")) { + install.packages("knitr") + library(knitr) +} + +# 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("ggrepel")) { + install.packages("ggrepel") + library(ggrepel) +} + +if (!require("farver")) { + install.packages("farver") + library(farver) +} + +if (!require("labeling")) { + install.packages("labeling") + library(labeling) +} + +knitr::opts_chunk$set(echo = TRUE) + +``` + +# Introductory Data Analytics Research Notebook + +This notebook is broken into two main parts: + +* Part 1: A basic introduction to github and RStudio Server +* Part 2: An introduction to the Mars 2020 PIXL dataset + +The RPI github repository for all the code and data required for this notebook may be found at: + +* https://github.rpi.edu/DataINCITE/DAR-Mars-F24 + + +## BEFORE YOU BEGIN: github account setup + +To contribute to any RPI github repository or read private repos you _must_ validate your RPI github.com ID and send a confirmation email to John Erickson at `erickj4@rpi.edu`. Please do the following **now**: + +**Enabling 2FA on the RPI github and saving personal access tokens, et.al.** + +* Browse to http://github.rpi.edu +* Login using your RPI credentials +* Enable github two-factor authentication (2FA) +* Under "Settings" -> "Password and authentication" +* Select "Authenticator app" (Duo or Google authenticator are recommended) + * Follow steps to set up authenticator app; may involve scanning a QR Code) + * See directions for 2FA at https://itssc.rpi.edu/hc/en-us/articles/360004801811-GitHub-Enterprise-Overview#2fa + * **CRITICAL:** Make sure to save your **recovery codes** in a safe place! Recovery codes can be used to access your account in the event you lose access to your device and cannot receive two-factor authentication codes. +* Create and save a *personal access token* + * Under "Settings" -> "Developer settings" + * Select "Personal access tokens" + * Click on "Generate new token (classic)" + * Set an expiration period for the end of the Fall 2024 term + * Enable everything (check the left-most boxes) + * Generate (green button) + * SAVE THE RESULT! You won't be able to see it again... +* _Use this token when command-line git asks you for a password_ +* **PLEASE DO THIS IMMEDIATELY BEFORE READING ANY FURTHER!!** + +# DAR ASSIGNMENT 1 (Part 1): CLONING A NOTEBOOK AND UPDATING THE REPOSITORY + +In this assignment we're asking you to + +* clone the `DAR-Mars-F24` github repository, +* create a personal branch using git, +* create a new notebook that includes your answers to questions in this notebook, +* make additions to the repository by adding your notebook to the repository. + +_The instructions which follow explain how to accomplish this._ + +**For DAR Fall 2024** you *must* be using RStudio Server on the IDEA Cluster. Instructions for accessing "The Cluster" appear at the end of this notebook. Don't forget to validate your RPI github ID as above and email `erickj4@rpi.edu` + +### Cloning an RPI github repository + +The recommended procedure for cloning and using this repository is as follows: + +* Access the RPI network via VPN + * See https://itssc.rpi.edu/hc/en-us/articles/360008783172-VPN-Connection-and-Installation for information + +* Access RStudio Server on the IDEA Cluster at http://lp01.idea.rpi.edu/rstudio-ose/ + * You must be on the RPI VPN!! +* Access the Linux shell on the IDEA Cluster by clicking the **Terminal** tab of RStudio Server (lower left panel). + * You now see the Linux shell on the IDEA Cluster + * `cd` (change directory) to enter your home directory using: `cd ~` + * Type `pwd` to confirm + * NOTE: Advanced users may use `ssh` to directly access the Linux shell from a macOS or Linux command line +* Type `git clone https://github.rpi.edu/DataINCITE/DAR-Mars-F24` from within your `home` directory + * Enter your RCS ID and your saved personal access token when asked + * This will create a new directory `DAR-Mars-F24` +* In the Linux shell, `cd` to `DAR-Mars-F24/StudentNotebooks/Assignment01` + * Type `ls -al` to list the current contents + * Don't be surprised if you see many files! +* In the Linux shell, type `git checkout -b dar-yourrcs` where `yourrcs` is your RCS id + * For example, if your RCS is `erickj4`, your new branch should be `dar-erickj4` + * It is _critical_ that you include your RCS id in your branch id! +* Back in the RStudio Server UI, navigate to the `DAR-Mars-F24/StudentNotebooks/Assignment01` directory via the **Files** panel (lower right panel) + * Under the **More** menu, set this to be your R working directory + * Setting the correct working directory is essential for interactive R use! + +## REQUIRED FOR ASSIGNMENT 1 + +1. In RStudio, make a **copy** of `dar-f24-assignment1-template.Rmd` file using a *new, original, descriptive* filename that **includes your RCS ID!** + * Open `darf24-assignment1-template.Rmd` + * **Save As...** using a new filename that includes your RCS ID + * Example filename for user `erickj4`: `erickj4-assignment1-f24.Rmd` + * POINTS OFF IF: + * You don't create a new filename! + * You don't include your RCS ID! + * You include `template` in your new filename! +2. Edit your new notebook using RStudio and save + * Change the `title:` and `subtitle:` headers (at the top of the file) + * Change the `author:` + * Don't bother changing the `date:`; it should update automagically... + * **Save** your changes +3. Use the RStudio `Knit` command to create an HTML file; repeat as necessary + * Use the down arrow next to the word `Knit` and select **Knit to HTML** + * You may also knit to PDF... +4. In the Linux terminal, use `git add` to add each new file you want to add to the repository + * Type: `git add yourfilename.Rmd` + * Type: `git add yourfilename.html` (created when you knitted) + * Add your PDF if you also created one... +5. Continue making changes to your personal notebook + * Add code where specified + * Answer questions were indicated. +6. When you're ready, in Linux commit your changes: + * Type: `git commit -m "some comment"` where "some comment" is a useful comment describing your changes + * This commits your changes to your local repo, and sets the stage for your next operation. +7. Finally, push your commits to the RPI github repo + * Type: `git push origin dar-yourrcs` (where `dar-yourrcs` is the branch you've been working in) + * Enter your RCS ID and personal access token (as a password) when asked. + * Your changes are now safely on the RPI github. +8. **REQUIRED:** On the RPI github, submit a pull request. + * In a web browser, navigate to https://github.rpi.edu/DataINCITE/DAR-Mars-F24.git + and log in using 2FA + * In the branch selector drop-down (by default says **main**), select your branch + * **Submit a pull request for your branch** + * One of the DAR instructors will merge your branch, and your new files will be added to the master branch of the repo. + +Please also see these handy github "cheatsheets": + + * https://education.github.com/git-cheat-sheet-education.pdf + +# DAR ASSIGNMENT 1 (Part 2): Exploring the Mars 2020 (M20) PIXL Dataset + +This part of the notebook demonstrates some basic analysis of data from the M20 PIXL (Planetary Instrument for X-ray Lithochemistry) experiment. + +PIXL (Planetary Instrument for X-ray Lithochemistry) is a microfocus X-ray fluorescence instrument that measures elemental chemistry at sub-millimeter scales. This is achieved by focusing an X-ray beam to a small spot ~ 150 µm, scanning the surface with this beam, and then measuring the induced X-ray fluorescence. PIXL observations consist of a suite of X-ray fluorescence measurements, context images, and metadata. The XRF measurements can be executed in a variety of geometries depending on target type and available observation time, and are accompanied by a set of images documenting the target and its position relative to the instrument. + +In this notebook we will be looking at pre-processed PIXL data that is ready for your next steps. + +* More about the PIXL instrument: https://an.rsl.wustl.edu/help/Content/About%20the%20mission/M20/Instruments/M20%20PIXL.htm +* Raw PIXL data bundle: https://pds-geosciences.wustl.edu/m2020/urn-nasa-pds-mars2020_pixl/ + +## Load the PIXL Data and display summary + +Here is the MARS PIXL data. Take note of the variables, their types, and distriubtions. + +```{r} +# Saved LIBS data with locations added + +# NOTE: Use course directory version during the semester +pixl.df<- readRDS("~/DAR-Mars-F24/Data/samples_pixl_wide.Rds") +# Use this version to use downloaded data from github +#pixl.df <- readRDS("~/DAR-Mars-F24/Data/samples_pixl_wide.Rds") + +# convert location to a number +pixl.df$location <- as.numeric(pixl.df$location ) + +# Automatically converts all strings to factors +pixl.df[sapply(pixl.df, is.character)] <- + lapply(pixl.df[sapply(pixl.df, + is.character)], as.factor) + +# Show summary of the data +summary(pixl.df) + +``` + + +Create a matrix containing the measurements without any meta data to prepare for clustering. Here we delibrately do not scale the data to get preliminary results. + +```{r} +# Prepare dataset for clustering selecting specific columns of interest and putting in a matrix +pixl_trim.mat <- pixl.df %>% + dplyr::select(c("Na20","Mgo","Al203","Si02", + "P205","S03","Cl","K20","Cao","Ti02", + "Cr203","Mno","FeO-T")) %>% as.matrix() +summary(pixl_trim.mat) +``` + +# Clustering + +Our first analysis goal is to cluster the mineralogy data using K-means and pick the appropriate number of clusters. + +Here we recall the function `wssplot` we created in MATP-4400 (IDM) to examine cluster sizes in order to perform the "elbow" test. The function takes as its arguments a matrix, the maximum number of clusters and a random seed. It creates clusters for each possible value of k and plots the k-means objective function. + +NOTE: The basic syntax for creating a user-defined function in R is: + +`output <- function(arguments){ do stuff }` + +The following plot shows the K-Means objective value for up to eight clusters. + +```{r} +# A user-defined function to examine clusters and plot the results +wssplot <- function(data, nc=15, seed=10){ + wss <- data.frame(cluster=1:nc, quality=c(0)) + for (i in 1:nc){ + set.seed(seed) + wss[i,2] <- kmeans(data, centers=i)$tot.withinss} + ggplot(data=wss,aes(x=cluster,y=quality)) + + geom_line() + + ggtitle("Quality of k-means by Cluster") +} + +# Apply `wssplot()` to our PIXL data +wssplot(pixl_trim.mat, nc=8, seed=2) +``` + + +Based on where the "elbow" occurs, it looks like `d` might be a good `k` choice for k-means clustering. + +## k-means Clustering + +We create the final clustering with 5 clusters. + +```{r} +# Use our chosen 'k' to perform k-means clustering +set.seed(2) +k <- 3 +km <- kmeans(pixl_trim.mat,k) + +``` + +## Examine cluster means + +Below is a heat map of the cluster centers with rows and columns clustered. We keep the scale the same as in the original data. + +```{r} + +pheatmap(km$centers,scale="none") + +``` + +Notice how the means of the clusters vary. + +## Perform PCA on PIXL Data + +We're now ready to perform PCA. Note we have already scaled data so set `scale=FALSE`. + +We first show a [Scree plot](https://en.wikipedia.org/wiki/Scree_plot) to understand the explained variance by principal component. Note the elbow in the Scree plot should roughly match the one you saw in k-means. + +```{r} +# Perform the PCA on the matrix `pixl_trim.mat` we created earlier + +pixl_trim.mat.pca <- prcomp(pixl_trim.mat, scale=FALSE) + +# generate the Scree plot +ggscreeplot(pixl_trim.mat.pca) +``` + +Make a table indicating how many samples are in each cluster. + +```{r} +# clusters sizes are in the km object produced by kmeans +cluster.df<-data.frame(cluster= 1:3, size=km$size) +kable(cluster.df,caption="Samples per cluster") +``` + + +## Create a PCA Biplot using ggbiplot + +Now we'll create a biplot of the data colored by cluster and label by rock type. + +```{r message=FALSE, warning=FALSE} +# For this lab we'll create a PCA biplot the easy way using ggbiplot! +ggbiplot::ggbiplot(pixl_trim.mat.pca, + labels = pixl.df$type, + groups = as.factor(km$cluster)) + + xlim(-2,2) + ylim(-2,2) + +``` + +## ANSWER THESE QUESTIONS! + +Add a description of each cluster here in your own words. + +Describe Cluster 1: Cluster 1 is the smallest in size compared to 2 and 3. Cluster 1 is also igneous. It's also high composed of SiO2 + +Describe Cluster 2: Cluster 2 is the second largest in size. Cluster 2 is full of sedimentary rocks. + +Describe Cluster 3: Cluster 3 is the largest in size. Cluster 3 is Igneous. It's also highly composed of SiO2 + + +What do the clustering and PCA results tell us about the data detected by the M20 PIXL experiment? _Feel free to add graphs or analyses to support your conclusions._ + +The clustering tells us about the groupings of rocks and their compositions of molecules. The PCA gives us explained variance and the levels of molecules based on variance on the biplot. + + +## SAVE, COMMIT and PUSH YOUR CHANGES! + +When you are satisfied with your edits and your notebook knits successfully, remember to push your changes to the repo using **steps 4-8** in **Section 2.2**, summarized here: + +**In the Linux terminal:** + +* `git branch` + * To double-check that you are in your working branch +* `git add ` + * Your Rmd and knitted PDF +* `git commit -m "Some useful comments"` +* `git push origin ` + +**On github:** + +* Log in at https://github.rpi.edu/DataINCITE/DAR-Mars-F24 +* Select your branch from drop-down (default is **main**) +* Submit a "pull request" for your branch +* DO NOT MERGE!!! + +# APPENDIX: Accessing RStudio Server on the IDEA Cluster + +The IDEA Cluster provides seven compute nodes (4x 48 cores, 3x 80 cores, 1x storage server) + +* The Cluster requires RCS credentials, enabled via registration in class + * email John Erickson for problems `erickj4@rpi.edu` +* RStudio, Jupyter, MATLAB, GPUs (on two nodes); lots of storage and computes +* Access via RPI physical network or VPN only + +# More info about Rstudio on our Cluster + +## RStudio GUI Access: + +* Use: + * http://lp01.idea.rpi.edu/rstudio-ose/ + * http://lp01.idea.rpi.edu/rstudio-ose-3/ + * http://lp01.idea.rpi.edu/rstudio-ose-6/ + * http://lp01.idea.rpi.edu/rstudio-ose-7/ +* Linux terminal accessible from within RStudio "Terminal" or via ssh (below) + +## Shared Data on Cluster: + +* Users enrolled in DAR have access to `/academics/MATP-4910-F24` + * Usually DAR users will see a symbolic ("soft") link in their home directories + * If you do not, type the following in the **Terminal** via RStudio: `ln -s /academics/MATP-4910-F23/ MATP-4910-F24` +* All idea_users have access to shared storage via `/data` ("data" in your home directories) + * You might wish to use this for data sharing in team projects... + * ...but we recommend using github for shared code development +* Shell access to nodes: You must access "landing pad" first, then compute node: +* `ssh your_rcs@lp01.idea.rpi.edu` For example: `ssh erickj4@lp01.idea.rpi.edu` +* Then, `ssh` to the desired compute node, e.g.: `ssh idea-node-02` \ No newline at end of file diff --git a/StudentNotebooks/Assignment01/quintd-assignment1-f24.html b/StudentNotebooks/Assignment01/quintd-assignment1-f24.html index 532e946..c9c4f4a 100644 --- a/StudentNotebooks/Assignment01/quintd-assignment1-f24.html +++ b/StudentNotebooks/Assignment01/quintd-assignment1-f24.html @@ -11,7 +11,7 @@ - + RPI github and Mars 2020 PIXL Example Notebook: @@ -167,7 +167,7 @@

RPI github and Mars 2020 PIXL Example Notebook:

DAR Assignment 1 (Fall 2024)

David Quintero

-

28 August 2024

+

03 September 2024

@@ -375,9 +375,9 @@

3.1 Load the PIXL Data and displa
# Saved LIBS data with locations added
 
 # NOTE: Use course directory version during the semester
-#pixl.df<- readRDS("/academics/MATP-4910-F24/DAR-Mars-F24/Data/samples_pixl_wide.Rds")
+pixl.df<- readRDS("~/DAR-Mars-F24/Data/samples_pixl_wide.Rds")
 # Use this version to  use downloaded data from github
-pixl.df <- readRDS("~/DAR-Mars-F24/Data/samples_pixl_wide.Rds")
+#pixl.df <- readRDS("~/DAR-Mars-F24/Data/samples_pixl_wide.Rds")
 
 # convert location to a number
 pixl.df$location <- as.numeric(pixl.df$location )
@@ -555,11 +555,11 @@ 

4.4 Create a PCA Biplot using ggb

4.5 ANSWER THESE QUESTIONS!

Add a description of each cluster here in your own words.

-

Describe Cluster 1: Your description here

-

Describe Cluster 2: Your description here

-

Describe Cluster 3: Your description here

+

Describe Cluster 1: Cluster 1 is the smallest in size compared to 2 and 3. Cluster 1 is also igneous. It’s also high composed of SiO2

+

Describe Cluster 2: Cluster 2 is the second largest in size. Cluster 2 is full of sedimentary rocks.

+

Describe Cluster 3: Cluster 3 is the largest in size. Cluster 3 is Igneous. It’s also highly composed of SiO2

What do the clustering and PCA results tell us about the data detected by the M20 PIXL experiment? Feel free to add graphs or analyses to support your conclusions.

-
# Student's code for graphs and analysis here!
+

The clustering tells us about the groupings of rocks and their compositions of molecules. The PCA gives us explained variance and the levels of molecules based on variance on the biplot.

4.6 SAVE, COMMIT and PUSH YOUR CHANGES!

diff --git a/StudentNotebooks/Assignment01/quintd-assignment1-f24.pdf b/StudentNotebooks/Assignment01/quintd-assignment1-f24.pdf new file mode 100644 index 0000000..44524ec Binary files /dev/null and b/StudentNotebooks/Assignment01/quintd-assignment1-f24.pdf differ diff --git a/StudentNotebooks/Assignment02/quintd-dar-f24-assignment2.Rmd b/StudentNotebooks/Assignment02/quintd-dar-f24-assignment2.Rmd new file mode 100644 index 0000000..fb4141d --- /dev/null +++ b/StudentNotebooks/Assignment02/quintd-dar-f24-assignment2.Rmd @@ -0,0 +1,530 @@ +--- +title: "Mars 2020 Mission Data Notebook:" +subtitle: "DAR Assignment 2 (Fall 2024)" +author: "David Quintero" +date: "`r format(Sys.time(), '%d %B %Y')`" +output: + pdf_document: default + html_document: + toc: true + number_sections: true + df_print: paged +--- +```{r setup, include=FALSE} + +# Required R package installation; RUN THIS BLOCK BEFORE ATTEMPTING TO KNIT THIS NOTEBOOK!!! +# This section install packages if they are not already installed. +# This block will not be shown in the knit file. +knitr::opts_chunk$set(echo = TRUE) + +# 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) +} + +# 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) +} + +``` + +# DAR ASSIGNMENT 2 (Introduction): Introductory DAR Notebook + +This notebook is broken into two main parts: + +* **Part 1:** Preparing your local repo for **DAR Assignment 2** +* **Part 2:** Loading and some analysis of the Mars 2020 (M20) Datasets + * Lithology: _Summarizes the mineral characteristics of samples collected at certain sample locations._ + * PIXL: Planetary Instrument for X-ray Lithochemistry. _Measures elemental chemistry of samples at sub-millimeter scales of samples._ + * SHERLOC: Scanning Habitable Environments with Raman and Luminescence for Organics and Chemicals. _Uses cameras, a spectrometer, and a laser of samples to search for organic compounds and minerals that have been altered in watery environments and may be signs of past microbial life._ + * LIBS: Laser-induced breakdown spectroscopy. _Uses a laser beam to help identify minerals in samples and other areas that are beyond the reach of the rover's robotic arm or in areas too steep for the rover to travel._ + +* **Part 3:** Individual analysis of your team's dataset + +**NOTE:** The RPI github repository for all the code and data required for this notebook may be found at: + +* https://github.rpi.edu/DataINCITE/DAR-Mars-F24 + +* **Part 4:** Preparation of Team Presentation + +# DAR ASSIGNMENT 2 (Part 1): Preparing your local repo for Assignment 2 + +In this assignment you'll start by making a copy of the Assignment 2 template notebook, then you'll add to your copy with your original work. The instructions which follow explain how to accomplish this. + +**NOTE:** You already cloned the `DAR-Mars-F24` repository for Assignment 1; you **do not** need to make another clone of the repo, but you must begin by updating your copy as instructed below: + +## Updating your local clone of the `DAR-Mars-F24` repository + +* Access RStudio Server on the IDEA Cluster at http://lp01.idea.rpi.edu/rstudio-ose/ + * REMINDER: You must be on the RPI VPN!! +* Access the Linux shell on the IDEA Cluster by clicking the **Terminal** tab of RStudio Server (lower left panel). + * You now see the Linux shell on the IDEA Cluster + * `cd` (change directory) to enter your home directory using: `cd ~` + * Type `pwd` to confirm where you are +* In the Linux shell, `cd` to `DAR-Mars-F24` + * Type `git pull origin main` to pull any updates + * Always do this when you being work; we might have added or changed something! +* In the Linux shell, `cd` into `Assignment02` + * Type `ls -al` to list the current contents + * Don't be surprised if you see many files! +* In the Linux shell, type `git branch` to verify your current working branch + * If it is not `dar-yourrcs`, type `git checkout dar-yourrcs` (where `yourrcs` is your RCS id) + * Re-type `git branch` to confirm +* Now in the RStudio Server UI, navigate to the `DAR-Mars-F24/StudentNotebooks/Assignment02` directory via the **Files** panel (lower right panel) + * Under the **More** menu, set this to be your R working directory + * Setting the correct working directory is essential for interactive R use! + +You're now ready to start coding Assignment 2! + +## Creating your copy of the Assignment 2 notebook + +1. In RStudio, make a **copy** of `dar-f24-assignment2-template.Rmd` file using a *new, original, descriptive* filename that **includes your RCS ID!** + * Open `dar-f24-assignment2-template.Rmd` + * **Save As...** using a new filename that includes your RCS ID + * Example filename for user `erickj4`: `erickj4-assignment2-f24.Rmd` + * POINTS OFF IF: + * You don't create a new filename! + * You don't include your RCS ID! + * You include `template` in your new filename! +2. Edit your new notebook using RStudio and save + * Change the `title:` and `subtitle:` headers (at the top of the file) + * Change the `author:` + * Don't bother changing the `date:`; it should update automagically... + * **Save** your changes +3. Use the RStudio `Knit` command to create an HTML file; repeat as necessary + * Use the down arrow next to the word `Knit` and select **Knit to HTML** + * You may also knit to PDF... +4. In the Linux terminal, use `git add` to add each new file you want to add to the repository + * Type: `git add yourfilename.Rmd` + * Type: `git add yourfilename.html` (created when you knitted) + * Add your PDF if you also created one... +5. When you're ready, in Linux commit your changes: + * Type: `git commit -m "some comment"` where "some comment" is a useful comment describing your changes + * This commits your changes to your local repo, and sets the stage for your next operation. +6. Finally, push your commits to the RPI github repo + * Type: `git push origin dar-yourrcs` (where `dar-yourrcs` is the branch you've been working in) + * Your changes are now safely on the RPI github. +7. **REQUIRED:** On the RPI github, **submit a pull request.** + * In a web browser, navigate to https://github.rpi.edu/DataINCITE/DAR-Mars-F24 + * In the branch selector drop-down (by default says **master**), select your branch + * **Submit a pull request for your branch** + * One of the DAR instructors will merge your branch, and your new files will be added to the master branch of the repo. _Do not merge your branch yourself!_ + +# DAR ASSIGNMENT 2 (Part 2): Loading the Mars 2020 (M20) Datasets + +In this assignment there are four datasets from separate instruments on the Mars Perserverance rover available for analysis: + +* **Lithology:** Summarizes the mineral characteristics of samples collected at certain sample locations +* **PIXL:** Planetary Instrument for X-ray Lithochemistry of collected samples +* **SHERLOC:** Scanning Habitable Environments with Raman and Luminescence for Organics and Chemicals for collected samples +* **LIBS:** Laser-induced breakdown spectroscopy which are measured in many areas (not just samples) + +Each dataset provides data about the mineralogy of the surface of Mars. Based on the purpose and nature of the instrument, the data is collected at different intervals along the path of Perseverance as it makes it way across the Jezero crater. Some of the data (esp. LIBS) is collected almost every Martian day, or _sol_. Some of the data (PIXL and SHERLOC) is only collected at certain sample locations of interest + +Your objective is to an analysis of the your teams dataset in order to learn all you can about these Mars samples. + +NOTES: + + * All of these datasets can be found in `/academics/MATP-4910-F24/DAR-Mars-F24/Data` + * We have included a comprehensive `samples.Rds` dataset that includes useful details about the sample locations, including Martian latitude and longitude and the sol that individual samples were collected. + * Also included is `rover.waypoints.Rds` that provides detailed location information (lat/lon) for the Perseverance rover throughout its journey, up to the present. This can be updated when necessary using the included `roverStatus-f24.R` script. + * A general guide to the available Mars 2020 data is available here: https://pds-geosciences.wustl.edu/missions/DAR-Mars2020/ + +## Data Set A: Load the Lithology Data + +The first five features of the dataset describe twenty-four (24) rover sample locations. + +The remaining features provides a simple binary (`1` or `0`) summary of presence or absence of 35 minerals at the 24 rover sample locations. + +Only the first sixteen (16) samples are maintained, as the remaining are missing the mineral descriptors. + +The following code "cleans" the dataset to prepare for analysis. It first creates a dataframe with metadata and measurements for samples, and then creates a matrix containing only numeric measurements for later analysis. + +```{r} +# Load the saved lithology data with locations added +lithology.df<- readRDS("/academics/MATP-4910-F24/DAR-Mars-F24/Data/mineral_data_static.Rds") + +# Cast samples as numbers +lithology.df$sample <- as.numeric(lithology.df$sample) + +# Convert rest into factors +lithology.df[sapply(lithology.df, is.character)] <- lapply(lithology.df[sapply(lithology.df, is.character)], + as.factor) + +# Keep only first 16 samples because the data for the rest of the samples is not available yet +lithology.df<-lithology.df[1:16,] + +# Look at summary of cleaned data frame +summary(lithology.df) + +# Create a matrix containing only the numeric measurements. The remaining features are metadata about the sample. +lithology.matrix <- sapply(lithology.df[,6:40],as.numeric)-1 + +# Review the structure of our matrix +str(lithology.matrix) +``` + + +## Data Set B: Load the PIXL Data - Assigned this one + +The PIXL data provides summaries of the mineral compositions measured at selected sample sites by the PIXL instrument. + +```{r} +# Load the saved PIXL data with locations added +pixl.df <- readRDS("/academics/MATP-4910-F24/DAR-Mars-F24/Data/samples_pixl_wide.Rds") + +# Convert to factors +pixl.df[sapply(pixl.df, is.character)] <- lapply(pixl.df[sapply(pixl.df, is.character)], + as.factor) + +# Review our dataframe +summary(pixl.df) + +# Make the matrix of just mineral percentage measurements +pixl.matrix <- pixl.df[,2:14] + +# Review the structure +str(pixl.matrix) +``` + +## Data Set C: Load the LIBS Data + +The LIBS data provides summaries of the mineral compositions measured at selected sample sites by the LIBS instrument, part of the Perseverance SuperCam. + +```{r} +# Load the saved LIBS data with locations added +libs.df <- readRDS("/academics/MATP-4910-F24/DAR-Mars-F24/Data/supercam_libs_moc_loc.Rds") + +#Drop features that are not to be used in the analysis for this notebook +libs.df <- libs.df %>% + select(!(c(distance_mm,Tot.Em.,SiO2_stdev,TiO2_stdev,Al2O3_stdev,FeOT_stdev, + MgO_stdev,Na2O_stdev,CaO_stdev,K2O_stdev,Total))) + +# Convert the points to numeric +libs.df$point <- as.numeric(libs.df$point) + +# Review what we have +summary(libs.df) + +# Make the a matrix contain only the libs measurements for each mineral +libs.matrix <- as.matrix(libs.df[,6:13]) + +# Review the structure +str(libs.matrix) +``` + + + +## Dataset D: Load the SHERLOC Data 0 - Assigned this one + +The SHERLOC data you will be using for this lab is the result of scientists' interpretations of extensive spectral analysis of abrasion samples provided by the SHERLOC instrument. + +**NOTE:** This dataset presents minerals as rows and sample sites as columns. You'll probably want to rotate the dataset for easier analysis.... + +```{r} + +# Read in data as provided. +sherloc_abrasion_raw <- readRDS("/academics/MATP-4910-F24/DAR-Mars-F24/Data/abrasions_sherloc_samples.Rds") + +# Clean up data types +sherloc_abrasion_raw$Mineral<-as.factor(sherloc_abrasion_raw$Mineral) +sherloc_abrasion_raw[sapply(sherloc_abrasion_raw, is.character)] <- lapply(sherloc_abrasion_raw[sapply(sherloc_abrasion_raw, is.character)], + as.numeric) +# Transform NA's to 0 +sherloc_abrasion_raw <- sherloc_abrasion_raw %>% replace(is.na(.), 0) + +# Reformat data so that rows are "abrasions" and columns list the presence of minerals. +# Do this by "pivoting" to a long format, and then back to the desired wide format. + +sherloc_long <- sherloc_abrasion_raw %>% + pivot_longer(!Mineral, names_to = "Name", values_to = "Presence") + +# Make abrasion a factor +sherloc_long$Name <- as.factor(sherloc_long$Name) + +# Make it a matrix +sherloc.matrix <- sherloc_long %>% + pivot_wider(names_from = Mineral, values_from = Presence) + +# Get sample information from PIXL and add to measurements -- assumes order is the same + +sherloc.df <- cbind(pixl.df[,c("sample","type","campaign","abrasion")],sherloc.matrix) + +# Review what we have +summary(sherloc.df) + +# Measurements are everything except first column +sherloc.matrix<-sherloc.matrix[,-1] + +# Sherlock measurement matrix +# Review the structure +str(sherloc.matrix) +``` + +## Data Set E: PIXL + Sherloc - Assigned this one +```{r} +# Combine PIXL and SHERLOC dataframes +pixl_sherloc.df <- cbind(pixl.df,sherloc.df ) + +# Review what we have +summary(pixl_sherloc.df) + +# Combine PIXL and SHERLOC matrices +pixl_sherloc.matrix<-cbind(pixl.matrix,sherloc.matrix) + +scaled_pixl_sherloc.matrix <- scale(pixl_sherloc.matrix) + +# Review the structure of our matrix +str(pixl_sherloc.matrix) + +``` + + + + +```{r} +pixl_sherloc_clean <- na.omit(pixl_sherloc.matrix) + +set.seed(240) +dist_matrix <- dist(pixl_sherloc_clean, method = "euclidean") + +hc <- hclust(dist_matrix, method = "complete") + +plot(hc, labels = FALSE, hang = -1, main = "Hierarchical Clustering Dendrogram (Not Scaled)") + +``` + +```{r} +pheatmap( + pixl_sherloc_clean, + cluster_rows = hc, + cluster_cols = TRUE, + scale = "none", + show_rownames = FALSE, + show_colnames = TRUE, + main = "Heatmap with Hierarchical Clustering (Not Scaled)" +) +``` + +```{r} + +set.seed(240) +scaled_dist_matrix <- dist(scaled_pixl_sherloc.matrix, method = "euclidean") + +scaled_hc <- hclust(scaled_dist_matrix, method = "complete") + +plot(scaled_hc, labels = FALSE, hang = -1, main = "Hierarchical Clustering Dendrogram (Scaled)") + + +``` + + +```{r} +scaled_pixl_sherloc_clean <- apply(scaled_pixl_sherloc.matrix, 2, function(x) { + ifelse(is.na(x) | is.nan(x) | is.infinite(x), 0, x) +}) + +scaled_dist_matrix_clean <- dist(scaled_pixl_sherloc_clean, method = "euclidean") + +scaled_hc_clean <- hclust(scaled_dist_matrix_clean, method = "complete") + + +pheatmap( + scaled_pixl_sherloc_clean, + cluster_rows = scaled_hc_clean, + cluster_cols = TRUE, + show_rownames = FALSE, + show_colnames = TRUE, + main = "Heatmap with Hierarchical Clustering (Scaled)" +) + +``` + + +## Data Set F: PIXL + Lithography + +Create data and matrix from prior datasets + +```{r} +# Combine our PIXL and Lithology dataframes +pixl_lithology.df <- cbind(pixl.df,lithology.df ) + +# Review what we have +summary(pixl_lithology.df) + +# Combine PIXL and Lithology matrices +pixl_lithology.matrix<-cbind(pixl.matrix,lithology.matrix) + +# Review the structure +str(pixl_lithology.matrix) + +``` + +## Data Set G: Sherloc + Lithology + +Create Data and matrix from prior datasets by taking on appropriate matrix + +```{r} +# Combine the Lithology and SHERLOC dataframes +sherloc_lithology.df <- cbind(sherloc.df,lithology.df ) + +# Review what we have +summary(sherloc_lithology.df) + +# Combine the Lithology and SHERLOC matrices +sherloc_lithology.matrix<-cbind(sherloc.matrix,lithology.matrix) + +# Review the resulting matrix +str(sherloc_lithology.matrix) + +``` + +# Analysis of Data (Part 3) + +```{r} +#invisible(str(pixl_sherloc.df)) + +summary(pixl_sherloc.df) + + +``` + + + +Each team has been assigned one of six datasets: + +1. Dataset B: PIXL: The PIXL team's goal is to understand and explain how scaling improves results from Assignment 1 + +2. Dataset C: LIBS (with appropriate scaling as necessary) + +3. Dataset D: Sherloc (with appropriate scaling as necessary) + +4. Dataset E: PIXL + Sherloc (with appropriate scaling as necessary) - I was assigned this one + +5. Dataset F: PIXL + Lithography (with appropriate scaling as necessary) + +6. Dataset G: Sherloc + Lithograpy (with appropriate scaling as necessary) + +**For each data set perform the following steps.** Feel free to use the methods/code from Assignment 1 as desired. Communicate with your teammates. Make sure that you are doing different variations of below analysis so that no team member does the exact same analysis. If you want to share clustering (which is okay but then vary rest), make sure you use the same random seeds. + +1. _Describe the data set contained in the data frame and matrix:_ How many rows does it have and how many features? Which features are measurements and which features are metadata about the samples? (3 pts) + +Dataset E, has 16 rows and 59 columns of data or rather features. The features that are measurements are Na20, Mgo, Al203, Si02, P205, S03, Cl, K20, Cao, Ti02, Cr203, Mno, and FeO-T. The features that are metadata are sample, name, type, campaign, location, and abrasion. + +2. _Scale this data appropriately (you can choose the scaling method):_ Explain why you chose that scaling method. (3 pts) +I chose the standard R-scaling method, the data was already said to be "scaled" but professor Bennett so to that end I didn't feel I needed to create some scaling method to show the difference, the standard one would be enough. + + +3. _Cluster the data using k-means or your favorite clustering method (like hierarchical clustering):_ Describe how you picked the best number of clusters. Indicate the number of points in each clusters. Coordinate with your team so you try different approaches. If you want to share results with your team mates, make sure to use the same random seeds. (6 pts) + +I used hierarchical clustering so I did not choose the number of clusters, instead I used a distance matrix and used all the clusters since the data was now scaled the points were spread out more evenly. + + +4. _Perform a **creative analysis** that provides insights into what one or more of the clusters are and what they tell you about the MARS data:_ + +I used a heatplot, I'll show you it here again as well as above: + +```{r} +pheatmap( + scaled_pixl_sherloc_clean, + cluster_rows = scaled_hc_clean, + cluster_cols = TRUE, + show_rownames = FALSE, + show_colnames = TRUE, + main = "Heatmap with Hierarchical Clustering (Scaled)" +) +``` + + + + +# Preparation of Team Presentation (Part 4) + +Prepare a presentation of your teams result to present in class on **September 11** starting at 9am in AE217 (20 pts) +The presentation should include the following elements + +1. A **Description** of the data set that you analyzed including how many observations and how many features. (<= 1.5 mins) +2. Each team member gets **three minutes** to explain their analysis: + * what analysis they performed + * the results of that analysis + * a brief discussion of their interpretation of these results + * <= 18 mins _total!_ +3. A **Conclusion** slide indicating major findings of the teams (<= 1.5 mins) +4. Thoughts on **potential next steps** for the MARS team (<= 1.5 mins) + +* A template for your team presentation is included here: https://bit.ly/dar-template-f24 + +* The rubric for the presentation is here: + +https://docs.google.com/document/d/1-4o1O4h2r8aMjAplmE-ItblQnyDAKZwNs5XCnmwacjs/pub + + + + + + + +# When you're done: SAVE, COMMIT and PUSH YOUR CHANGES! + +When you are satisfied with your edits and your notebook knits successfully, remember to push your changes to the repo using the following steps: + +* `git branch` + * To double-check that you are in your working branch +* `git add ` +* `git commit -m "Some useful comments"` +* `git push origin ` + +# Prepare group presentation + +Prepare a (at most) _three-slide_ presentation of your classification results and creative analysis. Create a joint presentation with your teammates using the Google Slides template available here: https://bit.ly/45twtUP (copy the template and customize with your content) + +Prepare a conclusion slide that summarizes all your results. + +Be prepared to present your results on xx Sep 2024 in class! + +# APPENDIX: Accessing RStudio Server on the IDEA Cluster + +The IDEA Cluster provides seven compute nodes (4x 48 cores, 3x 80 cores, 1x storage server) + +* The Cluster requires RCS credentials, enabled via registration in class + * email John Erickson for problems `erickj4@rpi.edu` +* RStudio, Jupyter, MATLAB, GPUs (on two nodes); lots of storage and computes +* Access via RPI physical network or VPN only + +# More info about Rstudio on our Cluster + +## RStudio GUI Access: + +* Use: + * http://lp01.idea.rpi.edu/rstudio-ose/ + * http://lp01.idea.rpi.edu/rstudio-ose-3/ + * http://lp01.idea.rpi.edu/rstudio-ose-6/ + * http://lp01.idea.rpi.edu/rstudio-ose-7/ +* Linux terminal accessible from within RStudio "Terminal" or via ssh (below) + diff --git a/StudentNotebooks/Assignment02/quintd-dar-f24-assignment2.pdf b/StudentNotebooks/Assignment02/quintd-dar-f24-assignment2.pdf new file mode 100644 index 0000000..90971a4 Binary files /dev/null and b/StudentNotebooks/Assignment02/quintd-dar-f24-assignment2.pdf differ