Preskoči

Vizualizacija podnebnih podatkov NetCDF4

Tu so zbrani zapiski o vizualizaciji podnebnih podatkov iz Climate Data Store s Panoply in R.

Dostop do podatkov #

We will be using data from the Climate Data Store. You must create a ECMWF account to submit requests for downloading data. The data is usually provided in NetCDF files (*.nc files).

Vizualizacija s Panoply #

We will use Panoply to visualize the data in NetCDF files. Panoply is useful to quickly create a map or line plot and get an overview of the data. It also lets you view geographical data in a table.

Namestitev #

You can download Panoply from https://www.giss.nasa.gov/tools/panoply/download/

The site also includes instructions on installing Panoply on your operating system. You may need to install Java to run Panoply. It is recommended to install Java Temurin from https://adoptium.net/

Basic plotting #

A tutorial on the basics of using Panoply to view map data can be found at https://disc.gsfc.nasa.gov/information/howto?title=Quick%20View%20Data%20with%20Panoply

Combining plots #

Two plots can be combined, for example to visualize differences between two datasets.

A tutoral on how to combine two arrays is at https://disc.gsfc.nasa.gov/information/howto?title=How%20to%20Combine%20Two%20Data%20Arrays%20in%20a%20Single%20Plot%20with%20Panoply

Delo z NetCDF podatki v R #

We will use the data from Temperature statistics for Europe derived from climate projections. In the download tab select Average temperature, Year, Time average, both RCP4.5 and RCP8.5, Ensemble members average. After submitting the form, the data will be prepared for download. In the downloaded zip file there should be two files: one with RCP4.5 data and one with RCP8.5 data.

Using R, we can extract data from the downloaded files and plot it. We will use the ncdf4 package, which can be used to read and create NetCDF files. First, we install the package (you only need to run this line once):

install.packages("ncdf4")

We then load the ncdf4 package and also ggplot2, which we will use to make plots.

library(ncdf4)
library(ggplot2)

Let’s start with RCP4.5 data.

