Copernicus Climate Data Store là một cơ sở dữ liệu khí hậu mở của Liên minh Châu Âu và được vận hành bởi European Centre for Medium-Range Weather Forecasts. Thông qua Copernicus Climate Data Store, người dùng có thể tiếp cận các bộ dữ liệu khí hậu mới nhất như:
Dữ liệu khí hậu đại dương ORAS5 từ 1958 đến hiện tại (lần cập nhật gần nhất vào 15/07/2024)
Dữ liệu khí hậu mặt đất ERA5-Land từ 1950 đến hiện tại (lần cập nhật gần nhất vào 06/09/2024)
# Đặt mã truy cập (Personal Access Token)
wf_set_key(key = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
# API mặc định từ ECMWF Python to list, tên file là "TMPFILE"
request <- list(
dataset_short_name = "reanalysis-oras5",
product_type = "consolidated",
vertical_resolution = "single_level",
variable = "sea_surface_temperature",
year = "2000",
month = "01",
download_format = "zip",
target = "TMPFILE"
)
# API với tên file "oras5.zip"
request <- list(
dataset_short_name = "reanalysis-oras5",
product_type = "consolidated",
vertical_resolution = "single_level",
variable = "sea_surface_temperature",
year = "2000",
month = "01",
download_format = "zip",
target = "oras5.zip"
)
file <- wf_request(
request = request, # API ở bước 3
transfer = TRUE, # TRUE để tải file
path = "." # Thư mục lưu file, "." nghĩa là sẽ lưu ở thư mục làm việc hiện tại (working directory)
)
# kiểm tra thư mục làm việc hiện tại
getwd()
oras5 <- read_ncdf("./sosstsst_control_monthly_highres_2D_200001_CONS_v0.1.nc")
oras5
stars object with 3 dimensions and 1 attribute
attribute(s), summary of first 1e+05 cells:
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
sosstsst [C] -2.039495 -1.878857 -1.844823 -1.365532 -0.6189743 0.1916933 72215
dimension(s):
from to refsys values x/y
x 1 1442 WGS 84 [1442x1021] -180,...,180 [x]
y 1 1021 WGS 84 [1442x1021] -77.01,...,89.95 [y]
time_counter 1 1 POSIXct 2000-01-16 UTC
curvilinear grid
dữ liệu ORAS5 có 3 chiều (dimensions): kinh độ (x), vĩ độ (y), và thời gian (time_counter); và 1 thuộc tính (attribute): nhiệt độ bề mặt nước biển (sostsst)
vì dữ liệu ORAS5 có phạm vi toàn cầu nên để tiện hiển thị mình sẽ cắt quanh khu vực Việt Nam
# cắt dữ liệu gần khu vực Việt Nam
oras5_sub <- oras5[, 100:200, 500:600, ]
# 100:200 là thứ tự chiều kinh độ x
# 500:600 là thứ tự chiều vĩ độ y
oras5_sub
stars object with 3 dimensions and 1 attribute
attribute(s):
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
sosstsst [C] 15.52323 25.36546 26.96291 26.31623 27.95051 29.54972 4115
dimension(s):
from to refsys values x/y
x 100 200 WGS 84 [101x101] 97.5,...,122.5 [x]
y 500 600 WGS 84 [101x101] 0.25,...,24.46 [y]
time_counter 1 1 POSIXct 2000-01-16 UTC
curvilinear grid
ggplot() +
geom_stars(data = oras5_sub) +
scale_fill_distiller(palette = "RdYlBu")
Lấy API tải dữ liệu và chuyển đổi API tải dữ liệu từ python sang R (tương tự như bước 1-2 ở phần Tải dữ liệu ORAS5). Các lựa chọn thuộc tính của dữ liệu ở ERA5 bao gồm: kiểu dữ liệu (product type, theo tháng hay theo giờ), biến (variable), năm (year), tháng (month), thời gian (nếu dữ liệu theo giờ), phạm vi địa lý, định dạng dữ liệu. Để ví dụ thì mình chọn như sau:
kiểu dữ liệu: theo tháng
biến: tổng lượng mưa (Total precipitation)
năm: 2000
tháng: 1-12
thời gian: không áp dụng
phạm vi địa lý: kinh độ 97.5°-122.5° và vĩ độ 0.26°-24.46° (quanh khu vực Việt Nam tương tự như ở dữ liệu ORAS5)
định dạng dữ liệu: NetCDF4 (file .nc giống như ở dữ liệu ORAS5)
Nhập API và tải dữ liệu
request <- list(
dataset_short_name = "reanalysis-era5-land-monthly-means",
product_type = "monthly_averaged_reanalysis",
variable = "total_precipitation",
year = "2000",
month = c("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"),
time = "00:00",
data_format = "netcdf",
download_format = "zip",
area = c(24.46, 97.5, 0.26, 122.5),
target = "era5.zip"
)
file <- wf_request(
request = request, # API
transfer = TRUE, # TRUE để tải file
path = "." # Thư mục lưu file
)
era5 <- read_ncdf("./data_0.nc")
era5
stars object with 3 dimensions and 1 attribute
attribute(s):
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
tp [m] 1.265877e-06 0.002358371 0.006183212 0.006319944 0.009148257 0.04215525 442164
dimension(s):
from to offset delta refsys values x/y
longitude 1 251 97.45 0.1 WGS 84 NULL [x]
latitude 1 243 24.51 -0.1 WGS 84 NULL [y]
valid_time 1 12 NA NA POSIXct 2000-01-01,...,2000-12-01
ggplot() +
geom_stars(data = era5) +
scale_fill_distiller(palette = "GnBu", na.value = "white") +
facet_wrap(~ valid_time)