3

I have two file netcdf4 ( latlon and other file without latlon)

i open the 2 file 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 i don't know why

the 2 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 2 file 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 ?

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, privacy policy and cookie policy

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