0

I extract temperature data from the netcdf4 file using python I used these code but it returns only null values.

from netCDF4 import Dataset

nc = Dataset("GLDAS_NOAH025_3H.A20170102.0000.021.nc4","r")
for temp in nc.variables['AvgSurfT_inst'] :
    print (temp)

Output:

[[[-- -- -- ..., -- -- --]
  [-- -- -- ..., -- -- --]
  [-- -- -- ..., -- -- --]
  ..., 
  [-- -- -- ..., -- -- --]
  [-- -- -- ..., -- -- --]
  [-- -- -- ..., -- -- --]]]
Vipul Gangwar
  • 149
  • 1
  • 1
  • 10

1 Answers1

0

You can easily check if all / how much values are masked (missing) by counting the amount of masked values with np.ma.count_masked(data). As an example, for a random NetCDF file:

import numpy as np
import netCDF4 as nc4

f = nc4.Dataset('bomex.ql.0000000.nc')

for v in f.variables:
    arr = f.variables[v][:]
    print('{0:}: values = {1:}, masked_values = {2:}'.format(v, np.size(arr), np.ma.count_masked(arr)))

Which gives me something like:

z: values = 32, masked_values = 0

zh: values = 33, masked_values = 0

u: values = 416, masked_values = 362

v: values = 416, masked_values = 362

w: values = 429, masked_values = 369

Community
  • 1
  • 1
Bart
  • 9,825
  • 5
  • 47
  • 73