Convert product to an array

Hello.

I am doing my final master’s thesis, here are the problems I am encountering.

  • After downloading the sentienel-5P satellite, with this code:

api = SentinelAPI(‘XXXXX’, ‘XXXXX’, ‘https://s5phub.copernicus.eu/dhus’)
map = geojson_to_wkt(read_geojson(‘spainspain.geojson’))

products = api.query(map,
date=(date(2020, 1, 2), date(2020,8, 8)),
producttype=‘L2__NO2___’,
platformname=‘Sentinel-5’)

api.download_all(products)

I manage to download the products with their metadata, I would like to be able to work with them from python i.e. select latitude,longitude, time and nitrogendioxide_tropospheric_column and convert it to dataframe to work.

I am trying this:
data3 = ‘C:/Escritorio/S5P_NRTI_L2__NO2____20210118T140732_20210118T141232_16928_01_010400_20210118T150113.nc’
fh0 = Dataset(data3, mode=‘r’)

lat=(fh0.groups[‘PRODUCT’].variables[‘latitude’])
log=(fh0.groups[‘PRODUCT’].variables[‘latitude’])
time=(fh0.groups[‘PRODUCT’].variables[‘time’])
no2=(fh0.groups[‘PRODUCT’].variables[‘nitrogendioxide_tropospheric_column_precision’])

lat = lat.to_dataframe()

error:
AttributeError: NetCDF: Attribute not found.

In short what I am looking for is to work with sentienel data in dataframe.

Thank you very much.

This forum is more focused on using the atmospheric toolbox to access S5P data (using e.g. HARP).
Maybe another user on the forum can provide you a solution.

Good morning Sebastian,

I am guessing that your
lat=(fh0.groups[‘PRODUCT’].variables[‘latitude’])
command has a syntax error.

I admit to be using a much more… basic function, i.e.

reads in the TROPOMI ncdf file [=fname] from the path it is located

file = Dataset(path+fname,“r”)

reads in the latitude and longitude arrays

lat= file[“latitude”][:]
lon= file[“longitude”][:]

or if you wish to turn them into numpy arrays

read in the lat/lon of the file

lat = np.array(file[“latitude”][:])
lon = np.array(file[“longitude”][:])

I have no experience with “to_dataframe” and cannot help with that bit, but from the error I am guessing that the reading is not performed properly, not the translation into a dataframe object.

Good luck,
MariLiza

1 Like

Thank you. I will try your method.