pmlmodelling / nctoolkit

A Python package for netCDF analysis and post-processing
https://nctoolkit.readthedocs.io/en/latest/
GNU General Public License v3.0
77 stars 10 forks source link

nctoolkit plot can not show figure in jupyter lab #115

Open onion5376 opened 1 month ago

onion5376 commented 1 month ago

I am new user of nctoolkit, so I follow the tutorial (https://nctoolkit.readthedocs.io/en/v1.1.11/visualization.html) to study this package.

My code is listed as following:

import nctoolkit as nc
ff = "/media/sf_E_DRIVE/Data/copernicus/sst.mon.mean.nc"
ds = nc.open_data(ff)
ds.spatial_mean()
ds.assign_coords(lon_name = "lon",lat_name = "lat")
ds.plot()

I had try use matlibplot to test the figure in jupyterlab,but it could work well,code is listed as following:

import matplotlib.pyplot as plt
plt.plot([1,2],[1,3])
robertjwilson commented 1 month ago

Hi @onion5376

Can you possibly make the problem reproducible? Without the data, it's difficult to figure out the issue.

Can you also give details on what's happening? Is it throwing an error?

Why are you assigning lon/lat after calculating the spatial average?

onion5376 commented 1 month ago

Hi @robertjwilson, Thanks for your help.

  1. I give a new example (https://nctoolkit.readthedocs.io/en/v1.1.11/interpolation.html) using the online data, the code is listed as following:
import nctoolkit as nc
ds = nc.open_thredds("https://psl.noaa.gov/thredds/dodsC/Datasets/COBE2/sst.mon.mean.nc")
ds.subset(time = 0)
ds.plot()

The result of running the code is shown in the following screenshot, it is just a blank display image

When i try to use matplotlib to plot a simple figure, it can work well with a right figure in jupyter lab. code:

import matplotlib.pyplot as plt
plt.plot([1,2],[1,3])

image

  1. Why are you assigning lon/lat after calculating the spatial average? Sometimes the coordinates are not specifically given, and running the program results in an error. So I refer to the advice given in the nctoolkit package website (https://nctoolkit.readthedocs.io/en/v1.1.11/troubleshoot.html).
onion5376 commented 1 month ago

Additional system platform and python installer information:

  1. os platform: centos 6.10 X86_64
  2. Python: 3.12.4
  3. nctookit: 1.1.11
  4. nco: 5.2.6
  5. cdo: 2.4.0
  6. jupyter lab: 4.2.3
robertjwilson commented 1 month ago

Thanks @onion5376. I just tired this on Ubuntu with that set up and it worked fine.

What browser are you using to view jupyterlab?

My guess is that the issue is caused by what version of nctoolkit's dependencies are installed. Are you working in conda? If so, can you possibly share the environment? Or have you installed with pip?

onion5376 commented 1 month ago

Thanks for your help @robertjwilson. The browser is firefox 78.5.0esr 64-bit. The nctookit is installed with mamba. I export this environment yam file from mamba, and upload it. environment.zip

robertjwilson commented 1 month ago

Thanks @onion5376.

I'll try to reproduce this later today.

In the meantime, you could check if these hvplot examples work for you. Internally, nctoolkit calls hvplot, so this is probably what's causing the issue.

https://hvplot.holoviz.org/user_guide/Gridded_Data.html

onion5376 commented 1 month ago

I operate the example in website (https://hvplot.holoviz.org/user_guide/Gridded_Data.html), it also fails to show figure. When installing nctoolkit with mamba, hvplot is automatically installed as a dependency package.

robertjwilson commented 1 month ago

Thanks @onion5376. That poins towards the problem being versioning issues. I will see if I can identify the problematic versions in the environment and maybe try adding some pinning on conda to ensure problematic versions don't get installed.

onion5376 commented 1 month ago

Hi @robertjwilson. I try another example in nctoolkit website (https://nctoolkit.readthedocs.io/en/v1.1.11/datasets.html). The script is shown below:

import nctoolkit as nc
ds = nc.open_thredds("https://psl.noaa.gov/thredds/dodsC/Datasets/COBE2/sst.mon.ltm.1981-2010.nc")
ds.subset(time = 0)
ds.plot()

It also get another errors:

The variable valid_yr_count has integer data type. Consider setting data type to float 'F64' or 'F32' using set_precision. Unable to decode time axis into full numpy.datetime64 objects, continuing using cftime.datetime objects instead, reason: dates out of range Unable to decode time axis into full numpy.datetime64 objects, continuing using cftime.datetime objects instead, reason: dates out of range Unable to decode time axis into full numpy.datetime64 objects, continuing using cftime.datetime objects instead, reason: dates out of range Unable to decode time axis into full numpy.datetime64 objects, continuing using cftime.datetime objects instead, reason: dates out of range

robertjwilson commented 1 month ago

Hi @onion5376. Those are warning messages, not errors.

robertjwilson commented 1 month ago

Hi @onion5376. I just tried reproducing the problem using your environment.yml. Everything worked fine. So I'm not sure what the issue is. Most likely this is a system-level problem with your web browser. Have you tried it with a different browser? Given the hvplot examples don't work, there must be something going on at the browser level