Extracting data from NetCDF file - r

I'm working in R trying to use the data found here (https://datadryad.org/resource/doi:10.5061/dryad.dk1j0; two top files) to create a table similar to this: [administrative_name, GDP2010, GDP2011....., GDP 2015]
As far as i can see i need to extract the name of the administrative units from the "admin_areas_GDP_HDI.nc" file and combine them with the annual data in the GDP_per_capita_PPP_1990_2015.nc file.
With the ncdf4 package i've managed to open the archives, and to get all the attributes and variables, however I don't know how to access the data and extract it.
I've been trying to access the data all day, but i have limited experience with NetCDF archives, and have not managed to extract the data. Any pointers would help me out!

I like to use the raster package for dealing with NetCDF files. It uses the ncdf4 package to read in the files, but offers some additional tools for processing rasters. You did not mention what data you want to extract, so the example below shows the mean GDP for each administrative unit.
library(raster)
#Read in NetCDF files
ad -> brick('admin_areas_GDP_HDI.nc')
gdp -> brick('GDP_per_capita_PPP_1990_2015_v2.nc')
#Calculate mean GDP using admin zones
zoneMean -> zonal(gdp, ad[[1]], fun='mean', na.rm=T)

Related

How can I convert a multiband geotiff to a timeseries netcdf file in xarray

I am trying to create a time series object from extracted climate data (NEX-GDDP) using the Google Earth Engine (GEE). The data is daily metrological data, and in the attached file, the data for January, 2005, is collected over an area of interest. The images from GEE are stored in the geotiff as bands (numbered 1-31), and now I am struggling to get these individual bands into a dataset, and add a time dimension to the file. GEE will not export for more than ten years, so my idea is to create yearly files, which, when saved locally, will be merged (concatenated) on the lat/lon and time dimensions.
I am using python in a windows environment, so I am a bit limited (for example, I can't use cdo as this is a Linux based library), and I think that what I would like to do is possible with xarray, but I am missing the (learning) resources to solve this problem with code. Any help and suggestions are more than welcome to help me with this problem.
The image shows the xarray view of the metadata:
xarray metadata view
Showing one band: Test data
Missing the time dimension.
This got resolved on another thread in a special group:
https://gis.stackexchange.com/questions/449759/convert-a-multiband-geotiff-to-a-timeseries-netcdf-file-in-xarray

How to work with WorldClim data for MaxEnt

I am looking to extract WorldClim climate data for (current data and future projections) and convert the .geotif to .asc in order to run this through MaxEnt and create future climate change projections.
Problem 1: Worldclim gives me 1 .geotif from which I need to extract 19 separate variables, each as their own .geotif file.
Problem 2: Converting these .geotif files into .asc to run using MaxEnt.
I have access to free GIS software (QGIS/DIVA-GIS) and R, although I am fairly new to R. Any solutions would be really helpful, thank you.

Read a sub-set of NetCDF file in R

Is there a possibility to read a subset of a NetCDF file in R?
In Matlab, I can use
ncread(filename,'WS',[i_timeseries,j_timeseries,1,1],[1,1,1,48])
I am trying to extract a time series from the New European Wind Atlas using free software (preferably R) on Windows.
Many thanks indeed.

How to load a xls or csv data file to work with the rugarch and rmgarch packages in R

I am new to R and have just started to use it. I am currently experimenting with the quantmod, rugarch and rmgarch packages.
In particular, I'm implementing the last package to make a multivariate portfolio analysis for the case of the european markets. In this sense, I need to download the 3-month german treasury bills, in order to use them as risk free rate. However, as far as I known, I canĀ“t download the the mentioned data serie from Yahoo, Google or FDRA databases, so I have already downloaded them from investing.com and I want to load them in R.
The fact here is, my data is different from the ones downloaded by the getsymbols () function of yahoo, because in this case I only have 2 columns, the date column and the closing price column. To sump up, the question arises here is, is there any way to load this type of data in R for rmgarch purposes??
thanks in advance
Not sure if this is the issue, but this is how you might go about getting the data from a csv file.
data <- read.csv(file="file/path/data.csv")
head(data) # Take a look at your data
# Do this if you want the data only replacing ColumnName with the proper name
data_only <- data$ColumnName
It looks like the input data for rugarch needs to be an xts vector. So, you might want to take a look at this. You might also want to take a look at ?read.csv.

R monthly plot with GGPlot2 in RMarkdown

I have a CSV file with the following data:
RegistrationDate;User_Id;Items
RegistrationDate has format like '22.05.2014 14:25'
Is there any easy way to connect CSV data to R markdown script? All of examples I've seen use random generated data, that looks too bad for reproducible research.
I need to create 2 plots with ggplot2:
a plot of users count per month.
a plot of items collected per month
I've checked a lot of graphs looks close to this one, but didn't find any right version. Looks like I don't understand something about R plotting :(.
What do you mean when you say "connect" CSV data to R markdown sript?
You mean reading them?
data <- read.csv("directory/name.csv", sep=";")
Or you mean adding somewhere a specific relation, telling that this data is related to this analysis? If the second, you can check the archivist package, stored on GitHub, that possess a set of tools for datasets and figures archivisation. There is a information how to install that package.
In question 2, you will need an extra column that specifies the month.

Resources