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?
-
1your code seems right, could you provide your sample data for tests ?Hicham Zouarhi– Hicham Zouarhi2019年07月19日 08:19:04 +00:00Commented 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 youSarah Tohami– Sarah Tohami2019年07月19日 08:23:59 +00:00Commented 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 ?Hicham Zouarhi– Hicham Zouarhi2019年07月19日 08:46:59 +00:00Commented 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 :!!Sarah Tohami– Sarah Tohami2019年07月19日 08:52:14 +00:00Commented Jul 19, 2019 at 8:52
1 Answer 1
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