{ "cells": [ { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "# Thinning datasets \n", "\n", "This function is used to thin a dataset by keeping every n-th value across the dimensions that are specified. This is useful for applications such as plotting wind data where using the original resolution would result in a crowded and unreadable figure.\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "import ecodata as eco\n", "import xarray as xr" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "This example uses wind data from ECMWF that has been installed by the user. The thinning function can be used by just providing the path to the dataset, but here we will read in the dataset to better visualize the examples. " ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "filein = eco.get_path('ECMWF_eagle_wind_full.nc')\n", "wind = xr.load_dataset(filein)" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "This dataset has dimensions of time, latitude, and longitude:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n",
"Dimensions: (longitude: 329, latitude: 265, time: 8784)\n",
"Coordinates:\n",
" * longitude (longitude) float32 -173.0 -172.8 -172.5 ... -91.5 -91.25 -91.0\n",
" * latitude (latitude) float32 78.0 77.75 77.5 77.25 ... 12.5 12.25 12.0\n",
" * time (time) datetime64[ns] 2008-01-01 ... 2008-12-31T23:00:00\n",
"Data variables:\n",
" u10 (time, latitude, longitude) float32 0.7963 0.8023 ... -4.058\n",
" v10 (time, latitude, longitude) float32 5.058 4.98 ... 0.4992 0.7828\n",
" t2m (time, latitude, longitude) float32 249.1 248.9 ... 300.2 300.1\n",
"Attributes:\n",
" Conventions: CF-1.6\n",
" history: 2022-06-14 00:45:00 GMT by grib_to_netcdf-2.24.3: /opt/ecmw...<xarray.Dataset>\n",
"Dimensions: (longitude: 17, latitude: 14, time: 440)\n",
"Coordinates:\n",
" * longitude (longitude) float32 -173.0 -168.0 -163.0 ... -103.0 -98.0 -93.0\n",
" * latitude (latitude) float32 78.0 73.0 68.0 63.0 ... 28.0 23.0 18.0 13.0\n",
" * time (time) datetime64[ns] 2008-01-01 ... 2008-12-31T20:00:00\n",
"Data variables:\n",
" u10 (time, latitude, longitude) float32 0.7963 1.159 ... -7.4 -0.3785\n",
" v10 (time, latitude, longitude) float32 5.058 3.698 ... -2.269 0.6049\n",
" t2m (time, latitude, longitude) float32 249.1 245.6 ... 300.4 300.6\n",
"Attributes:\n",
" Conventions: CF-1.6\n",
" history: 2022-06-14 00:45:00 GMT by grib_to_netcdf-2.24.3: /opt/ecmw...<xarray.Dataset>\n",
"Dimensions: (longitude: 66, latitude: 53, time: 879)\n",
"Coordinates:\n",
" * longitude (longitude) float32 -173.0 -171.8 -170.5 ... -94.25 -93.0 -91.75\n",
" * latitude (latitude) float32 78.0 76.75 75.5 74.25 ... 15.5 14.25 13.0\n",
" * time (time) datetime64[ns] 2008-01-01 ... 2008-12-31T20:00:00\n",
"Data variables:\n",
" u10 (time, latitude, longitude) float32 0.7963 0.8929 ... -0.7807\n",
" v10 (time, latitude, longitude) float32 5.058 4.742 ... -0.03834\n",
" t2m (time, latitude, longitude) float32 249.1 248.3 ... 300.6 300.4\n",
"Attributes:\n",
" Conventions: CF-1.6\n",
" history: 2022-06-14 00:45:00 GMT by grib_to_netcdf-2.24.3: /opt/ecmw...<xarray.Dataset>\n",
"Dimensions: (longitude: 33, latitude: 27, time: 879)\n",
"Coordinates:\n",
" * longitude (longitude) float32 -173.0 -170.5 -168.0 ... -98.0 -95.5 -93.0\n",
" * latitude (latitude) float32 78.0 75.5 73.0 70.5 ... 20.5 18.0 15.5 13.0\n",
" * time (time) datetime64[ns] 2008-01-01 ... 2008-12-31T20:00:00\n",
"Data variables:\n",
" u10 (time, latitude, longitude) float32 0.7963 1.041 ... -0.3785\n",
" v10 (time, latitude, longitude) float32 5.058 4.481 ... -5.771 0.6049\n",
" t2m (time, latitude, longitude) float32 249.1 247.6 ... 299.5 300.6\n",
"Attributes:\n",
" Conventions: CF-1.6\n",
" history: 2022-06-14 00:45:00 GMT by grib_to_netcdf-2.24.3: /opt/ecmw...