4

I downloaded a "Sentinel-3 Land Surface Temperature" netcdf file. I want to get the longitude and latitude for each temperature entry in the file. Well the file has pairs of rows and column. Using Python I can get the temperature using :

from netCDF4 import Dataset
with dataset as ncFile:
 nc_attrValue = ncFile.variables['LST'][1000][1000]
 print(type(nc_attrValue))

So any idea how I can convert [1000][1000] to longitude or latitude. Here is a snapshot of the file netcdf file converted to .cdl using NCO:

 netcdf LST_in {
dimensions:
 columns = 1500 ;
 orphan_pixels = 187 ;
 rows = 1200 ;
variables:
short LST(rows, columns) ;
 LST:_FillValue = -32768s ;
 LST:add_offset = 290.f ;
 LST:long_name = "Gridded Land Surface Temperature" ;
 LST:scale_factor = 0.002f ;
 LST:standard_name = "surface_temperature" ;
 LST:units = "K" ;
 LST:valid_max = 32767s ;
 LST:valid_min = -32767s ;
// global attributes:
 :absolute_orbit_number = 12616U ;
 :comment = " " ;
 :contact = "[email protected]" ;
 :creation_time = "20180720T144045Z" ;
 :history = " 2018年07月20日T14:40:45Z: PUGCoreProcessor /data/ipf-s3/workdir47/568114279/JobOrder.568114279.xml" ;
 :institution = "SVL" ;
 :netCDF_version = "4.2 of Mar 13 2018 10:14:33 $" ;
 :product_name = "S3A_SL_2_LST____20180720T124923_20180720T125223_20180720T144045_0179_033_323_3240_SVL_O_NR_003.SEN3" ;
 :references = "S3IPF PDS 005 - i2r7 - Product Data Format Specification - SLSTR, S3IPF PDS 002 - i1r6 - Product Data Format Specification - Product Structures, S3IPF DPM 007 - i1r8 - Detailed Processing Model - SLSTR Level 2" ;
 :resolution = "[ 1000 1000 ]" ;
 :source = "IPF-SL-2 06.13" ;
 :start_offset = 21649 ;
 :start_time = "2018-07-20T12:49:23.587859Z" ;
 :stop_time = "2018-07-20T12:52:23.279310Z" ;
 :title = "SLSTR Level 2 Product, Land Surface Temperature measurement" ;
 :track_offset = 998 ;
data:
 LST =
 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 
 _, _, _, _, _, _, _, -7188, -6706, -6884, -6249, -6173, -6721, -6924,
Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
asked Oct 3, 2018 at 11:48

1 Answer 1

1
# Imports
from netCDF4 import Dataset
# Define reading function
def slstr_read_nc(fdir):
 """
 Read lon, lat SLSTR data
 
 Args:
 fdir = string with the path and filename of the SLSTR product
 Returns:
 lon -- 2d ndarray of longitude
 lat -- 2d ndarray of latitude
 """
 # Read Data
 # Open NetCDF
 nc = Dataset(fdir, mode='r')
 
 # Read variables from ncdf
 lon = nc.variables['longitude_in'][:]
 lat = nc.variables['latitude_in'][:]
 # Close netcdf
 nc.close()
 
 return lon, lat
# Define path and NC filename
path = './'
fname = 'geodetic_in.nc' # this is the lat, lon NC file
fdir = os.path.join(path, fname)
# extract lat, lon
lon, lat = slstr_read_nc(fdir)
lon.shape
lat.shape

Output:

>>> lon.shape
(1200, 1500)
>>> lat.shape
(1200, 1500)
answered Dec 24, 2020 at 13:24

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.