# Open a NetCDF file
ncfile <- nc_open("mean_Tmean_Yearly_rcp45_mean_v1.0.nc")
print(ncfile)
File mean_Tmean_Yearly_rcp45_mean_v1.0.nc (NC_FORMAT_NETCDF4):

     2 variables (excluding dimension variables):
        float mean_Tmean_Yearly[lon,lat,time]   (Contiguous storage)  
            _FillValue: NaN
            units: degrees C
            long_name: Ensemble members average of mean Yearly Tmean for future climate under rcp45
            coordinates: height
        double height[]   (Contiguous storage)  
            _FillValue: NaN
            units: m
            axis: Z
            positive: up
            long_name: height
            standard_name: height

     3 dimensions:
        lat  Size:425 
            _FillValue: NaN
            units: degrees_north
            standard_name: latitude
        lon  Size:599 
            _FillValue: NaN
            units: degrees_east
            standard_name: longitude
        time  Size:100 
            standard_name: time
            units: days since 1986-01-01 00:00:00
            calendar: proleptic_gregorian

    7 global attributes:
        title: Processed EURO-CORDEX future climate data for the health sector
        conventions: CF-1.6
        project: Copernicus Climate Change Service Sectoral Information System European Health
        source: Processing of bias-corrected EURO-CORDEX data by VITO
        contact: [email protected]
        creation_date: Tue May 21 16:43:59 2019
        institution: VITO (https://vito.be/en)

In the output above we can see the names of the variables in the file and names of the dimensions (longitude, latitude, time). We can also see the length of each dimension. The values of variables and dimensions can be accessed by passing their name to nc_get.

# Read the longitude, latitude and time values 
lon <- ncvar_get(ncfile, "lon")
lat <- ncvar_get(ncfile, "lat")
time <- ncvar_get(ncfile, "time")
print(lon)
  [1] -24.9 -24.8 -24.7 -24.6 -24.5 -24.4 -24.3 -24.2 -24.1 -24.0 -23.9 -23.8
 [13] -23.7 -23.6 -23.5 -23.4 -23.3 -23.2 -23.1 -23.0 -22.9 -22.8 -22.7 -22.6
 [25] -22.5 -22.4 -22.3 -22.2 -22.1 -22.0 -21.9 -21.8 -21.7 -21.6 -21.5 -21.4
 [37] -21.3 -21.2 -21.1 -21.0 -20.9 -20.8 -20.7 -20.6 -20.5 -20.4 -20.3 -20.2
 [49] -20.1 -20.0 -19.9 -19.8 -19.7 -19.6 -19.5 -19.4 -19.3 -19.2 -19.1 -19.0
 [61] -18.9 -18.8 -18.7 -18.6 -18.5 -18.4 -18.3 -18.2 -18.1 -18.0 -17.9 -17.8
 [73] -17.7 -17.6 -17.5 -17.4 -17.3 -17.2 -17.1 -17.0 -16.9 -16.8 -16.7 -16.6
 [85] -16.5 -16.4 -16.3 -16.2 -16.1 -16.0 -15.9 -15.8 -15.7 -15.6 -15.5 -15.4
 [97] -15.3 -15.2 -15.1 -15.0 -14.9 -14.8 -14.7 -14.6 -14.5 -14.4 -14.3 -14.2
[109] -14.1 -14.0 -13.9 -13.8 -13.7 -13.6 -13.5 -13.4 -13.3 -13.2 -13.1 -13.0
[121] -12.9 -12.8 -12.7 -12.6 -12.5 -12.4 -12.3 -12.2 -12.1 -12.0 -11.9 -11.8
[133] -11.7 -11.6 -11.5 -11.4 -11.3 -11.2 -11.1 -11.0 -10.9 -10.8 -10.7 -10.6
[145] -10.5 -10.4 -10.3 -10.2 -10.1 -10.0  -9.9  -9.8  -9.7  -9.6  -9.5  -9.4
[157]  -9.3  -9.2  -9.1  -9.0  -8.9  -8.8  -8.7  -8.6  -8.5  -8.4  -8.3  -8.2
[169]  -8.1  -8.0  -7.9  -7.8  -7.7  -7.6  -7.5  -7.4  -7.3  -7.2  -7.1  -7.0
[181]  -6.9  -6.8  -6.7  -6.6  -6.5  -6.4  -6.3  -6.2  -6.1  -6.0  -5.9  -5.8
[193]  -5.7  -5.6  -5.5  -5.4  -5.3  -5.2  -5.1  -5.0  -4.9  -4.8  -4.7  -4.6
[205]  -4.5  -4.4  -4.3  -4.2  -4.1  -4.0  -3.9  -3.8  -3.7  -3.6  -3.5  -3.4
[217]  -3.3  -3.2  -3.1  -3.0  -2.9  -2.8  -2.7  -2.6  -2.5  -2.4  -2.3  -2.2
[229]  -2.1  -2.0  -1.9  -1.8  -1.7  -1.6  -1.5  -1.4  -1.3  -1.2  -1.1  -1.0
[241]  -0.9  -0.8  -0.7  -0.6  -0.5  -0.4  -0.3  -0.2  -0.1   0.0   0.1   0.2
[253]   0.3   0.4   0.5   0.6   0.7   0.8   0.9   1.0   1.1   1.2   1.3   1.4
[265]   1.5   1.6   1.7   1.8   1.9   2.0   2.1   2.2   2.3   2.4   2.5   2.6
[277]   2.7   2.8   2.9   3.0   3.1   3.2   3.3   3.4   3.5   3.6   3.7   3.8
[289]   3.9   4.0   4.1   4.2   4.3   4.4   4.5   4.6   4.7   4.8   4.9   5.0
[301]   5.1   5.2   5.3   5.4   5.5   5.6   5.7   5.8   5.9   6.0   6.1   6.2
[313]   6.3   6.4   6.5   6.6   6.7   6.8   6.9   7.0   7.1   7.2   7.3   7.4
[325]   7.5   7.6   7.7   7.8   7.9   8.0   8.1   8.2   8.3   8.4   8.5   8.6
[337]   8.7   8.8   8.9   9.0   9.1   9.2   9.3   9.4   9.5   9.6   9.7   9.8
[349]   9.9  10.0  10.1  10.2  10.3  10.4  10.5  10.6  10.7  10.8  10.9  11.0
[361]  11.1  11.2  11.3  11.4  11.5  11.6  11.7  11.8  11.9  12.0  12.1  12.2
[373]  12.3  12.4  12.5  12.6  12.7  12.8  12.9  13.0  13.1  13.2  13.3  13.4
[385]  13.5  13.6  13.7  13.8  13.9  14.0  14.1  14.2  14.3  14.4  14.5  14.6
[397]  14.7  14.8  14.9  15.0  15.1  15.2  15.3  15.4  15.5  15.6  15.7  15.8
[409]  15.9  16.0  16.1  16.2  16.3  16.4  16.5  16.6  16.7  16.8  16.9  17.0
[421]  17.1  17.2  17.3  17.4  17.5  17.6  17.7  17.8  17.9  18.0  18.1  18.2
[433]  18.3  18.4  18.5  18.6  18.7  18.8  18.9  19.0  19.1  19.2  19.3  19.4
[445]  19.5  19.6  19.7  19.8  19.9  20.0  20.1  20.2  20.3  20.4  20.5  20.6
[457]  20.7  20.8  20.9  21.0  21.1  21.2  21.3  21.4  21.5  21.6  21.7  21.8
[469]  21.9  22.0  22.1  22.2  22.3  22.4  22.5  22.6  22.7  22.8  22.9  23.0
[481]  23.1  23.2  23.3  23.4  23.5  23.6  23.7  23.8  23.9  24.0  24.1  24.2
[493]  24.3  24.4  24.5  24.6  24.7  24.8  24.9  25.0  25.1  25.2  25.3  25.4
[505]  25.5  25.6  25.7  25.8  25.9  26.0  26.1  26.2  26.3  26.4  26.5  26.6
[517]  26.7  26.8  26.9  27.0  27.1  27.2  27.3  27.4  27.5  27.6  27.7  27.8
[529]  27.9  28.0  28.1  28.2  28.3  28.4  28.5  28.6  28.7  28.8  28.9  29.0
[541]  29.1  29.2  29.3  29.4  29.5  29.6  29.7  29.8  29.9  30.0  30.1  30.2
[553]  30.3  30.4  30.5  30.6  30.7  30.8  30.9  31.0  31.1  31.2  31.3  31.4
[565]  31.5  31.6  31.7  31.8  31.9  32.0  32.1  32.2  32.3  32.4  32.5  32.6
[577]  32.7  32.8  32.9  33.0  33.1  33.2  33.3  33.4  33.5  33.6  33.7  33.8
[589]  33.9  34.0  34.1  34.2  34.3  34.4  34.5  34.6  34.7  34.8  34.9
print(lat)
  [1] 30.1 30.2 30.3 30.4 30.5 30.6 30.7 30.8 30.9 31.0 31.1 31.2 31.3 31.4 31.5
 [16] 31.6 31.7 31.8 31.9 32.0 32.1 32.2 32.3 32.4 32.5 32.6 32.7 32.8 32.9 33.0
 [31] 33.1 33.2 33.3 33.4 33.5 33.6 33.7 33.8 33.9 34.0 34.1 34.2 34.3 34.4 34.5
 [46] 34.6 34.7 34.8 34.9 35.0 35.1 35.2 35.3 35.4 35.5 35.6 35.7 35.8 35.9 36.0
 [61] 36.1 36.2 36.3 36.4 36.5 36.6 36.7 36.8 36.9 37.0 37.1 37.2 37.3 37.4 37.5
 [76] 37.6 37.7 37.8 37.9 38.0 38.1 38.2 38.3 38.4 38.5 38.6 38.7 38.8 38.9 39.0
 [91] 39.1 39.2 39.3 39.4 39.5 39.6 39.7 39.8 39.9 40.0 40.1 40.2 40.3 40.4 40.5
[106] 40.6 40.7 40.8 40.9 41.0 41.1 41.2 41.3 41.4 41.5 41.6 41.7 41.8 41.9 42.0
[121] 42.1 42.2 42.3 42.4 42.5 42.6 42.7 42.8 42.9 43.0 43.1 43.2 43.3 43.4 43.5
[136] 43.6 43.7 43.8 43.9 44.0 44.1 44.2 44.3 44.4 44.5 44.6 44.7 44.8 44.9 45.0
[151] 45.1 45.2 45.3 45.4 45.5 45.6 45.7 45.8 45.9 46.0 46.1 46.2 46.3 46.4 46.5
[166] 46.6 46.7 46.8 46.9 47.0 47.1 47.2 47.3 47.4 47.5 47.6 47.7 47.8 47.9 48.0
[181] 48.1 48.2 48.3 48.4 48.5 48.6 48.7 48.8 48.9 49.0 49.1 49.2 49.3 49.4 49.5
[196] 49.6 49.7 49.8 49.9 50.0 50.1 50.2 50.3 50.4 50.5 50.6 50.7 50.8 50.9 51.0
[211] 51.1 51.2 51.3 51.4 51.5 51.6 51.7 51.8 51.9 52.0 52.1 52.2 52.3 52.4 52.5
[226] 52.6 52.7 52.8 52.9 53.0 53.1 53.2 53.3 53.4 53.5 53.6 53.7 53.8 53.9 54.0
[241] 54.1 54.2 54.3 54.4 54.5 54.6 54.7 54.8 54.9 55.0 55.1 55.2 55.3 55.4 55.5
[256] 55.6 55.7 55.8 55.9 56.0 56.1 56.2 56.3 56.4 56.5 56.6 56.7 56.8 56.9 57.0
[271] 57.1 57.2 57.3 57.4 57.5 57.6 57.7 57.8 57.9 58.0 58.1 58.2 58.3 58.4 58.5
[286] 58.6 58.7 58.8 58.9 59.0 59.1 59.2 59.3 59.4 59.5 59.6 59.7 59.8 59.9 60.0
[301] 60.1 60.2 60.3 60.4 60.5 60.6 60.7 60.8 60.9 61.0 61.1 61.2 61.3 61.4 61.5
[316] 61.6 61.7 61.8 61.9 62.0 62.1 62.2 62.3 62.4 62.5 62.6 62.7 62.8 62.9 63.0
[331] 63.1 63.2 63.3 63.4 63.5 63.6 63.7 63.8 63.9 64.0 64.1 64.2 64.3 64.4 64.5
[346] 64.6 64.7 64.8 64.9 65.0 65.1 65.2 65.3 65.4 65.5 65.6 65.7 65.8 65.9 66.0
[361] 66.1 66.2 66.3 66.4 66.5 66.6 66.7 66.8 66.9 67.0 67.1 67.2 67.3 67.4 67.5
[376] 67.6 67.7 67.8 67.9 68.0 68.1 68.2 68.3 68.4 68.5 68.6 68.7 68.8 68.9 69.0
[391] 69.1 69.2 69.3 69.4 69.5 69.6 69.7 69.8 69.9 70.0 70.1 70.2 70.3 70.4 70.5
[406] 70.6 70.7 70.8 70.9 71.0 71.1 71.2 71.3 71.4 71.5 71.6 71.7 71.8 71.9 72.0
[421] 72.1 72.2 72.3 72.4 72.5
print(time)
  [1]     0   365   730  1096  1461  1826  2191  2557  2922  3287  3652  4018
 [13]  4383  4748  5113  5479  5844  6209  6574  6940  7305  7670  8035  8401
 [25]  8766  9131  9496  9862 10227 10592 10957 11323 11688 12053 12418 12784
 [37] 13149 13514 13879 14245 14610 14975 15340 15706 16071 16436 16801 17167
 [49] 17532 17897 18262 18628 18993 19358 19723 20089 20454 20819 21184 21550
 [61] 21915 22280 22645 23011 23376 23741 24106 24472 24837 25202 25567 25933
 [73] 26298 26663 27028 27394 27759 28124 28489 28855 29220 29585 29950 30316
 [85] 30681 31046 31411 31777 32142 32507 32872 33238 33603 33968 34333 34699
 [97] 35064 35429 35794 36160
# In the printed text, we see that the variable of interest is named mean_Tmean_Yearly
temp <- ncvar_get(ncfile, "mean_Tmean_Yearly")
# After getting the data we should close the NetCDF file
nc_close(ncfile)

We get a 3-dimensional array [lon,lat,time]. Let’s look at the [lon,lat] at the first time entry, which corresponds to 1986 (middle of 30-year period 1971-2000).

temp_first_table <- temp[,,1]
# Visualize the table for the first time entry
image(temp_first_table)

# Check the index corresponding to the point near Ljubljana (46.0N 14.5E)
print(lon[395])
[1] 14.5
print(lat[160])
[1] 46
# Access the value for Ljubljana for 1970-2000
print(temp_first_table[395,160])
[1] 10.3733
# Access the values for Ljubljana in the last period (2071-2100)
print(temp[395,160,100])
[1] 12.64245
# Access values for the chosen coordinates for all periods
temp_Ljubljana_RCP45 <- temp[395,160,]
print(temp_Ljubljana_RCP45)
  [1] 10.37330 10.40969 10.41473 10.41373 10.44592 10.48794 10.54408 10.58044
  [9] 10.60750 10.65774 10.68678 10.72603 10.75881 10.79806 10.83322 10.85831
 [17] 10.90655 10.93261 10.95412 10.99847 11.02307 11.03563 11.06941 11.08192
 [25] 11.07606 11.11603 11.15922 11.19318 11.21749 11.22657 11.23662 11.25818
 [33] 11.28755 11.31124 11.33801 11.34929 11.35216 11.39833 11.43960 11.49866
 [41] 11.52768 11.56144 11.56463 11.56806 11.59415 11.62253 11.62730 11.65783
 [49] 11.69197 11.69607 11.72961 11.75652 11.77154 11.79863 11.83682 11.88678
 [57] 11.91093 11.92822 11.96137 11.98587 11.99646 12.01689 12.03862 12.07371
 [65] 12.09351 12.13286 12.16952 12.16726 12.17873 12.16550 12.17491 12.18100
 [73] 12.21153 12.22814 12.25608 12.27929 12.30535 12.31716 12.31898 12.36077
 [81] 12.38916 12.42370 12.42962 12.45740 12.50144 12.48335 12.48907 12.52053
 [89] 12.53619 12.55270 12.57030 12.57410 12.59077 12.60277 12.61470 12.61660
 [97] 12.61825 12.64514 12.64020 12.64245
# Plot the mean projection of the average yearly temperature in Ljubljana vs time
#plot(temp_Ljubljana)
#plot(time, temp_Ljubljana)
plot(time/365.25+1986, temp_Ljubljana_RCP45)

# Plot temperature change relative to the 1971-2000 average
#plot(time/365.25+1986, temp_Ljubljana_RCP45-temp_first_table[395,160])
change_RCP45 <- temp_Ljubljana_RCP45 - temp_first_table[395,160]
plot(time/365.25+1986, change_RCP45)

# Let's do the same for RCP85 so we can compare
ncfile <- nc_open("mean_Tmean_Yearly_rcp85_mean_v1.0.nc")
temp <- ncvar_get(ncfile, "mean_Tmean_Yearly")
nc_close(ncfile)
change_RCP85 <- temp[395,160,] - temp[395,160,1]
plot(time/365.25+1986, change_RCP85)

# Prepare data for plot: create a table with time, temperature in RCP45 and temperature in RCP85
plotdata <- data.frame(x = time/365.25+1986, y45 = change_RCP45, y85 = change_RCP85)
print(plotdata)
           x        y45        y85
1   1986.000 0.00000000 0.00000000
2   1986.999 0.03639221 0.03639221
3   1987.999 0.04142857 0.04142857
4   1989.001 0.04042625 0.04042625
5   1990.000 0.07261658 0.07261658
6   1990.999 0.11464310 0.11464310
7   1991.999 0.17078114 0.15867043
8   1993.001 0.20714283 0.18704033
9   1994.000 0.23419857 0.23097038
10  1994.999 0.28444195 0.27253914
11  1995.999 0.31347370 0.30024433
12  1997.001 0.35272789 0.33452988
13  1998.000 0.38550663 0.35890770
14  1998.999 0.42475700 0.38620472
15  1999.999 0.45992184 0.43427372
16  2001.001 0.48500919 0.47550011
17  2002.000 0.53324509 0.51612759
18  2002.999 0.55930710 0.55255985
19  2003.999 0.58081436 0.57579994
20  2005.001 0.62517262 0.61712933
21  2006.000 0.64977264 0.65882969
22  2006.999 0.66233253 0.66609573
23  2007.999 0.69610786 0.70986843
24  2009.001 0.70862103 0.72747231
25  2010.000 0.70275497 0.74527264
26  2010.999 0.74273300 0.79337788
27  2011.999 0.78591919 0.83062649
28  2013.001 0.81987953 0.86634731
29  2014.000 0.84418392 0.90106678
30  2014.999 0.85327244 0.90408611
31  2015.999 0.86332321 0.90262985
32  2017.001 0.88488197 0.91084099
33  2018.000 0.91424751 0.95037651
34  2018.999 0.93793964 0.98895454
35  2019.999 0.96470833 1.02676773
36  2021.001 0.97598839 1.04468250
37  2022.000 0.97885418 1.06610584
38  2022.999 1.02502728 1.11194611
39  2023.999 1.06629372 1.14249897
40  2025.001 1.12535763 1.18590164
41  2026.000 1.15437508 1.21918392
42  2026.999 1.18813896 1.24562740
43  2027.999 1.19133186 1.27245140
44  2029.001 1.19475651 1.31396770
45  2030.000 1.22085285 1.33670521
46  2030.999 1.24922371 1.35449123
47  2031.999 1.25400066 1.39383221
48  2033.001 1.28452682 1.41616249
49  2034.000 1.31867218 1.42453766
50  2034.999 1.32276440 1.45147514
51  2035.999 1.35631084 1.48581314
52  2037.001 1.38322163 1.54252815
53  2038.000 1.39824104 1.56827736
54  2038.999 1.42532921 1.60920525
55  2039.999 1.46351528 1.65624428
56  2041.001 1.51348019 1.69470978
57  2042.000 1.53762913 1.74234486
58  2042.999 1.55492020 1.79725361
59  2043.999 1.58806419 1.83542538
60  2045.001 1.61256886 1.88332748
61  2046.000 1.62315750 1.94067669
62  2046.999 1.64359188 1.99069977
63  2047.999 1.66532040 2.03759575
64  2049.001 1.70040798 2.08555794
65  2050.000 1.72021103 2.12621498
66  2050.999 1.75956345 2.17373943
67  2051.999 1.79621506 2.21265793
68  2053.001 1.79395485 2.25470734
69  2054.000 1.80542374 2.30176258
70  2054.999 1.79220009 2.35371304
71  2055.999 1.80160999 2.40933418
72  2057.001 1.80770206 2.45055294
73  2058.000 1.83822441 2.49646282
74  2058.999 1.85483646 2.54080200
75  2059.999 1.88278103 2.59409332
76  2061.001 1.90598869 2.65756130
77  2062.000 1.93204880 2.71367836
78  2062.999 1.94386196 2.80047035
79  2063.999 1.94567966 2.87983894
80  2065.001 1.98747253 2.94308662
81  2066.000 2.01585770 2.99915409
82  2066.999 2.05040073 3.04403973
83  2067.999 2.05631542 3.09358215
84  2069.001 2.08409977 3.14963531
85  2070.000 2.12813377 3.19127083
86  2070.999 2.11005116 3.25215721
87  2071.999 2.11577129 3.31425762
88  2073.001 2.14723206 3.36216450
89  2074.000 2.16289139 3.41604233
90  2074.999 2.17939854 3.49062061
91  2075.999 2.19699669 3.54005623
92  2077.001 2.20079803 3.61339092
93  2078.000 2.21746635 3.65500832
94  2078.999 2.22946930 3.71486568
95  2079.999 2.24139404 3.76093102
96  2081.001 2.24329662 3.83106232
97  2082.000 2.24495220 3.89047623
98  2082.999 2.27184010 3.94866943
99  2083.999 2.26690102 4.00435257
100 2085.001 2.26914501 4.05499649
# Plot both
ggplot(plotdata) +
  geom_line(aes(x=x, y=y45, color="RCP45"), linewidth=1) +
  geom_line(aes(x=x, y=y85, color="RCP85"), linewidth=1) +
  xlab("middle year of 30-year period") +
  ylab("temperature change [\u00B0C]") +
  labs(color="scenario", subtitle="Average of ensamble projections", title="Temperature change relative to 1971-2000") +
  theme_classic()