03: Extracting data to different formats#

library(IRdisplay)
display_html('<iframe width="560" height="315" src="https://www.youtube.com/embed/9-EDaRQ8Aps?si=8AVrrzCQXntpG8ER" frameborder="0" allowfullscreen></iframe>')

In this notebook, we will look at how we can export data from a NetCDF file into a CSV or XLSX file.

Let’s import some modules first

library(RNetCDF)
library(writexl)

In this notebook you’ll find examples for 1D, 2D and 3D variables.

Variables with 1 dimension#

In this section, we will use some CTD data from the Nansen Legacy project. If you use these data, please cite them as recommended below:

Elizabeth Jones (2022) CTD data from Nansen Legacy Cruise - Joint cruise 2-1 Staion: P1_NLEG01-1 https://doi.org/10.21335/NMDC-2085836005-P1_NLEG01-1

Let’s load in the data.

url <- 'https://opendap1.nodc.no/opendap/physics/point/cruise/nansen_legacy-single_profile/NMDC_Nansen-Legacy_PR_CT_58US_2021708/CTD_station_P1_NLEG01-1_-_Nansen_Legacy_Cruise_-_2021_Joint_Cruise_2-1.nc'
data <- open.nc(url)
print.nc(data)
netcdf classic {
dimensions:
	PRES = 320 ;
variables:
	NC_FLOAT PRES(PRES) ;
		NC_FLOAT PRES:_FillValue = NaN ;
		NC_CHAR PRES:axis = "Z" ;
		NC_CHAR PRES:uncertainty = " " ;
		NC_CHAR PRES:comment = " " ;
		NC_CHAR PRES:ancillary_variables = "PRES_QC" ;
		NC_CHAR PRES:standard_name = "sea_water_pressure" ;
		NC_CHAR PRES:long_name = "Sea pressure" ;
		NC_CHAR PRES:units = "dbar" ;
		NC_CHAR PRES:positive = "down" ;
		NC_CHAR PRES:data_mode = "D" ;
		NC_CHAR PRES:coverage_content_type = "physicalMeasurement" ;
	NC_SHORT PRES_QC(PRES) ;
		NC_SHORT PRES_QC:_FillValue = -127 ;
		NC_CHAR PRES_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT PRES_QC:valid_min = 0 ;
		NC_SHORT PRES_QC:valid_max = 9 ;
		NC_SHORT PRES_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR PRES_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR PRES_QC:long_name = "Sea pressure quality flag" ;
	NC_FLOAT TEMP(PRES) ;
		NC_FLOAT TEMP:_FillValue = -2147483648 ;
		NC_CHAR TEMP:standard_name = "sea_water_temperature" ;
		NC_CHAR TEMP:long_name = "Sea temperature" ;
		NC_CHAR TEMP:units = "degrees_C" ;
		NC_DOUBLE TEMP:valid_min = -2.5 ;
		NC_DOUBLE TEMP:valid_max = 40 ;
		NC_CHAR TEMP:ancillary_variables = "TEMP_QC " ;
		NC_CHAR TEMP:data_mode = "D" ;
		NC_CHAR TEMP:coverage_content_type = "physicalMeasurement" ;
	NC_FLOAT PSAL(PRES) ;
		NC_FLOAT PSAL:_FillValue = -2147483648 ;
		NC_CHAR PSAL:standard_name = "sea_water_practical_salinity" ;
		NC_CHAR PSAL:long_name = "Practical salinity" ;
		NC_CHAR PSAL:units = "0.001" ;
		NC_DOUBLE PSAL:valid_min = 2 ;
		NC_DOUBLE PSAL:valid_max = 41 ;
		NC_CHAR PSAL:ancillary_variables = "PSAL_QC " ;
		NC_CHAR PSAL:data_mode = "D" ;
		NC_CHAR PSAL:coverage_content_type = "physicalMeasurement" ;
	NC_FLOAT FLU2(PRES) ;
		NC_FLOAT FLU2:_FillValue = -2147483648 ;
		NC_CHAR FLU2:standard_name = "mass_concentration_of_chlorophyll_a_in_sea_water" ;
		NC_CHAR FLU2:long_name = "Chlorophyll-a fluorescence" ;
		NC_CHAR FLU2:units = "mg m-3" ;
		NC_DOUBLE FLU2:valid_min = 0 ;
		NC_DOUBLE FLU2:valid_max = 100 ;
		NC_CHAR FLU2:ancillary_variables = "FLU2_QC " ;
		NC_CHAR FLU2:data_mode = "R" ;
		NC_CHAR FLU2:comment = "Fluorescence, WET Labs ECO-AFL/FL [mg/m^3]" ;
		NC_CHAR FLU2:coverage_content_type = "physicalMeasurement" ;
	NC_FLOAT CNDC(PRES) ;
		NC_FLOAT CNDC:_FillValue = -2147483648 ;
		NC_CHAR CNDC:standard_name = "sea_water_electrical_conductivity" ;
		NC_CHAR CNDC:long_name = "Electrical conductivity" ;
		NC_CHAR CNDC:units = "S m-1" ;
		NC_DOUBLE CNDC:valid_min = 0 ;
		NC_DOUBLE CNDC:valid_max = 50 ;
		NC_CHAR CNDC:ancillary_variables = "CNDC_QC " ;
		NC_CHAR CNDC:data_mode = "D" ;
		NC_CHAR CNDC:coverage_content_type = "physicalMeasurement" ;
	NC_FLOAT DENS(PRES) ;
		NC_FLOAT DENS:_FillValue = -2147483648 ;
		NC_CHAR DENS:standard_name = "sea_water_sigma_theta" ;
		NC_CHAR DENS:long_name = "Sea density (sigma-theta)" ;
		NC_CHAR DENS:units = "kg m-3" ;
		NC_DOUBLE DENS:valid_min = 20 ;
		NC_DOUBLE DENS:valid_max = 40 ;
		NC_CHAR DENS:ancillary_variables = "DENS_QC " ;
		NC_CHAR DENS:data_mode = "R" ;
		NC_CHAR DENS:comment = "density, sigma-theta [kg/m^3]" ;
		NC_CHAR DENS:coverage_content_type = "physicalMeasurement" ;
	NC_FLOAT SVEL(PRES) ;
		NC_FLOAT SVEL:_FillValue = -2147483648 ;
		NC_CHAR SVEL:standard_name = "speed_of_sound_in_sea_water" ;
		NC_CHAR SVEL:long_name = "Sound velocity" ;
		NC_CHAR SVEL:units = "m s-1" ;
		NC_DOUBLE SVEL:valid_min = 0 ;
		NC_DOUBLE SVEL:valid_max = 1000 ;
		NC_CHAR SVEL:ancillary_variables = "SVEL_QC " ;
		NC_CHAR SVEL:data_mode = "R" ;
		NC_CHAR SVEL:comment = "Sound Velocity [Chen-Millero, m/s]" ;
		NC_CHAR SVEL:coverage_content_type = "physicalMeasurement" ;
	NC_FLOAT CCOMD003(PRES) ;
		NC_FLOAT CCOMD003:_FillValue = -2147483648 ;
		NC_CHAR CCOMD003:standard_name = "concentration_of_colored_dissolved_organic_matter_in_sea_water_expressed_as_equivalent_mass_fraction_of_quinine_sulfate_dihydrate" ;
		NC_CHAR CCOMD003:long_name = "CDOM Gelbstoff per unit volume of the water body by in-situ fluorometer" ;
		NC_CHAR CCOMD003:units = "mg m-3" ;
		NC_DOUBLE CCOMD003:valid_min = 0 ;
		NC_DOUBLE CCOMD003:valid_max = 100 ;
		NC_CHAR CCOMD003:ancillary_variables = "CCOMD003_QC " ;
		NC_CHAR CCOMD003:data_mode = "R" ;
		NC_CHAR CCOMD003:comment = "Fluorescence, WET Labs CDOM [mg/m^3]" ;
		NC_CHAR CCOMD003:coverage_content_type = "physicalMeasurement" ;
	NC_FLOAT DOX1-1(PRES) ;
		NC_FLOAT DOX1-1:_FillValue = -2147483648 ;
		NC_CHAR DOX1-1:standard_name = "volume_fraction_of_oxygen_in_sea_water" ;
		NC_CHAR DOX1-1:long_name = "Dissolved oxygen" ;
		NC_CHAR DOX1-1:units = "ml l-1" ;
		NC_DOUBLE DOX1-1:valid_min = 0 ;
		NC_DOUBLE DOX1-1:valid_max = 1000 ;
		NC_CHAR DOX1-1:ancillary_variables = "DOX1-1_QC " ;
		NC_CHAR DOX1-1:data_mode = "R" ;
		NC_CHAR DOX1-1:comment = "Oxygen, SBE 43 [ml/l], WS = 2" ;
		NC_CHAR DOX1-1:coverage_content_type = "physicalMeasurement" ;
	NC_FLOAT DOX2-1(PRES) ;
		NC_FLOAT DOX2-1:_FillValue = -2147483648 ;
		NC_CHAR DOX2-1:standard_name = "moles_of_oxygen_per_unit_mass_in_sea_water" ;
		NC_CHAR DOX2-1:long_name = "Dissolved oxygen" ;
		NC_CHAR DOX2-1:units = "\302\265mol kg-1" ;
		NC_DOUBLE DOX2-1:valid_min = 0 ;
		NC_DOUBLE DOX2-1:valid_max = 1000 ;
		NC_CHAR DOX2-1:ancillary_variables = "DOX2-1_QC " ;
		NC_CHAR DOX2-1:data_mode = "R" ;
		NC_CHAR DOX2-1:comment = "Sbox0Mm/Kg" ;
		NC_CHAR DOX2-1:coverage_content_type = "physicalMeasurement" ;
	NC_FLOAT CNDC-2(PRES) ;
		NC_FLOAT CNDC-2:_FillValue = -2147483648 ;
		NC_CHAR CNDC-2:standard_name = "sea_water_electrical_conductivity" ;
		NC_CHAR CNDC-2:long_name = "Electrical conductivity" ;
		NC_CHAR CNDC-2:units = "S m-1" ;
		NC_DOUBLE CNDC-2:valid_min = 0 ;
		NC_DOUBLE CNDC-2:valid_max = 50 ;
		NC_CHAR CNDC-2:ancillary_variables = "CNDC-2_QC " ;
		NC_CHAR CNDC-2:data_mode = "R" ;
		NC_CHAR CNDC-2:comment = "Conductivity, 2 [S/m]" ;
		NC_CHAR CNDC-2:coverage_content_type = "physicalMeasurement" ;
	NC_FLOAT OXYOCPVL-1(PRES) ;
		NC_FLOAT OXYOCPVL-1:_FillValue = -2147483648 ;
		NC_CHAR OXYOCPVL-1:standard_name = "'\342\200\231" ;
		NC_CHAR OXYOCPVL-1:long_name = "Raw signal (voltage) of instrument output by oxygen senso" ;
		NC_CHAR OXYOCPVL-1:units = "V" ;
		NC_DOUBLE OXYOCPVL-1:valid_min = 0 ;
		NC_DOUBLE OXYOCPVL-1:valid_max = 1000 ;
		NC_CHAR OXYOCPVL-1:ancillary_variables = "OXYOCPVL-1_QC " ;
		NC_CHAR OXYOCPVL-1:data_mode = "R" ;
		NC_CHAR OXYOCPVL-1:comment = "Oxygen Voltage, SBE 43" ;
		NC_CHAR OXYOCPVL-1:coverage_content_type = "physicalMeasurement" ;
	NC_FLOAT SPAR(PRES) ;
		NC_FLOAT SPAR:_FillValue = -2147483648 ;
		NC_CHAR SPAR:standard_name = "'\342\200\231" ;
		NC_CHAR SPAR:long_name = "Photosynthetically active radiation" ;
		NC_CHAR SPAR:units = "\316\274mol m-2 s-1" ;
		NC_DOUBLE SPAR:valid_min = 0 ;
		NC_DOUBLE SPAR:valid_max = 10000 ;
		NC_CHAR SPAR:ancillary_variables = "SPAR_QC " ;
		NC_CHAR SPAR:data_mode = "R" ;
		NC_CHAR SPAR:comment = "SPAR/Surface Irradiance" ;
		NC_CHAR SPAR:coverage_content_type = "physicalMeasurement" ;
	NC_FLOAT PAR(PRES) ;
		NC_FLOAT PAR:_FillValue = -2147483648 ;
		NC_CHAR PAR:standard_name = "'\342\200\231" ;
		NC_CHAR PAR:long_name = "Photosynthetically active radiation" ;
		NC_CHAR PAR:units = "\316\274mol m-2 s-1" ;
		NC_DOUBLE PAR:valid_min = 0 ;
		NC_DOUBLE PAR:valid_max = 10000 ;
		NC_CHAR PAR:ancillary_variables = "PAR_QC " ;
		NC_CHAR PAR:data_mode = "R" ;
		NC_CHAR PAR:comment = "PAR/Irradiance, Biospherical/Licor" ;
		NC_CHAR PAR:coverage_content_type = "physicalMeasurement" ;
	NC_FLOAT PSAL-2(PRES) ;
		NC_FLOAT PSAL-2:_FillValue = -2147483648 ;
		NC_CHAR PSAL-2:standard_name = "sea_water_practical_salinity" ;
		NC_CHAR PSAL-2:long_name = "Practical salinity" ;
		NC_CHAR PSAL-2:units = "0.001" ;
		NC_DOUBLE PSAL-2:valid_min = 2 ;
		NC_DOUBLE PSAL-2:valid_max = 40 ;
		NC_CHAR PSAL-2:ancillary_variables = "PSAL-2_QC " ;
		NC_CHAR PSAL-2:data_mode = "R" ;
		NC_CHAR PSAL-2:comment = "Salinity, 2 [PSU]" ;
		NC_CHAR PSAL-2:coverage_content_type = "physicalMeasurement" ;
	NC_FLOAT TEMP-2(PRES) ;
		NC_FLOAT TEMP-2:_FillValue = -2147483648 ;
		NC_CHAR TEMP-2:standard_name = "sea_water_temperature" ;
		NC_CHAR TEMP-2:long_name = "Sea temperature" ;
		NC_CHAR TEMP-2:units = "degrees_C" ;
		NC_DOUBLE TEMP-2:valid_min = -2.5 ;
		NC_DOUBLE TEMP-2:valid_max = 40 ;
		NC_CHAR TEMP-2:ancillary_variables = "TEMP-2_QC " ;
		NC_CHAR TEMP-2:data_mode = "R" ;
		NC_CHAR TEMP-2:comment = "Temperature, 2 [ITS-68, deg C]" ;
		NC_CHAR TEMP-2:coverage_content_type = "physicalMeasurement" ;
	NC_FLOAT ATTNZS01(PRES) ;
		NC_FLOAT ATTNZS01:_FillValue = -2147483648 ;
		NC_CHAR ATTNZS01:standard_name = "'\342\200\231" ;
		NC_CHAR ATTNZS01:long_name = "WET Labs transmissometer calibrated to zero in clear water" ;
		NC_CHAR ATTNZS01:units = "%" ;
		NC_DOUBLE ATTNZS01:valid_min = 0 ;
		NC_DOUBLE ATTNZS01:valid_max = 100 ;
		NC_CHAR ATTNZS01:ancillary_variables = "ATTNZS01_QC " ;
		NC_CHAR ATTNZS01:data_mode = "R" ;
		NC_CHAR ATTNZS01:comment = "Beam Transmission, WET Labs C-Star [%]" ;
		NC_CHAR ATTNZS01:coverage_content_type = "physicalMeasurement" ;
	NC_SHORT TEMP_QC(PRES) ;
		NC_SHORT TEMP_QC:_FillValue = -127 ;
		NC_CHAR TEMP_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT TEMP_QC:valid_min = 0 ;
		NC_SHORT TEMP_QC:valid_max = 9 ;
		NC_SHORT TEMP_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR TEMP_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR TEMP_QC:long_name = "Sea temperature quality flag" ;
	NC_SHORT PSAL_QC(PRES) ;
		NC_SHORT PSAL_QC:_FillValue = -127 ;
		NC_CHAR PSAL_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT PSAL_QC:valid_min = 0 ;
		NC_SHORT PSAL_QC:valid_max = 9 ;
		NC_SHORT PSAL_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR PSAL_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR PSAL_QC:long_name = "Practical salinity quality flag" ;
	NC_SHORT FLU2_QC(PRES) ;
		NC_SHORT FLU2_QC:_FillValue = -127 ;
		NC_CHAR FLU2_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT FLU2_QC:valid_min = 0 ;
		NC_SHORT FLU2_QC:valid_max = 9 ;
		NC_SHORT FLU2_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR FLU2_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR FLU2_QC:long_name = "Chlorophyll-a fluorescence quality flag" ;
	NC_SHORT CNDC_QC(PRES) ;
		NC_SHORT CNDC_QC:_FillValue = -127 ;
		NC_CHAR CNDC_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT CNDC_QC:valid_min = 0 ;
		NC_SHORT CNDC_QC:valid_max = 9 ;
		NC_SHORT CNDC_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR CNDC_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR CNDC_QC:long_name = "Electrical conductivity quality flag" ;
	NC_SHORT DENS_QC(PRES) ;
		NC_SHORT DENS_QC:_FillValue = -127 ;
		NC_CHAR DENS_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT DENS_QC:valid_min = 0 ;
		NC_SHORT DENS_QC:valid_max = 9 ;
		NC_SHORT DENS_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR DENS_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR DENS_QC:long_name = "Sea density (sigma-theta) quality flag" ;
	NC_SHORT SVEL_QC(PRES) ;
		NC_SHORT SVEL_QC:_FillValue = -127 ;
		NC_CHAR SVEL_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT SVEL_QC:valid_min = 0 ;
		NC_SHORT SVEL_QC:valid_max = 9 ;
		NC_SHORT SVEL_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR SVEL_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR SVEL_QC:long_name = "Sound velocity quality flag" ;
	NC_SHORT CCOMD003_QC(PRES) ;
		NC_SHORT CCOMD003_QC:_FillValue = -127 ;
		NC_CHAR CCOMD003_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT CCOMD003_QC:valid_min = 0 ;
		NC_SHORT CCOMD003_QC:valid_max = 9 ;
		NC_SHORT CCOMD003_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR CCOMD003_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR CCOMD003_QC:long_name = "CDOM Gelbstoff per unit volume of the water body by in-situ fluorometer quality flag" ;
	NC_SHORT DOX1-1_QC(PRES) ;
		NC_SHORT DOX1-1_QC:_FillValue = -127 ;
		NC_CHAR DOX1-1_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT DOX1-1_QC:valid_min = 0 ;
		NC_SHORT DOX1-1_QC:valid_max = 9 ;
		NC_SHORT DOX1-1_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR DOX1-1_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR DOX1-1_QC:long_name = "Dissolved oxygen quality flag" ;
	NC_SHORT DOX2-1_QC(PRES) ;
		NC_SHORT DOX2-1_QC:_FillValue = -127 ;
		NC_CHAR DOX2-1_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT DOX2-1_QC:valid_min = 0 ;
		NC_SHORT DOX2-1_QC:valid_max = 9 ;
		NC_SHORT DOX2-1_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR DOX2-1_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR DOX2-1_QC:long_name = "Dissolved oxygen quality flag" ;
	NC_SHORT CNDC-2_QC(PRES) ;
		NC_SHORT CNDC-2_QC:_FillValue = -127 ;
		NC_CHAR CNDC-2_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT CNDC-2_QC:valid_min = 0 ;
		NC_SHORT CNDC-2_QC:valid_max = 9 ;
		NC_SHORT CNDC-2_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR CNDC-2_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR CNDC-2_QC:long_name = "Electrical conductivity quality flag" ;
	NC_SHORT OXYOCPVL-1_QC(PRES) ;
		NC_SHORT OXYOCPVL-1_QC:_FillValue = -127 ;
		NC_CHAR OXYOCPVL-1_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT OXYOCPVL-1_QC:valid_min = 0 ;
		NC_SHORT OXYOCPVL-1_QC:valid_max = 9 ;
		NC_SHORT OXYOCPVL-1_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR OXYOCPVL-1_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR OXYOCPVL-1_QC:long_name = "Raw signal (voltage) of instrument output by oxygen senso quality flag" ;
	NC_SHORT SPAR_QC(PRES) ;
		NC_SHORT SPAR_QC:_FillValue = -127 ;
		NC_CHAR SPAR_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT SPAR_QC:valid_min = 0 ;
		NC_SHORT SPAR_QC:valid_max = 9 ;
		NC_SHORT SPAR_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR SPAR_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR SPAR_QC:long_name = "Photosynthetically active radiation quality flag" ;
	NC_SHORT PAR_QC(PRES) ;
		NC_SHORT PAR_QC:_FillValue = -127 ;
		NC_CHAR PAR_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT PAR_QC:valid_min = 0 ;
		NC_SHORT PAR_QC:valid_max = 9 ;
		NC_SHORT PAR_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR PAR_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR PAR_QC:long_name = "Photosynthetically active radiation quality flag" ;
	NC_SHORT PSAL-2_QC(PRES) ;
		NC_SHORT PSAL-2_QC:_FillValue = -127 ;
		NC_CHAR PSAL-2_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT PSAL-2_QC:valid_min = 0 ;
		NC_SHORT PSAL-2_QC:valid_max = 9 ;
		NC_SHORT PSAL-2_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR PSAL-2_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR PSAL-2_QC:long_name = "Practical salinity quality flag" ;
	NC_SHORT TEMP-2_QC(PRES) ;
		NC_SHORT TEMP-2_QC:_FillValue = -127 ;
		NC_CHAR TEMP-2_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT TEMP-2_QC:valid_min = 0 ;
		NC_SHORT TEMP-2_QC:valid_max = 9 ;
		NC_SHORT TEMP-2_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR TEMP-2_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR TEMP-2_QC:long_name = "Sea temperature quality flag" ;
	NC_SHORT ATTNZS01_QC(PRES) ;
		NC_SHORT ATTNZS01_QC:_FillValue = -127 ;
		NC_CHAR ATTNZS01_QC:conventions = "Copernicus Marine In Situ reference table 2" ;
		NC_SHORT ATTNZS01_QC:valid_min = 0 ;
		NC_SHORT ATTNZS01_QC:valid_max = 9 ;
		NC_SHORT ATTNZS01_QC:flag_values = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
		NC_CHAR ATTNZS01_QC:flag_meanings = "no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed value_below_detection nominal_value interpolated_value missing_value" ;
		NC_CHAR ATTNZS01_QC:long_name = "WET Labs transmissometer calibrated to zero in clear water quality flag" ;

// global attributes:
		NC_CHAR :qc_manual = "Recommendations for in-situ data Near Real Time Quality Control https://doi.org/10.13155/36230" ;
		NC_CHAR :contact = "datahjelp@hi.no" ;
		NC_CHAR :distribution_statement = "These data are public and free of charge. User assumes all risk for use of data. User must display citation in any publication or product using data. User must contact PI prior to any commercial use of data." ;
		NC_CHAR :naming_authority = "no.unis" ;
		NC_CHAR :license = "https://creativecommons.org/licenses/by/4.0/ https://creativecommons.org/licenses/by/4.0/" ;
		NC_CHAR :data_assembly_center = "IMR" ;
		NC_CHAR :update_interval = "void" ;
		NC_CHAR :area = "Arctic Ocean" ;
		NC_CHAR :author = "" ;
		NC_CHAR :Conventions = "CF-1.8, ACDD-1.3, OceanSITES Manual 1.4" ;
		NC_CHAR :data_mode = "M" ;
		NC_CHAR :comment = "Descending CTD profile" ;
		NC_CHAR :history = "Created at 2022-08-08T12:43:51Z using the xarray library in Python" ;
		NC_CHAR :netcdf_version = "netCDF-4 classic model" ;
		NC_CHAR :quality_index = "A" ;
		NC_CHAR :quality_control_indicator = "0" ;
		NC_CHAR :publisher_name = "Elisabeth Jones" ;
		NC_CHAR :publisher_email = "datahjelp@imr.no" ;
		NC_CHAR :wmo_platform_code = "" ;
		NC_CHAR :ices_platform_code = "" ;
		NC_CHAR :site_code = "" ;
		NC_CHAR :bottom_depth = "" ;
		NC_CHAR :wmo_inst_type = "" ;
		NC_CHAR :geospatial_vertical_positive = "down" ;
		NC_CHAR :platform_code = "58US" ;
		NC_CHAR :platform_name = "Kronprins Haakon" ;
		NC_CHAR :source = "research vessel" ;
		NC_CHAR :institution_country = "Norway" ;
		NC_CHAR :source_platform_category_code = "31" ;
		NC_CHAR :data_type = "OceanSITES vertical profile" ;
		NC_CHAR :cdm_data_type = "PROFILE" ;
		NC_CHAR :instrument = "CTD Seabird" ;
		NC_CHAR :keywords = "EARTH SCIENCE > OCEANS > OCEAN OPTICS > FLUORESCENCE, EARTH SCIENCE > OCEANS > SALINITY/DENSITY > DENSITY, EARTH SCIENCE > OCEANS > SALINITY/DENSITY > OCEAN SALINITY, EARTH SCIENCE > OCEANS > OCEAN ACOUSTICS > ACOUSTIC VELOCITY, EARTH SCIENCE > OCEANS > OCEAN TEMPERATURE > WATER TEMPERATURE, EARTH SCIENCE > OCEANS > SALINITY/DENSITY > CONDUCTIVITY" ;
		NC_CHAR :keywords_vocabulary = "GCMD:GCMD Keywords" ;
		NC_CHAR :id = "NMDC_Nansen-Legacy_PR_CT_58US_2021708_P1_(NLEG01)" ;
		NC_CHAR :time_coverage_start = "2021-07-14T08:14:43Z" ;
		NC_CHAR :time_coverage_end = "2021-07-14T08:14:43Z" ;
		NC_CHAR :date_update = "2022-08-08T12:43:51Z" ;
		NC_FLOAT :geospatial_lat_min = 76 ;
		NC_FLOAT :geospatial_lat_max = 76 ;
		NC_FLOAT :geospatial_lon_min = 31.2196998596191 ;
		NC_FLOAT :geospatial_lon_max = 31.2196998596191 ;
		NC_FLOAT :geospatial_vertical_min = 1 ;
		NC_FLOAT :geospatial_vertical_max = 321 ;
		NC_CHAR :citation = "These data were collected and made freely available by the Nansen Legacy project and the programs that contribute to it." ;
		NC_CHAR :project = "The Nansen Legacy Project (RCN # 276730)" ;
		NC_CHAR :references = "https://doi.org/10.21335/NMDC-2085836005" ;
		NC_CHAR :featureType = "Profile" ;
		NC_CHAR :summary = "The Joint Cruise 2-1 addressed objectives of the work packages Physical drivers (Research Foci 1), Human impact (Research Foci 2) and The living Barents Sea (Research Foci 3) along the Nansen Legacy transect in open water and within the sea ice. The cruise focussed on comparing the state of the physical, chemical and biological conditions in the southern and northern parts of the study area. These data are created from the CTD data published by NMDC for the whole cruise (https://doi.org/10.21335/NMDC-2085836005). The values have not be changed." ;
		NC_CHAR :pi_name = "Elizabeth Jones" ;
		NC_CHAR :institution = "Institute of Marine Research" ;
		NC_INT :institution_edmo_code = 1351 ;
		NC_CHAR :institution_references = "https://www.hi.no/hi" ;
		NC_CHAR :creator_institution = "Institute of Marine Research" ;
		NC_CHAR :creator_name = "Elisabeth Jones" ;
		NC_CHAR :creator_type = "person" ;
		NC_CHAR :creator_email = "datahjelp@imr.no" ;
		NC_CHAR :creator_url = "https://www.hi.no/hi" ;
		NC_CHAR :publisher = "The Norwegian Marine Data Centre (NMD)" ;
		NC_CHAR :publisher_url = "https://www.hi.no/hi" ;
		NC_CHAR :acknowledgement = "The Nansen Legacy project is funded by the Research Council of Norway (RCN # 276730). These data are created from the CTD data published by NMDC for the whole cruise (10.21335/NMDC-2085836005). The values have not be changed. For information about this process, please contact Luke Marsden at data.nleg@unis.no" ;
		NC_CHAR :cruiseNumber = "2021708" ;
		NC_CHAR :cruiseName = "2021 Joint Cruise 2-1" ;
		NC_CHAR :geospatial_vertical_units = "dbar" ;
		NC_CHAR :geospatial_vertical_resolution = "1 dbar" ;
		NC_CHAR :pi_email = "elizabeth.jones@hi.no" ;
		NC_CHAR :pi_institution = "Institute of Marine Research" ;
		NC_CHAR :station_name = "P1 (NLEG01)" ;
		NC_CHAR :_NCProperties = "version=2,netcdf=4.6.3,hdf5=1.10.5" ;
		NC_CHAR :date_created = "2022-08-08T12:44:34Z" ;
		NC_CHAR :doi = "10.21335/NMDC-2085836005-P1_NLEG01-1" ;
		NC_CHAR :title = "CTD_station_P1_NLEG01-1_-_Nansen_Legacy_Cruise_-_2021_Joint_Cruise_2-1" ;
		NC_CHAR :metadata_link = "https://doi.org/10.21335/NMDC-2085836005-P1_NLEG01-1" ;
}

