I am new to using Python and also new to NetCDF, so apologies if I'm unclear. I have an nc file that has several variables and I need to extract data from those nc files in a new order.
My nc file has 8 variables (longitude, latitude, time, u10, v10, swh, mwd, mwp) and the logic I'm trying is "If I input longitude and latitude, my program outputs other variables (u10, v10, swh, mwd, mwp) ordered by time." Then I would put the extracted data in another database.
I tested my nc file as below:
import netCDF4
from netCDF4 import Dataset
jan = Dataset('2016_01.nc')
print jan.variables.keys()
lon = jan.variables['longitude']
lat = jan.variables['latitude']
time = jan.variables['time']
for d in jan.dimensions.items():
print d
lon_array = lon[:]
lat_array = lat[:]
time_array = time[:]
print lon_array
print lat_array
print time_array
and some of the result is below
[u'longitude', u'latitude', u'time', u'u10', u'v10', u'swh', u'mwd', u'mwp']
(u'longitude', <type 'netCDF4._netCDF4.Dimension'>: name = 'longitude', size = 1440)
(u'latitude', <type 'netCDF4._netCDF4.Dimension'>: name = 'latitude', size = 721)
(u'time', <type 'netCDF4._netCDF4.Dimension'> (unlimited): name = 'time', size = 186)
Any advice would be appreciated. Thank you.