I need to convert an "Aura OMI NO2 Data Product" in .he5 format to a Tiff.

Using Python, I achieve the conversion with the following code:

trans = "gdal_translate -of GTiff -sds -a_srs WGS84 -a_ullr -180 90 180 -90" + " " + input_file + " " + output_file"

I am trying to write this command within Python, but have not found how to override the georeferenced bounds as the GDAL command -a_ullr ulx uly lrx lry does.

The code I have is the following:

# Import gdal and osr
import gdal
import osr

# Open he5 file
src_ds = gdal.Open(input_file)

# Get the 4th subdataset and open it
subdatasets = src_ds.GetSubDatasets()
mysds = subdatasets[3][0]
sub_ds = gdal.Open(mysds)

# Set Projection
srs = osr.SpatialReference()

# Convert to Tiff
format = "GTiff"
driver = gdal.GetDriverByName( format )
dst_ds = driver.CreateCopy( destination_tif, sub_ds, 0 )

# Clean up
dst_ds = None
src_ds = None
sub_ds = None

I need to set the bounds of the generated raster, as it doesn't match up correctly. In the following picture, the top raster was generated with my imbedded Python code, whereas the bottom was created with the GDAL_translatePicture.

Furthermore, is it better practise to assign the Projection and Bounds to the subdataset or to the Tiff once it has been generated?


Using GDAL 2.1, the following command reproduces the gdal_translate code:

gdal.Translate(dst_f, ssub_ds, format = 'GTiff',
               outputSRS = 'EPSG:4326', outputBounds = [ -180, 90, 180, -90])
  • For some historical info - the way gdal_translate and gdal.Translate do this internally is to use an intermediate in-memory VRT. To replicate cate this prior to GDAL 2.1, you needed to write a lot of code to build the VRT XML string with different bounds which you then open as a dataset and pass to the CreateCopy function. – user2856 Sep 27 '16 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.