The data have 1 dimension, pressure. Let’s say we want to extract the data from the TEMP and PSAL variables to a CSV or XLSX file. We first need to create a dataframe.

pres <- var.get.nc(data, 'PRES')
temp <- var.get.nc(data, 'TEMP')
psal <- var.get.nc(data, 'PSAL')
df <- data.frame(Pressure = pres, Temperature = temp, Salinity = psal)
head(df)
A data.frame: 6 × 3
PressureTemperatureSalinity
<dbl><dbl><dbl>
113.73534.254
223.73834.260
333.73934.261
443.74134.267
553.73634.259
663.73734.260

We can write the data to a CSV or XLSX file

write_xlsx(df, '../data/exported_from_notebooks/ctd_data.xlsx')
write.csv(df, '../data/exported_from_notebooks/ctd_data.csv', row.names = FALSE)

Variables with 2 dimensions#

Let’s look at some sea ice concentration data.

If you use these data, please cite them as recommended below:

Lavergne, T.; Sørensen, A.; Tonboe, R.T.; Kreiner, M.; Saldo, R.; Birkedal, A.; Baordo, F.; Aspenes, T.; Eastwood, S. (2023): ESA Sea Ice Climate Change Initiative (Sea_Ice_cci): High(er) Resolution Sea Ice Concentration Climate Data Record Version 3 (SSM/I and SSMIS). NERC EDS Centre for Environmental Data Analysis, 17 May 2023. doi:10.5285/eade27004395466aaa006135e1b2ad1a. https://dx.doi.org/10.5285/eade27004395466aaa006135e1b2ad1a

url <- 'https://dap.ceda.ac.uk/thredds/dodsC/neodc/esacci/sea_ice/data/sea_ice_concentration/L4/ssmi_ssmis/12.5km/v3.0/NH/2007/09/ESACCI-SEAICE-L4-SICONC-RE_SSMI_12.5kmEASE2-NH-20070915-fv3.0.nc'
data <- open.nc(url)
print.nc(data)
netcdf classic {
dimensions:
	time = UNLIMITED ; // (1 currently)
	nv = 2 ;
	xc = 864 ;
	yc = 864 ;
variables:
	NC_INT Lambert_Azimuthal_Grid ;
		NC_CHAR Lambert_Azimuthal_Grid:grid_mapping_name = "lambert_azimuthal_equal_area" ;
		NC_DOUBLE Lambert_Azimuthal_Grid:longitude_of_projection_origin = 0 ;
		NC_DOUBLE Lambert_Azimuthal_Grid:latitude_of_projection_origin = 90 ;
		NC_DOUBLE Lambert_Azimuthal_Grid:false_easting = 0 ;
		NC_DOUBLE Lambert_Azimuthal_Grid:false_northing = 0 ;
		NC_DOUBLE Lambert_Azimuthal_Grid:semi_major_axis = 6378137 ;
		NC_DOUBLE Lambert_Azimuthal_Grid:inverse_flattening = 298.257223563 ;
		NC_CHAR Lambert_Azimuthal_Grid:proj4_string = "+proj=laea +lon_0=0 +datum=WGS84 +ellps=WGS84 +lat_0=90.0" ;
	NC_DOUBLE time(time) ;
		NC_CHAR time:units = "seconds since 1978-01-01 00:00:00" ;
		NC_CHAR time:long_name = "reference time of product" ;
		NC_CHAR time:standard_name = "time" ;
		NC_CHAR time:axis = "T" ;
		NC_CHAR time:calendar = "standard" ;
		NC_CHAR time:bounds = "time_bnds" ;
		NC_INT time:_ChunkSizes = 512 ;
	NC_DOUBLE time_bnds(nv, time) ;
		NC_INT time_bnds:_ChunkSizes = 1, 2 ;
	NC_DOUBLE xc(xc) ;
		NC_CHAR xc:units = "km" ;
		NC_CHAR xc:long_name = "x coordinate of projection (eastings)" ;
		NC_CHAR xc:standard_name = "projection_x_coordinate" ;
		NC_INT xc:_ChunkSizes = 864 ;
	NC_DOUBLE yc(yc) ;
		NC_CHAR yc:units = "km" ;
		NC_CHAR yc:long_name = "y coordinate of projection (northings)" ;
		NC_CHAR yc:standard_name = "projection_y_coordinate" ;
		NC_INT yc:_ChunkSizes = 864 ;
	NC_FLOAT lat(xc, yc) ;
		NC_CHAR lat:units = "degrees_north" ;
		NC_CHAR lat:long_name = "latitude coordinate" ;
		NC_CHAR lat:standard_name = "latitude" ;
		NC_INT lat:_ChunkSizes = 864, 864 ;
	NC_FLOAT lon(xc, yc) ;
		NC_CHAR lon:units = "degrees_east" ;
		NC_CHAR lon:long_name = "longitude coordinate" ;
		NC_CHAR lon:standard_name = "longitude" ;
		NC_INT lon:_ChunkSizes = 864, 864 ;
	NC_INT ice_conc(xc, yc, time) ;
		NC_INT ice_conc:_FillValue = -32767 ;
		NC_CHAR ice_conc:long_name = "fully filtered concentration of sea ice using atmospheric correction of brightness temperatures and open water filters" ;
		NC_CHAR ice_conc:standard_name = "sea_ice_area_fraction" ;
		NC_CHAR ice_conc:units = "%" ;
		NC_INT ice_conc:valid_min = 0 ;
		NC_INT ice_conc:valid_max = 10000 ;
		NC_CHAR ice_conc:grid_mapping = "Lambert_Azimuthal_Grid" ;
		NC_CHAR ice_conc:ancillary_variables = "total_standard_uncertainty status_flag" ;
		NC_DOUBLE ice_conc:scale_factor = 0.01 ;
		NC_CHAR ice_conc:comment = "this field is the primary sea ice concentration estimate for this climate data record" ;
		NC_CHAR ice_conc:coordinates = "time lat lon" ;
		NC_INT ice_conc:_ChunkSizes = 1, 864, 864 ;
	NC_INT raw_ice_conc_values(xc, yc, time) ;
		NC_INT raw_ice_conc_values:_FillValue = -32767 ;
		NC_CHAR raw_ice_conc_values:long_name = "sea ice concentration estimates as retrieved by the algorithm, and that were edited away by the various filters" ;
		NC_CHAR raw_ice_conc_values:units = "%" ;
		NC_CHAR raw_ice_conc_values:grid_mapping = "Lambert_Azimuthal_Grid" ;
		NC_DOUBLE raw_ice_conc_values:scale_factor = 0.01 ;
		NC_CHAR raw_ice_conc_values:comment = "this field can be used in combination with 'ice_conc' to access un-bounded normal distribution of sea ice concentration estimates corresponding to the uncertainty estimate in 'total_standard_uncertainty'. It does also feature some amount of un-physical data (below 0% and above 100%)." ;
		NC_CHAR raw_ice_conc_values:coordinates = "time lat lon" ;
		NC_INT raw_ice_conc_values:_ChunkSizes = 1, 864, 864 ;
	NC_INT total_standard_uncertainty(xc, yc, time) ;
		NC_INT total_standard_uncertainty:_FillValue = -32767 ;
		NC_CHAR total_standard_uncertainty:long_name = "total uncertainty (one standard deviation) of concentration of sea ice" ;
		NC_CHAR total_standard_uncertainty:standard_name = "sea_ice_area_fraction standard_error" ;
		NC_CHAR total_standard_uncertainty:units = "%" ;
		NC_CHAR total_standard_uncertainty:grid_mapping = "Lambert_Azimuthal_Grid" ;
		NC_DOUBLE total_standard_uncertainty:scale_factor = 0.01 ;
		NC_CHAR total_standard_uncertainty:coordinates = "time lat lon" ;
		NC_INT total_standard_uncertainty:_ChunkSizes = 1, 864, 864 ;
	NC_INT smearing_standard_uncertainty(xc, yc, time) ;
		NC_INT smearing_standard_uncertainty:_FillValue = -32767 ;
		NC_CHAR smearing_standard_uncertainty:long_name = "smearing uncertainty (one standard deviation) of concentration of sea ice" ;
		NC_CHAR smearing_standard_uncertainty:units = "%" ;
		NC_CHAR smearing_standard_uncertainty:grid_mapping = "Lambert_Azimuthal_Grid" ;
		NC_DOUBLE smearing_standard_uncertainty:scale_factor = 0.01 ;
		NC_CHAR smearing_standard_uncertainty:comment = "this is one of the two components contributing to 'total_standard_uncertainty'" ;
		NC_CHAR smearing_standard_uncertainty:coordinates = "time lat lon" ;
		NC_INT smearing_standard_uncertainty:_ChunkSizes = 1, 864, 864 ;
	NC_INT algorithm_standard_uncertainty(xc, yc, time) ;
		NC_INT algorithm_standard_uncertainty:_FillValue = -32767 ;
		NC_CHAR algorithm_standard_uncertainty:long_name = "algorithm uncertainty (one standard deviation) of concentration of sea ice" ;
		NC_CHAR algorithm_standard_uncertainty:units = "%" ;
		NC_CHAR algorithm_standard_uncertainty:grid_mapping = "Lambert_Azimuthal_Grid" ;
		NC_DOUBLE algorithm_standard_uncertainty:scale_factor = 0.01 ;
		NC_CHAR algorithm_standard_uncertainty:comment = "this is one of the two components contributing to 'total_standard_uncertainty'" ;
		NC_CHAR algorithm_standard_uncertainty:coordinates = "time lat lon" ;
		NC_INT algorithm_standard_uncertainty:_ChunkSizes = 1, 864, 864 ;
	NC_SHORT status_flag(xc, yc, time) ;
		NC_SHORT status_flag:_FillValue = -32768 ;
		NC_CHAR status_flag:long_name = "status flag bit array for sea ice concentration retrievals" ;
		NC_CHAR status_flag:standard_name = "sea_ice_area_fraction status_flag" ;
		NC_SHORT status_flag:valid_min = 0 ;
		NC_SHORT status_flag:valid_max = 32767 ;
		NC_CHAR status_flag:grid_mapping = "Lambert_Azimuthal_Grid" ;
		NC_SHORT status_flag:flag_masks = 1, 2, 4, 8, 16, 32, 64, 128 ;
		NC_CHAR status_flag:flag_meanings = "land lake open_water_filtered land_spill_over high_t2m spatial_interp temporal_interp max_ice_climo" ;
		NC_CHAR status_flag:flag_descriptions = "
all bits to 0 (flag 0): Nominal retrieval by the SIC algorithm
bit 1 (flag 1): Position is over land
bit 2 (flag 2): Position is lake
bit 3 (flag 4): SIC is set to zero by the open water filter
bit 4 (flag 8): SIC value is changed for correcting land spill-over effects
bit 5 (flag 16): Handle with caution, the 2m air temperature is high at this position, and this might be false ice
bit 6 (flag 32): Value is the result of spatial interpolation
bit 7 (flag 64): Value is the result of temporal interpolation
bit 8 (flag 128): SIC is set to zero since position is outside maximum sea ice climatology." ;
		NC_CHAR status_flag:comment = "Flag values found in the map might be combinations of those listed above. For example flag value 80 (= 2^4 + 2^6 = 16 + 64) indicates high_t2m AND temporal_interp" ;
		NC_CHAR status_flag:coordinates = "time lat lon" ;
		NC_INT status_flag:_ChunkSizes = 1, 864, 864 ;

// global attributes:
		NC_CHAR :title = "High(er) Resolution Sea Ice Concentration Climate Data Record Version 3 (SSM/I and SSMIS) from the ESA CCI+" ;
		NC_CHAR :summary = "This climate data record of sea ice concentration is obtained from passive microwave satellite data (SSM/I and SSMIS) over the polar regions (Arctic and Antarctic). The processing chain features: 1) dynamic tuning of tie-points and algorithms,  2) correction of atmospheric noise using a Radiative Transfer Model,  3) computation of per-pixel uncertainties, 4) an optimal hybrid sea ice concentration algorithm, and 5) pan-sharpening of the SIC fields using the near-90GHz imagery channels. This dataset was generated by the ESA Climate Change Initiative (CCI+) Sea Ice Phase 1 project. This dataset is an enhanced-resolution version of the OSI SAF OSI-450-a CDR over the period 1991-2020." ;
		NC_CHAR :topiccategory = "Oceans ClimatologyMeteorologyAtmosphere" ;
		NC_CHAR :keywords = "GCMDSK:Earth Science > Cryosphere > Sea Ice > Sea Ice Concentration, GCMDSK:Earth Science > Oceans > Sea Ice > Sea Ice Concentration, GCMDSK:Earth Science > Climate Indicators > Cryospheric Indicators > Sea Ice Concentration, GCMDLOC:Geographic Region > Northern Hemisphere, GCMDLOC:Vertical Location > Sea Surface, GCMDPROV: Government Agencies-non-US > Norway > NO/MET > Norwegian Meteorological Institute" ;
		NC_CHAR :keywords_vocabulary = "GCMDSK:GCMD Science Keywords:https://gcmd.earthdata.nasa.gov/kms/concepts/concept_scheme/sciencekeywords, GCMDPROV:GCMD Providers:https://gcmd.earthdata.nasa.gov/kms/concepts/concept_scheme/providers, GCMDLOC:GCMD Locations:https://gcmd.earthdata.nasa.gov/kms/concepts/concept_scheme/locations" ;
		NC_DOUBLE :geospatial_lat_min = 16.62393 ;
		NC_DOUBLE :geospatial_lat_max = 90 ;
		NC_DOUBLE :geospatial_lon_min = -180 ;
		NC_DOUBLE :geospatial_lon_max = 180 ;
		NC_DOUBLE :geospatial_vertical_min = 0 ;
		NC_DOUBLE :geospatial_vertical_max = 0 ;
		NC_CHAR :sensor = "SSM/I,SSMIS" ;
		NC_CHAR :platform = "DMSP-F<10,11,13,14,15>,DMSP-F<16,17,18>" ;
		NC_CHAR :source = "FCDR of SMMR / SSMI / SSMIS Brightness Temperatures R4 from EUMETSAT Climate Monitoring SAF (doi:10.5676/EUM_SAF_CM/FCDR_MWI/V004), ERA5" ;
		NC_CHAR :time_coverage_start = "2007-09-15T00:00:00Z" ;
		NC_CHAR :time_coverage_end = "2007-09-16T00:00:00Z" ;
		NC_CHAR :time_coverage_duration = "P1D" ;
		NC_CHAR :time_coverage_resolution = "P1D" ;
		NC_CHAR :project = "Climate Change Initiative - European Space Agency" ;
		NC_CHAR :institution = "Norwegian Meteorological Institute" ;
		NC_CHAR :creator_name = "Norwegian Meteorological Institute" ;
		NC_CHAR :creator_type = "institution" ;
		NC_CHAR :creator_url = "http://met.no" ;
		NC_CHAR :creator_email = "forskning@met.no" ;
		NC_CHAR :license = "Free and open access" ;
		NC_CHAR :references = "A Product User Guide (PUG), an Algorithm Theoretical Basis Document (ATBD) and a Validation Report (PVASR) are available from the doi landing page and from https://climate.esa.int/seaice" ;
		NC_CHAR :history = "2023-04-20T21:46:46Z creation" ;
		NC_CHAR :date_created = "2023-04-20" ;
		NC_CHAR :cdm_data_type = "Grid" ;
		NC_CHAR :spatial_resolution = "12.5 km grid spacing" ;
		NC_CHAR :algorithm = "reSICCI3LF: SIC from 19/37GHz channels, pan-sharpened with SIC from near-90GHz channels." ;
		NC_CHAR :geospatial_bounds_crs = "EPSG:6931" ;
		NC_CHAR :contributor_name = "Thomas Lavergne,Atle Soerensen,Rasmus Tonboe,Matilde Kreiner,Roberto Saldo,Anton Birkedal,Fabrizio Baordo,Trygve Aspenes,Steinar Eastwood" ;
		NC_CHAR :contributor_role = "PrincipalInvestigator,author,author,author,author,author,author,author,author" ;
		NC_CHAR :product_version = "3.0" ;
		NC_CHAR :tracking_id = "0a5f4360-8c19-40aa-a09a-bab17eb0b6fc" ;
		NC_CHAR :naming_authority = "NERC EDS Centre for Environmental Data Analysis" ;
		NC_CHAR :Conventions = "CF-1.7,ACDD-1.3" ;
		NC_CHAR :standard_name_vocabulary = "CF Standard Name Table (Version 80, 07 February 2023)" ;
		NC_CHAR :product_name = "cci_HRssmi_sea_ice_conc_climate_data_record" ;
		NC_CHAR :id = "10.5285/eade27004395466aaa006135e1b2ad1a" ;
		NC_CHAR :format_version = "CCI Data Standards v2.3" ;
		NC_CHAR :key_variables = "ice_conc" ;
		NC_CHAR :DODS_EXTRA.Unlimited_Dimension = "time" ;
}

