Open cdeciampa opened 1 year ago
Hi @cdeciampa ! Could you provide with your issue a minimal reproducible example with code for us to copy/paste and run to try to reproduce the problem you describe? That would help tremendously!
import os
import glob
import numpy as np
import xarray as xr
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib.colors import LinearSegmentedColormap
import hvplot.xarray
parent_28km_dir = "/path/to/28km/model/output/netCDFs"
h3p_files = glob.glob(os.path.join(parent_28km_dir, '*.h3.*.nc'))
h3pr_ds = xr.open_mfdataset([f for f in h3p_files if 'remap' in f])
def T_to_FLUT(T, unit='K'):
if unit == 'C':
T += 273.15
sigma = 5.6693E-8
olr = sigma*(T**4)
return olr
# Normalized CIMSS outgoing longwave radiation flux colormap
bw_colors = [(0, '#BCBCBC'), (1, '#000000')]
bw_cmp = LinearSegmentedColormap.from_list('FLUT bw', bw_colors, N=435)
levels = np.array([T_to_FLUT(temp, 'C') for temp in [-110, -105, -87.5, -80, -70, -60, -50, -35, -27.5, -22.5]])
fracs = levels-T_to_FLUT(-110, 'C')
rainbow_colors = [(0, '#0febff'), # cyan
((fracs[1]/fracs[-1]), '#7f007f'), # purple
((fracs[2]/fracs[-1]), '#e5e4e5'), # white
((fracs[3]/fracs[-1]), '#000000'), # black
((fracs[4]/fracs[-1]), '#ff0000'), # red
((fracs[5]/fracs[-1]), '#FFFF00'), # yellow
((fracs[6]/fracs[-1]), '#00FF00'), # green
((fracs[7]/fracs[-1]), '#000073'), # navy
(1, '#00ffff')] # cyan
rainbow_cmp = LinearSegmentedColormap.from_list('FLUT colors', rainbow_colors, N=184)
bws = plt.get_cmap(bw_cmp)
bws_colors = bws(np.linspace(0, 1, 435))
rainbow = plt.get_cmap(rainbow_cmp)
r_colors = rainbow(np.linspace(0, 1, 184))
all_colors = np.vstack((r_colors, bws_colors))
flut_cimss = LinearSegmentedColormap.from_list('FLUT_CIMSS', all_colors)
# Registers as matplotlib colormap
mpl.colormaps.register(flut_cimss, name='FLUT_CIMSS', force=True)
h3pr_ds.FLUT.isel(time=7).hvplot.quadmesh('lon', 'lat', geo=True, rasterize=True, dynamic=False,
clim=(T_to_FLUT(-110, 'C'), T_to_FLUT(55, 'C')),
cmap = 'FLUT_CIMSS', coastline='10m', frame_width=500)
Unfortunately @cdeciampa I won't be able to run this code without having the files you use. So either you could share with me one file or you could modify your script to generate data instead of relying on reading files.
I'm sharing two files so you don't need to modify xr.open_mfdataset
and should be able to run the code as-is. They're small files, ~4 mb each.
test_files.zip
Thanks for sharing the test files. I'll just note that the glob pattern didn't work with these files and that the dataset has not FLUT
variable. Yet I was able to reproduce the second problem reported by replacing FLUT by PRECC. It seems that HoloViews doesn't correctly retrieve the list of Matplotlib colormaps, I'll open an issue on HoloViews.
On the first issue, I realize that cmap
isn't documented anywhere on the website, I'm not sure what types it accepts so one would first need to document what it accepts.
I'm having two issues:
xarray.hvplot.quadmesh
, I'm unable to use a a customLinearSegmentedColormap
unless I register it with with matplotlib and call it that way.Successful environment (Python 3.10.5):
Failed environment (Python 3.8.13):