此异常错误消息有什么问题 [英] what is wrong with this shapely error message

查看:41
本文介绍了此异常错误消息有什么问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一本名为Rsize的字典,该字典具有数字列表作为键值对.字典就是这样

 <代码> {10:[0.6621485767296484、0.6610747762560114、0.659607022086639、0.6567761845867727、0.6535392433801197、0.6485977028504701、0.6393024556394106、0.6223866436257335、0.5999232392636733、0.5418403536642005、0.4961461278219237,0.18306363413831017],12:[0.6638977494825118,0.663295576452323,0.662262804664348,0.6610413916318628,0.6590939627030634,0.655212304186114,0.6492141689834672,0.6380632834031537,0.6096663492242224,0.5647498006858608,0.4983281599318278,0.3961350546063216,0.32119092575707087,0.2257230704567207,0.1816695139119151,0.14363448808684576],14:[0.6649598494971014,0.6644370245269158,0.6638578972784479,0.6630511299276417,0.6615070373022596、0.6596206155163766、0.6560628158033714、0.6487119276511941、0.6343385358239866、0.5792725000508062、0.49799837531709923、0.42482204326408324、0.26633662071414366、0.2028085235063155、0.12411214668987203,0.09336935548451253]}[0.6621485767296484、0.6610747762560114、0.659607022086639、0.6567761845867727、0.6535392433801197、0.6485977028504701、0.6393024556394106、0.6223866436257335、0.5999232392636733、0.5418403536642005、0.4961461379219235、0.4280278015788386、0.35462315989740956、0.2863017830 

键是10、14、16.我已使用每个列表进行绘图,并想找出它们的成对相交点.我为此编写了以下脚本,并使用整形的交点函数进行交点检测.

  from shapely.geometry导入LineStringRSIZE = {10:[0.6621485767296484,0.6610747762560114,0.659607022086639,0.6567761845867727,0.6535392433801197,0.6485977028504701,0.6393024556394106,0.6223866436257335,0.5999232392636733,0.5418403536642005,0.4961461379219235,0.4280278015788386,0.35462315989740956,0.2863017237662875,0.2312185739351389,0.18306363413831017],12:[0.6638977494825118,0.663295576452323,0.662262804664348,0.6610413916318628,0.6590939627030634,0.655212304186114,0.6492141689834672,0.6380632834031537,0.6096663492242224,0.5647498006858608,0.4983281599318278,0.3961350546063216,0.32119092575707087,0.2257230704567207,0.1816695139119151,0.14363448808684576],14:[0.6649598494971014,0.6644370245269158,0.6638578972784479,0.6630511299276417,0.6615070373022596,0.6596206155163766,0.6560628158033714,0.6487119276511941,0.6343385358239866,0.5792725000508062,0.49799837531709923,0.42482204326408324、0.26633662071414366、0.2028085235063155、0.12411214668987203、0.09336935548451253]}}[0.6621485767296484、0.6610747762560114、0.659607022086639、0.6567761845867727、0.6535392433801197、0.6485977028504701、0.6393024556394106、0.6223866436257335、0.5999232392636733、0.5418403536642005、0.4961461379219235、0.4280278015788386、0.35462315989740956、0.2863017830listkT = np.arange(4.0,4.8,0.05)打印(Rsize [10])plt.figure(figsize =(18,10))plt.title(关键点的活页夹累积量")plt.plot(listkT,Rsize [10],'-',label ='Lattice sie 10')plt.plot(listkT,Rsize [12],'-',label ='Lattice sie 12')plt.plot(listkT,Rsize [14],'-',label ='Lattice sie 14')plt.legend()plt.show()curve_10 = LineString(np.column_stack((listkT,Rsize [10])))curve_12 = LineString(np.column_stack((listkT,Rsize [12])))curve_14 = LineString(np.column_stack((listkT,Rsize [14])))交集12 = curve_10.intersection(curve_12)交点14 = curve_10.intersection(curve_14)plt.plot(* LineString(intersection12).xy,'o')plt.plot(* LineString(intersection14).xy,'o')x12,y = LineString(intersection12).xyx14,y = LineString(intersection14).xy打印(np.intersect1d(x12,x14))打印(x12,x14) 

但是会抛出一个AssertionError.

 运行文件中的文件"C:\ Users \ Endeavour \ Anaconda3 \ lib \ site-packages \ spyder_kernels \ customize \ spydercustomize.py",第827行execfile(文件名,命名空间)execfile中的文件"C:\ Users \ Endeavour \ Anaconda3 \ lib \ site-packages \ spyder_kernels \ customize \ spydercustomize.py",第110行exec(编译(f.read(),文件名,'exec'),命名空间)< module>中的文件"E:/Project/Codes/3D.py"第118行.plt.plot(* LineString(intersection12).xy,'o')__init__中的文件"C:\ Users \ Endeavour \ Anaconda3 \ lib \ site-packages \ shapely \ geometry \ linestring.py",第48行self._set_coords(坐标)文件"C:\ Users \ Endeavour \ Anaconda3 \ lib \ site-packages \ shapely \ geometry \ linestring.py",第97行,位于_set_coords中ret = geos_linestring_from_py(坐标)在shapely.speedups._speedups.geos_linestring_from_py中的文件"shapely/speedups/_speedups.pyx",第87行断言错误 

尽管如此,但由matplotlib正确绘制了图.我是第一次使用匀称笔,没有任何先验经验.任何帮助都感激不尽.谢谢你.注意:最终目标是获得3条曲线的交点.如果没有找到相交点,那么它们最接近的点就足够了.找到的任何建议或库函数都会有很大帮助.

谢谢.

解决方案

在断言错误之后,我检查了 shapely/speedups/_speedups.pyx

红色圆圈代表您的 intersection12 ,紫色圆圈代表 intersection14 .如果您正在寻找一个近似的解决方案,也许找到这些点的平均值可以在这种情况下有所帮助,但是对于每对具有多个相交的更复杂的曲线,也不建议这样做.

I have a dictionary called Rsize which have number-List as key-value pair. The dictionary is like this

{10: [0.6621485767296484, 0.6610747762560114, 0.659607022086639, 0.6567761845867727, 0.6535392433801197, 0.6485977028504701, 0.6393024556394106, 0.6223866436257335, 0.5999232392636733, 0.5418403536642005, 0.4961461379219235, 0.4280278015788386, 0.35462315989740956, 0.2863017237662875, 0.2312185739351389, 0.18306363413831017], 12: [0.6638977494825118, 0.663295576452323, 0.662262804664348, 0.6610413916318628, 0.6590939627030634, 0.655212304186114, 0.6492141689834672, 0.6380632834031537, 0.6096663492242224, 0.5647498006858608, 0.4983281599318278, 0.3961350546063216, 0.32119092575707087, 0.2257230704567207, 0.1816695139119151, 0.14363448808684576], 14: [0.6649598494971014, 0.6644370245269158, 0.6638578972784479, 0.6630511299276417, 0.6615070373022596, 0.6596206155163766, 0.6560628158033714, 0.6487119276511941, 0.6343385358239866, 0.5792725000508062, 0.49799837531709923, 0.42482204326408324, 0.26633662071414366, 0.2028085235063155, 0.12411214668987203, 0.09336935548451253]}
[0.6621485767296484, 0.6610747762560114, 0.659607022086639, 0.6567761845867727, 0.6535392433801197, 0.6485977028504701, 0.6393024556394106, 0.6223866436257335, 0.5999232392636733, 0.5418403536642005, 0.4961461379219235, 0.4280278015788386, 0.35462315989740956, 0.2863017237662875, 0.2312185739351389, 0.18306363413831017]


The keys are 10,14,16. I have used each list for plotting and want to find out their pairwise intersection points. I have written the following script for that and used shapely intersection function for the intersection points detection.

from shapely.geometry import LineString
Rsize={10: [0.6621485767296484, 0.6610747762560114, 0.659607022086639, 0.6567761845867727, 0.6535392433801197, 0.6485977028504701, 0.6393024556394106, 0.6223866436257335, 0.5999232392636733, 0.5418403536642005, 0.4961461379219235, 0.4280278015788386, 0.35462315989740956, 0.2863017237662875, 0.2312185739351389, 0.18306363413831017], 12: [0.6638977494825118, 0.663295576452323, 0.662262804664348, 0.6610413916318628, 0.6590939627030634, 0.655212304186114, 0.6492141689834672, 0.6380632834031537, 0.6096663492242224, 0.5647498006858608, 0.4983281599318278, 0.3961350546063216, 0.32119092575707087, 0.2257230704567207, 0.1816695139119151, 0.14363448808684576], 14: [0.6649598494971014, 0.6644370245269158, 0.6638578972784479, 0.6630511299276417, 0.6615070373022596, 0.6596206155163766, 0.6560628158033714, 0.6487119276511941, 0.6343385358239866, 0.5792725000508062, 0.49799837531709923, 0.42482204326408324, 0.26633662071414366, 0.2028085235063155, 0.12411214668987203, 0.09336935548451253]}
[0.6621485767296484, 0.6610747762560114, 0.659607022086639, 0.6567761845867727, 0.6535392433801197, 0.6485977028504701, 0.6393024556394106, 0.6223866436257335, 0.5999232392636733, 0.5418403536642005, 0.4961461379219235, 0.4280278015788386, 0.35462315989740956, 0.2863017237662875, 0.2312185739351389, 0.18306363413831017]

listkT = np.arange(4.0,4.8,0.05)

print(Rsize[10])

plt.figure(figsize=(18, 10))
plt.title ('Binder cumulant for critical point')

plt.plot(listkT, Rsize[10], '-',label='Lattice sie 10')
plt.plot(listkT, Rsize[12], '-',label='Lattice sie 12')
plt.plot(listkT, Rsize[14], '-',label='Lattice sie 14')
plt.legend() 
plt.show()

curve_10=LineString(np.column_stack((listkT, Rsize[10])))
curve_12=LineString(np.column_stack((listkT, Rsize[12])))
curve_14=LineString(np.column_stack((listkT, Rsize[14])))

intersection12 = curve_10.intersection(curve_12)
intersection14 = curve_10.intersection(curve_14)

plt.plot(*LineString(intersection12).xy, 'o')
plt.plot(*LineString(intersection14).xy, 'o')

x12, y = LineString(intersection12).xy
x14, y = LineString(intersection14).xy
print(np.intersect1d(x12, x14))
print(x12,x14)

But shapely throws an AssertionError.


  File "C:\Users\Endeavour\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\Users\Endeavour\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)
  File "E:/Project/Codes/3D.py", line 118, in <module>
    plt.plot(*LineString(intersection12).xy, 'o')

  File "C:\Users\Endeavour\Anaconda3\lib\site-packages\shapely\geometry\linestring.py", line 48, in __init__
    self._set_coords(coordinates)

  File "C:\Users\Endeavour\Anaconda3\lib\site-packages\shapely\geometry\linestring.py", line 97, in _set_coords
    ret = geos_linestring_from_py(coordinates)

  File "shapely/speedups/_speedups.pyx", line 87, in shapely.speedups._speedups.geos_linestring_from_py

AssertionError

The plots are drawn correctly by matplotlib though. I am using shapely for first time with no prior experience in it. Any help will be much appreciated. Thank you. Note: The final goal is to get the intersection of 3 curves. If no intersection found the point where they come closest is good enough. Any suggestion or library function to find that will be of great help.

Thank you in advance.

解决方案

Following the assertion error, I checked shapely/speedups/_speedups.pyx, line 87. geos_linestring_from_py function expects you to either pass a LineString or a LinearRing. When I print your intersection12 and intersection14 I get:

POINT (4.503201814825258 0.4917840919384173)
POINT (4.51830999373466 0.4712012116887737)

So you are passing a Point instance to create a LineString, which creates an AssertionError.

Aside from the error you have, your approach is also wrong because it assumes that (1) there will be multiple intersections between two curves, and (2) there will be one absolute point where three curves intersect. If you zoom into your plot, you can see that neither is the case.

The red circle corresponds to your intersection12 and the purple one is intersection14. If you are looking for an approximate solution, maybe finding the mean of these points can help in this situation, but for more complex curves with multiple intersections per pair, it is also not recommended.

这篇关于此异常错误消息有什么问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