## Overview
This MATLAB script processes BGC-Argo (Biogeochemical Argo) float profile data for the California Upwelling region, combining data from MBARI-managed and non-MBARI managed floats, applying quality control filters, and estimating additional biogeochemical parameters using empirical algorithms.

## Study Area
- **Latitude bounds:** 30°N to 48°N
- **Longitude bounds:** -134°E to -115°E (West Coast of North America)
- **Temporal coverage:** January 1, 2018 onwards
- **Region:** California Current System

## Data Sources

### Primary Data
1. **BGC-Argo Synthetic Profile Index**
   - File: `argo_synthetic-profile_index.txt`
   - Source: https://usgodae.org/ftp/outgoing/argo/dac/
   - Contains metadata for all BGC-Argo profiles globally

2. **MBARI Float Data**
   - Directory: `SOCCOM_GO-BGC_LoResQC_LIAR_26Jun2025_odvtxt`
   - Source: https://library.ucsd.edu/dc/object/bb1310816p
   - Format: ODV (Ocean Data View) text files
   - Reference file: `MBARI_float_list.txt`

3. **Non-MBARI Floats (MBARI-managed)**
   - Directory: `MBARI_floatviz_QC`
   - Source: Downloaded via ARGO_PROCESSING/DATA/FLOATVIZ/QC
   - 12 of 24 non-MBARI floats have complete ODV files

### Excluded Floats
- **Argo Canada floats (8):** WMOs 4902663, 4902643, 4902642, 4902624, 4902554, 4902551, 4902549, 4901784
- **Temperature/Salinity only floats (3):** WMOs 4902541, 4902474, 4902472
- **Triple O2 float (1):** WMO 5906445

## Quality Control

### Quality Flags Applied
All profiles retained must have QF = 0 (good data) for:
- GPS position (Position_QF)
- Pressure (Pressure_dbar_QF)
- Temperature (Temperature_C_QF)
- Salinity (Salinity_pss_QF)
- Oxygen (Oxygen_umol_kg_QF)
- pHin (pHinsitu_Total_QF)

### Spatial Filtering
Only profiles within the defined lat/lon bounding box are retained.

## Derived Parameters

### 1. Total Alkalinity (TA)
- **Method:** ESPER_Mixed algorithm
- **Equation:** 7 (Salinity, Temperature, Oxygen)
- **Inputs:** Salinity, Temperature, Latitude, Longitude, Depth, DateTime
- **Output columns:**
  - TALK_ESPER_umol_kg
  - TALK_ESPER_umol_kg_Uncertainty

### 2. Dissolved Inorganic Carbon (DIC)
- **Method:** ESPER_Mixed algorithm
- **Equation:** 7 (Salinity, Temperature, Oxygen)
- **Inputs:** Salinity, Temperature, O2, Latitude, Longitude, Depth, DateTime
- **Output columns:**
  - DIC_ESPER_umol_kg
  - DIC_ESPER_umol_kg_Uncertainty

### 3. pH
- **Method:** ESPER_Mixed algorithm
- **Equation:** 7 (Salinity, Temperature, Oxygen)
- **Inputs:** Salinity, Temperature, O2, Latitude, Longitude, Depth, DateTime
- **Output columns:**
  - pH_ESPER_insitu_total
  - pH_ESPER_insitu_total_Uncertainty

### 4. Nutrients (NO3, SiOH4, PO4)
- **Method:** ESPER_Mixed algorithm
- **Equation:** 7 (Salinity, Temperature, Oxygen)
- **Inputs:** Salinity, Temperature, O2, Latitude, Longitude, Depth, DateTime
- **Output columns:**
    - PO4_ESPER_umol_kg
    - PO4_ESPER_umol_kg_Uncertainty
    - NO3_ESPER_umol_kg
    - NO3_ESPER_umol_kg_Uncertainty
    - SILICATE_ESPER_umol_kg
    - SILICATE_ESPER_umol_kg_Uncertainty

### 5. CO2 System Parameters
- **Method:** CO2SYSv3
- **Inputs:** TA (derived from ESPER_Mixed), pH (in situ Total scale), Temperature, Salinity, Pressure, Silicate (ESPER_Mixed), Phosphate (ESPER_Mixed)
- **Configuration:**
  - PAR1TYPE = 1 (Total Alkalinity)
  - PAR2TYPE = 3 (pH)
  - pHSCALEIN = 1 (Total scale)
  - K1K2CONSTANTS = 10
  - KSO4CONSTANT = 1
  - KFCONSTANT = 2
  - BORON = 2
- **Output columns:**
  - DIC_pHTA_umol_kg
  - PCO2_pHTA_uatm

## Data Processing Steps

1. **Index file filtering:** Extract profiles within spatial and temporal bounds
2. **Float identification:** Separate MBARI and non-MBARI managed floats
3. **File matching:** Match float WMOs to available ODV data files
4. **Table concatenation:** Combine all float data, adding NaN columns for missing variables
5. **Coordinate correction:** Convert longitude from degrees East to standard format (subtract 360)
6. **Quality control:** Apply QF filters, spatial bounds, pH with flag > 0 become NaN
7. **Parameter estimation:** Run ESPER_Mixed
8. **CO2 system calculation:** Use CO2SYSv3 to derive additional carbonate parameters
9. **Missing value standardization:** Replace -10000000000 and -999 with NaN

## Output Files

### Maps Generated
- `MAP_2018_2025.jpg` - All profiles since 2018
- `MAP_YYYY.jpg` - Annual maps for 2018-2025
- `MBARI_MANAGED_FLOATS_2018_2025.jpg` - MBARI-managed float profiles

### Final Data Product
- **Filename:** 'BGC_ARGO_ROMS.csv`
- **Description:** Quality-controlled BGC-Argo data with derived biogeochemical parameters for the California Upwelling region

## Notes
- Longitude values in ODV files are in degrees East and are corrected by subtracting 360
- Missing values are represented as -10000000000 in raw data, converted to NaN
- CO2SYSv3 missing values are represented as -999 and converted to NaN
- pH values are on the in situ Total scale
- All carbon system parameters use TEOS-10 compatible formulations

## References
- SOCCOM and GO-BGC float data - Snapshot 2025-06-26: Johnson, Kenneth S.; Fassbender, Andrea; Gray, Alison; Nicholson, David; Purkey, Sarah; Riser, Stephen C.; Takeshita, Yui; Talley, Lynne D.; Wijffels, Susan E.; Bartoloni, Sarah; Gilson, John; Grady, Logan A.; Guisewhite, Nicola J.; Maurer, Tanya L.; Parise, Katherine; Plant, Josh N.; Robbins, Pelle; Rupan, Rick A.; Swift, Dana D. (2025). SOCCOM and GO-BGC float data - Snapshot 2025-06-26. In Southern Ocean Carbon and Climate Observations and Modeling (SOCCOM) and Global Ocean Biogeochemistry (GO-BGC) Biogeochemical-Argo Float Data Archive. UC San Diego Library Digital Collections. https://doi.org/10.6075/J07P8ZSF
- MBARI managed PMEL: ARGO_PROCESSING/DATA/FLOATVIZ/QC. Need DOI.
- Canadian Argo: Not included right now. data from Sprof and converted to ODV format. Need DOI.
- ESPER_Mixed: Empirical algorithm for estimating ocean biogeochemical parameters
- CO2SYSv3: Carbon dioxide system calculations (Sharp et al., updated October 2021)

## Contact
For questions about data processing, refer to the Ben Werb bwerb@mbari.org or Yui Takeshita Yui@mbari.org