Grouping by key value property in List of dict python - python

I have orig list of tuples that comprises dict & text values.
orig = [({'x': 28.346, 'y': 19},'Text0'),
({'x': 109.726, 'y': 19},'Text1'),
({'x': 147.776, 'y': 19},'Text2'),
({'x': 153.606, 'y': 24}, 'Text3'),
({'x': 452.788, 'y': 24}, 'Text4'),
({'x': 504.168, 'y': 34}, 'Text5'),
({'x': 527.768, 'y': 34}, 'Text6'),
({'x': 533.598, 'y': 45},'Text7'),
({'x': 64.291, 'y': 55},'Text8'),
({'x': 98.623, 'y': 55},'Text9')]
and I want to filter group from the key='y' in the which would give me list it according to unique values in y. Something like following:
res = [
[({'x': 28.346, 'y': 19},'Text0'),
({'x': 109.726, 'y': 19},'Text1'),
({'x': 147.776, 'y': 19},'Text2')],
[({'x': 153.606, 'y': 24}, 'Text3'),
({'x': 452.788, 'y': 24}, 'Text4')],
[({'x': 504.168, 'y': 34}, 'Text5'),
({'x': 527.768, 'y': 34}, 'Text6')],
[({'x': 533.598, 'y': 45},'Text7')],
[({'x': 64.291, 'y': 55},'Text8'),
({'x': 98.623, 'y': 55},'Text9')]]

If you use numpy it will be bit easier.
import numpy as np
orig = [({'x': 28.346, 'y': 19}, 'Text0'),
({'x': 109.726, 'y': 19}, 'Text1'),
({'x': 147.776, 'y': 19}, 'Text2'),
({'x': 153.606, 'y': 24}, 'Text3'),
({'x': 452.788, 'y': 24}, 'Text4'),
({'x': 504.168, 'y': 34}, 'Text5'),
({'x': 527.768, 'y': 34}, 'Text6'),
({'x': 533.598, 'y': 45}, 'Text7'),
({'x': 64.291, 'y': 55}, 'Text8'),
({'x': 98.623, 'y': 55}, 'Text9')]
input_array = np.array([val[0]['y'] for val in orig])
out_array = [np.where(input_array == element)[0].tolist() for element in np.unique(input_array)]
res = [[orig[i] for i in ind_arr] for ind_arr in out_array]
print(res)
Output:
[[({'x': 28.346, 'y': 19}, 'Text0'),
({'x': 109.726, 'y': 19}, 'Text1'),
({'x': 147.776, 'y': 19}, 'Text2')],
[({'x': 153.606, 'y': 24}, 'Text3'),
({'x': 452.788, 'y': 24}, 'Text4')],
[({'x': 504.168, 'y': 34}, 'Text5'),
({'x': 527.768, 'y': 34}, 'Text6')],
[({'x': 533.598, 'y': 45}, 'Text7')],
[({'x': 64.291, 'y': 55}, 'Text8'),
({'x': 98.623, 'y': 55}, 'Text9')]]

A two-liner solution using itertools.groupby and list comprehension:
from itertools import groupby
# group by the input orig with a key of dict "y" and then take it in a list of list comprehension
print ([[x for x in v] for k, v in groupby(orig, key= lambda x: x[0]["y"])])
Result:
[[({'x': 28.346, 'y': 19}, 'Text0'), ({'x': 109.726, 'y': 19}, 'Text1'), ({'x': 147.776, 'y': 19}, 'Text2')], [({'x': 153.606, 'y': 24}, 'Text3'), ({'x': 452.788, 'y': 24}, 'Text4')], [({'x': 504.168, 'y': 34}, 'Text5'), ({'x': 527.768, 'y': 34}, 'Text6')], [({'x': 533.598, 'y': 45}, 'Text7')], [({'x': 64.291, 'y': 55}, 'Text8'), ({'x': 98.623, 'y': 55}, 'Text9')]]
I hope this counts :)

Related

Python - plotting surface around 3D plot cloud

