@@ -1492,7 +1492,13 @@ function getallxyinr(Xin, Yin, Δr; rangelenth=0)
1492
1492
end
1493
1493
xyfine, gridr
1494
1494
end
1495
-
1495
+
1496
+ function cumulativelinedist (soundings:: Vector{T} ) where T<: Sounding
1497
+ X = [s. X for s in soundings]
1498
+ Y = [s. Y for s in soundings]
1499
+ cumulativelinedist (X,Y)
1500
+ end
1501
+
1496
1502
function cumulativelinedist (X,Y)
1497
1503
dx = diff (X)
1498
1504
dy = diff (Y)
@@ -1638,83 +1644,74 @@ function plotprofile(ax, idxs, Z, R)
1638
1644
end
1639
1645
end
1640
1646
1641
- function getRsplits (R, Rmax)
1642
- q, rmn = divrem (maximum (R), Rmax)
1643
- thereisrmn = ! iszero (rmn)
1644
- idx = thereisrmn ? zeros (Int, Int (q+ 1 )) : zeros (Int, Int (q))
1645
- i = 1
1646
- for (ir, r) in enumerate (R)
1647
- if r >= Rmax* i
1648
- idx[i] = ir
1649
- i += 1
1650
- end
1651
- end
1652
- idx, thereisrmn
1653
- end
1654
-
1655
- function getinterpsplits (idx_split, nimages, gridx)
1656
- i_idx = 1 : nimages
1657
- ab = zeros (Int, nimages,2 )
1658
- for i in i_idx
1659
- a = i == firstindex (i_idx) ? 1 : idx_split[i- 1 ]
1660
- b = i != lastindex (i_idx) ? idx_split[i] : lastindex (gridx)
1661
- b = b- 1 # as we are now providing 1 less than the number of edges since 26c19a0d2e4a
1662
- ab[i,1 ] = a
1663
- ab[i,2 ] = b
1664
- end
1665
- if ab[end ,1 ] == ab[end ,2 ]
1666
- ab = ab[1 : end - 1 ,:]
1667
- nimages = nimages- 1
1668
- end
1669
- ab, nimages
1670
- end
1671
-
1672
1647
function plotsummarygrids1 (soundings, meangrid, phgrid, plgrid, pmgrid, gridx, gridz, topofine, R, Z, χ²mean, χ²sd, lname; qp1= 0.05 , qp2= 0.95 ,
1673
1648
figsize= (10 ,10 ), fontsize= 12 , cmap= " turbo" , vmin= - 2 , vmax= 0.5 , Rmax= nothing ,
1674
1649
topowidth= 2 , idx= nothing , omitconvergence= false , useML= false , preferEright= false , preferNright= false ,
1675
1650
saveplot= false , yl= nothing , dpi= 300 , showplot= true , showmean= false , logscale= true )
1651
+
1652
+ f (Rm) = plotsummarygrids (soundings, meangrid, phgrid, plgrid, pmgrid, gridx, gridz, topofine, R, Z, χ²mean, χ²sd, lname; qp1, qp2,
1653
+ figsize, fontsize, cmap, vmin, vmax, Rmax= Rm,topowidth, idx, omitconvergence, useML, preferEright, preferNright,
1654
+ saveplot, yl, dpi, showplot, showmean, logscale)
1655
+
1656
+ f (nothing ) # whole line
1657
+ if ! isnothing (Rmax) # also do Rmax slits
1658
+ f (Rmax)
1659
+ end
1660
+ end
1661
+
1662
+ function plotsummarygrids (soundings, meangrid, phgrid, plgrid, pmgrid, gridx, gridz, topofine, R, Z, χ²mean, χ²sd, lname; qp1= 0.05 , qp2= 0.95 ,
1663
+ figsize= (10 ,10 ), fontsize= 12 , cmap= " turbo" , vmin= - 2 , vmax= 0.5 , Rmax= nothing ,
1664
+ topowidth= 2 , idx= nothing , omitconvergence= false , useML= false , preferEright= false , preferNright= false ,
1665
+ saveplot= false , yl= nothing , dpi= 300 , showplot= true , showmean= false , logscale= true )
1676
1666
if isnothing (Rmax)
1677
- Rmax = maximum (gridx)
1678
- end
1679
- while true
1680
- idx_split, thereisrmn = getRsplits (gridx, Rmax)
1681
- nimages = length (idx_split)
1682
- dr = gridx[2 ] - gridx[1 ]
1683
- dr >= Rmax && error (" dr:$dr >= Rmax:$Rmax , decrease dr" )
1684
- if iszero (idx_split[1 ]) && thereisrmn # Rmax is larger than section
1685
- nx = length (range (gridx[1 ], Rmax, step= dr))
1686
- elseif ! iszero (idx_split[1 ]) && ! thereisrmn # Rmax is exactly the section length
1687
- nx = length (gridx)
1688
- elseif iszero (idx_split[2 ]) # Rmax is smaller than the section
1689
- nx = idx_split[1 ]
1690
- else
1691
- nx = idx_split[2 ]- idx_split[1 ] # There are many Rmax length splits
1692
- end
1693
- ab, nimages = getinterpsplits (idx_split, nimages, gridx)
1694
- i_idx = 1 : nimages
1695
- for i in i_idx
1696
- a, b = ab[i,1 ], ab[i,2 ]
1697
- a_uninterp = i == firstindex (i_idx) ? 1 : findlast (R.<= gridx[a])
1698
- b_uninterp = i != lastindex (i_idx) ? findlast (R.<= gridx[b]) : lastindex (soundings)
1699
- if thereisrmn && i == lastindex (i_idx)
1700
- xrangelast = range (gridx[a], step= dr, length= nx)
1701
- else
1702
- xrangelast = nothing
1703
- end
1704
- f, s, icol = setupconductivityplot (gridx[a: b], omitconvergence, showmean, R[a_uninterp: b_uninterp],
1705
- figsize, fontsize, lname, χ²mean[a_uninterp: b_uninterp], χ²sd[a_uninterp: b_uninterp], useML, i, nimages, logscale)
1706
-
1707
- summaryconductivity (s, icol, f, soundings[a_uninterp: b_uninterp],
1708
- meangrid[:,a: b], phgrid[:,a: b], plgrid[:,a: b], pmgrid[:,a: b],
1709
- gridx[a: b], gridz, topofine[a: b], R[a_uninterp: b_uninterp], Z[a_uninterp: b_uninterp], ; qp1, qp2, fontsize,
1667
+ Rmax = maximum (R)
1668
+ end
1669
+ # much better name than grids1
1670
+ # is for the probabilistic inversions
1671
+ dr = gridx[2 ] - gridx[1 ]
1672
+ dr >= Rmax && error (" dr:$dr >= Rmax:$Rmax , decrease dr" )
1673
+ startendimageindex = getgridxsplits (gridx, Rmax)
1674
+ a_im, b_im = startendimageindex[:,1 ], startendimageindex[:,2 ]
1675
+ startendsoundingindex = getsoundingsplits (soundings, gridx[b_im])
1676
+ a_s, b_s = startendsoundingindex[:,1 ], startendsoundingindex[:,2 ]
1677
+ @assert size (startendimageindex, 1 ) == size (startendsoundingindex, 1 ) # number of splits
1678
+ nimages = length (a_im)
1679
+ for i in 1 : nimages
1680
+ gridx_, topo_ = map (x-> x[a_im[i]: b_im[i]+ 1 ], (gridx, topofine))
1681
+ meangrid_, phgrid_, plgrid_, pmgrid_ = map (x-> x[:,a_im[i]: b_im[i]], (meangrid, phgrid, plgrid, pmgrid))
1682
+ soundings_, R_, Z_, χ²mean_, χ²sd_ = map (x-> x[a_s[i]: b_s[i]], (soundings, R, Z, χ²mean, χ²sd))
1683
+ f, s, icol = setupconductivityplot (gridx_, omitconvergence, showmean, R_,
1684
+ figsize, fontsize, lname, χ²mean_, χ²sd_, useML, i, nimages, logscale)
1685
+ xrangelast = i == nimages ? [gridx_[1 ], gridx_[1 ]+ Rmax] : nothing
1686
+ summaryconductivity (s, icol, f, soundings_,
1687
+ meangrid_, phgrid_, plgrid_, pmgrid_,
1688
+ gridx_, gridz, topo_, R_, Z_, ; qp1, qp2, fontsize,
1710
1689
cmap, vmin, vmax, topowidth, idx, omitconvergence, preferEright, preferNright, yl, showmean, xrangelast)
1711
- postfix = nimages == 1 ? " _whole" : " _split_$(i) _of_$(nimages) "
1712
- saveplot && savefig (lname* postfix* " .png" , dpi= dpi)
1713
- showplot || close (f)
1714
- end
1715
- nimages == 1 && break # don't need another pass if it was whole line to start with
1716
- Rmax = maximum (gridx) # this will ensure nimages=1 on next pass
1717
- end
1690
+ postfix = nimages == 1 ? " _whole" : " _split_$(i) _of_$(nimages) "
1691
+ saveplot && savefig (lname* postfix* " .png" , dpi= dpi)
1692
+ showplot || close (f)
1693
+ end
1694
+ end
1695
+
1696
+ function getgridxsplits (gridx:: StepRangeLen , Rmax)
1697
+ nsplits = ceil (gridx[end ]/ Rmax)
1698
+ rwanted = [i* Rmax for i in 1 : nsplits]
1699
+ tree = KDTree (gridx[:]' )
1700
+ idx, _ = nn (tree, rwanted' )
1701
+ b = idx # end index of split
1702
+ b[end ] -= 1 # 1 less pixel than grid edges
1703
+ a = [1 , (b[1 : end - 1 ] .+ 1 ). .. ] # start of split
1704
+ [a b]
1705
+ end
1706
+
1707
+ function getsoundingsplits (soundings:: Vector{S} , gridxendofsplit) where S<: Sounding
1708
+ R = cumulativelinedist (soundings)
1709
+ tree = KDTree (R[:]' )
1710
+ idx, _ = nn (tree, gridxendofsplit[:]' )
1711
+ b = idx # end index of split
1712
+ b[end ] = length (R) # ensure last sounding is last split
1713
+ a = [1 , (b[1 : end - 1 ] .+ 1 ). .. ] # start of split
1714
+ [a b]
1718
1715
end
1719
1716
1720
1717
function setupconductivityplot (gridx, omitconvergence, showmean, R, figsize, fontsize, lname, χ²mean, χ²sd, useML, iimage, nimages, logscale)
0 commit comments