The ice_conc variable has 3 dimensions; xc, yc and time. However, since there is only one time slice in this dataset, this is essentially a 2D variable.

Let’s write the ice_conc variable to a dataframe alongside the xc and yc coordinate variables.

xc <- var.get.nc(data, 'xc')
yc <- var.get.nc(data, 'yc')
ice_conc <- var.get.nc(data, 'ice_conc')
dim(ice_conc) # Showing that this is 2D, not 3D.
  1. 864
  2. 864

The order of the dimensions is important. xc and then yc.

So the values are sorted such that all the values cooresponding to the first xc coordinate are first, before moving onto the second xc coordinate.

Now let’s create a 1D vector of the ice_conc data.

ice_conc_vector <- as.vector(ice_conc)

We then need to extend the xc coordinate values by repeating the first xc value 864 times before moving onto the second value.

xc_repeat <- rep(xc, each = length(yc))
xc_repeat
  1. -5393.75
  2. -5393.75
  3. -5393.75
  4. -5393.75
  5. -5393.75
  6. -5393.75
  7. -5393.75
  8. -5393.75
  9. -5393.75
  10. -5393.75
  11. -5393.75
  12. -5393.75
  13. -5393.75
  14. -5393.75
  15. -5393.75
  16. -5393.75
  17. -5393.75
  18. -5393.75
  19. -5393.75
  20. -5393.75
  21. -5393.75
  22. -5393.75
  23. -5393.75
  24. -5393.75
  25. -5393.75
  26. -5393.75
  27. -5393.75
  28. -5393.75
  29. -5393.75
  30. -5393.75
  31. -5393.75
  32. -5393.75
  33. -5393.75
  34. -5393.75
  35. -5393.75
  36. -5393.75
  37. -5393.75
  38. -5393.75
  39. -5393.75
  40. -5393.75
  41. -5393.75
  42. -5393.75
  43. -5393.75
  44. -5393.75
  45. -5393.75
  46. -5393.75
  47. -5393.75
  48. -5393.75
  49. -5393.75
  50. -5393.75
  51. -5393.75
  52. -5393.75
  53. -5393.75
  54. -5393.75
  55. -5393.75
  56. -5393.75
  57. -5393.75
  58. -5393.75
  59. -5393.75
  60. -5393.75
  61. -5393.75
  62. -5393.75
  63. -5393.75
  64. -5393.75
  65. -5393.75
  66. -5393.75
  67. -5393.75
  68. -5393.75
  69. -5393.75
  70. -5393.75
  71. -5393.75
  72. -5393.75
  73. -5393.75
  74. -5393.75
  75. -5393.75
  76. -5393.75
  77. -5393.75
  78. -5393.75
  79. -5393.75
  80. -5393.75
  81. -5393.75
  82. -5393.75
  83. -5393.75
  84. -5393.75
  85. -5393.75
  86. -5393.75
  87. -5393.75
  88. -5393.75
  89. -5393.75
  90. -5393.75
  91. -5393.75
  92. -5393.75
  93. -5393.75
  94. -5393.75
  95. -5393.75
  96. -5393.75
  97. -5393.75
  98. -5393.75
  99. -5393.75
  100. -5393.75
  101. -5393.75
  102. -5393.75
  103. -5393.75
  104. -5393.75
  105. -5393.75
  106. -5393.75
  107. -5393.75
  108. -5393.75
  109. -5393.75
  110. -5393.75
  111. -5393.75
  112. -5393.75
  113. -5393.75
  114. -5393.75
  115. -5393.75
  116. -5393.75
  117. -5393.75
  118. -5393.75
  119. -5393.75
  120. -5393.75
  121. -5393.75
  122. -5393.75
  123. -5393.75
  124. -5393.75
  125. -5393.75
  126. -5393.75
  127. -5393.75
  128. -5393.75
  129. -5393.75
  130. -5393.75
  131. -5393.75
  132. -5393.75
  133. -5393.75
  134. -5393.75
  135. -5393.75
  136. -5393.75
  137. -5393.75
  138. -5393.75
  139. -5393.75
  140. -5393.75
  141. -5393.75
  142. -5393.75
  143. -5393.75
  144. -5393.75
  145. -5393.75
  146. -5393.75
  147. -5393.75
  148. -5393.75
  149. -5393.75
  150. -5393.75
  151. -5393.75
  152. -5393.75
  153. -5393.75
  154. -5393.75
  155. -5393.75
  156. -5393.75
  157. -5393.75
  158. -5393.75
  159. -5393.75
  160. -5393.75
  161. -5393.75
  162. -5393.75
  163. -5393.75
  164. -5393.75
  165. -5393.75
  166. -5393.75
  167. -5393.75
  168. -5393.75
  169. -5393.75
  170. -5393.75
  171. -5393.75
  172. -5393.75
  173. -5393.75
  174. -5393.75
  175. -5393.75
  176. -5393.75
  177. -5393.75
  178. -5393.75
  179. -5393.75
  180. -5393.75
  181. -5393.75
  182. -5393.75
  183. -5393.75
  184. -5393.75
  185. -5393.75
  186. -5393.75
  187. -5393.75
  188. -5393.75
  189. -5393.75
  190. -5393.75
  191. -5393.75
  192. -5393.75
  193. -5393.75
  194. -5393.75
  195. -5393.75
  196. -5393.75
  197. -5393.75
  198. -5393.75
  199. -5393.75
  200. -5393.75
  201. 5393.75
  202. 5393.75
  203. 5393.75
  204. 5393.75
  205. 5393.75
  206. 5393.75
  207. 5393.75
  208. 5393.75
  209. 5393.75
  210. 5393.75
  211. 5393.75
  212. 5393.75
  213. 5393.75
  214. 5393.75
  215. 5393.75
  216. 5393.75
  217. 5393.75
  218. 5393.75
  219. 5393.75
  220. 5393.75
  221. 5393.75
  222. 5393.75
  223. 5393.75
  224. 5393.75
  225. 5393.75
  226. 5393.75
  227. 5393.75
  228. 5393.75
  229. 5393.75
  230. 5393.75
  231. 5393.75
  232. 5393.75
  233. 5393.75
  234. 5393.75
  235. 5393.75
  236. 5393.75
  237. 5393.75
  238. 5393.75
  239. 5393.75
  240. 5393.75
  241. 5393.75
  242. 5393.75
  243. 5393.75
  244. 5393.75
  245. 5393.75
  246. 5393.75
  247. 5393.75
  248. 5393.75
  249. 5393.75
  250. 5393.75
  251. 5393.75
  252. 5393.75
  253. 5393.75
  254. 5393.75
  255. 5393.75
  256. 5393.75
  257. 5393.75
  258. 5393.75
  259. 5393.75
  260. 5393.75
  261. 5393.75
  262. 5393.75
  263. 5393.75
  264. 5393.75
  265. 5393.75
  266. 5393.75
  267. 5393.75
  268. 5393.75
  269. 5393.75
  270. 5393.75
  271. 5393.75
  272. 5393.75
  273. 5393.75
  274. 5393.75
  275. 5393.75
  276. 5393.75
  277. 5393.75
  278. 5393.75
  279. 5393.75
  280. 5393.75
  281. 5393.75
  282. 5393.75
  283. 5393.75
  284. 5393.75
  285. 5393.75
  286. 5393.75
  287. 5393.75
  288. 5393.75
  289. 5393.75
  290. 5393.75
  291. 5393.75
  292. 5393.75
  293. 5393.75
  294. 5393.75
  295. 5393.75
  296. 5393.75
  297. 5393.75
  298. 5393.75
  299. 5393.75
  300. 5393.75
  301. 5393.75
  302. 5393.75
  303. 5393.75
  304. 5393.75
  305. 5393.75
  306. 5393.75
  307. 5393.75
  308. 5393.75
  309. 5393.75
  310. 5393.75
  311. 5393.75
  312. 5393.75
  313. 5393.75
  314. 5393.75
  315. 5393.75
  316. 5393.75
  317. 5393.75
  318. 5393.75
  319. 5393.75
  320. 5393.75
  321. 5393.75
  322. 5393.75
  323. 5393.75
  324. 5393.75
  325. 5393.75
  326. 5393.75
  327. 5393.75
  328. 5393.75
  329. 5393.75
  330. 5393.75
  331. 5393.75
  332. 5393.75
  333. 5393.75
  334. 5393.75
  335. 5393.75
  336. 5393.75
  337. 5393.75
  338. 5393.75
  339. 5393.75
  340. 5393.75
  341. 5393.75
  342. 5393.75
  343. 5393.75
  344. 5393.75
  345. 5393.75
  346. 5393.75
  347. 5393.75
  348. 5393.75
  349. 5393.75
  350. 5393.75
  351. 5393.75
  352. 5393.75
  353. 5393.75
  354. 5393.75
  355. 5393.75
  356. 5393.75
  357. 5393.75
  358. 5393.75
  359. 5393.75
  360. 5393.75
  361. 5393.75
  362. 5393.75
  363. 5393.75
  364. 5393.75
  365. 5393.75
  366. 5393.75
  367. 5393.75
  368. 5393.75
  369. 5393.75
  370. 5393.75
  371. 5393.75
  372. 5393.75
  373. 5393.75
  374. 5393.75
  375. 5393.75
  376. 5393.75
  377. 5393.75
  378. 5393.75
  379. 5393.75
  380. 5393.75
  381. 5393.75
  382. 5393.75
  383. 5393.75
  384. 5393.75
  385. 5393.75
  386. 5393.75
  387. 5393.75
  388. 5393.75
  389. 5393.75
  390. 5393.75
  391. 5393.75
  392. 5393.75
  393. 5393.75
  394. 5393.75
  395. 5393.75
  396. 5393.75
  397. 5393.75
  398. 5393.75
  399. 5393.75
  400. 5393.75

