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?

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Jul 19, 2019 at 7:41
4
  • 1
    your code seems right, could you provide your sample data for tests ? Commented Jul 19, 2019 at 8:19
  • @HichamZouarhi you can get data here latlon[drive.google.com/file/d/1UjTv0aYttGYoVaUUAT9gjEPuTgcOvOHj/view] and other file data [drive.google.com/file/d/1IT-F7AbIx4bCjMLosjBx4F4UCoIX5DU0/view] thank you Commented Jul 19, 2019 at 8:23
  • there are indeed no data ( or corrupted data since many attributes of the variables are missing ) in the first file ( the one with lat lon ), are those coordinates supposed to refer to X and Y on the second file ? Commented Jul 19, 2019 at 8:46
  • yes the 2 files have same dimensions when you open the file1 latlon with the second you can get value of lon & lat i don't know how but yesterday i did it and today i can get the value :!! Commented Jul 19, 2019 at 8:52

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

answered Jul 19, 2019 at 9:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.