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

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

Related

Spatstat - how to compare two temperature spatial domains?

I would like to compare a satellite pseudo-image generated by the WRF model and a real satellite image with the R-package named Spatstat. However, I do not know how to begin. I have read that it is possible to carry out a spatial pattern comparison but I do not know which function I should use. I have two temperature images in a predefined domain and I would like to know if the comparison is carried out point-by-point over those images or I have to facilitate the model output and satellite data. In that case, how should I do that? Is there any available script?
Thanks in advance.
Kind regards, Lara.
The spatstat package is designed mainly to analyse spatial patterns of point locations (like the pattern of locations of accidents that occurred in a given year). It does have some basic facilities for comparing pixel images. If A and B are two pixel images, you can do arithmetic by typing e.g. mean(A-B) or mean(abs(A-B)). There are also some image metrics (distances between images) available. Please visit the spatstat.org website for more information.

Extracting data from NetCDF file

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)

Extracting and importing untidy Excel tables into R to wrangle for Tableau export

I want to read in to R an EXCEL tab that has the following content configuration into a more Tidy data format. The next picture shows how I want the content to look like once all of the code has run. The table below just represents file that will come in daily. Each day, the numbers and the date will change, but the format will be exactly the same. So I need to learn how to automate the extraction of the pieces of this format into R from EXCEL. The end goal is to stack the daily data into a format that can be exported to Tableau.
The image above (figure 2) represents the final format I want to arrive at. I know there are several packages to read in EXCEL data into R, however I cannot figure out how I can possibly automate this tasks with readr or readxl etc... I am at least hoping some one has faced this type of problem before and can give me general directions.

How to export time series from Netlogo using the time extension

I am using Netlogo and I would like to use the time extension by Colin Sheppard to export automatically data generated by my model as time series, so that it will look like this.
Normally, one could export all data by using export-all-plots, but the data are not well sorted for later use in R.
Unfortunately, I do not understand well the documentation (available here) about how to export data generated by the model into a .csv file as the documentation describes only how to load existing data into the model.
Does somebody has experiences about how to export files as time series from Netlogo or understand the documentation linked above?
Might it be adequate to your needs to use BehaviorSpace to export the data (in table format), with the current time as one of the metrics? This will give you a CSV file with the time (and your other metrics) reported each tick.

What is the best way to store anciliary data with a 2D timeseries object in R?

I currently try to move from matlab to R.
I have 2D measurements, consisting of irradiance in time and wavelength together with quality flags and uncertainty and error estimates.
In Matlab I extended the timeseries object to store both the wavelength array and the auxiliary data.
What is the best way in R to store this data?
Ideally I would like this data to be stored together such that e.g. window(...) keeps all data synchronized.
So far I had a look at the different timeseries classes like ts, zoo etc and some spatial-time series. However none of them allow me to neither attach auxiliary data to observations nor can they give me a secondary axes.
Not totally sure what you want, but here is a simple tutorial mentioning
R's "ts" and"zoo" time series classes:
http://faculty.washington.edu/ezivot/econ424/Working%20with%20Time%20Series%20Data%20in%20R.pdf
and here is a more comprehensive outline of many more classes(see the Time Series Classes section)
http://cran.r-project.org/web/views/TimeSeries.html

Resources