-1

I am just a python begginner and I am having some trouble in extracting data from a netcdf file.

For example, in this code I was trying to create a variable with the temperature but it is not appearing at the variable explorer console. Does anyone know why?

import netCDF4 as nc
import numpy as np
fn ='C:/Users/Public/Documents/Python Scripts/MERRA2_300.tavgM_2d_slv_Nx.201001.nc4'
ds = nc.Dataset(fn) 
AMC
  • 2,642
  • 7
  • 13
  • 35
  • Does anything happen if you print the value of _ds_ ? Also, I would recommend reading https://ericlippert.com/2014/03/05/how-to-debug-small-programs/. – AMC May 12 '21 at 13:42
  • Yes, it apears all the details of the dataset. Actually I can open and extract other variables from this dataset but I don't know why with the temperatura speacifically I can not.. I will take a look on this link. Thankss – Julia Moore May 12 '21 at 13:53

1 Answers1

0

print(ds.variables.keys()) to see all the variables in the netcdf file. Printing the above statement would also give the key for the temperature variable in the file.

Assign it to a variable as shown:temp_variable =ds.variables["#temp#"]

Note: Replace #temp# with the key for temperature variable