MyNixOS website logo
Description

R Interface to Copernicus Marine Service.

Provides an R interface to the Copernicus Marine Service for downloading and accessing marine data. Integrates with the official 'copernicusmarine' Python library through 'reticulate'. Requires Python 3.7+ and a free Copernicus Marine account. See <https://marine.copernicus.eu/> and <https://pypi.org/project/copernicusmarine/> for more information.

copernicusR

R Python License

R package to download marine data from Copernicus Marine directly in R using Python and the official copernicusmarine library.


πŸš€ Description

copernicusR provides a seamless R interface to the Copernicus Marine Service, allowing you to download and access marine data directly from R. The package handles Python environment setup, credential management, and data access through the official Copernicus Marine API.

Key Features:

  • 🐍 Automatic Python setup - No manual Python configuration needed
  • πŸ” Secure credential management - Multiple secure storage options
  • πŸ“Š Direct dataset access - Explore data without downloading (open_dataset)
  • 🌊 Full NetCDF downloads - Download complete files with filtering
  • πŸ—ΊοΈ Advanced filtering - Spatial, temporal, and depth filtering
  • βœ… Built-in validation - Test functions to ensure everything works

πŸ“¦ Installation

Prerequisites

Install from GitHub

# Install if you don't have remotes
if (!requireNamespace("remotes", quietly = TRUE)) {
  install.packages("remotes")
}

# Install copernicusR
remotes::install_github("HansTtito/copernicusR")

# Load the package
library(copernicusR)

βš™οΈ Quick Start

1. Basic Setup

# One-time setup per session
setup_copernicus(username = "your_username", password = "your_password")

# Verify everything is working
copernicus_is_ready()
#> Checking Copernicus Marine environment:
#> βœ“ Python module copernicusmarine: OK
#> βœ“ Credentials configured for user: your_username
#> Ready to use Copernicus Marine!

# Test with a small download
copernicus_test()
#> Testing download from Copernicus Marine...
#> βœ“ Test download successful!

2. Alternative Setup (Recommended for Security)

# Method 1: Environment variables (.Renviron)
copernicus_set_env_credentials("your_username", "your_password")
# Restart R, then:
setup_copernicus()

# Method 2: Interactive setup
setup_copernicus()  # Will prompt for credentials

# Method 3: Manual environment variables
Sys.setenv(COPERNICUS_USERNAME = "your_username")
Sys.setenv(COPERNICUS_PASSWORD = "your_password")
setup_copernicus()

πŸ“Š Usage Examples

Open Dataset (Explore Without Downloading)

Perfect for data exploration and small extractions:

# Open dataset for exploration
dataset <- copernicus_open_dataset(
  dataset_id = "cmems_mod_glo_phy_anfc_0.083deg_P1D-m",
  variables = "zos",           # Sea water temperature
  start_date = "2024-01-01",
  end_date = "2024-01-03",
  bbox = c(-75, -73, -41, -38),   # Chilean coast [xmin, xmax, ymin, ymax]
  depth = c(0, 50)                # Surface to 50m
)

# Convert to R data structures if needed
data_r <- reticulate::py_to_r(dataset)

Download NetCDF Files

For full data downloads and local processing:

# Download sea temperature and salinity
file_path <- copernicus_download(
  dataset_id = "cmems_mod_glo_phy_anfc_0.083deg_P1D-m",
  variables = c("zos", "tob"), 
  start_date = "2024-01-01",
  end_date = "2024-01-31",
  bbox = c(-75, -70, -45, -17),   # Chilean coast
  depth = c(0, 100),
  output_file = "chile_coast_jan2024.nc"
)

# Process with R packages
library(terra)
temperature <- rast(file_path, lyrs = "zos")
plot(temperature[[1]])  # Plot first time step

Advanced Examples

# Multiple variables with custom output location
copernicus_download(
  dataset_id = "cmems_mod_glo_phy_anfc_0.083deg_P1D-m",
  variables = c("sob", "tob", "usi", "vsi", "zos"),  
  start_date = "2024-06-01",
  end_date = "2024-06-30",
  bbox = c(-80, -70, -45, -35),
  depth = c(0, 200),
  output_file = "data/summer_ocean_data.nc"
)

# Surface data only (no depth filtering)
surface_data <- copernicus_download(
  dataset_id = "cmems_mod_glo_phy_anfc_0.083deg_P1D-m",
  variables = "zos",         
  start_date = "2024-01-15",
  end_date = "2024-01-15",
  bbox = c(-180, 180, -90, 90)    # Global
)