For the yc coordinate, we need to repeat the whole list 864 times.

yc_repeat <- rep(yc, times = length(xc))
yc_repeat
  1. 5393.75
  2. 5381.25
  3. 5368.75
  4. 5356.25
  5. 5343.75
  6. 5331.25
  7. 5318.75
  8. 5306.25
  9. 5293.75
  10. 5281.25
  11. 5268.75
  12. 5256.25
  13. 5243.75
  14. 5231.25
  15. 5218.75
  16. 5206.25
  17. 5193.75
  18. 5181.25
  19. 5168.75
  20. 5156.25
  21. 5143.75
  22. 5131.25
  23. 5118.75
  24. 5106.25
  25. 5093.75
  26. 5081.25
  27. 5068.75
  28. 5056.25
  29. 5043.75
  30. 5031.25
  31. 5018.75
  32. 5006.25
  33. 4993.75
  34. 4981.25
  35. 4968.75
  36. 4956.25
  37. 4943.75
  38. 4931.25
  39. 4918.75
  40. 4906.25
  41. 4893.75
  42. 4881.25
  43. 4868.75
  44. 4856.25
  45. 4843.75
  46. 4831.25
  47. 4818.75
  48. 4806.25
  49. 4793.75
  50. 4781.25
  51. 4768.75
  52. 4756.25
  53. 4743.75
  54. 4731.25
  55. 4718.75
  56. 4706.25
  57. 4693.75
  58. 4681.25
  59. 4668.75
  60. 4656.25
  61. 4643.75
  62. 4631.25
  63. 4618.75
  64. 4606.25
  65. 4593.75
  66. 4581.25
  67. 4568.75
  68. 4556.25
  69. 4543.75
  70. 4531.25
  71. 4518.75
  72. 4506.25
  73. 4493.75
  74. 4481.25
  75. 4468.75
  76. 4456.25
  77. 4443.75
  78. 4431.25
  79. 4418.75
  80. 4406.25
  81. 4393.75
  82. 4381.25
  83. 4368.75
  84. 4356.25
  85. 4343.75
  86. 4331.25
  87. 4318.75
  88. 4306.25
  89. 4293.75
  90. 4281.25
  91. 4268.75
  92. 4256.25
  93. 4243.75
  94. 4231.25
  95. 4218.75
  96. 4206.25
  97. 4193.75
  98. 4181.25
  99. 4168.75
  100. 4156.25
  101. 4143.75
  102. 4131.25
  103. 4118.75
  104. 4106.25
  105. 4093.75
  106. 4081.25
  107. 4068.75
  108. 4056.25
  109. 4043.75
  110. 4031.25
  111. 4018.75
  112. 4006.25
  113. 3993.75
  114. 3981.25
  115. 3968.75
  116. 3956.25
  117. 3943.75
  118. 3931.25
  119. 3918.75
  120. 3906.25
  121. 3893.75
  122. 3881.25
  123. 3868.75
  124. 3856.25
  125. 3843.75
  126. 3831.25
  127. 3818.75
  128. 3806.25
  129. 3793.75
  130. 3781.25
  131. 3768.75
  132. 3756.25
  133. 3743.75
  134. 3731.25
  135. 3718.75
  136. 3706.25
  137. 3693.75
  138. 3681.25
  139. 3668.75
  140. 3656.25
  141. 3643.75
  142. 3631.25
  143. 3618.75
  144. 3606.25
  145. 3593.75
  146. 3581.25
  147. 3568.75
  148. 3556.25
  149. 3543.75
  150. 3531.25
  151. 3518.75
  152. 3506.25
  153. 3493.75
  154. 3481.25
  155. 3468.75
  156. 3456.25
  157. 3443.75
  158. 3431.25
  159. 3418.75
  160. 3406.25
  161. 3393.75
  162. 3381.25
  163. 3368.75
  164. 3356.25
  165. 3343.75
  166. 3331.25
  167. 3318.75
  168. 3306.25
  169. 3293.75
  170. 3281.25
  171. 3268.75
  172. 3256.25
  173. 3243.75
  174. 3231.25
  175. 3218.75
  176. 3206.25
  177. 3193.75
  178. 3181.25
  179. 3168.75
  180. 3156.25
  181. 3143.75
  182. 3131.25
  183. 3118.75
  184. 3106.25
  185. 3093.75
  186. 3081.25
  187. 3068.75
  188. 3056.25
  189. 3043.75
  190. 3031.25
  191. 3018.75
  192. 3006.25
  193. 2993.75
  194. 2981.25
  195. 2968.75
  196. 2956.25
  197. 2943.75
  198. 2931.25
  199. 2918.75
  200. 2906.25
  201. -2906.25
  202. -2918.75
  203. -2931.25
  204. -2943.75
  205. -2956.25
  206. -2968.75
  207. -2981.25
  208. -2993.75
  209. -3006.25
  210. -3018.75
  211. -3031.25
  212. -3043.75
  213. -3056.25
  214. -3068.75
  215. -3081.25
  216. -3093.75
  217. -3106.25
  218. -3118.75
  219. -3131.25
  220. -3143.75
  221. -3156.25
  222. -3168.75
  223. -3181.25
  224. -3193.75
  225. -3206.25
  226. -3218.75
  227. -3231.25
  228. -3243.75
  229. -3256.25
  230. -3268.75
  231. -3281.25
  232. -3293.75
  233. -3306.25
  234. -3318.75
  235. -3331.25
  236. -3343.75
  237. -3356.25
  238. -3368.75
  239. -3381.25
  240. -3393.75
  241. -3406.25
  242. -3418.75
  243. -3431.25
  244. -3443.75
  245. -3456.25
  246. -3468.75
  247. -3481.25
  248. -3493.75
  249. -3506.25
  250. -3518.75
  251. -3531.25
  252. -3543.75
  253. -3556.25
  254. -3568.75
  255. -3581.25
  256. -3593.75
  257. -3606.25
  258. -3618.75
  259. -3631.25
  260. -3643.75
  261. -3656.25
  262. -3668.75
  263. -3681.25
  264. -3693.75
  265. -3706.25
  266. -3718.75
  267. -3731.25
  268. -3743.75
  269. -3756.25
  270. -3768.75
  271. -3781.25
  272. -3793.75
  273. -3806.25
  274. -3818.75
  275. -3831.25
  276. -3843.75
  277. -3856.25
  278. -3868.75
  279. -3881.25
  280. -3893.75
  281. -3906.25
  282. -3918.75
  283. -3931.25
  284. -3943.75
  285. -3956.25
  286. -3968.75
  287. -3981.25
  288. -3993.75
  289. -4006.25
  290. -4018.75
  291. -4031.25
  292. -4043.75
  293. -4056.25
  294. -4068.75
  295. -4081.25
  296. -4093.75
  297. -4106.25
  298. -4118.75
  299. -4131.25
  300. -4143.75
  301. -4156.25
  302. -4168.75
  303. -4181.25
  304. -4193.75
  305. -4206.25
  306. -4218.75
  307. -4231.25
  308. -4243.75
  309. -4256.25
  310. -4268.75
  311. -4281.25
  312. -4293.75
  313. -4306.25
  314. -4318.75
  315. -4331.25
  316. -4343.75
  317. -4356.25
  318. -4368.75
  319. -4381.25
  320. -4393.75
  321. -4406.25
  322. -4418.75
  323. -4431.25
  324. -4443.75
  325. -4456.25
  326. -4468.75
  327. -4481.25
  328. -4493.75
  329. -4506.25
  330. -4518.75
  331. -4531.25
  332. -4543.75
  333. -4556.25
  334. -4568.75
  335. -4581.25
  336. -4593.75
  337. -4606.25
  338. -4618.75
  339. -4631.25
  340. -4643.75
  341. -4656.25
  342. -4668.75
  343. -4681.25
  344. -4693.75
  345. -4706.25
  346. -4718.75
  347. -4731.25
  348. -4743.75
  349. -4756.25
  350. -4768.75
  351. -4781.25
  352. -4793.75
  353. -4806.25
  354. -4818.75
  355. -4831.25
  356. -4843.75
  357. -4856.25
  358. -4868.75
  359. -4881.25
  360. -4893.75
  361. -4906.25
  362. -4918.75
  363. -4931.25
  364. -4943.75
  365. -4956.25
  366. -4968.75
  367. -4981.25
  368. -4993.75
  369. -5006.25
  370. -5018.75
  371. -5031.25
  372. -5043.75
  373. -5056.25
  374. -5068.75
  375. -5081.25
  376. -5093.75
  377. -5106.25
  378. -5118.75
  379. -5131.25
  380. -5143.75
  381. -5156.25
  382. -5168.75
  383. -5181.25
  384. -5193.75
  385. -5206.25
  386. -5218.75
  387. -5231.25
  388. -5243.75
  389. -5256.25
  390. -5268.75
  391. -5281.25
  392. -5293.75
  393. -5306.25
  394. -5318.75
  395. -5331.25
  396. -5343.75
  397. -5356.25
  398. -5368.75
  399. -5381.25
  400. -5393.75

