0

I have an interpolated file which has positive Z values , so I want to use gdal_calc to make them negative. This works on the gdalcommand line with

gdal_calc -a interpolated.tif --outfile gdal_negative.tif --calc="-abs(-a)"

Based on this, I wanted to incorporate this into a python script so have done it with subprocess as follows (please note that the interpolated tiff seen above is already stored in the variable interpolated_file:

print('Pre calc')
        negative_file = output_file + '_negative.tif'
        calculation = '--calc=-abs(-a)'
        subprocess.call(['gdal_calc.py', '-a', interpolated_file, '--outfile', negative_file, '--overwrite', calculation])
        print('Post calc')

This runs ok, no errors thrown. HOWEVER, the result is the expected image for about 3/4 of it, and then the top of the raster extent is blank? Why is the top of the raster blank when there's data?! It's also the exact same command as the command line

  • Those are not the same command in several respects, although only the lack of `.py` in the former version seems likely to be relevant. – Davis Herring Oct 01 '22 at 20:41
  • @DavisHerring how are they not the same command? They give the same output except for the top blank space – user09873920134 Oct 01 '22 at 20:53
  • Upon checking again, it’s actually just two things: the added `.py` in the command and the added `--overwrite` option. – Davis Herring Oct 01 '22 at 22:42
  • @DavisHerring yes because ```.py``` is how it's called in python and ```--overwrite``` is just to overwrite the output file each time I run the script so that I don't end up with numerous outputs. Neither of which should be causing the blank part of the raster – user09873920134 Oct 01 '22 at 23:17
  • Does running `gdalinfo` on both files reveal anything? – Robert Davy Oct 03 '22 at 23:25

0 Answers0