Answers for "downsample python"

3

resampling data python

#Resample to monthly
df.resample('M').asfreq()
Posted by: Guest on August-13-2021
1

use functions to resample python

#We can also use custom functions and apply them when resampling using the .apply(method_name) method
#This is an example used in a downsampling example
def custom_resampler(arraylike):
    return np.sum(arraylike) + 5
data.resample('Q').apply(custom_resampler)
Posted by: Guest on August-13-2021
0

how to do downsampling in python

import xarray as xr
import numpy as np
import matplotlib.pyplot as plt

fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(15,5))

# Create a 10x10 array of random numbers
a = xr.DataArray(np.random.rand(10,10)*100, dims=['x', 'y'])

# "Downscale" the array, mean of blocks of size (2x2)
b = a.coarsen(x=2, y=2).mean()

# "Downscale" the array, mean of blocks of size (5x5)
c = a.coarsen(x=5, y=5).mean()

# Plot and cosmetics
a.plot(ax=ax1)
ax1.set_title("Full Data")

b.plot(ax=ax2)
ax2.set_title("mean of (2x2) boxes")

c.plot(ax=ax3)
ax3.set_title("mean of (5x5) boxes")
Posted by: Guest on August-26-2021

Python Answers by Framework

Browse Popular Code Answers by Language