3

I have two files in NetCDF4 (latlon and other file without latlon).

I open the two files in the same code and I choose one variable and the two variable lon and lat. When I write lon I have the value nan and I don't know why.

The two files have same dimensions (size) and same dimensions for variables all I need is to show the value of lat&lon when I open the two files. How can I do it?

In [54]: import numpy as np
    ...: import netCDF4
    ...: 
    ...: 
    ...: fic1='/data/latlon_+000.0_globe.nc'
    ...: 
    ...: nc1 = netCDF4.Dataset(fic1,'r')
    ...: 
    ...: lon = nc1.variables['lon'][:]
    ...: lat = nc1.variables['lat'][:]
    ...: 
    ...: fic='/data/Mmultic3kmNC4_msg04_201905080200
    ...: .nc'
    ...: 
    ...: 
    ...: nc = netCDF4.Dataset(fic,'r')
    ...: IR=nc.variables['IR_108'][:]
    ...: 
    ...: 


In [55]: 

In [55]: lon
Out[55]: 
masked_array(
  data=[[nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        ...,
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan]],
  mask=False,
  fill_value=1e+20,
  dtype=float32)

In [56]: lat
Out[56]: 
masked_array(
  data=[[nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        ...,
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan]],
  mask=False,
  fill_value=1e+20,
  dtype=float32)

In [57]: 

How I can get value of lat & lon?

4

1 Answer 1

0

after checking the contents of the 2 files, there seems to be a problem with the dimensions of the one with lat lon variables since the attribute current_shape = (3712, 3712) for lat and lon while it should be (3712,).

The file may be corrupted and you'll have to create it again from the X and Y attributes of the second file since they are linked.

to do so you can start with this answer , you will also need to transform the projected coordinates to lat lon, and for that you can use pyproj

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.