I run computational fluid dynamic simulation and I want to refine my mesh in the areas for which a quantity is superior to a threshold. I manage to extract the point locations so I obtain a list of points describing the areas that correspond to my criteria for refining.
To refine my mesh, I need to provide to the software the external boundaries of the surface (or curve if we are in 2D) that is described by the point cloud.
More particularly, I need to remove all the points that are in the center of the area to get the coordinates of those which are on the boundary. Then I would like to surround the points with a curve.
I found similar post on the forum but the question was to interpolate the point cloud, so not exactly what I want: Fit Curve-Spline to 3D Point Cloud
May you help me to do that ?
Here is a 2D example of point cloud for which I would like to only keep the boundary points and plot the surrounding curve:
0.20215,0.29703,0
0.22857,0.29703,0
0.25526,0.29703,0
0.28221,0.29703,0
0.30943,0.29703,0
0.33692,0.29703,0
0.36469,0.29703,0
0.39273,0.29703,0
0.42106,0.29703,0
0.44966,0.29703,0
0.47856,0.29703,0
0.50774,0.29703,0
0.53722,0.29703,0
0.56699,0.29703,0
0.59706,0.29703,0
0.62742,0.29703,0
0.6581,0.29703,0
0.68907,0.29703,0
0.72036,0.29703,0
0.75196,0.29703,0
0.78388,0.29703,0
0.81612,0.29703,0
0.84868,0.29703,0
0.88156,0.29703,0
0.91478,0.29703,0
0.94832,0.29703,0
0.9822,0.29703,0
1.0164,0.29703,0
1.051,0.29703,0
1.0859,0.29703,0
1.1211,0.29703,0
1.1568,0.29703,0
1.1927,0.29703,0
1.229,0.29703,0
1.2657,0.29703,0
1.3028,0.29703,0
1.3402,0.29703,0
1.378,0.29703,0
1.4162,0.29703,0
1.4548,0.29703,0
1.4937,0.29703,0
1.533,0.29703,0
1.5728,0.29703,0
1.6129,0.29703,0
1.6534,0.29703,0
1.6944,0.29703,0
1.7357,0.29703,0
1.7774,0.29703,0
1.8196,0.29703,0
1.8622,0.29703,0
1.9052,0.29703,0
1.9487,0.29703,0
1.9926,0.29703,0
2.0369,0.29703,0
2.0817,0.29703,0
2.1269,0.29703,0
2.1725,0.29703,0
2.2187,0.29703,0
2.2652,0.29703,0
2.3123,0.29703,0
2.3598,0.29703,0
2.4078,0.29703,0
2.4563,0.29703,0
2.5053,0.29703,0
2.5547,0.29703,0
2.6046,0.29703,0
2.6551,0.29703,0
2.706,0.29703,0
2.7575,0.29703,0
2.8095,0.29703,0
2.862,0.29703,0
2.915,0.29703,0
2.9685,0.29703,0
3.0226,0.29703,0
3.0772,0.29703,0
3.1324,0.29703,0
3.1881,0.29703,0
3.2444,0.29703,0
3.3013,0.29703,0
3.3587,0.29703,0
3.4166,0.29703,0
3.4752,0.29703,0
3.5344,0.29703,0
3.5941,0.29703,0
3.6544,0.29703,0
3.7154,0.29703,0
3.7769,0.29703,0
3.8391,0.29703,0
3.9019,0.29703,0
3.9653,0.29703,0
4.0294,0.29703,0
4.094,0.29703,0
4.1594,0.29703,0
4.2254,0.29703,0
4.292,0.29703,0
4.3593,0.29703,0
4.4273,0.29703,0
4.496,0.29703,0
4.5654,0.29703,0
4.6354,0.29703,0
4.7062,0.29703,0
4.7776,0.29703,0
4.8498,0.29703,0
4.9227,0.29703,0
0.28221,0.28425,0
0.30943,0.28425,0
0.33692,0.28425,0
0.36469,0.28425,0
0.39273,0.28425,0
0.42106,0.28425,0
0.44966,0.28425,0
0.47856,0.28425,0
0.50774,0.28425,0
0.53722,0.28425,0
0.56699,0.28425,0
0.59706,0.28425,0
0.62742,0.28425,0
0.6581,0.28425,0
0.68907,0.28425,0
0.72036,0.28425,0
0.75196,0.28425,0
0.78388,0.28425,0
0.81612,0.28425,0
0.84868,0.28425,0
0.88156,0.28425,0
0.91478,0.28425,0
0.94832,0.28425,0
0.9822,0.28425,0
1.0164,0.28425,0
1.051,0.28425,0
1.0859,0.28425,0
1.1211,0.28425,0
1.1568,0.28425,0
1.1927,0.28425,0
1.229,0.28425,0
1.2657,0.28425,0
1.3028,0.28425,0
1.3402,0.28425,0
1.378,0.28425,0
1.4162,0.28425,0
1.4548,0.28425,0
1.4937,0.28425,0
1.533,0.28425,0
1.5728,0.28425,0
1.6129,0.28425,0
1.6534,0.28425,0
1.6944,0.28425,0
1.7357,0.28425,0
1.7774,0.28425,0
1.8196,0.28425,0
1.8622,0.28425,0
1.9052,0.28425,0
1.9487,0.28425,0
1.9926,0.28425,0
2.0369,0.28425,0
2.0817,0.28425,0
2.1269,0.28425,0
2.1725,0.28425,0
2.2187,0.28425,0
2.2652,0.28425,0
2.3123,0.28425,0
2.3598,0.28425,0
2.4078,0.28425,0
2.4563,0.28425,0
2.5053,0.28425,0
2.5547,0.28425,0
2.6046,0.28425,0
2.6551,0.28425,0
2.706,0.28425,0
2.7575,0.28425,0
2.8095,0.28425,0
2.862,0.28425,0
2.915,0.28425,0
2.9685,0.28425,0
3.0226,0.28425,0
3.0772,0.28425,0
3.1324,0.28425,0
3.1881,0.28425,0
3.2444,0.28425,0
3.3013,0.28425,0
3.3587,0.28425,0
3.4166,0.28425,0
3.4752,0.28425,0
3.5344,0.28425,0
3.5941,0.28425,0
3.6544,0.28425,0
3.7154,0.28425,0
3.7769,0.28425,0
3.8391,0.28425,0
3.9019,0.28425,0
3.9653,0.28425,0
4.0294,0.28425,0
4.094,0.28425,0
4.1594,0.28425,0
4.2254,0.28425,0
4.292,0.28425,0
4.3593,0.28425,0
4.4273,0.28425,0
4.496,0.28425,0
4.5654,0.28425,0
0.39273,0.27117,0
0.42106,0.27117,0
0.44966,0.27117,0
0.47856,0.27117,0
0.50774,0.27117,0
0.53722,0.27117,0
0.56699,0.27117,0
0.59706,0.27117,0
0.62742,0.27117,0
0.6581,0.27117,0
0.68907,0.27117,0
0.72036,0.27117,0
0.75196,0.27117,0
0.78388,0.27117,0
0.81612,0.27117,0
0.84868,0.27117,0
0.88156,0.27117,0
0.91478,0.27117,0
0.94832,0.27117,0
0.9822,0.27117,0
1.0164,0.27117,0
1.051,0.27117,0
1.0859,0.27117,0
1.1211,0.27117,0
1.1568,0.27117,0
1.1927,0.27117,0
1.229,0.27117,0
1.2657,0.27117,0
1.3028,0.27117,0
1.3402,0.27117,0
1.378,0.27117,0
1.4162,0.27117,0
1.4548,0.27117,0
1.4937,0.27117,0
1.533,0.27117,0
1.5728,0.27117,0
1.6129,0.27117,0
1.6534,0.27117,0
1.6944,0.27117,0
1.7357,0.27117,0
1.7774,0.27117,0
1.8196,0.27117,0
1.8622,0.27117,0
1.9052,0.27117,0
1.9487,0.27117,0
1.9926,0.27117,0
2.0369,0.27117,0
2.0817,0.27117,0
2.1269,0.27117,0
2.1725,0.27117,0
2.2187,0.27117,0
2.2652,0.27117,0
2.3123,0.27117,0
2.3598,0.27117,0
2.4078,0.27117,0
2.4563,0.27117,0
2.5053,0.27117,0
2.5547,0.27117,0
2.6046,0.27117,0
2.6551,0.27117,0
2.706,0.27117,0
2.7575,0.27117,0
2.8095,0.27117,0
2.862,0.27117,0
2.915,0.27117,0
2.9685,0.27117,0
3.0226,0.27117,0
3.0772,0.27117,0
3.1324,0.27117,0
3.1881,0.27117,0
3.2444,0.27117,0
3.3013,0.27117,0
3.3587,0.27117,0
3.4166,0.27117,0
3.4752,0.27117,0
3.5344,0.27117,0
3.5941,0.27117,0
3.6544,0.27117,0
3.7154,0.27117,0
3.7769,0.27117,0
3.8391,0.27117,0
3.9019,0.27117,0
3.9653,0.27117,0
4.0294,0.27117,0
4.094,0.27117,0
4.1594,0.27117,0
0.47856,0.25781,0
0.50774,0.25781,0
0.53722,0.25781,0
0.56699,0.25781,0
0.59706,0.25781,0
0.62742,0.25781,0
0.6581,0.25781,0
0.68907,0.25781,0
0.72036,0.25781,0
0.75196,0.25781,0
0.78388,0.25781,0
0.81612,0.25781,0
0.84868,0.25781,0
0.88156,0.25781,0
0.91478,0.25781,0
0.94832,0.25781,0
0.9822,0.25781,0
1.0164,0.25781,0
1.051,0.25781,0
1.0859,0.25781,0
1.1211,0.25781,0
1.1568,0.25781,0
1.1927,0.25781,0
1.229,0.25781,0
1.2657,0.25781,0
1.3028,0.25781,0
1.3402,0.25781,0
1.378,0.25781,0
1.4162,0.25781,0
1.4548,0.25781,0
1.4937,0.25781,0
1.533,0.25781,0
1.5728,0.25781,0
1.6129,0.25781,0
1.6534,0.25781,0
1.6944,0.25781,0
1.7357,0.25781,0
1.7774,0.25781,0
1.8196,0.25781,0
1.8622,0.25781,0
1.9052,0.25781,0
1.9487,0.25781,0
1.9926,0.25781,0
2.0369,0.25781,0
2.0817,0.25781,0
2.1269,0.25781,0
2.1725,0.25781,0
2.2187,0.25781,0
2.2652,0.25781,0
2.3123,0.25781,0
2.3598,0.25781,0
2.4078,0.25781,0
2.4563,0.25781,0
2.5053,0.25781,0
2.5547,0.25781,0
2.6046,0.25781,0
2.6551,0.25781,0
2.706,0.25781,0
2.7575,0.25781,0
2.8095,0.25781,0
2.862,0.25781,0
2.915,0.25781,0
2.9685,0.25781,0
3.0226,0.25781,0
3.0772,0.25781,0
3.1324,0.25781,0
3.1881,0.25781,0
3.2444,0.25781,0
3.3013,0.25781,0
3.3587,0.25781,0
3.4166,0.25781,0
3.4752,0.25781,0
3.5344,0.25781,0
3.5941,0.25781,0
3.6544,0.25781,0
3.7154,0.25781,0
3.7769,0.25781,0
3.8391,0.25781,0
0.53722,0.24422,0
0.56699,0.24422,0
0.59706,0.24422,0
0.62742,0.24422,0
0.6581,0.24422,0
0.68907,0.24422,0
0.72036,0.24422,0
0.75196,0.24422,0
0.78388,0.24422,0
0.81612,0.24422,0
0.84868,0.24422,0
0.88156,0.24422,0
0.91478,0.24422,0
0.94832,0.24422,0
0.9822,0.24422,0
1.0164,0.24422,0
1.051,0.24422,0
1.0859,0.24422,0
1.1211,0.24422,0
1.1568,0.24422,0
1.1927,0.24422,0
1.229,0.24422,0
1.2657,0.24422,0
1.3028,0.24422,0
1.3402,0.24422,0
1.378,0.24422,0
1.4162,0.24422,0
1.4548,0.24422,0
1.4937,0.24422,0
1.533,0.24422,0
1.5728,0.24422,0
1.6129,0.24422,0
1.6534,0.24422,0
1.6944,0.24422,0
1.7357,0.24422,0
1.7774,0.24422,0
1.8196,0.24422,0
1.8622,0.24422,0
1.9052,0.24422,0
1.9487,0.24422,0
1.9926,0.24422,0
2.0369,0.24422,0
2.0817,0.24422,0
2.1269,0.24422,0
2.1725,0.24422,0
2.2187,0.24422,0
2.2652,0.24422,0
2.3123,0.24422,0
2.3598,0.24422,0
2.4078,0.24422,0
2.4563,0.24422,0
2.5053,0.24422,0
2.5547,0.24422,0
2.6046,0.24422,0
2.6551,0.24422,0
2.706,0.24422,0
2.7575,0.24422,0
2.8095,0.24422,0
2.862,0.24422,0
2.915,0.24422,0
2.9685,0.24422,0
3.0226,0.24422,0
3.0772,0.24422,0
3.1324,0.24422,0
3.1881,0.24422,0
3.2444,0.24422,0
3.3013,0.24422,0
3.3587,0.24422,0
3.4166,0.24422,0
3.4752,0.24422,0
0.62742,0.23041,0
0.6581,0.23041,0
0.68907,0.23041,0
0.72036,0.23041,0
0.75196,0.23041,0
0.78388,0.23041,0
0.81612,0.23041,0
0.84868,0.23041,0
0.88156,0.23041,0
0.91478,0.23041,0
0.94832,0.23041,0
0.9822,0.23041,0
1.0164,0.23041,0
1.051,0.23041,0
1.0859,0.23041,0
1.1211,0.23041,0
1.1568,0.23041,0
1.1927,0.23041,0
1.229,0.23041,0
1.2657,0.23041,0
1.3028,0.23041,0
1.3402,0.23041,0
1.378,0.23041,0
1.4162,0.23041,0
1.4548,0.23041,0
1.4937,0.23041,0
1.533,0.23041,0
1.5728,0.23041,0
1.6129,0.23041,0
1.6534,0.23041,0
1.6944,0.23041,0
1.7357,0.23041,0
1.7774,0.23041,0
1.8196,0.23041,0
1.8622,0.23041,0
1.9052,0.23041,0
1.9487,0.23041,0
1.9926,0.23041,0
2.0369,0.23041,0
2.0817,0.23041,0
2.1269,0.23041,0
2.1725,0.23041,0
2.2187,0.23041,0
2.2652,0.23041,0
2.3123,0.23041,0
2.3598,0.23041,0
2.4078,0.23041,0
2.4563,0.23041,0
2.5053,0.23041,0
2.5547,0.23041,0
2.6046,0.23041,0
2.6551,0.23041,0
2.706,0.23041,0
2.7575,0.23041,0
2.8095,0.23041,0
2.862,0.23041,0
2.915,0.23041,0
2.9685,0.23041,0
3.0226,0.23041,0
3.0772,0.23041,0
3.1324,0.23041,0
3.1881,0.23041,0
0.68907,0.21643,0
0.72036,0.21643,0
0.75196,0.21643,0
0.78388,0.21643,0
0.81612,0.21643,0
0.84868,0.21643,0
0.88156,0.21643,0
0.91478,0.21643,0
0.94832,0.21643,0
0.9822,0.21643,0
1.0164,0.21643,0
1.051,0.21643,0
1.0859,0.21643,0
1.1211,0.21643,0
1.1568,0.21643,0
1.1927,0.21643,0
1.229,0.21643,0
1.2657,0.21643,0
1.3028,0.21643,0
1.3402,0.21643,0
1.378,0.21643,0
1.4162,0.21643,0
1.4548,0.21643,0
1.4937,0.21643,0
1.533,0.21643,0
1.5728,0.21643,0
1.6129,0.21643,0
1.6534,0.21643,0
1.6944,0.21643,0
1.7357,0.21643,0
1.7774,0.21643,0
1.8196,0.21643,0
1.8622,0.21643,0
1.9052,0.21643,0
1.9487,0.21643,0
1.9926,0.21643,0
2.0369,0.21643,0
2.0817,0.21643,0
2.1269,0.21643,0
2.1725,0.21643,0
2.2187,0.21643,0
2.2652,0.21643,0
2.3123,0.21643,0
2.3598,0.21643,0
2.4078,0.21643,0
2.4563,0.21643,0
2.5053,0.21643,0
2.5547,0.21643,0
2.6046,0.21643,0
2.6551,0.21643,0
2.706,0.21643,0
2.7575,0.21643,0
2.8095,0.21643,0
0.78388,0.20231,0
0.81612,0.20231,0
0.84868,0.20231,0
0.88156,0.20231,0
0.91478,0.20231,0
0.94832,0.20231,0
0.9822,0.20231,0
1.0164,0.20231,0
1.051,0.20231,0
1.0859,0.20231,0
1.1211,0.20231,0
1.1568,0.20231,0
1.1927,0.20231,0
1.229,0.20231,0
1.2657,0.20231,0
1.3028,0.20231,0
1.3402,0.20231,0
1.378,0.20231,0
1.4162,0.20231,0
1.4548,0.20231,0
1.4937,0.20231,0
1.533,0.20231,0
1.5728,0.20231,0
1.6129,0.20231,0
1.6534,0.20231,0
1.6944,0.20231,0
1.7357,0.20231,0
1.7774,0.20231,0
1.8196,0.20231,0
1.8622,0.20231,0
1.9052,0.20231,0
1.9487,0.20231,0
1.9926,0.20231,0
2.0369,0.20231,0
2.0817,0.20231,0
2.1269,0.20231,0
2.1725,0.20231,0
2.2187,0.20231,0
2.2652,0.20231,0
2.3123,0.20231,0
2.3598,0.20231,0
2.4078,0.20231,0
2.4563,0.20231,0
1.051,0.1881,0
1.0859,0.1881,0
1.1211,0.1881,0
1.1568,0.1881,0
1.1927,0.1881,0
1.229,0.1881,0
1.2657,0.1881,0
1.3028,0.1881,0
1.3402,0.1881,0
1.378,0.1881,0
1.4162,0.1881,0
1.4548,0.1881,0
1.4937,0.1881,0
1.533,0.1881,0
1.5728,0.1881,0
1.6129,0.1881,0
1.6534,0.1881,0
1.6944,0.1881,0
1.7357,0.1881,0
1.7774,0.1881,0
1.8196,0.1881,0
1.8622,0.1881,0
1.9052,0.1881,0
1.9487,0.1881,0
1.9926,0.1881,0
2.0369,0.1881,0
Thanks for your help,
Sincerely
It's possible to do with ConvexHull from SciPy and this function together with convex_hull_plot_2d yield this result for the provided dataset. Below is the code to reproduce the pictures. hull.points at the end of the code contain the resulting outlining set of points that you are looking for.
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from scipy.spatial import ConvexHull, convex_hull_plot_2d
df = pd.DataFrame([{'x': 0.20215, 'y': 0.29703, 'z': 0},
{'x': 0.22857, 'y': 0.29703, 'z': 0},
{'x': 0.25526, 'y': 0.29703, 'z': 0},
{'x': 0.28221, 'y': 0.29703, 'z': 0},
{'x': 0.30943, 'y': 0.29703, 'z': 0},
{'x': 0.33692, 'y': 0.29703, 'z': 0},
{'x': 0.36469, 'y': 0.29703, 'z': 0},
{'x': 0.39273, 'y': 0.29703, 'z': 0},
{'x': 0.42106, 'y': 0.29703, 'z': 0},
{'x': 0.44966, 'y': 0.29703, 'z': 0},
{'x': 0.47856, 'y': 0.29703, 'z': 0},
{'x': 0.50774, 'y': 0.29703, 'z': 0},
{'x': 0.53722, 'y': 0.29703, 'z': 0},
{'x': 0.56699, 'y': 0.29703, 'z': 0},
{'x': 0.59706, 'y': 0.29703, 'z': 0},
{'x': 0.62742, 'y': 0.29703, 'z': 0},
{'x': 0.6581, 'y': 0.29703, 'z': 0},
{'x': 0.68907, 'y': 0.29703, 'z': 0},
{'x': 0.72036, 'y': 0.29703, 'z': 0},
{'x': 0.75196, 'y': 0.29703, 'z': 0},
{'x': 0.78388, 'y': 0.29703, 'z': 0},
{'x': 0.81612, 'y': 0.29703, 'z': 0},
{'x': 0.84868, 'y': 0.29703, 'z': 0},
{'x': 0.88156, 'y': 0.29703, 'z': 0},
{'x': 0.91478, 'y': 0.29703, 'z': 0},
{'x': 0.94832, 'y': 0.29703, 'z': 0},
{'x': 0.9822, 'y': 0.29703, 'z': 0},
{'x': 1.0164, 'y': 0.29703, 'z': 0},
{'x': 1.051, 'y': 0.29703, 'z': 0},
{'x': 1.0859, 'y': 0.29703, 'z': 0},
{'x': 1.1211, 'y': 0.29703, 'z': 0},
{'x': 1.1568, 'y': 0.29703, 'z': 0},
{'x': 1.1927, 'y': 0.29703, 'z': 0},
{'x': 1.229, 'y': 0.29703, 'z': 0},
{'x': 1.2657, 'y': 0.29703, 'z': 0},
{'x': 1.3028, 'y': 0.29703, 'z': 0},
{'x': 1.3402, 'y': 0.29703, 'z': 0},
{'x': 1.378, 'y': 0.29703, 'z': 0},
{'x': 1.4162, 'y': 0.29703, 'z': 0},
{'x': 1.4548, 'y': 0.29703, 'z': 0},
{'x': 1.4937, 'y': 0.29703, 'z': 0},
{'x': 1.533, 'y': 0.29703, 'z': 0},
{'x': 1.5728, 'y': 0.29703, 'z': 0},
{'x': 1.6129, 'y': 0.29703, 'z': 0},
{'x': 1.6534, 'y': 0.29703, 'z': 0},
{'x': 1.6944, 'y': 0.29703, 'z': 0},
{'x': 1.7357, 'y': 0.29703, 'z': 0},
{'x': 1.7774, 'y': 0.29703, 'z': 0},
{'x': 1.8196, 'y': 0.29703, 'z': 0},
{'x': 1.8622, 'y': 0.29703, 'z': 0},
{'x': 1.9052, 'y': 0.29703, 'z': 0},
{'x': 1.9487, 'y': 0.29703, 'z': 0},
{'x': 1.9926, 'y': 0.29703, 'z': 0},
{'x': 2.0369, 'y': 0.29703, 'z': 0},
{'x': 2.0817, 'y': 0.29703, 'z': 0},
{'x': 2.1269, 'y': 0.29703, 'z': 0},
{'x': 2.1725, 'y': 0.29703, 'z': 0},
{'x': 2.2187, 'y': 0.29703, 'z': 0},
{'x': 2.2652, 'y': 0.29703, 'z': 0},
{'x': 2.3123, 'y': 0.29703, 'z': 0},
{'x': 2.3598, 'y': 0.29703, 'z': 0},
{'x': 2.4078, 'y': 0.29703, 'z': 0},
{'x': 2.4563, 'y': 0.29703, 'z': 0},
{'x': 2.5053, 'y': 0.29703, 'z': 0},
{'x': 2.5547, 'y': 0.29703, 'z': 0},
{'x': 2.6046, 'y': 0.29703, 'z': 0},
{'x': 2.6551, 'y': 0.29703, 'z': 0},
{'x': 2.706, 'y': 0.29703, 'z': 0},
{'x': 2.7575, 'y': 0.29703, 'z': 0},
{'x': 2.8095, 'y': 0.29703, 'z': 0},
{'x': 2.862, 'y': 0.29703, 'z': 0},
{'x': 2.915, 'y': 0.29703, 'z': 0},
{'x': 2.9685, 'y': 0.29703, 'z': 0},
{'x': 3.0226, 'y': 0.29703, 'z': 0},
{'x': 3.0772, 'y': 0.29703, 'z': 0},
{'x': 3.1324, 'y': 0.29703, 'z': 0},
{'x': 3.1881, 'y': 0.29703, 'z': 0},
{'x': 3.2444, 'y': 0.29703, 'z': 0},
{'x': 3.3013, 'y': 0.29703, 'z': 0},
{'x': 3.3587, 'y': 0.29703, 'z': 0},
{'x': 3.4166, 'y': 0.29703, 'z': 0},
{'x': 3.4752, 'y': 0.29703, 'z': 0},
{'x': 3.5344, 'y': 0.29703, 'z': 0},
{'x': 3.5941, 'y': 0.29703, 'z': 0},
{'x': 3.6544, 'y': 0.29703, 'z': 0},
{'x': 3.7154, 'y': 0.29703, 'z': 0},
{'x': 3.7769, 'y': 0.29703, 'z': 0},
{'x': 3.8391, 'y': 0.29703, 'z': 0},
{'x': 3.9019, 'y': 0.29703, 'z': 0},
{'x': 3.9653, 'y': 0.29703, 'z': 0},
{'x': 4.0294, 'y': 0.29703, 'z': 0},
{'x': 4.094, 'y': 0.29703, 'z': 0},
{'x': 4.1594, 'y': 0.29703, 'z': 0},
{'x': 4.2254, 'y': 0.29703, 'z': 0},
{'x': 4.292, 'y': 0.29703, 'z': 0},
{'x': 4.3593, 'y': 0.29703, 'z': 0},
{'x': 4.4273, 'y': 0.29703, 'z': 0},
{'x': 4.496, 'y': 0.29703, 'z': 0},
{'x': 4.5654, 'y': 0.29703, 'z': 0},
{'x': 4.6354, 'y': 0.29703, 'z': 0},
{'x': 4.7062, 'y': 0.29703, 'z': 0},
{'x': 4.7776, 'y': 0.29703, 'z': 0},
{'x': 4.8498, 'y': 0.29703, 'z': 0},
{'x': 4.9227, 'y': 0.29703, 'z': 0},
{'x': 0.28221, 'y': 0.28425, 'z': 0},
{'x': 0.30943, 'y': 0.28425, 'z': 0},
{'x': 0.33692, 'y': 0.28425, 'z': 0},
{'x': 0.36469, 'y': 0.28425, 'z': 0},
{'x': 0.39273, 'y': 0.28425, 'z': 0},
{'x': 0.42106, 'y': 0.28425, 'z': 0},
{'x': 0.44966, 'y': 0.28425, 'z': 0},
{'x': 0.47856, 'y': 0.28425, 'z': 0},
{'x': 0.50774, 'y': 0.28425, 'z': 0},
{'x': 0.53722, 'y': 0.28425, 'z': 0},
{'x': 0.56699, 'y': 0.28425, 'z': 0},
{'x': 0.59706, 'y': 0.28425, 'z': 0},
{'x': 0.62742, 'y': 0.28425, 'z': 0},
{'x': 0.6581, 'y': 0.28425, 'z': 0},
{'x': 0.68907, 'y': 0.28425, 'z': 0},
{'x': 0.72036, 'y': 0.28425, 'z': 0},
{'x': 0.75196, 'y': 0.28425, 'z': 0},
{'x': 0.78388, 'y': 0.28425, 'z': 0},
{'x': 0.81612, 'y': 0.28425, 'z': 0},
{'x': 0.84868, 'y': 0.28425, 'z': 0},
{'x': 0.88156, 'y': 0.28425, 'z': 0},
{'x': 0.91478, 'y': 0.28425, 'z': 0},
{'x': 0.94832, 'y': 0.28425, 'z': 0},
{'x': 0.9822, 'y': 0.28425, 'z': 0},
{'x': 1.0164, 'y': 0.28425, 'z': 0},
{'x': 1.051, 'y': 0.28425, 'z': 0},
{'x': 1.0859, 'y': 0.28425, 'z': 0},
{'x': 1.1211, 'y': 0.28425, 'z': 0},
{'x': 1.1568, 'y': 0.28425, 'z': 0},
{'x': 1.1927, 'y': 0.28425, 'z': 0},
{'x': 1.229, 'y': 0.28425, 'z': 0},
{'x': 1.2657, 'y': 0.28425, 'z': 0},
{'x': 1.3028, 'y': 0.28425, 'z': 0},
{'x': 1.3402, 'y': 0.28425, 'z': 0},
{'x': 1.378, 'y': 0.28425, 'z': 0},
{'x': 1.4162, 'y': 0.28425, 'z': 0},
{'x': 1.4548, 'y': 0.28425, 'z': 0},
{'x': 1.4937, 'y': 0.28425, 'z': 0},
{'x': 1.533, 'y': 0.28425, 'z': 0},
{'x': 1.5728, 'y': 0.28425, 'z': 0},
{'x': 1.6129, 'y': 0.28425, 'z': 0},
{'x': 1.6534, 'y': 0.28425, 'z': 0},
{'x': 1.6944, 'y': 0.28425, 'z': 0},
{'x': 1.7357, 'y': 0.28425, 'z': 0},
{'x': 1.7774, 'y': 0.28425, 'z': 0},
{'x': 1.8196, 'y': 0.28425, 'z': 0},
{'x': 1.8622, 'y': 0.28425, 'z': 0},
{'x': 1.9052, 'y': 0.28425, 'z': 0},
{'x': 1.9487, 'y': 0.28425, 'z': 0},
{'x': 1.9926, 'y': 0.28425, 'z': 0},
{'x': 2.0369, 'y': 0.28425, 'z': 0},
{'x': 2.0817, 'y': 0.28425, 'z': 0},
{'x': 2.1269, 'y': 0.28425, 'z': 0},
{'x': 2.1725, 'y': 0.28425, 'z': 0},
{'x': 2.2187, 'y': 0.28425, 'z': 0},
{'x': 2.2652, 'y': 0.28425, 'z': 0},
{'x': 2.3123, 'y': 0.28425, 'z': 0},
{'x': 2.3598, 'y': 0.28425, 'z': 0},
{'x': 2.4078, 'y': 0.28425, 'z': 0},
{'x': 2.4563, 'y': 0.28425, 'z': 0},
{'x': 2.5053, 'y': 0.28425, 'z': 0},
{'x': 2.5547, 'y': 0.28425, 'z': 0},
{'x': 2.6046, 'y': 0.28425, 'z': 0},
{'x': 2.6551, 'y': 0.28425, 'z': 0},
{'x': 2.706, 'y': 0.28425, 'z': 0},
{'x': 2.7575, 'y': 0.28425, 'z': 0},
{'x': 2.8095, 'y': 0.28425, 'z': 0},
{'x': 2.862, 'y': 0.28425, 'z': 0},
{'x': 2.915, 'y': 0.28425, 'z': 0},
{'x': 2.9685, 'y': 0.28425, 'z': 0},
{'x': 3.0226, 'y': 0.28425, 'z': 0},
{'x': 3.0772, 'y': 0.28425, 'z': 0},
{'x': 3.1324, 'y': 0.28425, 'z': 0},
{'x': 3.1881, 'y': 0.28425, 'z': 0},
{'x': 3.2444, 'y': 0.28425, 'z': 0},
{'x': 3.3013, 'y': 0.28425, 'z': 0},
{'x': 3.3587, 'y': 0.28425, 'z': 0},
{'x': 3.4166, 'y': 0.28425, 'z': 0},
{'x': 3.4752, 'y': 0.28425, 'z': 0},
{'x': 3.5344, 'y': 0.28425, 'z': 0},
{'x': 3.5941, 'y': 0.28425, 'z': 0},
{'x': 3.6544, 'y': 0.28425, 'z': 0},
{'x': 3.7154, 'y': 0.28425, 'z': 0},
{'x': 3.7769, 'y': 0.28425, 'z': 0},
{'x': 3.8391, 'y': 0.28425, 'z': 0},
{'x': 3.9019, 'y': 0.28425, 'z': 0},
{'x': 3.9653, 'y': 0.28425, 'z': 0},
{'x': 4.0294, 'y': 0.28425, 'z': 0},
{'x': 4.094, 'y': 0.28425, 'z': 0},
{'x': 4.1594, 'y': 0.28425, 'z': 0},
{'x': 4.2254, 'y': 0.28425, 'z': 0},
{'x': 4.292, 'y': 0.28425, 'z': 0},
{'x': 4.3593, 'y': 0.28425, 'z': 0},
{'x': 4.4273, 'y': 0.28425, 'z': 0},
{'x': 4.496, 'y': 0.28425, 'z': 0},
{'x': 4.5654, 'y': 0.28425, 'z': 0},
{'x': 0.39273, 'y': 0.27117, 'z': 0},
{'x': 0.42106, 'y': 0.27117, 'z': 0},
{'x': 0.44966, 'y': 0.27117, 'z': 0},
{'x': 0.47856, 'y': 0.27117, 'z': 0},
{'x': 0.50774, 'y': 0.27117, 'z': 0},
{'x': 0.53722, 'y': 0.27117, 'z': 0},
{'x': 0.56699, 'y': 0.27117, 'z': 0},
{'x': 0.59706, 'y': 0.27117, 'z': 0},
{'x': 0.62742, 'y': 0.27117, 'z': 0},
{'x': 0.6581, 'y': 0.27117, 'z': 0},
{'x': 0.68907, 'y': 0.27117, 'z': 0},
{'x': 0.72036, 'y': 0.27117, 'z': 0},
{'x': 0.75196, 'y': 0.27117, 'z': 0},
{'x': 0.78388, 'y': 0.27117, 'z': 0},
{'x': 0.81612, 'y': 0.27117, 'z': 0},
{'x': 0.84868, 'y': 0.27117, 'z': 0},
{'x': 0.88156, 'y': 0.27117, 'z': 0},
{'x': 0.91478, 'y': 0.27117, 'z': 0},
{'x': 0.94832, 'y': 0.27117, 'z': 0},
{'x': 0.9822, 'y': 0.27117, 'z': 0},
{'x': 1.0164, 'y': 0.27117, 'z': 0},
{'x': 1.051, 'y': 0.27117, 'z': 0},
{'x': 1.0859, 'y': 0.27117, 'z': 0},
{'x': 1.1211, 'y': 0.27117, 'z': 0},
{'x': 1.1568, 'y': 0.27117, 'z': 0},
{'x': 1.1927, 'y': 0.27117, 'z': 0},
{'x': 1.229, 'y': 0.27117, 'z': 0},
{'x': 1.2657, 'y': 0.27117, 'z': 0},
{'x': 1.3028, 'y': 0.27117, 'z': 0},
{'x': 1.3402, 'y': 0.27117, 'z': 0},
{'x': 1.378, 'y': 0.27117, 'z': 0},
{'x': 1.4162, 'y': 0.27117, 'z': 0},
{'x': 1.4548, 'y': 0.27117, 'z': 0},
{'x': 1.4937, 'y': 0.27117, 'z': 0},
{'x': 1.533, 'y': 0.27117, 'z': 0},
{'x': 1.5728, 'y': 0.27117, 'z': 0},
{'x': 1.6129, 'y': 0.27117, 'z': 0},
{'x': 1.6534, 'y': 0.27117, 'z': 0},
{'x': 1.6944, 'y': 0.27117, 'z': 0},
{'x': 1.7357, 'y': 0.27117, 'z': 0},
{'x': 1.7774, 'y': 0.27117, 'z': 0},
{'x': 1.8196, 'y': 0.27117, 'z': 0},
{'x': 1.8622, 'y': 0.27117, 'z': 0},
{'x': 1.9052, 'y': 0.27117, 'z': 0},
{'x': 1.9487, 'y': 0.27117, 'z': 0},
{'x': 1.9926, 'y': 0.27117, 'z': 0},
{'x': 2.0369, 'y': 0.27117, 'z': 0},
{'x': 2.0817, 'y': 0.27117, 'z': 0},
{'x': 2.1269, 'y': 0.27117, 'z': 0},
{'x': 2.1725, 'y': 0.27117, 'z': 0},
{'x': 2.2187, 'y': 0.27117, 'z': 0},
{'x': 2.2652, 'y': 0.27117, 'z': 0},
{'x': 2.3123, 'y': 0.27117, 'z': 0},
{'x': 2.3598, 'y': 0.27117, 'z': 0},
{'x': 2.4078, 'y': 0.27117, 'z': 0},
{'x': 2.4563, 'y': 0.27117, 'z': 0},
{'x': 2.5053, 'y': 0.27117, 'z': 0},
{'x': 2.5547, 'y': 0.27117, 'z': 0},
{'x': 2.6046, 'y': 0.27117, 'z': 0},
{'x': 2.6551, 'y': 0.27117, 'z': 0},
{'x': 2.706, 'y': 0.27117, 'z': 0},
{'x': 2.7575, 'y': 0.27117, 'z': 0},
{'x': 2.8095, 'y': 0.27117, 'z': 0},
{'x': 2.862, 'y': 0.27117, 'z': 0},
{'x': 2.915, 'y': 0.27117, 'z': 0},
{'x': 2.9685, 'y': 0.27117, 'z': 0},
{'x': 3.0226, 'y': 0.27117, 'z': 0},
{'x': 3.0772, 'y': 0.27117, 'z': 0},
{'x': 3.1324, 'y': 0.27117, 'z': 0},
{'x': 3.1881, 'y': 0.27117, 'z': 0},
{'x': 3.2444, 'y': 0.27117, 'z': 0},
{'x': 3.3013, 'y': 0.27117, 'z': 0},
{'x': 3.3587, 'y': 0.27117, 'z': 0},
{'x': 3.4166, 'y': 0.27117, 'z': 0},
{'x': 3.4752, 'y': 0.27117, 'z': 0},
{'x': 3.5344, 'y': 0.27117, 'z': 0},
{'x': 3.5941, 'y': 0.27117, 'z': 0},
{'x': 3.6544, 'y': 0.27117, 'z': 0},
{'x': 3.7154, 'y': 0.27117, 'z': 0},
{'x': 3.7769, 'y': 0.27117, 'z': 0},
{'x': 3.8391, 'y': 0.27117, 'z': 0},
{'x': 3.9019, 'y': 0.27117, 'z': 0},
{'x': 3.9653, 'y': 0.27117, 'z': 0},
{'x': 4.0294, 'y': 0.27117, 'z': 0},
{'x': 4.094, 'y': 0.27117, 'z': 0},
{'x': 4.1594, 'y': 0.27117, 'z': 0},
{'x': 0.47856, 'y': 0.25781, 'z': 0},
{'x': 0.50774, 'y': 0.25781, 'z': 0},
{'x': 0.53722, 'y': 0.25781, 'z': 0},
{'x': 0.56699, 'y': 0.25781, 'z': 0},
{'x': 0.59706, 'y': 0.25781, 'z': 0},
{'x': 0.62742, 'y': 0.25781, 'z': 0},
{'x': 0.6581, 'y': 0.25781, 'z': 0},
{'x': 0.68907, 'y': 0.25781, 'z': 0},
{'x': 0.72036, 'y': 0.25781, 'z': 0},
{'x': 0.75196, 'y': 0.25781, 'z': 0},
{'x': 0.78388, 'y': 0.25781, 'z': 0},
{'x': 0.81612, 'y': 0.25781, 'z': 0},
{'x': 0.84868, 'y': 0.25781, 'z': 0},
{'x': 0.88156, 'y': 0.25781, 'z': 0},
{'x': 0.91478, 'y': 0.25781, 'z': 0},
{'x': 0.94832, 'y': 0.25781, 'z': 0},
{'x': 0.9822, 'y': 0.25781, 'z': 0},
{'x': 1.0164, 'y': 0.25781, 'z': 0},
{'x': 1.051, 'y': 0.25781, 'z': 0},
{'x': 1.0859, 'y': 0.25781, 'z': 0},
{'x': 1.1211, 'y': 0.25781, 'z': 0},
{'x': 1.1568, 'y': 0.25781, 'z': 0},
{'x': 1.1927, 'y': 0.25781, 'z': 0},
{'x': 1.229, 'y': 0.25781, 'z': 0},
{'x': 1.2657, 'y': 0.25781, 'z': 0},
{'x': 1.3028, 'y': 0.25781, 'z': 0},
{'x': 1.3402, 'y': 0.25781, 'z': 0},
{'x': 1.378, 'y': 0.25781, 'z': 0},
{'x': 1.4162, 'y': 0.25781, 'z': 0},
{'x': 1.4548, 'y': 0.25781, 'z': 0},
{'x': 1.4937, 'y': 0.25781, 'z': 0},
{'x': 1.533, 'y': 0.25781, 'z': 0},
{'x': 1.5728, 'y': 0.25781, 'z': 0},
{'x': 1.6129, 'y': 0.25781, 'z': 0},
{'x': 1.6534, 'y': 0.25781, 'z': 0},
{'x': 1.6944, 'y': 0.25781, 'z': 0},
{'x': 1.7357, 'y': 0.25781, 'z': 0},
{'x': 1.7774, 'y': 0.25781, 'z': 0},
{'x': 1.8196, 'y': 0.25781, 'z': 0},
{'x': 1.8622, 'y': 0.25781, 'z': 0},
{'x': 1.9052, 'y': 0.25781, 'z': 0},
{'x': 1.9487, 'y': 0.25781, 'z': 0},
{'x': 1.9926, 'y': 0.25781, 'z': 0},
{'x': 2.0369, 'y': 0.25781, 'z': 0},
{'x': 2.0817, 'y': 0.25781, 'z': 0},
{'x': 2.1269, 'y': 0.25781, 'z': 0},
{'x': 2.1725, 'y': 0.25781, 'z': 0},
{'x': 2.2187, 'y': 0.25781, 'z': 0},
{'x': 2.2652, 'y': 0.25781, 'z': 0},
{'x': 2.3123, 'y': 0.25781, 'z': 0},
{'x': 2.3598, 'y': 0.25781, 'z': 0},
{'x': 2.4078, 'y': 0.25781, 'z': 0},
{'x': 2.4563, 'y': 0.25781, 'z': 0},
{'x': 2.5053, 'y': 0.25781, 'z': 0},
{'x': 2.5547, 'y': 0.25781, 'z': 0},
{'x': 2.6046, 'y': 0.25781, 'z': 0},
{'x': 2.6551, 'y': 0.25781, 'z': 0},
{'x': 2.706, 'y': 0.25781, 'z': 0},
{'x': 2.7575, 'y': 0.25781, 'z': 0},
{'x': 2.8095, 'y': 0.25781, 'z': 0},
{'x': 2.862, 'y': 0.25781, 'z': 0},
{'x': 2.915, 'y': 0.25781, 'z': 0},
{'x': 2.9685, 'y': 0.25781, 'z': 0},
{'x': 3.0226, 'y': 0.25781, 'z': 0},
{'x': 3.0772, 'y': 0.25781, 'z': 0},
{'x': 3.1324, 'y': 0.25781, 'z': 0},
{'x': 3.1881, 'y': 0.25781, 'z': 0},
{'x': 3.2444, 'y': 0.25781, 'z': 0},
{'x': 3.3013, 'y': 0.25781, 'z': 0},
{'x': 3.3587, 'y': 0.25781, 'z': 0},
{'x': 3.4166, 'y': 0.25781, 'z': 0},
{'x': 3.4752, 'y': 0.25781, 'z': 0},
{'x': 3.5344, 'y': 0.25781, 'z': 0},
{'x': 3.5941, 'y': 0.25781, 'z': 0},
{'x': 3.6544, 'y': 0.25781, 'z': 0},
{'x': 3.7154, 'y': 0.25781, 'z': 0},
{'x': 3.7769, 'y': 0.25781, 'z': 0},
{'x': 3.8391, 'y': 0.25781, 'z': 0},
{'x': 0.53722, 'y': 0.24422, 'z': 0},
{'x': 0.56699, 'y': 0.24422, 'z': 0},
{'x': 0.59706, 'y': 0.24422, 'z': 0},
{'x': 0.62742, 'y': 0.24422, 'z': 0},
{'x': 0.6581, 'y': 0.24422, 'z': 0},
{'x': 0.68907, 'y': 0.24422, 'z': 0},
{'x': 0.72036, 'y': 0.24422, 'z': 0},
{'x': 0.75196, 'y': 0.24422, 'z': 0},
{'x': 0.78388, 'y': 0.24422, 'z': 0},
{'x': 0.81612, 'y': 0.24422, 'z': 0},
{'x': 0.84868, 'y': 0.24422, 'z': 0},
{'x': 0.88156, 'y': 0.24422, 'z': 0},
{'x': 0.91478, 'y': 0.24422, 'z': 0},
{'x': 0.94832, 'y': 0.24422, 'z': 0},
{'x': 0.9822, 'y': 0.24422, 'z': 0},
{'x': 1.0164, 'y': 0.24422, 'z': 0},
{'x': 1.051, 'y': 0.24422, 'z': 0},
{'x': 1.0859, 'y': 0.24422, 'z': 0},
{'x': 1.1211, 'y': 0.24422, 'z': 0},
{'x': 1.1568, 'y': 0.24422, 'z': 0},
{'x': 1.1927, 'y': 0.24422, 'z': 0},
{'x': 1.229, 'y': 0.24422, 'z': 0},
{'x': 1.2657, 'y': 0.24422, 'z': 0},
{'x': 1.3028, 'y': 0.24422, 'z': 0},
{'x': 1.3402, 'y': 0.24422, 'z': 0},
{'x': 1.378, 'y': 0.24422, 'z': 0},
{'x': 1.4162, 'y': 0.24422, 'z': 0},
{'x': 1.4548, 'y': 0.24422, 'z': 0},
{'x': 1.4937, 'y': 0.24422, 'z': 0},
{'x': 1.533, 'y': 0.24422, 'z': 0},
{'x': 1.5728, 'y': 0.24422, 'z': 0},
{'x': 1.6129, 'y': 0.24422, 'z': 0},
{'x': 1.6534, 'y': 0.24422, 'z': 0},
{'x': 1.6944, 'y': 0.24422, 'z': 0},
{'x': 1.7357, 'y': 0.24422, 'z': 0},
{'x': 1.7774, 'y': 0.24422, 'z': 0},
{'x': 1.8196, 'y': 0.24422, 'z': 0},
{'x': 1.8622, 'y': 0.24422, 'z': 0},
{'x': 1.9052, 'y': 0.24422, 'z': 0},
{'x': 1.9487, 'y': 0.24422, 'z': 0},
{'x': 1.9926, 'y': 0.24422, 'z': 0},
{'x': 2.0369, 'y': 0.24422, 'z': 0},
{'x': 2.0817, 'y': 0.24422, 'z': 0},
{'x': 2.1269, 'y': 0.24422, 'z': 0},
{'x': 2.1725, 'y': 0.24422, 'z': 0},
{'x': 2.2187, 'y': 0.24422, 'z': 0},
{'x': 2.2652, 'y': 0.24422, 'z': 0},
{'x': 2.3123, 'y': 0.24422, 'z': 0},
{'x': 2.3598, 'y': 0.24422, 'z': 0},
{'x': 2.4078, 'y': 0.24422, 'z': 0},
{'x': 2.4563, 'y': 0.24422, 'z': 0},
{'x': 2.5053, 'y': 0.24422, 'z': 0},
{'x': 2.5547, 'y': 0.24422, 'z': 0},
{'x': 2.6046, 'y': 0.24422, 'z': 0},
{'x': 2.6551, 'y': 0.24422, 'z': 0},
{'x': 2.706, 'y': 0.24422, 'z': 0},
{'x': 2.7575, 'y': 0.24422, 'z': 0},
{'x': 2.8095, 'y': 0.24422, 'z': 0},
{'x': 2.862, 'y': 0.24422, 'z': 0},
{'x': 2.915, 'y': 0.24422, 'z': 0},
{'x': 2.9685, 'y': 0.24422, 'z': 0},
{'x': 3.0226, 'y': 0.24422, 'z': 0},
{'x': 3.0772, 'y': 0.24422, 'z': 0},
{'x': 3.1324, 'y': 0.24422, 'z': 0},
{'x': 3.1881, 'y': 0.24422, 'z': 0},
{'x': 3.2444, 'y': 0.24422, 'z': 0},
{'x': 3.3013, 'y': 0.24422, 'z': 0},
{'x': 3.3587, 'y': 0.24422, 'z': 0},
{'x': 3.4166, 'y': 0.24422, 'z': 0},
{'x': 3.4752, 'y': 0.24422, 'z': 0},
{'x': 0.62742, 'y': 0.23041, 'z': 0},
{'x': 0.6581, 'y': 0.23041, 'z': 0},
{'x': 0.68907, 'y': 0.23041, 'z': 0},
{'x': 0.72036, 'y': 0.23041, 'z': 0},
{'x': 0.75196, 'y': 0.23041, 'z': 0},
{'x': 0.78388, 'y': 0.23041, 'z': 0},
{'x': 0.81612, 'y': 0.23041, 'z': 0},
{'x': 0.84868, 'y': 0.23041, 'z': 0},
{'x': 0.88156, 'y': 0.23041, 'z': 0},
{'x': 0.91478, 'y': 0.23041, 'z': 0},
{'x': 0.94832, 'y': 0.23041, 'z': 0},
{'x': 0.9822, 'y': 0.23041, 'z': 0},
{'x': 1.0164, 'y': 0.23041, 'z': 0},
{'x': 1.051, 'y': 0.23041, 'z': 0},
{'x': 1.0859, 'y': 0.23041, 'z': 0},
{'x': 1.1211, 'y': 0.23041, 'z': 0},
{'x': 1.1568, 'y': 0.23041, 'z': 0},
{'x': 1.1927, 'y': 0.23041, 'z': 0},
{'x': 1.229, 'y': 0.23041, 'z': 0},
{'x': 1.2657, 'y': 0.23041, 'z': 0},
{'x': 1.3028, 'y': 0.23041, 'z': 0},
{'x': 1.3402, 'y': 0.23041, 'z': 0},
{'x': 1.378, 'y': 0.23041, 'z': 0},
{'x': 1.4162, 'y': 0.23041, 'z': 0},
{'x': 1.4548, 'y': 0.23041, 'z': 0},
{'x': 1.4937, 'y': 0.23041, 'z': 0},
{'x': 1.533, 'y': 0.23041, 'z': 0},
{'x': 1.5728, 'y': 0.23041, 'z': 0},
{'x': 1.6129, 'y': 0.23041, 'z': 0},
{'x': 1.6534, 'y': 0.23041, 'z': 0},
{'x': 1.6944, 'y': 0.23041, 'z': 0},
{'x': 1.7357, 'y': 0.23041, 'z': 0},
{'x': 1.7774, 'y': 0.23041, 'z': 0},
{'x': 1.8196, 'y': 0.23041, 'z': 0},
{'x': 1.8622, 'y': 0.23041, 'z': 0},
{'x': 1.9052, 'y': 0.23041, 'z': 0},
{'x': 1.9487, 'y': 0.23041, 'z': 0},
{'x': 1.9926, 'y': 0.23041, 'z': 0},
{'x': 2.0369, 'y': 0.23041, 'z': 0},
{'x': 2.0817, 'y': 0.23041, 'z': 0},
{'x': 2.1269, 'y': 0.23041, 'z': 0},
{'x': 2.1725, 'y': 0.23041, 'z': 0},
{'x': 2.2187, 'y': 0.23041, 'z': 0},
{'x': 2.2652, 'y': 0.23041, 'z': 0},
{'x': 2.3123, 'y': 0.23041, 'z': 0},
{'x': 2.3598, 'y': 0.23041, 'z': 0},
{'x': 2.4078, 'y': 0.23041, 'z': 0},
{'x': 2.4563, 'y': 0.23041, 'z': 0},
{'x': 2.5053, 'y': 0.23041, 'z': 0},
{'x': 2.5547, 'y': 0.23041, 'z': 0},
{'x': 2.6046, 'y': 0.23041, 'z': 0},
{'x': 2.6551, 'y': 0.23041, 'z': 0},
{'x': 2.706, 'y': 0.23041, 'z': 0},
{'x': 2.7575, 'y': 0.23041, 'z': 0},
{'x': 2.8095, 'y': 0.23041, 'z': 0},
{'x': 2.862, 'y': 0.23041, 'z': 0},
{'x': 2.915, 'y': 0.23041, 'z': 0},
{'x': 2.9685, 'y': 0.23041, 'z': 0},
{'x': 3.0226, 'y': 0.23041, 'z': 0},
{'x': 3.0772, 'y': 0.23041, 'z': 0},
{'x': 3.1324, 'y': 0.23041, 'z': 0},
{'x': 3.1881, 'y': 0.23041, 'z': 0},
{'x': 0.68907, 'y': 0.21643, 'z': 0},
{'x': 0.72036, 'y': 0.21643, 'z': 0},
{'x': 0.75196, 'y': 0.21643, 'z': 0},
{'x': 0.78388, 'y': 0.21643, 'z': 0},
{'x': 0.81612, 'y': 0.21643, 'z': 0},
{'x': 0.84868, 'y': 0.21643, 'z': 0},
{'x': 0.88156, 'y': 0.21643, 'z': 0},
{'x': 0.91478, 'y': 0.21643, 'z': 0},
{'x': 0.94832, 'y': 0.21643, 'z': 0},
{'x': 0.9822, 'y': 0.21643, 'z': 0},
{'x': 1.0164, 'y': 0.21643, 'z': 0},
{'x': 1.051, 'y': 0.21643, 'z': 0},
{'x': 1.0859, 'y': 0.21643, 'z': 0},
{'x': 1.1211, 'y': 0.21643, 'z': 0},
{'x': 1.1568, 'y': 0.21643, 'z': 0},
{'x': 1.1927, 'y': 0.21643, 'z': 0},
{'x': 1.229, 'y': 0.21643, 'z': 0},
{'x': 1.2657, 'y': 0.21643, 'z': 0},
{'x': 1.3028, 'y': 0.21643, 'z': 0},
{'x': 1.3402, 'y': 0.21643, 'z': 0},
{'x': 1.378, 'y': 0.21643, 'z': 0},
{'x': 1.4162, 'y': 0.21643, 'z': 0},
{'x': 1.4548, 'y': 0.21643, 'z': 0},
{'x': 1.4937, 'y': 0.21643, 'z': 0},
{'x': 1.533, 'y': 0.21643, 'z': 0},
{'x': 1.5728, 'y': 0.21643, 'z': 0},
{'x': 1.6129, 'y': 0.21643, 'z': 0},
{'x': 1.6534, 'y': 0.21643, 'z': 0},
{'x': 1.6944, 'y': 0.21643, 'z': 0},
{'x': 1.7357, 'y': 0.21643, 'z': 0},
{'x': 1.7774, 'y': 0.21643, 'z': 0},
{'x': 1.8196, 'y': 0.21643, 'z': 0},
{'x': 1.8622, 'y': 0.21643, 'z': 0},
{'x': 1.9052, 'y': 0.21643, 'z': 0},
{'x': 1.9487, 'y': 0.21643, 'z': 0},
{'x': 1.9926, 'y': 0.21643, 'z': 0},
{'x': 2.0369, 'y': 0.21643, 'z': 0},
{'x': 2.0817, 'y': 0.21643, 'z': 0},
{'x': 2.1269, 'y': 0.21643, 'z': 0},
{'x': 2.1725, 'y': 0.21643, 'z': 0},
{'x': 2.2187, 'y': 0.21643, 'z': 0},
{'x': 2.2652, 'y': 0.21643, 'z': 0},
{'x': 2.3123, 'y': 0.21643, 'z': 0},
{'x': 2.3598, 'y': 0.21643, 'z': 0},
{'x': 2.4078, 'y': 0.21643, 'z': 0},
{'x': 2.4563, 'y': 0.21643, 'z': 0},
{'x': 2.5053, 'y': 0.21643, 'z': 0},
{'x': 2.5547, 'y': 0.21643, 'z': 0},
{'x': 2.6046, 'y': 0.21643, 'z': 0},
{'x': 2.6551, 'y': 0.21643, 'z': 0},
{'x': 2.706, 'y': 0.21643, 'z': 0},
{'x': 2.7575, 'y': 0.21643, 'z': 0},
{'x': 2.8095, 'y': 0.21643, 'z': 0},
{'x': 0.78388, 'y': 0.20231, 'z': 0},
{'x': 0.81612, 'y': 0.20231, 'z': 0},
{'x': 0.84868, 'y': 0.20231, 'z': 0},
{'x': 0.88156, 'y': 0.20231, 'z': 0},
{'x': 0.91478, 'y': 0.20231, 'z': 0},
{'x': 0.94832, 'y': 0.20231, 'z': 0},
{'x': 0.9822, 'y': 0.20231, 'z': 0},
{'x': 1.0164, 'y': 0.20231, 'z': 0},
{'x': 1.051, 'y': 0.20231, 'z': 0},
{'x': 1.0859, 'y': 0.20231, 'z': 0},
{'x': 1.1211, 'y': 0.20231, 'z': 0},
{'x': 1.1568, 'y': 0.20231, 'z': 0},
{'x': 1.1927, 'y': 0.20231, 'z': 0},
{'x': 1.229, 'y': 0.20231, 'z': 0},
{'x': 1.2657, 'y': 0.20231, 'z': 0},
{'x': 1.3028, 'y': 0.20231, 'z': 0},
{'x': 1.3402, 'y': 0.20231, 'z': 0},
{'x': 1.378, 'y': 0.20231, 'z': 0},
{'x': 1.4162, 'y': 0.20231, 'z': 0},
{'x': 1.4548, 'y': 0.20231, 'z': 0},
{'x': 1.4937, 'y': 0.20231, 'z': 0},
{'x': 1.533, 'y': 0.20231, 'z': 0},
{'x': 1.5728, 'y': 0.20231, 'z': 0},
{'x': 1.6129, 'y': 0.20231, 'z': 0},
{'x': 1.6534, 'y': 0.20231, 'z': 0},
{'x': 1.6944, 'y': 0.20231, 'z': 0},
{'x': 1.7357, 'y': 0.20231, 'z': 0},
{'x': 1.7774, 'y': 0.20231, 'z': 0},
{'x': 1.8196, 'y': 0.20231, 'z': 0},
{'x': 1.8622, 'y': 0.20231, 'z': 0},
{'x': 1.9052, 'y': 0.20231, 'z': 0},
{'x': 1.9487, 'y': 0.20231, 'z': 0},
{'x': 1.9926, 'y': 0.20231, 'z': 0},
{'x': 2.0369, 'y': 0.20231, 'z': 0},
{'x': 2.0817, 'y': 0.20231, 'z': 0},
{'x': 2.1269, 'y': 0.20231, 'z': 0},
{'x': 2.1725, 'y': 0.20231, 'z': 0},
{'x': 2.2187, 'y': 0.20231, 'z': 0},
{'x': 2.2652, 'y': 0.20231, 'z': 0},
{'x': 2.3123, 'y': 0.20231, 'z': 0},
{'x': 2.3598, 'y': 0.20231, 'z': 0},
{'x': 2.4078, 'y': 0.20231, 'z': 0},
{'x': 2.4563, 'y': 0.20231, 'z': 0},
{'x': 1.051, 'y': 0.1881, 'z': 0},
{'x': 1.0859, 'y': 0.1881, 'z': 0},
{'x': 1.1211, 'y': 0.1881, 'z': 0},
{'x': 1.1568, 'y': 0.1881, 'z': 0},
{'x': 1.1927, 'y': 0.1881, 'z': 0},
{'x': 1.229, 'y': 0.1881, 'z': 0},
{'x': 1.2657, 'y': 0.1881, 'z': 0},
{'x': 1.3028, 'y': 0.1881, 'z': 0},
{'x': 1.3402, 'y': 0.1881, 'z': 0},
{'x': 1.378, 'y': 0.1881, 'z': 0},
{'x': 1.4162, 'y': 0.1881, 'z': 0},
{'x': 1.4548, 'y': 0.1881, 'z': 0},
{'x': 1.4937, 'y': 0.1881, 'z': 0},
{'x': 1.533, 'y': 0.1881, 'z': 0},
{'x': 1.5728, 'y': 0.1881, 'z': 0},
{'x': 1.6129, 'y': 0.1881, 'z': 0},
{'x': 1.6534, 'y': 0.1881, 'z': 0},
{'x': 1.6944, 'y': 0.1881, 'z': 0},
{'x': 1.7357, 'y': 0.1881, 'z': 0},
{'x': 1.7774, 'y': 0.1881, 'z': 0},
{'x': 1.8196, 'y': 0.1881, 'z': 0},
{'x': 1.8622, 'y': 0.1881, 'z': 0},
{'x': 1.9052, 'y': 0.1881, 'z': 0},
{'x': 1.9487, 'y': 0.1881, 'z': 0},
{'x': 1.9926, 'y': 0.1881, 'z': 0},
{'x': 2.0369, 'y': 0.1881, 'z': 0}])
plt.scatter(data=df, x='x', y='y', label='original_data')
plt.legend()
plt.title('original data')
plt.show()
hull = ConvexHull(df[['x', 'y']])
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
convex_hull_plot_2d(hull, ax=ax)
fig.tight_layout()
plt.title('convex hull with points')
plt.show()
hull.points
array([[0.20215, 0.29703],
[0.22857, 0.29703],
[0.25526, 0.29703],
...,
[1.9487 , 0.1881 ],
[1.9926 , 0.1881 ],
[2.0369 , 0.1881 ]])
The convex hull is a nice approach, although it wouldn't solve the case that you are showing (the donut shape with an inner boundary).
I think that the algorithm that you need is called "Marching cubes" (or Marching squares, in 2D). It is a broadly used method, so you should be able to easily find some libraries in python that implement it.
https://en.wikipedia.org/wiki/Marching_squares
Basically, considering the 2D case, the algorithm works like this:
Discretize the space in a grid.
Count the number of points in every cell
Apply a threshold to the cells so you end up with either "empty" or "filled" cells
According to the state of every cell, and its neighbors, there are some predefined cases (16 in 2D) on how the boundary curve should look like.
Merge all the small curves
In 3D the idea is the same, but with cubes instead of squares, and with higher number of predefined cases.
The convex hull approaches mentioned by others do not work when the shape has holes (as in the case with your torus 🍩 example).
The problem you’re trying to solve is called surface reconstruction. The final mesh will not have the internal points as you wanted.
Open3D has some algorithms implemented for this and you can them on your data in Python.
Surface reconstruction
To convert your numpy point cloud to Open3D’s use
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(xyz)

extract data from interactive graph

I'm trying to scrape the data from this interactive chart which is located at the bottom of the website below: https://www.vgchartz.com/tools/hw_date.php?reg=USA&ending=Yearly
I've used developer tools in chrome but cannot find the data points in the elements tab.
Would appreciate if someone can take a look and tell me if the data points are stored on the page somewhere or there is any way to do using Python
Thank you very much!
The data is included inside <script> tag on that page. To parse it, you can use js2py library. For example:
import ast
import js2py
import requests
url = "https://www.vgchartz.com/tools/hw_date.php?reg=USA&ending=Yearly"
data = re.search(
r"StockChart\(({.*?})\);", requests.get(url).text, flags=re.S
).group(1)
data = js2py.eval_js("data = " + data + ";")
data = ast.literal_eval(str(data))
print(data)
Prints:
{
"chart": {
"endOnTick": False,
"marginBottom": 90,
"marginLeft": 80,
"marginRight": 20,
"renderTo": "chart_container",
"startOnTick": False,
"zoomType": "y",
},
"legend": {"enabled": True},
"plotOptions": {"series": {"dataGrouping": {"smoothed": True}}},
"rangeSelector": {"selected": 5},
"series": [
{
"cropThreshold": 1,
"data": [
{"x": 1072933200000, "y": 1302609},
{"x": 1104555600000, "y": 2604003},
{"x": 1136091600000, "y": 5074726},
{"x": 1167627600000, "y": 8757992},
{"x": 1199163600000, "y": 10156740},
{"x": 1230786000000, "y": 10369446},
{"x": 1262322000000, "y": 8434877},
{"x": 1293858000000, "y": 4335275},
{"x": 1325394000000, "y": 2164269},
{"x": 1357016400000, "y": 600849},
],
...
The chart data is imbedded in the HTML response of a basic GET request to the link. The data points themselves can be found in a Javascript Object formatted in a script tag. To pull these points, you will need to use some sort of Javascript parser to access the Object and convert the JS object representation to a Python dictionary. Pure JSON parsing cannot easily be used here, since the Object is not initialized in valid JSON syntax. The code below uses the module pyjsparser which can be installed via pip: pip3 install pyjsparser.
import requests, pyjsparser
from bs4 import BeautifulSoup as soup
d = soup(requests.get('https://www.vgchartz.com/tools/hw_date.php?reg=USA&ending=Yearly'), 'html.parser')
ast = pyjsparser.parse(d.select_one('#chart_body > .chart_date_selector ~ script').text)
def to_json(ast):
if ast['type'] == 'ArrayExpression':
return [to_json(i) for i in ast['elements']]
if ast['type'] == 'ObjectExpression':
return {i['key']['name']:to_json(i['value']) for i in ast['properties']}
if ast['type'] == 'Literal':
return ast['value']
def get_chart_data(ast):
if isinstance(ast, dict):
if ast.get('type') == 'Property' and ast['key']['name'] == 'series' and ast['value']['type'] == 'ArrayExpression':
yield to_json(ast['value'])
return
for b in ast.values():
yield from get_chart_data(b)
elif isinstance(ast, list):
for i in ast:
yield from get_chart_data(i)
data = next(get_chart_data(ast))
Output:
[{'showLastLabel': True, 'cropThreshold': 1.0, 'name': 'PSP', 'data': [{'x': 1072933200000.0, 'y': 0.0}, {'x': 1104555600000.0, 'y': 3527367.0}, {'x': 1136091600000.0, 'y': 2952955.0}, {'x': 1167627600000.0, 'y': 3563757.0}, {'x': 1199163600000.0, 'y': 3815680.0}, {'x': 1230786000000.0, 'y': 2452361.0}, {'x': 1262322000000.0, 'y': 1824105.0}, {'x': 1293858000000.0, 'y': 1245169.0}, {'x': 1325394000000.0, 'y': 274023.0}, {'x': 1357016400000.0, 'y': 128378.0}, {'x': 1388552400000.0, 'y': 26999.0}]}, {'showLastLabel': True, 'cropThreshold': 1.0, 'name': 'Wii', 'data': [{'x': 1136091600000.0, 'y': 1075329.0}, {'x': 1167627600000.0, 'y': 6444409.0}, {'x': 1199163600000.0, 'y': 9826502.0}, {'x': 1230786000000.0, 'y': 8989309.0}, {'x': 1262322000000.0, 'y': 7398500.0}, {'x': 1293858000000.0, 'y': 4878060.0}, {'x': 1325394000000.0, 'y': 2042064.0}, {'x': 1357016400000.0, 'y': 773488.0}, {'x': 1388552400000.0, 'y': 216453.0}, {'x': 1420088400000.0, 'y': 58765.0}]}, {'showLastLabel': True, 'cropThreshold': 1.0, 'name': 'X360', 'data': [{'x': 1104555600000.0, 'y': 563282.0}, {'x': 1136091600000.0, 'y': 3832778.0}, {'x': 1167627600000.0, 'y': 4356599.0}, {'x': 1199163600000.0, 'y': 4784134.0}, {'x': 1230786000000.0, 'y': 4691537.0}, {'x': 1262322000000.0, 'y': 6999773.0}, {'x': 1293858000000.0, 'y': 7777810.0}, {'x': 1325394000000.0, 'y': 6488715.0}, {'x': 1357016400000.0, 'y': 3164108.0}, {'x': 1388552400000.0, 'y': 855780.0}, {'x': 1420088400000.0, 'y': 165018.0}, {'x': 1451624400000.0, 'y': 67456.0}, {'x': 1483246800000.0, 'y': 5433.0}]}, {'showLastLabel': True, 'cropThreshold': 1.0, 'name': 'DS', 'data': [{'x': 1072933200000.0, 'y': 1302609.0}, {'x': 1104555600000.0, 'y': 2604003.0}, {'x': 1136091600000.0, 'y': 5074726.0}, {'x': 1167627600000.0, 'y': 8757992.0}, {'x': 1199163600000.0, 'y': 10156740.0}, {'x': 1230786000000.0, 'y': 10369446.0}, {'x': 1262322000000.0, 'y': 8434877.0}, {'x': 1293858000000.0, 'y': 4335275.0}, {'x': 1325394000000.0, 'y': 2164269.0}, {'x': 1357016400000.0, 'y': 600849.0}]}, {'showLastLabel': True, 'cropThreshold': 1.0, 'name': 'PS3', 'data': [{'x': 1136091600000.0, 'y': 667762.0}, {'x': 1167627600000.0, 'y': 2474435.0}, {'x': 1199163600000.0, 'y': 3547363.0}, {'x': 1230786000000.0, 'y': 4255949.0}, {'x': 1262322000000.0, 'y': 4737437.0}, {'x': 1293858000000.0, 'y': 4486935.0}, {'x': 1325394000000.0, 'y': 3480788.0}, {'x': 1357016400000.0, 'y': 2237467.0}, {'x': 1388552400000.0, 'y': 721523.0}, {'x': 1420088400000.0, 'y': 274884.0}, {'x': 1451624400000.0, 'y': 125072.0}, {'x': 1483246800000.0, 'y': 12482.0}]}, {'showLastLabel': True, 'cropThreshold': 1.0, 'name': '3DS', 'data': [{'x': 1293858000000.0, 'y': 4056029.0}, {'x': 1325394000000.0, 'y': 3542069.0}, {'x': 1357016400000.0, 'y': 3905067.0}, {'x': 1388552400000.0, 'y': 2518536.0}, {'x': 1420088400000.0, 'y': 2499074.0}, {'x': 1451624400000.0, 'y': 2456456.0}, {'x': 1483246800000.0, 'y': 2060575.0}, {'x': 1514782800000.0, 'y': 1534418.0}, {'x': 1546318800000.0, 'y': 615394.0}, {'x': 1577854800000.0, 'y': 249847.0}, {'x': 1609477200000.0, 'y': 2787.0}]}, {'showLastLabel': True, 'cropThreshold': 1.0, 'name': 'PSV', 'data': [{'x': 1293858000000.0, 'y': 0.0}, {'x': 1325394000000.0, 'y': 1227049.0}, {'x': 1357016400000.0, 'y': 509085.0}, {'x': 1388552400000.0, 'y': 324396.0}, {'x': 1420088400000.0, 'y': 247162.0}, {'x': 1451624400000.0, 'y': 108422.0}, {'x': 1483246800000.0, 'y': 20908.0}, {'x': 1514782800000.0, 'y': 3119.0}, {'x': 1546318800000.0, 'y': 0.0}]}, {'showLastLabel': True, 'cropThreshold': 1.0, 'name': 'WiiU', 'data': [{'x': 1325394000000.0, 'y': 899502.0}, {'x': 1357016400000.0, 'y': 1214283.0}, {'x': 1388552400000.0, 'y': 1565573.0}, {'x': 1420088400000.0, 'y': 1361771.0}, {'x': 1451624400000.0, 'y': 460025.0}, {'x': 1483246800000.0, 'y': 9553.0}]}, {'showLastLabel': True, 'cropThreshold': 1.0, 'name': 'PS4', 'data': [{'x': 1357016400000.0, 'y': 2072802.0}, {'x': 1388552400000.0, 'y': 4656798.0}, {'x': 1420088400000.0, 'y': 5802890.0}, {'x': 1451624400000.0, 'y': 5077809.0}, {'x': 1483246800000.0, 'y': 5404655.0}, {'x': 1514782800000.0, 'y': 5245644.0}, {'x': 1546318800000.0, 'y': 3824746.0}, {'x': 1577854800000.0, 'y': 2084519.0}, {'x': 1609477200000.0, 'y': 613650.0}, {'x': 1641013200000.0, 'y': 168996.0}]}, {'showLastLabel': True, 'cropThreshold': 1.0, 'name': 'XOne', 'data': [{'x': 1357016400000.0, 'y': 1928445.0}, {'x': 1388552400000.0, 'y': 4325832.0}, {'x': 1420088400000.0, 'y': 4938473.0}, {'x': 1451624400000.0, 'y': 4696984.0}, {'x': 1483246800000.0, 'y': 4307564.0}, {'x': 1514782800000.0, 'y': 4304447.0}, {'x': 1546318800000.0, 'y': 2971031.0}, {'x': 1577854800000.0, 'y': 1508975.0}, {'x': 1609477200000.0, 'y': 503439.0}, {'x': 1641013200000.0, 'y': 22086.0}]}, {'showLastLabel': True, 'cropThreshold': 1.0, 'name': 'NS', 'data': [{'x': 1483246800000.0, 'y': 4880477.0}, {'x': 1514782800000.0, 'y': 5613050.0}, {'x': 1546318800000.0, 'y': 6479134.0}, {'x': 1577854800000.0, 'y': 9027556.0}, {'x': 1609477200000.0, 'y': 8012707.0}, {'x': 1641013200000.0, 'y': 2163947.0}]}, {'showLastLabel': True, 'cropThreshold': 1.0, 'name': 'PS5', 'data': [{'x': 1577854800000.0, 'y': 1940361.0}, {'x': 1609477200000.0, 'y': 4302047.0}, {'x': 1641013200000.0, 'y': 1328693.0}]}, {'showLastLabel': True, 'cropThreshold': 1.0, 'name': 'XS', 'data': [{'x': 1577854800000.0, 'y': 1525675.0}, {'x': 1609477200000.0, 'y': 3893991.0}, {'x': 1641013200000.0, 'y': 1937560.0}]}]

How to access integer value from a list [duplicate]

This question already has answers here:
Getting a list of values from a list of dicts
(10 answers)
Closed 3 years ago.
result = [{'label': 'butterfly', 'confidence': 0.16034618, 'topleft': {'x': 195, 'y': 23}, 'bottomright': {'x': 220, 'y': 45}}, {'label': 'butterfly', 'confidence': 0.27062774, 'topleft': {'x': 64, 'y': 58}, 'bottomright': {'x': 98, 'y': 85}}, {'label': 'butterfly', 'confidence': 0.114007816, 'topleft': {'x': 247, 'y': 191}, 'bottomright': {'x': 268, 'y': 211}}]
I want to return only the confidence value from each element.
Try this:
my_list = [
{
'label': 'butterfly',
'confidence': 0.16034618,
'topleft': {'x': 195, 'y': 23},
'bottomright': {'x': 220, 'y': 45}
},
{
'label': 'butterfly',
'confidence': 0.27062774,
'topleft': {'x': 64, 'y': 58},
'bottomright': {'x': 98, 'y': 85}
}
]
confidence_values = list(
map(
lambda x: x['confidence'],
my_list
)
)
print(confidence_values)

Groupby and sort the values in dict in Python

I have a dictionary as follows in python and I have to group by 'label' and get the highest value of 'confidence' for each 'label'
[{'label': 'id',
'confidence': 0.11110526,
'topleft': {'x': 0, 'y': 0},
'bottomright': {'x': 187, 'y': 57}},
{'label': 'id',
'confidence': 0.10690566,
'topleft': {'x': 265, 'y': 0},
'bottomright': {'x': 525, 'y': 54}},
{'label': 'name',
'confidence': 0.15541315,
'topleft': {'x': 9, 'y': 24},
'bottomright': {'x': 116, 'y': 58}},
{'label': 'group',
'confidence': 0.12578075,
'topleft': {'x': 53, 'y': 24},
'bottomright': {'x': 153, 'y': 61}},
{'label': 'name',
'confidence': 0.12709439,
'topleft': {'x': 0, 'y': 0},
'bottomright': {'x': 247, 'y': 84}},
{'label': 'group',
'confidence': 0.116156094,
'topleft': {'x': 96, 'y': 23},
'bottomright': {'x': 191, 'y': 61}}]
How do I achieve this efficiently
You can do this with groupby
for n,g in groupby(tst,key=lambda x:x['label']):
print n,max(list(g),key=lambda x:x['confidence']).get('confidence')
Result:
id 0.11110526
name 0.15541315
group 0.12578075
name 0.12709439
group 0.116156094

Combine elements by the key in list

I have the following list
some_list = [{'key': 'YOUNG', 'x': 22, 'y': 0.9},
{'key': 'OLD', 'x': 45, 'y': 0.6},
{'key': 'OLD', 'x': 40, 'y': 0.3},
{'key': 'YOUNG', 'x': 25, 'y': 0.3}]
and I would like to change it to:
[{'key': 'YOUNG', 'values': [ {'x': 25, 'y': 0.3}, {'x': 22, 'y': 0.9} ]}
{'key': 'OLD', 'values': [ {'x': 40, 'y': 0.3}, {'x': 45, 'y': 0.6} ]}]
Added some of my attempts
arr = [{'key': 'YOUNG', 'x': 22, 'y': 0.9},
{'key': 'OLD', 'x': 45, 'y': 0.6},
{'key': 'OLD', 'x': 40, 'y': 0.3},
{'key': 'YOUNG', 'x': 25, 'y': 0.3}]
all_keys = []
for item in arr:
all_keys.append(item['key'])
all_keys = list(set(all_keys))
res = [[{
'key': key,
'values': {'x': each['x'], 'y': each['y']}
} for each in arr if each['key'] == key]
for key in all_keys]
print res
But the result is not right, it constructs more lists:
[[{'values': {'y': 0.6, 'x': 45}, 'key': 'OLD'}, {'values': {'y': 0.3, 'x': 40}, 'key': 'OLD'}], [{'values': {'y': 0.9, 'x': 22}, 'key': 'YOUNG'}, {'values': {'y': 0.3, 'x': 25}, 'key': 'YOUNG'}]]
Thanks.
The loops should be like this:
res = [{ 'key': key,
'values': [{'x': each['x'], 'y': each['y']}
for each in arr if each['key'] == key] }
for key in all_keys]
Using an intermediate dictionary you can do:
>>> temp_data = {}
>>> for x in some_list:
... temp_data.setdefault(x['key'], []).append({k: x[k] for k in ['x', 'y']})
>>> [{'key': k, 'values': v} for k,v in temp_data.items()]
[{'key': 'OLD', 'values': [{'x': 45, 'y': 0.6}, {'x': 40, 'y': 0.3}]},
{'key': 'YOUNG', 'values': [{'x': 22, 'y': 0.9}, {'x': 25, 'y': 0.3}]}]
Though personally I would just leave it in dictionary form:
>>> temp_data
{'OLD': [{'x': 45, 'y': 0.6}, {'x': 40, 'y': 0.3}],
'YOUNG': [{'x': 22, 'y': 0.9}, {'x': 25, 'y': 0.3}]}
from itertools import *
data = [{'key': 'YOUNG', 'x': 22, 'y': 0.9},
{'key': 'OLD', 'x': 45, 'y': 0.6},
{'key': 'OLD', 'x': 40, 'y': 0.3},
{'key': 'YOUNG', 'x': 25, 'y': 0.3}]
data = sorted(data, key=lambda x: x['key'])
groups = []
uniquekeys = []
for k, v in groupby(data, lambda x: x['key'] ):
val_list = []
for each_val in v:
val_list.append({ 'x' : each_val['x'], 'y': each_val['y']})
groups.append(val_list)
uniquekeys.append(k)
print uniquekeys
print groups
print zip(uniquekeys, groups)
You will get your output as a list of tuples where the first element is your key and the second one is the group/list of values,
[('OLD', [{'y': 0.6, 'x': 45}, {'y': 0.3, 'x': 40}]), ('YOUNG', [{'y': 0.9, 'x': 22}, {'y': 0.3, 'x': 25}])]
some_list = [{'key': 'YOUNG', 'x': 22, 'y': 0.9},
{'key': 'OLD', 'x': 45, 'y': 0.6},
{'key': 'OLD', 'x': 40, 'y': 0.3},
{'key': 'YOUNG', 'x': 25, 'y': 0.3}]
outDict = {}
for dictionary in some_list:
key = dictionary['key']
copyDict = dictionary.copy() #This leaves the original dict list unaltered
del copyDict['key']
if key in outDict:
outDict[key].append(copyDict)
else:
outDict[key] = [copyDict]
print(outDict)
print(some_list)
Here you go-
some_list = [{'key': 'YOUNG', 'x': 22, 'y': 0.9},
{'key': 'OLD', 'x': 45, 'y': 0.6},
{'key': 'OLD', 'x': 40, 'y': 0.3},
{'key': 'YOUNG', 'x': 25, 'y': 0.3}]
dict_young_vals = []
dict_old_vals = []
for dict_step in some_list:
temp_dict = {}
if (dict_step['key'] == 'YOUNG'):
for keys in dict_step.keys():
if keys != 'key':
temp_dict[keys] = dict_step[keys]
if temp_dict != {}:
dict_young_vals.append(temp_dict)
if (dict_step['key'] == 'OLD'):
for keys in dict_step.keys():
if keys != 'key':
temp_dict[keys] = dict_step[keys]
if temp_dict != {}:
dict_old_vals.append(temp_dict)
dict_young = {'key':'YOUNG'}
dict_young['values'] = dict_young_vals
dict_old = {'key': 'OLD'}
dict_old['values'] = dict_old_vals
print(dict_young_vals)
result_dict = []
result_dict.append(dict_young)
result_dict.append(dict_old)
print(result_dict)
Another try may be using defaultdict- It will run faster if data is larger.
from collections import defaultdict
data = defaultdict(list)
some_list = [{'key': 'YOUNG', 'x': 22, 'y': 0.9},
{'key': 'OLD', 'x': 45, 'y': 0.6},
{'key': 'OLD', 'x': 40, 'y': 0.3},
{'key': 'YOUNG', 'x': 25, 'y': 0.3}]
for item in some_list:
vals = item.copy()
del vals['key']
data[item['key']].append(vals)
print [{'key':k,'values':v} for k,v in data.items()]
Output (dictionary does not care about ordering)-
[{'values': [{'y': 0.6, 'x': 45}, {'y': 0.3, 'x': 40}], 'key': 'OLD'}, {'values': [{'y': 0.9, 'x': 22}, {'y': 0.3, 'x': 25}], 'key': 'YOUNG'}]
some_list = [{'key': 'YOUNG', 'x': 22, 'y': 0.9},
{'key': 'OLD', 'x': 45, 'y': 0.6},
{'key': 'OLD', 'x': 40, 'y': 0.3},
{'key': 'YOUNG', 'x': 25, 'y': 0.3}]
x=[]
for i in some_list:
d={}
d["key"]=i["key"]
d["values"]=[{m:n for m,n in i.items() if m!="key"}]
if d["key"] not in [j["key"] for j in x]:
x.append(d)
else:
for k in x:
if k["key"]==d["key"]:
k["values"].append(d["values"][0])
print x
Output:[{'values': [{'y': 0.9, 'x': 22}, {'y': 0.3, 'x': 25}], 'key': 'YOUNG'}, {'values': [{'y': 0.6, 'x': 45}, {'y': 0.3, 'x': 40}], 'key': 'OLD'}]

Categories