And now let’s combing them all in a dataframe and export the data.

df <- data.frame(
  Xc = xc_repeat,
  Yc = yc_repeat,
  SeaIceConcentration = ice_conc_vector
)
head(df)
A data.frame: 6 × 3
XcYcSeaIceConcentration
<dbl><dbl><dbl>
1-5393.755393.750
2-5393.755381.250
3-5393.755368.750
4-5393.755356.250
5-5393.755343.750
6-5393.755331.250

Let’s add the latitude and longitude values as separate columns.

latitude <- var.get.nc(data, "lat")
latitude_vector <- as.vector(latitude)
df$latitude <- latitude_vector

longitude <- var.get.nc(data, "lon")
longitude_vector <- as.vector(longitude)
df$longitude <- longitude_vector

head(df)
write_xlsx(df, '../data/exported_from_notebooks/2d_data.xlsx')
write.csv(df, '../data/exported_from_notebooks/2d_data.csv', row.names = FALSE)
A data.frame: 6 × 5
XcYcSeaIceConcentrationlatitudelongitude
<dbl><dbl><dbl><dbl><dbl>
1-5393.755393.75016.52435-135.0000
2-5393.755381.25016.62387-135.0665
3-5393.755368.75016.72321-135.1331
4-5393.755356.25016.82236-135.1999
5-5393.755343.75016.92134-135.2668
6-5393.755331.25017.02014-135.3339

