Skip to content

Instantly share code, notes, and snippets.

@ceholden
Last active February 23, 2018 13:13
Show Gist options
  • Save ceholden/77a9ecf90cd8ce0bf4ec504e65310693 to your computer and use it in GitHub Desktop.
Save ceholden/77a9ecf90cd8ce0bf4ec504e65310693 to your computer and use it in GitHub Desktop.
ARD resampling for pyCCD
name: resample
channels:
- conda-forge
dependencies:
# pyccd deps
- numpy
- scipy
- scikit-learn
- click
- click-plugins
- cachetools
- pyyaml
# read / resample data
- xarray
# notebook and visualize
- jupyter
- notebook
- matplotlib
- pip:
- git+https://github.com/USGS-EROS/lcmap-pyccd.git
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Resampling ARD"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"One approach to achieving spatial-temporal consistency when using ARD is to resample the data to some standard (or regular) temporal interval before running anything.\n",
"\n",
"Resampling, often referred to as compositing within remote sensing literature, is the process of grouping observations by time and reducing this group according to some criteria. One commonly used example of this is generating monthly \"maximum NDVI\" composites, often at an annual or monthly time intervals. Even more sophisticated approaches, like the \"Best Available Pixel\" approach from Wulder _et al_, can be described by this logic.\n",
"\n",
"The resample operation can be considered to have the following parameters:\n",
"\n",
"* Dimension (in this example, the time dimension)\n",
"* Interval\n",
"* Resampling criteria (usually a band or index)\n",
"* Reduction function (e.g., \"max\" or \"min\")"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import datetime as dt\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import toolz\n",
"import xarray as xr\n",
"\n",
"import ccd\n",
"\n",
"plt.style.use('ggplot')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load data"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<xarray.Dataset>\n",
"Dimensions: (time: 2916, x: 10, y: 10)\n",
"Coordinates:\n",
" * y (y) float64 1.935e+06 1.935e+06 1.935e+06 1.935e+06 1.935e+06 ...\n",
" * x (x) float64 -2.11e+06 -2.11e+06 -2.11e+06 -2.109e+06 -2.109e+06 ...\n",
" crs int32 ...\n",
" * time (time) datetime64[ns] 1982-11-15 1982-11-24 1982-12-01 ...\n",
"Data variables:\n",
" blue (time, y, x) float64 ...\n",
" green (time, y, x) float64 ...\n",
" red (time, y, x) float64 ...\n",
" nir (time, y, x) float64 ...\n",
" swir1 (time, y, x) float64 ...\n",
" swir2 (time, y, x) float64 ...\n",
" bt (time, y, x) float64 ...\n",
" cfmask (time, y, x) float64 ...\n",
"Attributes:\n",
" crs: +datum=WGS84 +lat_0=23 +lat_1=29.5 +lat_2=45.5 +lon_0=-96 +...\n",
" crs_wkt: PROJCS[\"unnamed\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[...\n",
" Conventions: CF-1.6\n",
" spatial_ref: PROJCS[\"unnamed\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[..."
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_res
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment