docstr: Downsample an Xarray.
docstr_tok: ["Downsample","an","Xarray","."]
code: def decimate_xarray_after_load(
      xr_input: xarray.Dataset, decimate_factor: int
  ):
      """
      Downsample an Xarray.
      """
      # Infer the output chunk shape since FFT does
      # not preserve input chunk shape.
      start_chunks = xr_input.data_var.data.chunks
  
      data_0 = xr_input.data_var.data[0] - xr_input.data_var.data[2]
      data_1 = xr_input.data_var.data[2]
      data_2 = xr_input.data_var.data[0]
  
      stacked_data = dask.array.stack([data_0, data_1, data_2], axis=0)
  
      stacked_chunks = stacked_data.chunks
  
      rechunking_to_chunks = (start_chunks[0], stacked_chunks[1])
      xr_input.data_var.data = stacked_data.rechunk(
          rechunking_to_chunks
      )
  
      in_chunks = xr_input.data_var.data.chunks
      out_chunks = (
          in_chunks[0],
          tuple(
              [int(chunk / decimate_factor) for chunk in in_chunks[1]]
          ),
      )
  
      data_ds_data = xr_input.data_var.data.map_overlap(
          TransformRoutines.decimate_raw_data,
          decimate_time=decimate_factor,
          overlap_time=10,
          depth=(0, decimate_factor * 10),
          trim=False,
          dtype="float32",
          chunks=out_chunks,
      )
  
      data_ds = copy(xr_input)
      data_ds = data_ds.isel(time=slice(0, data_ds_data.shape[1]))
      data_ds.data_var.data = data_ds_data
  
      return data_ds
  
imports: import argparse
  import json
  import logging
  import math
  import os
  import random
  import time
  from copy import copy, deepcopy
  from typing import List, Tuple
  import dask.array
  import numpy
  import xarray
  import ray
  from ray._private.test_utils import monitor_memory_usage
  from ray.util.dask import ray_dask_get
label_desc: Use image node_id 2 for calling the TransformRoutines obj's underlying member method code with example usage: obj.decimate_xarray_after_load(xr_input, decimate_factor) and returns: data_ds