1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| In [19]:
...: def ExtractVarsFromNetcdf(x_coord, y_coord, path, varnames):
...: """
...: @params:
...: x_coord - Required : the x coordinate of the point
...: x_coord - Required : the y coordinate of the point
...: ncdir - Required : The directory of the netcdf file.
...: varnames - Required : The netcdf variables
...: """
...:
...: with Dataset(ncdir, "r") as nc:
...:
...: # Get the nc lat and lon from the point's x, y
...: lon = nc.variables["lon"][int(round(x_coord))]
...: lat = nc.variables["lat"][int(round(y_coord))]
...:
...: # Return a np.array with the netcdf data
...: air_dep = np.ma.getdata(
...: [nc.variables[air_dep][:, x_coord, y_coord] for air_dep in
...: varnames]
...: )
...:
...: return air_dep, lon, lat
...:
In [20]: nc, lon, lat = ExtractVarsFromNetcdf(89.9877, 35.8141, ncdir, [ air_dep
...: ])
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-20-e3b0979e7612> in <module>()
----> 1 nc, lon, lat = ExtractVarsFromNetcdf(89.9877, 35.8141, ncdir, [ air_dep])
NameError: name 'air_dep' is not defined |
Partager