Variables with 3 dimensions#

Let’s look at the same data we used in tutorial #01.

If you use these data, please cite them as recommended below:

H.-M. Zhang, B. Huang, J. H. Lawrimore, M. J. Menne, and T. M. Smith (2019): NOAA Global Surface Temperature Dataset (NOAAGlobalTemp), Version 5.0. NOAA National Centers for Environmental Information. doi:10.25921/9qth-2p70 Accessed 2024-04-09.

Let’s load in the data, and extract the data from the anom varaible.

url <- 'https://www.ncei.noaa.gov/thredds/dodsC/noaa-global-temp-v5/NOAAGlobalTemp_v5.0.0_gridded_s188001_e202212_c20230108T133308.nc'
data <- open.nc(url)
print.nc(data)
netcdf classic {
dimensions:
	lat = 36 ;
	lon = 72 ;
	time = 1716 ;
	z = 1 ;
variables:
	NC_FLOAT time(time) ;
		NC_CHAR time:long_name = "reference time of global temperature anomalies" ;
		NC_CHAR time:standard_name = "time" ;
		NC_CHAR time:coverage_content_type = "coordinate" ;
		NC_CHAR time:units = "days since 1800-01-01 00:00:00" ;
		NC_CHAR time:calendar = "gregorian" ;
		NC_CHAR time:axis = "T" ;
	NC_FLOAT lat(lat) ;
		NC_CHAR lat:long_name = "Latitude" ;
		NC_CHAR lat:standard_name = "latitude" ;
		NC_CHAR lat:coverage_content_type = "coordinate" ;
		NC_CHAR lat:units = "degrees_north" ;
		NC_CHAR lat:grids = "Uniform grid from -87.5 to 87.5 by 5" ;
		NC_FLOAT lat:valid_min = -87.5 ;
		NC_FLOAT lat:valid_max = 87.5 ;
		NC_CHAR lat:axis = "Y" ;
		NC_CHAR lat:_CoordinateAxisType = "Lat" ;
		NC_CHAR lat:coordinate_defines = "center" ;
	NC_FLOAT lon(lon) ;
		NC_CHAR lon:long_name = "Longitude" ;
		NC_CHAR lon:standard_name = "longitude" ;
		NC_CHAR lon:coverage_content_type = "coordinate" ;
		NC_CHAR lon:units = "degrees_east" ;
		NC_CHAR lon:grids = "Uniform grid from 2.5 to 357.5 by 5" ;
		NC_CHAR lon:axis = "X" ;
		NC_FLOAT lon:valid_min = 2.5 ;
		NC_FLOAT lon:valid_max = 357.5 ;
		NC_CHAR lon:_CoordinateAxisType = "Lon" ;
		NC_CHAR lon:coordinate_defines = "center" ;
	NC_FLOAT z(z) ;
		NC_CHAR z:long_name = "height of surface temperature" ;
		NC_CHAR z:standard_name = "height" ;
		NC_CHAR z:coverage_content_type = "coordinate" ;
		NC_CHAR z:geospatial_bounds_vertical_crs = "EPSG:5703" ;
		NC_CHAR z:units = "meters" ;
		NC_CHAR z:positive = "up" ;
		NC_FLOAT z:valid_min = 0 ;
		NC_FLOAT z:valid_max = 0 ;
		NC_CHAR z:axis = "Z" ;
		NC_CHAR z:_CoordinateAxisType = "Height" ;
		NC_CHAR z:comment = "Actual measurement depth of in situ sea surface temperature varies from 0.2 to 10 m, but corrected to the nominal depth of buoy at 0.2 m; for air temperature over land is 2m." ;
	NC_FLOAT anom(lon, lat, z, time) ;
		NC_CHAR anom:long_name = "Global Temperature Anomalies" ;
		NC_CHAR anom:standard_name = "surface_temperature_anomaly" ;
		NC_CHAR anom:coverage_content_type = "physicalMeasurement" ;
		NC_CHAR anom:units = "degrees C" ;
		NC_FLOAT anom:missing_value = -999.900024414062 ;
		NC_FLOAT anom:_FillValue = -999.900024414062 ;
		NC_FLOAT anom:add_offset = 0 ;
		NC_FLOAT anom:scale_factor = 1 ;
		NC_FLOAT anom:valid_min = -40 ;
		NC_FLOAT anom:valid_max = 40 ;
		NC_CHAR anom:coordinates = "time z lat lon" ;

// global attributes:
		NC_CHAR :Conventions = "CF-1.6, ACDD-1.3" ;
		NC_CHAR :title = "NOAA Merged Land Ocean Global Surface Temperature Analysis (NOAAGlobalTemp)" ;
		NC_CHAR :summary = "NOAAGlobalTemp is a merged land-ocean surface temperature analysis, formerly abbreviated as MLOST. The SST dataset is the Extended Reconstructed Sea Surface Temperature (ERSST) and the land surface air temperature dataset is from the Global Historical Climatology Network Monthly (GHCN-M) database." ;
		NC_CHAR :institution = "DOC/NOAA/NESDIS/National Centers for Environmental Information(NCEI)" ;
		NC_CHAR :id = " gov.noaa.ncdc:C00934 " ;
		NC_CHAR :naming_authority = " gov.noaa.ncei " ;
		NC_CHAR :project = " NOAAGlobalTemp " ;
		NC_CHAR :platform = "Ships, moored buoys, surface drifting buoys, Argo floats, and weather stations" ;
		NC_CHAR :instrument = "Conventional thermometers" ;
		NC_CHAR :history = "Version 5.0.0, blending ERSST V5 and GHCN-M V4." ;
		NC_CHAR :comment = "Merged land ocean surface temperature anomalies." ;
		NC_CHAR :product_version = "5.0.0" ;
		NC_CHAR :source = "NOAAGlobalTemp combines a global sea surface temperature with a global land surface air temperature data" ;
		NC_CHAR :ncei_template_version = "NCEI_NetCDF_Grid_Template_v2.0" ;
		NC_CHAR :Metadata_Conventions = "Unidata Dataset Discovery v1.0" ;
		NC_CHAR :license = "These data are available for use without restriction." ;
		NC_CHAR :creator_name = "Boyin Huang, Xungang Yin, Ph.D" ;
		NC_CHAR :creator_email = "Boyin.Huang@noaa.gov, Xungang.Yin@noaa.gov" ;
		NC_CHAR :creator_type = "group" ;
		NC_CHAR :creator_institution = "US DOC/NOAA/NESDIS/National Centers for Environmental Information(NCEI)" ;
		NC_CHAR :contributor_name = "Huai-min Zhang, Ph.D" ;
		NC_CHAR :contributor_role = "Chief, NOAA/NESDIS/NCEI/CCOG/OSB Ocean Surface Section" ;
		NC_CHAR :publisher_name = "NCEI" ;
		NC_CHAR :publisher_institution = "NCEI" ;
		NC_CHAR :publisher_url = "https://www.ncdc.noaa.gov/" ;
		NC_CHAR :publisher_email = "ncei.info@noaa.gov" ;
		NC_CHAR :publisher_type = "institution" ;
		NC_CHAR :keywords = "Earth Science > Oceans > Ocean Temperature > Sea Surface Temperature, Earth Science > Atmosphere > Atmospheric Temperature > Surface Temperature > Air Temperature" ;
		NC_CHAR :keywords_vocabulary = "NASA Global Change Master Directory (GCMD) Science Keywords" ;
		NC_CHAR :standard_name_vocabulary = "Climate and Forecast (CF) Standard Name Table (Version 46, 25 July 2017)" ;
		NC_CHAR :date_created = "2023-01-08T18:33:09Z" ;
		NC_CHAR :necdf_version_id = "4.2.1.1" ;
		NC_CHAR :netcdf_creator_name = "Yongsheng Zhang, Ph.D" ;
		NC_CHAR :netcdf_creator_email = "yongsheng.zhang@noaa.gov" ;
		NC_CHAR :dataset_citation_product = "NOAA Merged Land Ocean Global Surface Temperature Analysis (NOAAGlobalTemp)" ;
		NC_CHAR :dataset_citation_version = "5.0.0" ;
		NC_CHAR :dataset_citation_institution = "NOAA/NESDIS/NCEI, Asheville, NC, USA" ;
		NC_CHAR :dataset_citation_url = "https://doi.org/10.25921/9qth-2p70" ;
		NC_CHAR :metadata_link = "https://doi.org/10.25921/9qth-2p70" ;
		NC_CHAR :cdm_data_type = "Grid" ;
		NC_CHAR :grid_mapping_name = "latitude_longitude" ;
		NC_CHAR :processing_level = "NOAA Processing Level 4" ;
		NC_FLOAT :geospatial_lon_min = 2.5 ;
		NC_FLOAT :geospatial_lon_max = 357.5 ;
		NC_CHAR :geospatial_lon_units = "degrees_east" ;
		NC_CHAR :geospatial_lon_resolution = "5.0 degree" ;
		NC_FLOAT :geospatial_lat_min = -87.5 ;
		NC_FLOAT :geospatial_lat_max = 87.5 ;
		NC_CHAR :geospatial_lat_units = "degrees_north" ;
		NC_CHAR :geospatial_lat_resolution = "5.0 degree" ;
		NC_CHAR :geospatial_bounds = "POLYGON ((2.5 -87.5, 2.5 87.5, 357.5 87.5, 357.5 -87.5, 2.5 -87.5))" ;
		NC_CHAR :geospatial_bounds_crs = "EPSG:4326" ;
		NC_FLOAT :geospatial_vertical_min = 0 ;
		NC_FLOAT :geospatial_vertical_max = 0 ;
		NC_CHAR :geospatial_vertical_units = "meters" ;
		NC_CHAR :geospatial_vertical_resolution = "0.f" ;
		NC_CHAR :geospatial_vertical_positive = "up" ;
		NC_CHAR :time_coverage_start = "1880-01" ;
		NC_CHAR :time_coverage_end = "2022-12" ;
		NC_CHAR :time_coverage_resolution = "P1M" ;
		NC_CHAR :time_coverage_duration = "P143Y0M" ;
		NC_CHAR :references = "Vose, R. S., et al., 2012: NOAAs merged land-ocean surface temperature analysis. Bulletin of the American Meteorological Society, 93, 1677-1685. doi: 10.1175/BAMS-D-11-00241.1. Huang, B., Peter W. Thorne, et. al, 2017: Extended Reconstructed Sea Surface Temperature version 5 (ERSSTv5), Upgrades, validations, and intercomparisons. J. Climate, 30, 8179-8205. doi: 10.1175/JCLI-D-16-0836.1" ;
		NC_CHAR :climatology = "Climatology is based on 1971-2000 monthly climatology" ;
		NC_CHAR :acknowledgment = "The NOAA Global Surface Temperature Dataset is provided by the NOAA National Centers for Environmental Information(NCEI)" ;
		NC_CHAR :date_modified = "2023-01-08T18:33:09Z" ;
		NC_CHAR :date_issued = "2023-01-08T18:33:09Z" ;
}