πŸ” Credential Management

Secure Storage (Recommended)

# Store in .Renviron (persists across R sessions)
copernicus_set_env_credentials("your_username", "your_password")
# Restart R, credentials automatically loaded

# Check what's stored
copernicus_get_credentials()
#> $username
#> [1] "your_username"
#> $password
#> [1] "***MASKED***"

Session Management

# Set for current session only
copernicus_setup_credentials("username", "password")

# Clear when done
copernicus_clear_credentials()

# Validate credentials work
copernicus_validate_credentials()

πŸ“‹ Function Reference

Setup and Configuration

FunctionDescription
setup_copernicus()Main setup function (Python + credentials)
copernicus_is_ready()Check if everything is configured
copernicus_setup_credentials()Configure credentials only

Data Access

FunctionDescription
copernicus_download()Download NetCDF files
copernicus_open_dataset()Open datasets without downloading
copernicus_test()Test download functionality
copernicus_test_open()Test dataset opening

Credential Management

FunctionDescription
copernicus_get_credentials()View stored credentials
copernicus_clear_credentials()Clear session credentials
copernicus_set_env_credentials()Store in .Renviron
copernicus_validate_credentials()Test credentials

πŸ—ΊοΈ Common Dataset IDs

# Global Ocean Physics (0.083Β° resolution, daily)
"cmems_mod_glo_phy_anfc_0.083deg_P1D-m"

# Mediterranean Sea Physics (4.2km resolution)
"cmems_mod_med_phy_anfc_4.2km_P1D-m"

# Baltic Sea Physics
"cmems_mod_bal_phy_anfc_P1D-m"

# North West Shelf Physics
"cmems_mod_nws_phy_anfc_0.027deg_P1D-m"

πŸ’‘ Find more datasets: Browse the full catalog at data.marine.copernicus.eu


πŸ“Š Variable Reference

Physical Variables

CodeDescriptionUnits
"thetao"Sea water potential temperatureΒ°C
"so"Sea water salinityPSU
"uo", "vo"Sea water velocity (x, y)m/s
"zos"Sea surface height above geoidm
"mlotst"Mixed layer thicknessm

Biogeochemical Variables

CodeDescriptionUnits
"chl"Chlorophyll-a concentrationmg/mΒ³
"no3"Nitrate concentrationmmol/mΒ³
"po4"Phosphate concentrationmmol/mΒ³
"ph"pH-

πŸ—ΊοΈ Example Regions

# Predefined bounding boxes [xmin, xmax, ymin, ymax]
global    <- c(-180, 180, -90, 90)
chile     <- c(-75, -70, -45, -17)
med_sea   <- c(-6, 37, 30, 46)
north_sea <- c(-4, 9, 51, 62)
caribbean <- c(-87, -58, 9, 27)

⚠️ Troubleshooting

Common Issues

Python not found:

# Check Python configuration
reticulate::py_config()

# Manual Python setup
reticulate::use_python("/path/to/python")
setup_copernicus()

Authentication errors:

# Reset and reconfigure credentials
copernicus_clear_credentials()
copernicus_setup_credentials("username", "password")
copernicus_validate_credentials()

Download failures:

# Check system status
copernicus_is_ready()

# Try a test download
copernicus_test()

# Reduce data size (smaller bbox, fewer days)

Module import errors:

# Reinstall Python package
reticulate::py_install("copernicusmarine", pip = TRUE)

Getting Help

  1. Check function documentation: ?copernicus_download
  2. Validate your setup: copernicus_is_ready()
  3. Test with small requests before large downloads

πŸ“š Dependencies

R Packages

  • reticulate - Python integration
  • getPass - Secure password input (optional)

Python Packages

  • copernicusmarine - Official Copernicus Marine library (auto-installed)

🀝 Contributing

Contributions are welcome! Here's how you can help:

  1. Report bugs by opening an issue
  2. Suggest features through discussions
  3. Submit pull requests with improvements
  4. Improve documentation and examples

Development Setup

# Clone and install development version
git clone https://github.com/HansTtito/copernicusR.git
devtools::install("copernicusR")

# Run tests
devtools::test()

# Check package
devtools::check()

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments


πŸ“ˆ Citation

If you use this package in your research, please cite:

[Hans Ttito] (2025). copernicusR: R Interface to Copernicus Marine Service. 
R package version [version]. https://github.com/HansTtito/copernicusR
Metadata

Version

0.1.0

License

Unknown

PlatformsΒ (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows