You must look at the GetCapabilities of that server. The layer name is not "AlleghenyCountyImagery2010" but it is "0". Edit that into your XML file and your gdal_translate command will work.
SizeX and SizeY comes from extents and native resolution of the WMS service. If the site is 100 km wide and resolution is 1 m/pixel then SizeX is 100000.
Thanks for all of the suggestions and help. The scale normalization is very useful when doing code, however in my case the original idea of putting the minimum and maximum in code looks like the only solution at this point.
I did not find a solution for doing it at the command line.
Here is a code snippet from the working solution:
(Note that originally I was writing nodata to 0 as well, and this method breaks the nodata transformation. In my code I had to re-run the translate with nodata set to 0 as the only transformation to get it to finish the whole task!)
from qgis.core import *
from qgis.utils import *
from qgis.gui import *
import processing
from PyQt4.QtCore import *
#define functions
def loadraster(cur_raster):
fileInfo = QFileInfo(cur_raster)
baseName = fileInfo.baseName()
rlayer = QgsRasterLayer(cur_raster, baseName)
if not rlayer.isValid():
print "Layer failed to load!"
return rlayer
proj = QgsProject.instance()
proj.clear()
infile = "C:/QGISwork/ving_script/mergetest.tif"
outfile = "C:/QGISwork/ving_script/mergetest_out.tif"
#load raster file
mlayer = loadraster(infile)
#this part gets the extent from the original file
ext = mlayer.extent()
extrep = ','.join([unicode(ext.xMinimum()), unicode(ext.xMaximum()), unicode(ext.yMinimum()), unicode(ext.yMaximum())])
#now get the stats whcih contain min and max values
renderer = mlayer.renderer()
provider = mlayer.dataProvider()
extent = mlayer.extent()
stats = provider.bandStatistics(1, QgsRasterBandStats.All,extent, 0)
print stats.minimumValue
print stats.maximumValue
#we don't need the layer any more so clear memory
QgsMapLayerRegistry.instance().removeMapLayer(mlayer.id())
#Run the algorithm with all of the inputs:
processing.runalg('gdalogr:translate', infile, 100, True, "0", 0, "", extrep , False, 5, 4, 75, 6, 1, False, 3, False, "-scale "+str(stats.minimumValue)+" "+str(stats.maximumValue)+" "+"0 1", outfile)
Best Answer
I would consider using GDAL VRT as outputformat which leaves the image untouched and creates only XML file that describes how to read the source data. Delete the VRT file and you have unscaled your image.
You can also edit the result tiff with gdal_edit.py utility http://www.gdal.org/gdal_edit.html. Since GDAL 2.2 it has options -scale and -offset. Command is used as
The -scale option of gdal_translate does not take input as scale and offset but as documented
In simple case when all bands are scaled with the same settings it should be possible to define backward conversion with -scale and -offset but not when bands are stretched with different values. Neither would if work with exponential scaling with -exponent.
I may be wrong but I believe that your idea would not generally work. Easiest solution would be to do a virtual scaling with VRT file.