I have 16 years of daily meteorological data in NetCDF, it has and each data contain a grid size of 501 x 572. This means each year has dimensions of 365 x 501 x 572. I converted it into a one-dimensional array. Then I am trying to plot probability distribution. But since the data size is so large, the python kernel restarts. How to optimize my code to convert 16 (years) x 365 (days) x 501 (lat) x 572 (lon) into a single array to plot distribution? I used chunks to optimize the input, but still, it fails when I convert it into a single array. It shows kernel restarts on the laptop. How to do it? How can I handle this much of data using xarray?
import matplotlib.pyplot as plt
import xarray as xr
import numpy as np
import seaborn as sns
fname='20*.nc'
ds=xr.open_mfdataset(fname,parallel=True,chunks=100)
prec = ds.irwin_cdr.values.flatten()
sns.displot(prec, bins=50, color="g", ax=ax)