Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when running code on Google Colab #9

Open
WxAnalyst opened this issue Dec 25, 2022 · 2 comments
Open

TypeError when running code on Google Colab #9

WxAnalyst opened this issue Dec 25, 2022 · 2 comments

Comments

@WxAnalyst
Copy link

I'm running code from HRRR Data. It works perfectly in a local Jupyter notebook, but runs into an error on Google Colab (with condacolab installed). Am I missing a library somewhere?

My code :


!pip install -q condacolab
import condacolab
condacolab.install()

!mamba install -q -c conda-forge cartopy metpy herbie-data
!pip install git+https://github.com/blaylockbk/Carpenter_Workshop.git

from herbie import Herbie
from toolbox import EasyMap, pc
from paint.standard2 import cm_tmp

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from metpy import units

H = Herbie(
    "2022-12-24",
    model="hrrr",
    product="sfc",
    fxx=0,
)

ds = H.xarray("TMP:2 m above")

ax = EasyMap("50m", crs=ds.herbie.crs, figsize=[20, 12]).STATES().ax
ax.set_extent([-125, -105, 35, 50])
p = ax.pcolormesh(
    ds.longitude,
    ds.latitude,
    ds.t2m.metpy.convert_units('degF'),
    transform=pc,
    **cm_tmp(units="F").cmap_kwargs,
)
plt.colorbar(
    p,
    ax=ax,
    orientation="horizontal",
    pad=0.01,
    shrink=0.8,
    **cm_tmp(units="F").cbar_kwargs,
)

ax.set_title(
    f"{ds.model.upper()}: {H.product_description}\nValid: {ds.valid_time.dt.strftime('%H:%M UTC %d %b %Y').item()}",
    loc="left",
)
ax.set_title(ds.t2m.GRIB_name, loc="right")

The resulting error on Colab:

TypeError                                 Traceback (most recent call last)
<ipython-input-9-5245a609d364> in <module>
     24     ds.t2m.metpy.convert_units('degF'),
     25     transform=pc,
---> 26     **cm_tmp(units="F").cmap_kwargs,
     27 )
     28 plt.colorbar(

1 frames
/usr/local/lib/python3.8/site-packages/paint/standard2.py in _segmented_cmap(name, colors, bounds, extend)
    101 def _segmented_cmap(name, colors, bounds, extend="neither"):
    102     cmap = mcolors.LinearSegmentedColormap.from_list(name, colors, N=len(bounds) + 1)
--> 103     norm = mcolors.BoundaryNorm(bounds, cmap.N, extend=extend)
    104     return cmap, norm
    105 

TypeError: __init__() got an unexpected keyword argument 'extend'
@blaylockbk
Copy link
Owner

I have never tried running this on Google colab. I did hear from someone once that they had an issue due to a python or matplotlib version.

It looks like you are using python 3.8. That should be fine. But what version of matplotlib is installed? That error TypeError: __init__() got an unexpected keyword argument 'extend' seems like the version of matplotlib might be out of date.

@WxAnalyst
Copy link
Author

Matplotlib version is 3.6.2, which I believe is current. Perhaps Google has problems with **kwargs. Those are the only lines that produce the error. Given that it works perfectly on Jupyter Lab, the issue must be on Google's side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants