<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>That's because numpy.median expects one array and keyword arguments, not three arrays. It's unclear to me what gdal_calc.py does under the hood (I admit I did not read it) but the correct way to get the median of the three bands would be:<div><br></div><div>--calc median([A,B,C], 0)</div><div><br></div><div>The strange part is that</div><div><span style="font-size: 12pt;">--calc median([A,B,C])</span></div><div>works as well and generates a different output. When axis is not specified median should return a single value. At this point I suggest you take three 2D arrays, calculate their median as a 2D array, convert the three arrays to rasters, run gdal_calc.py and compare results.</div><div><br></div><div>-marius<br><br><div><hr id="stopSpelling">Date: Tue, 25 Nov 2014 17:56:46 +0900<br>From: simlangen@gmail.com<br>To: chris.yesson@ioz.ac.uk<br>CC: gdal-dev@lists.osgeo.org<br>Subject: Re: [gdal-dev] gdal_calc.py: produce median raster<br><br><div dir="ltr">Dear Dr Chris Yesson<br><br>Thanks for your quick response.<br><br>I got the following error:<br><br>ValueError: The truth value of an array with more than one element is ambiguous. <br>Use a.any() or a.all()`<br><br>Perhaps the expression for calc seems to be revised...<div><br></div><div><br><div class="ecxgmail_extra"><div class="ecxgmail_quote">On Tue, Nov 25, 2014 at 4:59 PM, Chris Yesson <span dir="ltr"><<a href="mailto:chris.yesson.phd@gmail.com" target="_blank">chris.yesson.phd@gmail.com</a>></span> wrote:<br><blockquote class="ecxgmail_quote" style="border-left:1px #ccc solid;padding-left:1ex;"><div dir="ltr">Dear Simen,<div><br></div><div>You can refer to each band explicitly using the --A_band option.</div><div>Try something like this</div><div><br></div><div>gdal_calc.py -A infile --A_band 1 -B infile --B_band 2 -C infile --C_band 3 --outfile outfile --calc median(A,B,C)</div><div class="ecxgmail_extra"><br></div><div class="ecxgmail_extra">- Chris</div><div class="ecxgmail_extra"><br clear="all"><div><div><div dir="ltr"><em><span style="font-size:12pt;">Dr Chris Yesson</span></em><i><span style="font-size:10pt;font-family:Arial;"><br></span><em><span style="font-size:12pt;">Institute of Zoology, </span></em><em><span style="font-size:12pt;">Zoological Society of London</span></em></i><div><div><i><font size="3">Tel: 020 7449 6267</font></i><br></div><div><i><font size="3">email: <a href="mailto:chris.yesson@ioz.ac.uk" target="_blank">chris.yesson@ioz.ac.uk</a><br></font></i><span style="font-size:10pt;font-family:Arial;"><em><span style="font-size:12pt;">web: <a href="http://www.zsl.org/chrisyesson/" target="_blank">http://www.zsl.org/chrisyesson/</a></span></em><br>
</span></div></div><div><em style="font-family:Arial;"><span style="font-size:12pt;">Note: I work Mon-Thurs and do not check email on Fri</span></em><br></div></div></div></div>
<br><div class="ecxgmail_quote"><div><div class="h5">On 25 November 2014 at 07:44, Simen Langseth <span dir="ltr"><<a href="mailto:simlangen@gmail.com" target="_blank">simlangen@gmail.com</a>></span> wrote:<br></div></div><blockquote class="ecxgmail_quote" style="border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex;"><div><div class="h5"><div dir="ltr">Dear Respected Authors:<div><br></div><div>I would be grateful if you could share any hints on it.</div><div><br></div><div class="ecxgmail_extra"><br><div class="ecxgmail_quote">On Tue, Nov 25, 2014 at 4:33 PM, Simen Langseth <span dir="ltr"><<a href="mailto:simlangen@gmail.com" target="_blank">simlangen@gmail.com</a>></span> wrote:<br><blockquote class="ecxgmail_quote" style="border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex;"><div dir="ltr">Dear Marius Jigmond:<br><br>Thanks for your attempt.<br><br>Unfortunately, it is producing 3 band outfile, rather than 1 band median image.<br><br>I could not figure out what this code computed, all the resulted 3 bands images are also different.<br><br>I hope someone can help me.<br></div><div><div><div class="ecxgmail_extra"><br><div class="ecxgmail_quote">On Tue, Nov 25, 2014 at 12:09 PM, Marius Jigmond <span dir="ltr"><<a href="mailto:mariusjigmond@hotmail.com" target="_blank">mariusjigmond@hotmail.com</a>></span> wrote:<br><blockquote class="ecxgmail_quote" style="border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex;">
<div><div dir="ltr">Does the following work:<div><br><div>gdal_calc.py -A infile --allBands=A --outfile=outfile --calc="median(A)"</div><div><br><br><div><hr>Date: Mon, 24 Nov 2014 19:14:06 +0900<br>From: <a href="mailto:simlangen@gmail.com" target="_blank">simlangen@gmail.com</a><br>To: <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>Subject: [gdal-dev] gdal_calc.py: produce median raster<div><div><br><br><div dir="ltr">I have one GeoTiff file with 3 bands. I want to produce a raster file computing pixel wise median value for the three raster bands. How can I do that?<div><br></div><div>I tried as follows:</div><div><br></div><div>gdal_calc.py -A infile --allBands --outfile outfile --calc median(A)</div><div><br></div><div>But could not get any out file.</div><div><br></div><div> </div></div>
<br></div></div>_______________________________________________
gdal-dev mailing list
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a></div></div></div> </div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>
<br><br>
</div></div><p align="center"><font style="background-color:rgb(255,255,255);" size="1">This message has been scanned for viruses by </font><a href="http://www.mailcontrol.com/" target="_blank"><font style="background-color:rgb(255,255,255);" size="1">MailControl</font></a><font style="background-color:rgb(255,255,255);" size="1">, a service from </font><a href="http://www.blackspider.com/" target="_blank"><font style="background-color:rgb(255,255,255);" size="1">BlackSpider Technologies</font></a><font style="background-color:rgb(255,255,255);" size="1">.</font></p>
<p align="center"><span style="background:white;"><font size="1">Click <a href="https://www.mailcontrol.com/sr/MZbqvYs5QwJvpeaetUwhCQ==" target="_blank">here</a> to report this email as spam.<u></u><u></u><u></u></font></span></p>
<br><br>
The Zoological Society of London is incorporated by Royal Charter<br>Principal Office England. Company Number RC000749<br>Registered address: <br>Regent's Park, London, England NW1 4RY<br>Registered Charity in England and Wales no. 208728
<p align="left"></p>
<p align="center"><font style="background-color:rgb(255,255,255);"><font size="1">_________________________________________________________________________<br>This e-mail has been sent in confidence to the named addressee(s).<br>If you are not the intended recipient, you must not disclose or distribute<br>it in any form, and you are asked to contact the sender immediately.<br>Views or opinions expressed in this communication may not be those<br>of The Zoological Society of London and, therefore, The Zoological<br>Society of London does not accept legal responsibility for the contents<br>of this message. The recipient(s) must be aware that e-mail is not a<br>secure communication medium and that the contents of this mail may<br>have been altered by a third party in transit.<br>If you have any issues regarding this mail please contact:<br></font><a href="mailto:administrator@zsl.org" target="_blank"><font size="1">administrator@zsl.org</font></a><font size="1">.<br>___________________________________________________________________________<br></font></font></p>
<p align="center"><font style="background-color:rgb(255,255,255);"></font><font size="1"></font></p>
<p align="center"><font style="background-color:rgb(255,255,255);" size="1">This message has been scanned for viruses by </font><a href="http://www.mailcontrol.com/" target="_blank"><font style="background-color:rgb(255,255,255);" color="#000000" size="1">MailControl</font></a><font style="background-color:rgb(255,255,255);" size="1">, a service from </font><a href="http://www.blackspider.com/" target="_blank"><font style="background-color:rgb(255,255,255);" color="#000000" size="1">BlackSpider Technologies</font></a><font style="background-color:rgb(255,255,255);" size="1">.</font></p>
</blockquote></div><br></div></div>
</blockquote></div><br></div></div></div>
<br>_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev</div></div> </div></body>
</html>