{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {
    "id": "aKILrYGWpRCg",
    "vscode": {
     "languageId": "raw"
    }
   },
   "source": [
    "---\n",
    "title: \"Data Collection 1 — Colab Notebook\"\n",
    "date: \"March 31, 2026\"\n",
    "visible-after: \"2026-09-18T20:00:00-06:00\"\n",
    "---\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- **Team Name:** `[Write in the name of your team.]`\n- **Authors:** `[Write in the name of the authors of this notebook.]`\n- **Cell Number:** `[Write in your cell number.]`\n- **J-V Apparatus Number:** `[Write in the number of your apparatus (JV1, JV2, or JV3) that you used for your measurements.]`\n- **EQE Apparatus Number:** `[Write in the number of the apparatus (EQE1, EQE2, or EQE3) that you used for your measurements.]`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "gxyIg4wVsG2p"
   },
   "source": [
    "**Reminder.** For consistency across team notebooks, please include Markdown cells and inline comments to clarify key steps.\n",
    "\n",
    "You can also find additional boilerplate code for creating multi-week subplots in the [Multi-Week Plotting Helpers](multi-week-plotting.ipynb) notebook."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "6INEocJnNpwa"
   },
   "source": [
    "## J-V Analysis\n",
    "\n",
    "Now that you have two weeks of data, you will begin to make plots that show how the $J_{sc}$ and PCE change with time. The measurements you took last week prior to stressing will be at time equal to zero hours and the measurements this week will be after approximately 168 hours of stressing.\n",
    "\n",
    "1. Calculate the $J_{sc}$ for each of your pixels using the **forward scans**. Remember you can copy and paste code from previous notebooks and use AI tools. Consider using a loop in your python code to be more efficient."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "ipiTT_IRLs_H"
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "4FVxWZrfwMOX"
   },
   "outputs": [],
   "source": [
    "# Use this cell and any additional ones you copy and paste to calculate the Jsc values for each of your pixels\n",
    "# The J-V data files have columns: Voltage (V), Forward_mean (mA), Forward_std (mA), Forward_n,\n",
    "#                                   Reverse_mean (mA), Reverse_std (mA), Reverse_n\n",
    "# Example: jv_data = pd.read_csv('2026_02_04_IV_cellR34_pixel1.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "c3k4og1AhBgY"
   },
   "source": [
    "2. Calculate the Power Conversion Efficiency (PCE) for each of your pixels using the **forward scans**.\n",
    "\n",
    "    a. Remember you can copy and paste code from previous notebooks and use AI tools. Consider using a loop in your python code to be more efficient.\n",
    "    b. The light power hitting the pixel has been set to $P_{in} = 99.8\\ mW/cm^{2}$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "7LUWSN7MgyJk"
   },
   "outputs": [],
   "source": [
    "# Use this cell and any additional ones you copy and paste to calculate the PCE values for each of your pixels"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Rd-l4PFywiU_"
   },
   "source": [
    "3. Create a csv file with $J_{sc}$ and PCE values you just calculated for this week's measurements. This will allow you to easily reference previous weeks' data and plot data from multiple weeks at once.  **Be sure to download the csv file you create and add it to your team's Google Drive folder.**\n",
    "\n",
    "We have written the code for you to do this below. You just have to make sure the variable and file names are the ones you used."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "NwkOtaYXYeui"
   },
   "outputs": [],
   "source": [
    "# This code creates a csv file with your Jsc and PCE values for this week.\n",
    "# Update the filenames to match your data.\n",
    "\n",
    "# Time in hours since baseline measurement — update depending on week\n",
    "t = 168\n",
    "\n",
    "# Create a dictionary with the data.\n",
    "# Dictionaries store data values in key:value pairs.\n",
    "# Make sure the variable names in the dictionary match what you named them\n",
    "# when you calculated the Jsc and PCE values.\n",
    "week6_jsc_pce = {\n",
    "    'Pixel Number': [1, 2, 3, 4, 5, 6, 7, 8],\n",
    "    'Jsc (mA/cm^2)': [jsc_pix1, jsc_pix2, jsc_pix3, jsc_pix4, jsc_pix5, jsc_pix6, jsc_pix7, jsc_pix8],\n",
    "    'PCE': [pce_pix1, pce_pix2, pce_pix3, pce_pix4, pce_pix5, pce_pix6, pce_pix7, pce_pix8],\n",
    "    'Time (hr)': [t, t, t, t, t, t, t, t],\n",
    "}\n",
    "\n",
    "# Create a DataFrame from the dictionary\n",
    "df = pd.DataFrame(week6_jsc_pce)\n",
    "\n",
    "# Write the DataFrame to a CSV file\n",
    "# Update the file name to reflect correct date and cell ID\n",
    "df.to_csv('2026_02_04_jsc_pce_cellR34.csv', index=False)\n",
    "\n",
    "# Print statement to confirm your CSV has been made\n",
    "print(\"Data has been written to 2026_02_04_jsc_pce_cellR34.csv\")\n",
    "\n",
    "# Download the csv files you create to your team Google Drive folder\n",
    "# so they are easy to access for future weeks"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "uW518_qQc-5L"
   },
   "source": [
    "4. Copy and paste the code in the above cell into your Colab notebook from **the first time you took J-V data** to create a csv file of those $J_{sc}$ and PCE values as well. Make sure the variable and file names are correct. **You will need to change at least the date in the csv file name and set `t = 0` for the baseline measurement.**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "r8EiA2IvaPrS"
   },
   "source": [
    "5. Create figures that compare the $J_{sc}$ measurements and the PCE measurements from the first week to the measurements from this week. Start by uploading both csv files to Colab. The plotting code has been provided below to create one figure for each parameter with multiple sub-plots. Each plot is a different pixel."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "NaLqmNTcZ94z"
   },
   "outputs": [],
   "source": [
    "# Load the data from the uploaded CSV files. You will continue to add weeks\n",
    "# as you collect more data. Update file names to match yours.\n",
    "week5data = pd.read_csv('2026_01_28_jsc_pce_cellR34.csv')\n",
    "week6data = pd.read_csv('2026_02_04_jsc_pce_cellR34.csv')\n",
    "\n",
    "# Combine the data\n",
    "combined_df = pd.concat([week5data, week6data])\n",
    "\n",
    "# Plot for Jsc (4x2 grid)\n",
    "# The loop goes through each unique Pixel Number in the dataset (e.g., 1–8).\n",
    "# For each pixel, it selects the relevant subset of data and plots Jsc vs. Time\n",
    "# on the correct subplot. The safeguard (if idx >= len(axes)) ensures the code\n",
    "# won't break if there are fewer or more than 8 pixels. Any unused subplots are hidden.\n",
    "\n",
    "# 4 rows × 2 columns = 8 subplots\n",
    "fig, axes = plt.subplots(4, 2, figsize=(12, 16))\n",
    "\n",
    "# Flatten the axes array so you can index them as axes[0] ... axes[7]\n",
    "axes = axes.flatten()\n",
    "\n",
    "for idx, pixel in enumerate(combined_df['Pixel Number'].unique()):\n",
    "    if idx >= len(axes):   # safeguard in case there are fewer than 8 pixels\n",
    "        break\n",
    "\n",
    "    subset = combined_df[combined_df['Pixel Number'] == pixel]\n",
    "\n",
    "    ax = axes[idx]\n",
    "    ax.scatter(subset['Time (hr)'], subset['Jsc (mA/cm^2)'], color='g')  # customize style as needed\n",
    "\n",
    "    ax.set_title(f'Pixel {pixel}')\n",
    "    ax.set_xlabel('Time (hr)')\n",
    "    ax.set_ylabel('Jsc (mA/cm^2)')\n",
    "\n",
    "# Adjust layout and show plot\n",
    "plt.tight_layout()\n",
    "plt.show()\n",
    "\n",
    "\n",
    "# Plot for PCE (4x2 grid)\n",
    "fig, axes = plt.subplots(4, 2, figsize=(12, 16))\n",
    "axes = axes.flatten()\n",
    "\n",
    "for idx, pixel in enumerate(combined_df['Pixel Number'].unique()):\n",
    "    if idx >= len(axes):   # safeguard again\n",
    "        break\n",
    "\n",
    "    subset = combined_df[combined_df['Pixel Number'] == pixel]\n",
    "\n",
    "    ax = axes[idx]\n",
    "    ax.scatter(subset['Time (hr)'], subset['PCE'], color='b')  # customize style as needed\n",
    "\n",
    "    ax.set_title(f'Pixel {pixel}')\n",
    "    ax.set_xlabel('Time (hr)')\n",
    "    ax.set_ylabel('PCE')\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Sqe0osgJpjJC"
   },
   "source": [
    "**Question 1:** Discuss what you observe from looking at the comparison of the $J_{sc}$ and PCE values from this week and the first week. Do you have any pixels showing different behaviors after their first week of stressing?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "_sCRfnTYdnfP"
   },
   "source": [
    "## EQE Analysis\n",
    "\n",
    "1. Calculate the EQE for each pixel you measured this week.\n",
    "\n",
    "    a. Remember you can copy and paste code from previous notebooks and use AI tools. Consider using a loop in your python code to be more efficient."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "CeylU17bEvFW"
   },
   "outputs": [],
   "source": [
    "# Use this cell and any additional ones you copy and paste to calculate the EQE for each of your measured pixels\n",
    "# Power data columns: Wavelength (nm), Power_mean (uW), Power_std (uW), n\n",
    "# Current data columns: Wavelength (nm), Current_mean (nA), Current_std (nA), n\n",
    "# Example: power_data = pd.read_csv('2026_02_04_power_cellR34.csv')\n",
    "#          pix1_current = pd.read_csv('2026_02_04_current_cellR34_pixel1.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "kucAp-FTEtVZ"
   },
   "source": [
    "2. Now we will create a csv file for your EQE data to simplify plotting multiple weeks worth of data on one plot.  The code below will help to create a csv file combining all your pixel EQE data from this week."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "W4fDSLf_hQMG"
   },
   "outputs": [],
   "source": [
    "# This code creates a single csv file combining your EQE results for all pixels.\n",
    "# Update the variable and file names to match your data.\n",
    "\n",
    "import pandas as pd\n",
    "\n",
    "# You can use any pixel's current data to get the Wavelength column\n",
    "# (they all share the same wavelengths)\n",
    "pix1_current_data = pd.read_csv('2026_02_04_current_cellR34_pixel1.csv')\n",
    "\n",
    "# Create a combined DataFrame with all pixel EQE values.\n",
    "# The column names should be 'eqe_pix1', 'eqe_pix2', etc.\n",
    "# Make sure the variable names match what you calculated in the cell(s) above.\n",
    "eqe_df = pd.DataFrame({\n",
    "    'Wavelength (nm)': pix1_current_data['Wavelength (nm)'],\n",
    "    'eqe_pix1': eqe_pix1,\n",
    "    'eqe_pix2': eqe_pix2,\n",
    "    'eqe_pix3': eqe_pix3,\n",
    "    'eqe_pix4': eqe_pix4,\n",
    "    'eqe_pix5': eqe_pix5,\n",
    "    'eqe_pix6': eqe_pix6,\n",
    "    'eqe_pix7': eqe_pix7,\n",
    "    'eqe_pix8': eqe_pix8,\n",
    "})\n",
    "\n",
    "# Write to CSV - update the file name to reflect correct date and cell ID\n",
    "eqe_df.to_csv('2026_02_04_eqe_cellR34.csv', index=False)\n",
    "\n",
    "print(\"EQE data has been written to 2026_02_04_eqe_cellR34.csv\")\n",
    "\n",
    "# Download the csv files you create to your team Google Drive folder so they\n",
    "# are easy to access for future weeks"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "OfE5R1SIjNVS"
   },
   "source": [
    "3. If you did not create a csv file of your EQE data from your first week of baseline data collection, copy and paste the code in the above cell into your Colab notebook from **the first week** to create a csv file of those EQE data as well. Make sure the variable and file names are correct. **You will need to change at least the date in the csv file name.**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Srl6iBTBiERe"
   },
   "source": [
    "4. Update and use the code below to create a figure that compares the EQE measurements from the first week to the measurements from this week. The code included here plots data for the first pixel."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "JZyjlo5Th_rC"
   },
   "outputs": [],
   "source": [
    "# Load EQE data for each week - update file names to match yours.\n",
    "# You will continue to add weeks as you collect more data.\n",
    "eqe_week5 = pd.read_csv('2026_01_28_eqe_cellR34.csv')\n",
    "eqe_week6 = pd.read_csv('2026_02_04_eqe_cellR34.csv')\n",
    "\n",
    "# Create a figure with 8 subplots arranged in 4 rows x 2 columns\n",
    "fig, axes = plt.subplots(4, 2, figsize=(12, 16))\n",
    "axes = axes.flatten()\n",
    "\n",
    "for i in range(8):\n",
    "    ax = axes[i]\n",
    "    col = f'eqe_pix{i+1}'\n",
    "\n",
    "    if col in eqe_week5.columns:\n",
    "        ax.plot(eqe_week5['Wavelength (nm)'], eqe_week5[col],\n",
    "                label='Week 5', color='blue', linestyle='-')\n",
    "    if col in eqe_week6.columns:\n",
    "        ax.plot(eqe_week6['Wavelength (nm)'], eqe_week6[col],\n",
    "                label='Week 6', color='red', linestyle='-.')\n",
    "\n",
    "    ax.set_title(f'Pixel {i+1}')\n",
    "    ax.set_xlabel('Wavelength (nm)')\n",
    "    ax.set_ylabel('EQE')\n",
    "    ax.legend()\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.show()\n",
    "\n",
    "# Note: As you add more weeks, see the Multi-Week Plotting Helpers notebook\n",
    "# for a version that loads datasets from a list automatically."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "ux-YbP3JiHHg"
   },
   "source": [
    "\n",
    "**Question 2:** Discuss what you observe from looking at the comparison of the EQE plots from this week and last week. Do you have any pixels showing different behaviors after their first week of stressing?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "NhaldreWFciG"
   },
   "source": [
    "## Author Contributions (required)\n",
    "\n",
    "List the name of each team member and please describe briefly how each member contributed to the work in lab this week. (e.g., taking a measurement, updating the Colab notebook, etc.)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "wzuOP0_l4LG0"
   },
   "source": [
    "## Use of AI (required)\n",
    "\n",
    "1.   How your team used AI tools: Describe the specific tasks where AI-assisted tools were involved. For example, did AI help with writing, debugging, optimizing, or refining your code? Which components of the analysis did your team use AI on?\n",
    "2.   When your team used AI tools: Specify at what stage(s) of your programming process you used AI. Was it during initial code development, troubleshooting, etc.?\n",
    "3.   Which AI tools your team used: Identify the AI tools or platforms your team consulted (e.g., ChatGPT, GitHub Copilot, etc.)."
   ]
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
