Skip to content

How to convert OLCI Sentinel 3 .nc file to GeoTIFF composite? #2

Description

@HafezAhmad

I have downloaded level 2 data from https://data.eumetsat.int/data/map/EO:EUM:DAT:0407?start=2021-02-15T18:39:00.000Z&end=2024-10-30T18:39:40.167Z&facets=timeliness%7CNT&bbox=-89.6,30.05,-88.95,30.27&sort=start,time,0 like filename: S3A_OL_2_WFR____20241023T160700_20241023T161000_20241023T180154_0179_118_211_2520_MAR_O_NR_003.SEN3.zip

I am trying to convert all bands like 0a1 to 12 into single composite using any program like Python or R or QGIS/ ArcGIS.

I am facing problem because the zipped file contained geo_coordinates.nc and my desired bands does have lat long. The code, I have attached that does not georeferenced file.

import rasterio
import netCDF4

# Extract geolocation data from geo_coordinates.nc
nc = netCDF4.Dataset('geo_coordinates.nc', 'r')
lat = nc.variables['latitude'][:]
lon = nc.variables['longitude'][:]
nc.close()

# Define the output composite image
output_filename = 'composite_image.tif'
output_transform = rasterio.transform.from_origin(lon.min(), lat.max(), 0.01, 0.01)
output_crs = 'EPSG:4326'

# Combine the band files
with rasterio.open('0a1.tif', 'r') as src0a1, \
     rasterio.open('0a1.tif', 'r') as src01, \
     ...  # Add more bands as needed
     rasterio.open('output_filename', 'w', driver='GTiff', \
                   width=lon.shape[1], height=lat.shape[0], \
                   count=len(bands), dtype=rasterio.uint16, \
                   crs=output_crs, transform=output_transform) as dst:
    for band in bands:
        dst.write(band.read(1), band+1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions