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

bug reading netcdf via opendap #753

Open
jhlasheras opened this issue Jan 18, 2018 · 7 comments
Open

bug reading netcdf via opendap #753

jhlasheras opened this issue Jan 18, 2018 · 7 comments

Comments

@jhlasheras
Copy link

I found, what i guess is a bug in the netcdf4 library.

I am using anaconda with python 3.6.3 and Ipython 6.1.0

I tried to read a file via opendap when just starting my ipython, which works:

import netCDF4
ds = netCDF4.Dataset('http://thredds.socib.es/thredds/dodsC/hf_radar/hf_radar_ibiza-scb_codarssproc001/L1/2016/dep0001_hf-radar-ibiza_scb-codarssproc001_L1_2016-02.nc')

The problem arises when I load some other libraries and try to load the same file. Doing the following:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

ds = netCDF4.Dataset('http://thredds.socib.es/thredds/dodsC/hf_radar/hf_radar_ibiza-scb_codarssproc001/L1/2016/dep0001_hf-radar-ibiza_scb-codarssproc001_L1_2016-02.nc')

OSError: [Errno -36] NetCDF: Invalid argument: b'http://thredds.socib.es/thredds/dodsC/hf_radar/hf_radar_ibiza-scb_codarssproc001/L1/2016/dep0001_hf-radar-ibiza_scb-codarssproc001_L1_2016-02.nc'

However, I can read local netcdf files and also files via opendap with a shorter name:

ds2 = netCDF4.Dataset('http://thredds.socib.es/thredds/dodsC/operational_models/oceanographical/hydrodynamics/wmop_surface/latest.nc')

This works fine! It also works fine when executing the same code in jupyter notebook. Any explanation? Cheers

@jswhit
Copy link
Collaborator

jswhit commented Jan 18, 2018

Sorry, but I have no idea. Does it work if you don't import pandas, or if you import netCDF4 last?

@rsignell-usgs
Copy link

rsignell-usgs commented Jan 18, 2018

The provided example:

import netCDF4
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

ds = netCDF4.Dataset('http://thredds.socib.es/thredds/dodsC/hf_radar/hf_radar_ibiza-scb_codarssproc001/L1/2016/dep0001_hf-radar-ibiza_scb-codarssproc001_L1_2016-02.nc')

works fine for me, produces no errors.

My NetCDF version is 1.3.1

@jswhit
Copy link
Collaborator

jswhit commented Jan 18, 2018

Works here too.

@jhlasheras
Copy link
Author

jhlasheras commented Jan 18, 2018

That's rigth. I have tried it in a macbook and it works fine. However in my ubuntu 14.04 it continuosly give an error. Both of them using netCDF4 version 1.3.1. Also in other mates computer with similar configuration the same error happened.

May anaconda netcdf library be interfering with some other netcdf library?

@dopplershift
Copy link
Member

This might depend on the version of the netCDF-C library being used. IIRC, there were some versions that got a bit more picky about some of the opendap parsing.

@cgohlke
Copy link
Contributor

cgohlke commented Feb 18, 2018

At least on Windows, this issue is fixed by Unidata/netcdf-c#366 (for me)

@jhlasheras
Copy link
Author

I found the problem may be due to the matplotlib backend.
When initializing with Tk backend the problem dissaspears.

Adding this at the begining of the script solves the problem:

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

everything works fine untill I execute %matplotlib

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

5 participants