Example Copernicus data download#
This notebook provides a rough, non-optimised example of how to download Copernicus Marine data using the copernicusmarine Python package.
This will download:
Global bathymetry data (static)
Global biogeochemical monthly data (0.25 degree hindcast)
Global physical daily data (0.25 degree reanalysis)
For a singular year (2023) and two months (June and July).
This notebook is intended as a basic example only. Modifications will be needed to adapt this to your own use case.
[ ]:
import copernicusmarine
import os
from datetime import datetime
[ ]:
YEAR = "2023"
MONTHS = ["06", "07"]
DAYS = [
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
]
[ ]:
### PHYSICAL DAILY FILES
os.chdir("~/data/phys/")
DATASET_ID = "cmems_mod_glo_phy-all_my_0.25deg_P1D-m"
for month in MONTHS:
for day in DAYS:
# check is valid date
try:
datetime(year=int(YEAR), month=int(month), day=int(day), hour=0)
except ValueError:
continue
filename = f"{DATASET_ID}_global_fulldepth_{YEAR}_{month}_{day}.nc"
if os.path.exists(filename):
print(f"File {filename} already exists, skipping...")
continue
copernicusmarine.subset(
dataset_id=DATASET_ID,
variables=["uo_glor", "vo_glor", "thetao_glor", "so_glor"],
minimum_longitude=-180,
maximum_longitude=179.75,
minimum_latitude=-80,
maximum_latitude=90,
start_datetime=f"{YEAR}-{month}-{day}T00:00:00",
end_datetime=f"{YEAR}-{month}-{day}T00:00:00",
minimum_depth=0.5057600140571594,
maximum_depth=5902.0576171875,
output_filename=filename,
)
[ ]:
### BIOGEOCHEMICAL MONTHLY FILES
os.chdir("~/data/bgc/")
DATASET_ID = "cmems_mod_glo_bgc_my_0.25deg_P1M-m"
DAY = "01"
for month in MONTHS:
try:
datetime(year=int(YEAR), month=int(month), day=int(DAY), hour=0)
except ValueError:
continue
filename = f"{DATASET_ID}_global_fulldepth_{YEAR}_{month}_{DAY}.nc"
if os.path.exists(filename):
print(f"File {filename} already exists, skipping...")
continue
copernicusmarine.subset(
dataset_id="cmems_mod_glo_bgc_my_0.25deg_P1M-m",
variables=["chl", "no3", "nppv", "o2", "ph", "phyc", "po4"],
minimum_longitude=-180,
maximum_longitude=179.75,
minimum_latitude=-80,
maximum_latitude=90,
start_datetime=f"{YEAR}-{month}-{DAY}T00:00:00",
end_datetime=f"{YEAR}-{month}-{DAY}T00:00:00",
minimum_depth=0.5057600140571594,
maximum_depth=5902.05810546875,
output_filename=filename,
)
[ ]:
### BATHYMETRY FILE
os.chdir("~/data/bathymetry/")
DATASET_ID = "cmems_mod_glo_phy_anfc_0.083deg_static"
filename = "cmems_mod_glo_phy_anfc_0.083deg_static_bathymetry.nc"
copernicusmarine.subset(
dataset_id=DATASET_ID,
dataset_part="bathy",
variables=["deptho"],
minimum_longitude=-180,
maximum_longitude=179.91668701171875,
minimum_latitude=-80,
maximum_latitude=90,
minimum_depth=0.49402499198913574,
maximum_depth=0.49402499198913574,
output_filename=filename,
)