The anom variable actually has 4 dimensions (lon, lat, z and time). However, the z dimension is equal to 1, which means all the values are from the same elevation. Therefore, the data are essentially 3D.

Let’s start by extracting the latitude, longitude and time variables as 1D vectors, and converting the time values to timestamps.

lat <- var.get.nc(data, 'lat')
lon <- var.get.nc(data, 'lon')
time <- var.get.nc(data, "time")

# Convert time to readable dates
start_date <- as.Date("1800-01-01")
timestamps <- as.Date(time, origin = start_date)

Now let’s extract the temperature anomaly values. We can convert the 3D matrix into a 1D vector.

anom <- var.get.nc(data, 'anom')
anom_vector <- as.vector(anom)

The order of the dimensions is now important. We have longitude, latitude and then time.

This means that the anomaly values are sorted such that the all the values from the first longitude come first.

The values are next sorted by common latitude, and finally by common time.

It is a 3D grid has 72 points of longitude, 36 points of latitude, and 1716 points in time.

dim(anom)
  1. 72
  2. 36
  3. 1716

So when flattening the first dimension, longitude, to a 1D vector, we need to repeat the first value 36 x 1716 times before moving onto the second value.

lon_repeat <- rep(lon, each = length(time) * length(lat))

To flatten the second dimension, latitude, to a 1D vector, we need repeat the first value 1716 times before moving on to the second value. Then, after we have reached the last latitude, we need to start from the beginning and repeat 72 times.

lat_repeat <- rep(rep(lat, each = length(time)), times = length(lon))

Finally, for the third dimension, time, we need to list all the timestamps in order first, and then repeat the list 36 x 72 times.

timestamps_repeat <- rep(timestamps, times = length(lon) * length(lat))

Finally, let’s write the data to a dataframe and export them.

df <- data.frame(
  Timestamp = timestamps_repeat,
  Latitude = lat_repeat,
  Longitude = lon_repeat,
  TemperatureAnomalies = anom_vector
)

head(df)
write.csv(df, '../data/exported_from_notebooks/3d_data.csv', row.names = FALSE)
# There are too many rows in this data frame to convert it to a XLSX file
A data.frame: 6 × 4
TimestampLatitudeLongitudeTemperatureAnomalies
<date><dbl><dbl><dbl>
11880-01-01-87.52.5NA
21880-02-01-87.52.5NA
31880-03-01-87.52.5NA
41880-04-01-87.52.5NA
51880-05-01-87.52.5NA
61880-06-01-87.52.5NA

How to cite this course#

If you think this course contributed to the work you are doing, consider citing it in your list of references. Here is a recommended citation:

Marsden, L. (2024, May 31). NetCDF in R - from beginner to pro. Zenodo. https://doi.org/10.5281/zenodo.11400754

And you can navigate to the publication and export the citation in different styles and formats by clicking the icon below.

DOI