Search code examples
pythonnetcdf4

Error when running a slightly modified NWW3 example code


I am new to Python and I am trying to write a code that gets the wave amplitude using a set of lat and long coordinates. I am using NOAA's Wavewatch III which provides an example here and I want to modify it to get a dataset at different coordinates in an array instead of plotting it using the code below.

import numpy as np
import netCDF4

mydate = '20200829'
url = 'https://nomads.ncep.noaa.gov:9090/dods/wave/nww3/nww3'+ \
    mydate + '/nww3' + mydate+'_00z'

file = netCDF4.Dataset(url)
lat = file.variables['lat'][:]
lon = file.variables['lon'][:]
data = file.variables['htsgwsfc'][1,:,:]
file.close()

print(data)

However, when I try to run the code I keep getting this error:

OSError: [Errno -77] NetCDF: Access failure: b'https://nomads.ncep.noaa.gov:9090/dods/wave/nww3/nww320200829/nww320200829_00z'

If anybody has experience working with NWW3 and can tell me what's wrong with my code or perhaps knows if this is an error with NOAA's code (I've already found a mistake so I wouldn't be surprised), I'd greatly appreciate any help.


Solution

  • Remove the port :9090 from the url. This is the correct url:

    https://nomads.ncep.noaa.gov/dods/wave/nww3

    Looks like an older tutorial. Probably best to navigate to that url in your browser and find the file(s) you're looking for to get a feel for the url pattern.