How can I solve a non-linear algebraic equation in ArcGIS python over multiple rasters. Let me Rephrase. I want to solve the following 3 non linear equations , and for 46 8 day time steps. I have 46 rasters each for an 8 day period for Β(σ) , and σ, where I need to take input values from per time step. Is/Io is a constant. The three unknowns I have are E, G and H. The solution should ideally produce 46 rasters each for the 3 unknowns. I don't know if this can be done in ArcGIS though. I know I can solve this equations easily in SciPy using the Fsolve function but I don't know how to get this working with rasters. Any code that could help will be greatly appreciated.
Thanks Dan, I appreciate this. I am looking into this. I'll feed everyone back on my progress. Thanks all
here is the principle... I have some work to do so you can fill in the technical gaps... I have kept it simple, I haven't included the determining the 'unique triplets', but If you are good with the idea and can test the principle on a small sample, I can fill in that bit
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">dan_func</SPAN><SPAN class="punctuation token">(</SPAN>z<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"""feed in the input array, do the stuff and return"""</SPAN> d<SPAN class="punctuation token">,</SPAN> e<SPAN class="punctuation token">,</SPAN> f<SPAN class="punctuation token">,</SPAN> ans <SPAN class="operator token">=</SPAN> z<SPAN class="punctuation token">.</SPAN>T ans <SPAN class="operator token">=</SPAN> d <SPAN class="operator token">+</SPAN> e <SPAN class="operator token">+</SPAN> f z<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> ans <SPAN class="keyword token">return</SPAN> d<SPAN class="punctuation token">,</SPAN> e<SPAN class="punctuation token">,</SPAN> f<SPAN class="punctuation token">,</SPAN> ans<SPAN class="punctuation token">,</SPAN> z a <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> b <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> c <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">8</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">6</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">6</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> a0 <SPAN class="operator token">=</SPAN> a<SPAN class="punctuation token">.</SPAN>ravel<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> b0 <SPAN class="operator token">=</SPAN> b<SPAN class="punctuation token">.</SPAN>ravel<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> c0 <SPAN class="operator token">=</SPAN> c<SPAN class="punctuation token">.</SPAN>ravel<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> z <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>zeros<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">9</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> z<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> a0 z<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> b0 z<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> c0 <SPAN class="comment token"># do the work</SPAN> d<SPAN class="punctuation token">,</SPAN> e<SPAN class="punctuation token">,</SPAN> f<SPAN class="punctuation token">,</SPAN> ans<SPAN class="punctuation token">,</SPAN> z <SPAN class="operator token">=</SPAN> dan_func<SPAN class="punctuation token">(</SPAN>z<SPAN class="punctuation token">)</SPAN> my_map <SPAN class="operator token">=</SPAN> z<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>reshape<SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">.</SPAN>shape<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Take 3 input rasters, unravel them, fill in an array that contains the number of cells wide by 1 more than the variables... ie a 3x3 raster with 4 variables gives you 'z ' which is 9x4
Call your function (dan_func is trademarked )
Now this function simply adds the 3 values together and puts the result in the 4th column, then a bunch of stuff is returned, which you can print. here is the 'z' array then it is reshaped into a map of 'dan stuff' defined by dan func.
z Out<SPAN class="punctuation token">[</SPAN><SPAN class="number token">21</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN> array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">14</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">9</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">15</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">11</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">9</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">16</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> my_map Out<SPAN class="punctuation token">[</SPAN><SPAN class="number token">22</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN> array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">14</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="number token">9</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">15</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">11</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN> <SPAN class="number token">9</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">16</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
now tell your brother to give you a hand
Good luck
that is what I was saying would be ridiculously slow.
I suggested something similar a long time ago. If you have 3 arrays/rasters, stacked one on top of the other, you pull your 3 values from each cell, giving you the 3 z's for your function. then you would solve for that..
Give me 3 ascii files, one for each variable in ascii format, for the same area... how about 10 rows and 10 columns and I will see if I can simplify the solution for you.
I still think a reclassification to reduce the number of combinations is the way to go. I just don't want to make up data
see this older thread https://community.esri.com/message/732916-re-solving-3-non-linear-algebraic-equations-in-python?commentID=732916#comment-732916
a0, b0 and c0 represent your three values for a location... Find like 'cells' that have that combination... chuck the tuple into the equation,throw the result into those cells.
Move on to the next unique triplet, repeat until you have run out of combinations.
Post data, it is doable, but I still think there must be a better way
Thanks for looking into it. Actually I found a possible way to do this, just that I technically dont know how to write the code. My brother has written something for me in C sharp but it is extremely slow because it is basically calling my python script and it is doing a lot of round tripping between the programs. It is in order of a day for a single set of files and I have 46 set of files.
The solution is as follows perhaps someone can help write a few lines in python to do this;
I converted the three input rasters to ASCII. Hence I have 4064 rows by 4876 columns. The program then calls each row and column at a time (i.e x,y), which essentially is a single value and computes fsolve for it. It then writes the answer for E, H and G from fsolve into 3 different .txt file for each x,y position. I imagine this is doable in python as well, unfortunately, my brother doesnt know code in python and the non linear solvers in C Sharp have been problematic hence my conundrum. IF anyone can help write something along the lines of what I explained, it will be much appreciated.
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">import</SPAN> arcpy <SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">import</SPAN> scipy <SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">import</SPAN> numpy <SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">as</SPAN> np <SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">def</SPAN> <SPAN class="" style="color: #d74444; border: 0px; font-weight: inherit;">myFunction</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>z<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">:</SPAN> E <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> z<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">]</SPAN> G <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> z<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">1</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">]</SPAN> H <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> z<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">2</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">]</SPAN> F <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> np<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>empty<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">3</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN> F<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">]</SPAN> <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> <SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">3.356</SPAN><SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">/</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">1.024</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">*</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">3</SPAN><SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">*</SPAN>H<SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">*</SPAN>pow<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>abs<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>H<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN><SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">-</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">1</SPAN><SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">/</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">6</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN><SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">-</SPAN>G F<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">1</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">]</SPAN> <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> <SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">300</SPAN><SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">-</SPAN>E<SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">-</SPAN>H<SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">-</SPAN>G F<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">2</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">]</SPAN> <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> <SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">3.356</SPAN><SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">*</SPAN>H<SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">-</SPAN>E <SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">return</SPAN> F zGuess<SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> np<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">.</SPAN>array<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">1</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">1</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;">1</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">]</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN> z <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;">=</SPAN> fsolve<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">(</SPAN>myFunction<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">,</SPAN>zGuess<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;">)</SPAN> <SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;">print</SPAN> z
I looked. The grids are floating point grids... there are millions of combinations, you will never pull out a lookup table nor will you be able to reclass the grids into something that combine will use. Using a root finding solution just isn't going to work in this situation. You might be advised to classify your input data into groupings of integer types, then come up with an representative value based on the combinations of the classes.... or... come up with an alternative approach, perhaps using different data.
Hi Dan,
Thanks for your suggestion. But I honestly am struggling to fully understand it as I am still a newbie to python. I have included some sample data in the link below. If you have sometime. I'll appreciate if you can put this suggestion in a script as I really have no clue on how to write it. Thanks
https://drive.google.com/file/d/1dE32qKVm0V83d4pvmPUD0nWvDmrOaz3w/view?usp=sharing
Still think the lookup table with the 3 values as input and one value as output.
You would have to produce that table using 'Combine'
You need to indicate how many different classes do you have for each variable? That will tell you the combinations possible.
By all appearance there is no way to solve the whole array at once... an array of combinations will give you the output value for each triplet. The table of triplets and result gives you the lookup table which can be used to reclass the combined array (using Combine) which is the combinations of the 3 variables at each location
Please this is still an on going challenge. If you have any other suggestions. It will be very much appreciated. The flattening of the arrays did not work.
visually what I am talking about and how the values need to be generated... they do not represent the actual data you are using but represent 3 arrays with values and how do you generate the inputs from them.
<SPAN class="comment token"># ---- 3 arrays, a, b, c ----</SPAN> a array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> b array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> c array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">8</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">6</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">6</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># ---- flatten them out so you can have a look ------</SPAN> a0 <SPAN class="operator token">=</SPAN> a<SPAN class="punctuation token">.</SPAN>ravel<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> b0 <SPAN class="operator token">=</SPAN> b<SPAN class="punctuation token">.</SPAN>ravel<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> c0 <SPAN class="operator token">=</SPAN> c<SPAN class="punctuation token">.</SPAN>ravel<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> a0<SPAN class="punctuation token">,</SPAN> b0<SPAN class="punctuation token">,</SPAN> c0 <SPAN class="punctuation token">(</SPAN>array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">8</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># ---- now look down each 'column' aka location to get the values----</SPAN> d <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN>a0<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> b0<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> c0<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">9</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> d <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Which basically means the inputs can be reshaped
d0 <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>asarray<SPAN class="punctuation token">(</SPAN>d<SPAN class="punctuation token">)</SPAN> d0<SPAN class="punctuation token">.</SPAN>reshape<SPAN class="punctuation token">(</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN> array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">7</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
So the original inputs from array a, b, c can be reshuffled in a variety of ways, but the formulation of 'd' is probably easier to visualize how to get 3 values for each location ... aka combination, of a, b, and c.
In a practical sense, you would need to find out the plausible combinations of your inputs to produce a 'lookup' table
I think I get your point. However I have no idea on how to possibly attempt to extract one variable at a time. Could you possibly write something that I can insert into the code to do the suggestion you made?
my only thought at the moment is that you are using 2D arrays as input. I suspect that fsolve is looking for a single value for each of the inputs... effectively burrowing downwards through the stack of inputs and it only solves for each combination of the inputs.
What you are trying to do is get a value for each of the inputs at each location. This would be analogous to doing the root solve for each location based on the values at each location. It doesn't seem to be able to handle the 2D inputs but requires a list/tuple of the values for zguess at each location
Xander BakkerDan Patterson think I am getting closer to concluding that the Fsolve function may not be capable of doing what I need it to do.
I ran my code for a single set of rasters below and got the error below. It appears that just as Xander Bakker suggested in line 50 of his code, maybe this cant be done with numpy arrays. Any other ideas of how to get this solved?
Runtime error Traceback (most recent call last):File "<string>", line 29, in <module>File "C:\Program Files (x86)\python27\ArcGIS10.4\lib\site-packages\scipy\optimize\minpack.py", line 140, in fsolveres = _root_hybr(func, x0, args, jac=fprime, **options)File "C:\Program Files (x86)\python27\ArcGIS10.4\lib\site-packages\scipy\optimize\minpack.py", line 197, in _root_hybrshape, dtype = _check_func('fsolve', 'func', func, x0, args, n, (n,))File "C:\Program Files (x86)\python27\ArcGIS10.4\lib\site-packages\scipy\optimize\minpack.py", line 20, in _check_funcres = atleast_1d(thefunc(*((x0[:numinputs],) + args)))File "<string>", line 23, in myFunctionValueError: setting an array element with a sequence.
<SPAN class="keyword token">import</SPAN> os <SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">import</SPAN> scipy <SPAN class="keyword token">import</SPAN> numpy <SPAN class="keyword token">as</SPAN> np <SPAN class="keyword token">def</SPAN> <SPAN class="token function">myFunction</SPAN><SPAN class="punctuation token">(</SPAN>z<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> inRas1 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Raster<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"C:\\Workspace\\test geowrite\\Betasigma\\Rad_meantiff_001.tif"</SPAN><SPAN class="punctuation token">)</SPAN> lowerleft <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN>inRas1<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>XMin<SPAN class="punctuation token">,</SPAN>inRas1<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>YMin<SPAN class="punctuation token">)</SPAN> cellSize <SPAN class="operator token">=</SPAN> inRas1<SPAN class="punctuation token">.</SPAN>meanCellWidth np_file <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>RasterToNumPyArray<SPAN class="punctuation token">(</SPAN>inRas1<SPAN class="punctuation token">,</SPAN>nodata_to_value<SPAN class="operator token">=</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> inRas2 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Raster<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"C:\\Workspace\\test geowrite\\sigma\\Rad_meantiff_001.tif"</SPAN><SPAN class="punctuation token">)</SPAN> lowerleft <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN>inRas2<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>XMin<SPAN class="punctuation token">,</SPAN>inRas2<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>YMin<SPAN class="punctuation token">)</SPAN> cellSize <SPAN class="operator token">=</SPAN> inRas2<SPAN class="punctuation token">.</SPAN>meanCellWidth np_fize <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>RasterToNumPyArray<SPAN class="punctuation token">(</SPAN>inRas2<SPAN class="punctuation token">,</SPAN>nodata_to_value<SPAN class="operator token">=</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> inRas3 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Raster<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"C:\\Workspace\\test geowrite\\Netrad\\Rad_meantiff_001.tif"</SPAN><SPAN class="punctuation token">)</SPAN> lowerleft <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">(</SPAN>inRas3<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>XMin<SPAN class="punctuation token">,</SPAN>inRas3<SPAN class="punctuation token">.</SPAN>extent<SPAN class="punctuation token">.</SPAN>YMin<SPAN class="punctuation token">)</SPAN> cellSize <SPAN class="operator token">=</SPAN> inRas3<SPAN class="punctuation token">.</SPAN>meanCellWidth np_fixe <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>RasterToNumPyArray<SPAN class="punctuation token">(</SPAN>inRas3<SPAN class="punctuation token">,</SPAN>nodata_to_value<SPAN class="operator token">=</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> E <SPAN class="operator token">=</SPAN> z<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> G <SPAN class="operator token">=</SPAN> z<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> H <SPAN class="operator token">=</SPAN> z<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> F<SPAN class="operator token">=</SPAN>np<SPAN class="punctuation token">.</SPAN>empty<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> F<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>np_file<SPAN class="operator token">/</SPAN>np_fize<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">*</SPAN><SPAN class="number token">3</SPAN><SPAN class="operator token">*</SPAN>H<SPAN class="operator token">*</SPAN>pow<SPAN class="punctuation token">(</SPAN>abs<SPAN class="punctuation token">(</SPAN>H<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="operator token">-</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="operator token">/</SPAN><SPAN class="number token">6</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">-</SPAN>G F<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> np_fixe<SPAN class="operator token">-</SPAN>E<SPAN class="operator token">-</SPAN>H<SPAN class="operator token">-</SPAN>G F<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> np_file<SPAN class="operator token">*</SPAN>H<SPAN class="operator token">-</SPAN>E <SPAN class="keyword token">return</SPAN> F zGuess<SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> z <SPAN class="operator token">=</SPAN> fsolve<SPAN class="punctuation token">(</SPAN>myFunction<SPAN class="punctuation token">,</SPAN>zGuess<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
<SPAN class="keyword token">import</SPAN> os <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="keyword token">import</SPAN> arcpy <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="keyword token">import</SPAN> scipy <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="keyword token">import</SPAN> numpy <SPAN class="keyword token">as</SPAN> np <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">myFunction</SPAN><SPAN class="punctuation token">(</SPAN>z<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> E <SPAN class="operator token">=</SPAN> z<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> G <SPAN class="operator token">=</SPAN> z<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> H <SPAN class="operator token">=</SPAN> z<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> F <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>empty<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> F<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>file<SPAN class="operator token">/</SPAN>fize<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">*</SPAN><SPAN class="number token">3</SPAN><SPAN class="operator token">*</SPAN>H<SPAN class="operator token">*</SPAN>pow<SPAN class="punctuation token">(</SPAN>abs<SPAN class="punctuation token">(</SPAN>H<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="operator token">-</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="operator token">/</SPAN><SPAN class="number token">6</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="operator token">-</SPAN>G <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> F<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> fixe<SPAN class="operator token">-</SPAN>E<SPAN class="operator token">-</SPAN>H<SPAN class="operator token">-</SPAN>G <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> F<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> file<SPAN class="operator token">*</SPAN>H<SPAN class="operator token">-</SPAN>E <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="keyword token">return</SPAN> F <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> zGuess<SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN><SPAN class="string token">"D:/GIS Data/Sixth Creek ET.gdb"</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> rasters <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListRasters<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"*"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"All"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> path <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:\\Workspace\\test geowrite\\Betasigma\\"</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> path2 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:\\Workspace\\test geowrite\\sigma\\"</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> path3 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:\\Workspace\\test geowrite\\Netrad\\"</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> files<SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>f <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> os<SPAN class="punctuation token">.</SPAN>listdir<SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> f<SPAN class="punctuation token">.</SPAN>endswith<SPAN class="punctuation token">(</SPAN><SPAN class="string token">".tif"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> fizes<SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>f <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> os<SPAN class="punctuation token">.</SPAN>listdir<SPAN class="punctuation token">(</SPAN>path2<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> f<SPAN class="punctuation token">.</SPAN>endswith<SPAN class="punctuation token">(</SPAN><SPAN class="string token">".tif"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> fixes<SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>f <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> os<SPAN class="punctuation token">.</SPAN>listdir<SPAN class="punctuation token">(</SPAN>path2<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> f<SPAN class="punctuation token">.</SPAN>endswith<SPAN class="punctuation token">(</SPAN><SPAN class="string token">".tif"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">46</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> file <SPAN class="operator token">=</SPAN> path<SPAN class="operator token">+</SPAN>files<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> fize <SPAN class="operator token">=</SPAN> path2<SPAN class="operator token">+</SPAN>fizes<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> fixe <SPAN class="operator token">=</SPAN> path3<SPAN class="operator token">+</SPAN>fixes<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> z <SPAN class="operator token">=</SPAN> fsolve<SPAN class="punctuation token">(</SPAN>myFunction<SPAN class="punctuation token">,</SPAN>zGuess<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> Runtime error Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> File <SPAN class="string token">"<string>"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">28</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN> File <SPAN class="string token">"C:\Program Files (x86)\python27\ArcGIS10.4\lib\site-packages\scipy\optimize\minpack.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">140</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> fsolve res <SPAN class="operator token">=</SPAN> _root_hybr<SPAN class="punctuation token">(</SPAN>func<SPAN class="punctuation token">,</SPAN> x0<SPAN class="punctuation token">,</SPAN> args<SPAN class="punctuation token">,</SPAN> jac<SPAN class="operator token">=</SPAN>fprime<SPAN class="punctuation token">,</SPAN> <SPAN class="operator token">**</SPAN>options<SPAN class="punctuation token">)</SPAN> File <SPAN class="string token">"C:\Program Files (x86)\python27\ArcGIS10.4\lib\site-packages\scipy\optimize\minpack.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">197</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> _root_hybr shape<SPAN class="punctuation token">,</SPAN> dtype <SPAN class="operator token">=</SPAN> _check_func<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'fsolve'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'func'</SPAN><SPAN class="punctuation token">,</SPAN> func<SPAN class="punctuation token">,</SPAN> x0<SPAN class="punctuation token">,</SPAN> args<SPAN class="punctuation token">,</SPAN> n<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">(</SPAN>n<SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> File <SPAN class="string token">"C:\Program Files (x86)\python27\ArcGIS10.4\lib\site-packages\scipy\optimize\minpack.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">20</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> _check_func res <SPAN class="operator token">=</SPAN> atleast_1d<SPAN class="punctuation token">(</SPAN>thefunc<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">*</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>x0<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN>numinputs<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> args<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> File <SPAN class="string token">"<string>"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">10</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> myFunction TypeError<SPAN class="punctuation token">:</SPAN> unsupported operand type<SPAN class="punctuation token">(</SPAN>s<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> <SPAN class="operator token">/</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'str'</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="string token">'str'</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Below is the code formatted with a bunch of questions. In order to test anything sample data must be provided.
<SPAN class="keyword token">import</SPAN> os <SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">import</SPAN> scipy <SPAN class="keyword token">import</SPAN> numpy <SPAN class="keyword token">as</SPAN> np <SPAN class="keyword token">def</SPAN> <SPAN class="token function">main</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"D:\GIS Data\Sixth Creek ET.gdb"</SPAN> path1 <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:\Workspace\test geowrite\Betasigma"</SPAN> path2 <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:\Workspace\test geowrite\sigma"</SPAN> path3 <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:\Workspace\test geowrite\Netrad"</SPAN> zGuess<SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>array<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> rasters <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListRasters<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"*"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"All"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># where do you use this?</SPAN> lst_files <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>f <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> os<SPAN class="punctuation token">.</SPAN>listdir<SPAN class="punctuation token">(</SPAN>path1<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> f<SPAN class="punctuation token">.</SPAN>endswith<SPAN class="punctuation token">(</SPAN><SPAN class="string token">".tif"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> lst_fizes <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>f <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> os<SPAN class="punctuation token">.</SPAN>listdir<SPAN class="punctuation token">(</SPAN>path2<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> f<SPAN class="punctuation token">.</SPAN>endswith<SPAN class="punctuation token">(</SPAN><SPAN class="string token">".tif"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> lst_fixes <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>f <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> os<SPAN class="punctuation token">.</SPAN>listdir<SPAN class="punctuation token">(</SPAN>path2<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> f<SPAN class="punctuation token">.</SPAN>endswith<SPAN class="punctuation token">(</SPAN><SPAN class="string token">".tif"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">46</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># very risky to do this.</SPAN> <SPAN class="comment token"># does each folder have the same 46 raster?</SPAN> <SPAN class="comment token"># is the order the same so that the correct rasters will be used together?</SPAN> path_ras_file <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>path1<SPAN class="punctuation token">,</SPAN> lst_files<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> path_ras_fize <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>path1<SPAN class="punctuation token">,</SPAN> lst_fizes<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> path_ras_fixe <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>path1<SPAN class="punctuation token">,</SPAN> lst_fixes<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># I guess you will have to convert to numpy</SPAN> <SPAN class="comment token"># asuming all have the same dimensiones</SPAN> np_file <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>RasterToNumPyArray<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Raster<SPAN class="punctuation token">(</SPAN>path_ras_file<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> np_fize <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>RasterToNumPyArray<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Raster<SPAN class="punctuation token">(</SPAN>path_ras_fize<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> np_fixe <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>RasterToNumPyArray<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Raster<SPAN class="punctuation token">(</SPAN>path_ras_fixe<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># your function uses a parameter. What is this parameter?</SPAN> param <SPAN class="operator token">=</SPAN><SPAN class="string token">"define parameter!"</SPAN> result_function <SPAN class="operator token">=</SPAN> myFunction<SPAN class="punctuation token">(</SPAN>param<SPAN class="punctuation token">,</SPAN> np_file<SPAN class="punctuation token">,</SPAN> np_fixe<SPAN class="punctuation token">,</SPAN> np_fize<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># are you sure that all the necessary parameters are provided?</SPAN> z <SPAN class="operator token">=</SPAN> scipy<SPAN class="punctuation token">.</SPAN>optimize<SPAN class="punctuation token">.</SPAN>fsolve<SPAN class="punctuation token">(</SPAN>result_function<SPAN class="punctuation token">,</SPAN> zGuess<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># do something with the z</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">myFunction</SPAN><SPAN class="punctuation token">(</SPAN>z<SPAN class="punctuation token">,</SPAN> np_file<SPAN class="punctuation token">,</SPAN> np_fixe<SPAN class="punctuation token">,</SPAN> np_fize<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># what is z?</SPAN> E <SPAN class="operator token">=</SPAN> z<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> G <SPAN class="operator token">=</SPAN> z<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> H <SPAN class="operator token">=</SPAN> z<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> F <SPAN class="operator token">=</SPAN> np<SPAN class="punctuation token">.</SPAN>empty<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> F<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>np_file<SPAN class="operator token">/</SPAN>np_fize<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">*</SPAN> <SPAN class="number token">3</SPAN> <SPAN class="operator token">*</SPAN> H <SPAN class="operator token">*</SPAN> pow<SPAN class="punctuation token">(</SPAN>abs<SPAN class="punctuation token">(</SPAN>H<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="operator token">/</SPAN><SPAN class="number token">6</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">-</SPAN> G <SPAN class="comment token"># can this be done with numpy arrays?</SPAN> F<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> np_fixe <SPAN class="operator token">-</SPAN> E <SPAN class="operator token">-</SPAN> H <SPAN class="operator token">-</SPAN> G F<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> np_file <SPAN class="operator token">*</SPAN> H <SPAN class="operator token">-</SPAN> E <SPAN class="keyword token">return</SPAN> F <SPAN class="keyword token">if</SPAN> __name__ <SPAN class="operator token">==</SPAN> <SPAN class="string token">'__main__'</SPAN><SPAN class="punctuation token">:</SPAN> main<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Larry you are going to have to edit your last code post so it is readable
Code Formatting
plus I don't see where you have converted the input rasters to arrays using RasterToNumPyArray
perhaps show where you have one condition working first before you start with the batch part. Some may ask for a sample of the three inputs, so I will do it for them.
Xander Bakker,@Dan Patterson, Randy burton, @kevin Dunlop, @Joshua Bixby After getting the code to run using just numbers to replace the rasters, I tried this code but it didn't quite work. Please help. This is doing my head in. I tried this code which I basically tried to cut out a chunk of a code that once worked in iteration. Please help. I am running out of time for a dealine
import os
... import arcpy
... import scipy
... import numpy as np
... def myFunction(z):
... E = z[0]
... G = z[1]
... H = z[2]
... F = np.empty((3))
... F[0] = (file/fize)*3*H*pow(abs(H),-(1/6))-G
... F[1] = fixe-E-H-G
... F[2] = file*H-E
... return F
...
... zGuess= np.array([1,1,1])
... arcpy.env.workspace ="D:/GIS Data/Sixth Creek ET.gdb"
... rasters = arcpy.ListRasters("*", "All")
... path = "C:\\Workspace\\test geowrite\\Betasigma\\"
... path2 = "C:\\Workspace\\test geowrite\\sigma\\"
... path3 = "C:\\Workspace\\test geowrite\\Netrad\\"
... files= [f for f in os.listdir(path) if f.endswith(".tif")]
... fizes= [f for f in os.listdir(path2) if f.endswith(".tif")]
... fixes= [f for f in os.listdir(path2) if f.endswith(".tif")]
... for i in range(0,46):
... file = path+files
... fize = path2+fizes
... fixe = path3+fixes
... z = fsolve(myFunction,zGuess)
Runtime error
Traceback (most recent call last):
File "<string>", line 28, in <module>
File "C:\Program Files (x86)\python27\ArcGIS10.4\lib\site-packages\scipy\optimize\minpack.py", line 140, in fsolve
res = _root_hybr(func, x0, args, jac=fprime, **options)
File "C:\Program Files (x86)\python27\ArcGIS10.4\lib\site-packages\scipy\optimize\minpack.py", line 197, in _root_hybr
shape, dtype = _check_func('fsolve', 'func', func, x0, args, n, (n,))
File "C:\Program Files (x86)\python27\ArcGIS10.4\lib\site-packages\scipy\optimize\minpack.py", line 20, in _check_func
res = atleast_1d(thefunc(*((x0[:numinputs],) + args)))
File "<string>", line 10, in myFunction
TypeError: unsupported operand type(s) for /: 'str' and 'str'
After getting the code to run using just numbers to replace the rasters, I tried this code but it didn't quite work. Please help. This is doing my head in. I tried this code which I basically tried to cut out a chunk of a code that once worked in iteration. Please help. I am running out of time for a dealine
Hi Dan, I fixed the numpy thing as you said. I fiddled around with it a little and it appears to be working now, however, I still need help with coding it to take those rasters in sequentially and also to write each of the E, G and H out as individual raster for each time step it iterates through. See below the code that worked. Look forward to your response.
import arcpyimport scipyimport numpy as npdef myFunction(z):... E = z[0]... G = z[1]... H = z[2]... F = np.empty((3))... F[0] = (3.356/1.024)*3*H*pow(abs(H),-(1/6))-G... F[1] = 300-E-H-G... F[2] = 3.356*H-E... return F
zGuess= np.array([1,1,1])z = fsolve(myFunction,zGuess)
print z[ 70.96121951 207.89419779 21.14458269]
Right! Makes sense. Noted. Thanks I'll wait for your response after your class.
Cheers
immediate issues... I will deal with the rest after classes
empty... can't just doe that, it has to be np.empty
when you import numpy as np... as other functions should be preceeded by np... don't do an import all either to save two letterd
Thanks for your response.
While I thought it should be fairly easy with scipy...I was wrong. I wrote this basic part of the code however it didn't quite work with all the errors below and I am struggling to figure it out. As u can guess I am a newbie.
My struggles are now that I cant even get the fsolve to work. I found out scipy is included in ArcGIS 10.4.1 (which is my current version), so I imported it and tried my hands on it. As a sample instead of trying to work with rasters, I used single values for the raster component...with no success. The values 1.024 in F(0), 300 in F(1) and 3.356 in F(0) and F(2) are daily rasters which I want the code to iterate through and pick the set for each day. There are 46 each in different folders. I hope the information below can help explain the problems a bit more clearly. Thanks.
If you can solve it with SciPy and the input takes 2D arrays then you can convert the raster to an array using
RasterToNumPyArray
the only concern is to ensure that the extent and cell sizes are the same. If the data types are the same that is good, but the array can be promoted or demoted as necessary.
If the inputs require a 1D array, then you can 'ravel()' the 2D array.
Perhaps some more information would facilitate devising a workflow to permit the integration
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.