Covering a nonrectangle shape with s2sphere/Python
I am having a hard time figuring out how to create a region that would be defined by a set of geographical coordinates (more than 4) using s2sphere for Python 2.7. Does anyone have an idea how i could do this?
See also questions close to this topic

Reading from CSV file raising value error
I tried this piece of code in Python 3.6.2
import csv with open ('kk.csv') as csvfile: data=CSV(csvfile,delimiter=',') for value in data: print(value)
It produced a
ValueError: I/O operation on closed file
. I can't understand what is going on. 
Setting up qt4py2 with with python 2.7 in virtualenv  cannot find the files :(
hopefully this question fits here, I have tried googling and reading "http://pyqt.sourceforge.net/Docs/PyQt4/installation.html" but unfortunately I'm such a newbie in all things linux that I cannot figure out what applies here... anyway:
I have a virtual env (in Python 2.7)
I am trying to set up labelImg as instructed in : https://github.com/tzutalin/labelImg, specifically I run (with my virtualenv active):
sudo aptget install pyqt4devtools sudo pip install lxml (< did run this as "pip install lxml")
Then I run into problems with this:
make qt4py2
I got error:
"make: *** No rule to make target 'qt4py2'. Stop."
Now from googling I got the impression that I should be in the same directory as the make file when I run make (is this even true?), but when I try to find where pyqt4 is, I cannot find the folder (it is not in
~/.virtualenvs/virP2/lib/python2.7/sitepackages$
(virP2
is the name of the virtualenv)I have also tried to run (with the
virP2
still active)sudo aptget install pythonqt4
but I got:
"pythonqt4 is already the newest version"
and I still cannot find where the directory with qt4 files is. (I also looked into the python2.7 folder outside the virtualenv, but it was not there)
Thanks for any advice!

pandas  pivot_table while preserving order fails
I have the following data frame where week are not ISO weeks but fiscal weeks (1 is 1st week of July, 52 is last week of June):
> df domain week count 0 A 43 5 1 A 45 1 2 A 50 1 3 A 51 4 4 A 1 3 5 A 3 12 6 B 43 1 7 B 44 1 8 B 45 4 9 B 50 11 10 B 2 3 11 B 3 12 12 C 51 6 13 C 1 14 14 C 5 1
I want to pivot this table while preserving the order of the week to get a new data frame that would look like the following with the values being count and the columns being the domain:
> new_df week A B C 43 5 1 NaN 44 NaN 1 NaN 45 1 4 NaN 50 1 11 NaN 51 4 NaN 6 1 3 NaN 14 2 NaN 3 NaN 3 12 12 NaN 5 NaN NaN 1
I tried using groupie and unstuck but got this error:
> df = df.groupby(['week'], sort=False)['count'].unstack('domain') AttributeError: Cannot access callable attribute 'unstack' of 'SeriesGroupBy' objects, try using the 'apply' method

Python + Mysql : Insert geojson polygon value to mysql sptial column
I have a geojson file that contains polygon data. below is example of it.
[[[127.00733253963132, 37.583203339216226], [127.00884131783923, 37.58045263873488], [127.00861398800201, 37.57670881432089], [127.00783306341832, 37.57663511179821], [126.99967765278153, 37.57589728327857], [126.9971834726848, 37.57693224535312], [126.99675796489285, 37.578422160319896], [126.99660663904614, 37.579345394336194], [126.99641172469617, 37.580645880422686], [126.99649978451932, 37.581022567729896], [126.99823026308687, 37.581266540341], [127.00180462191403, 37.58253031283794], [127.00172112834049, 37.583133635452405], [127.00272082947205, 37.583723680505784], [127.00580459526145, 37.584756278282704], [127.00618219538146, 37.58396129485959], [127.00733253963132, 37.583203339216226]]]
I have spatial table in mysql. I'm trying to insert this polygon data into polygon column using row sql, however, keep failing. Later, I found polygon data that inserted in mysql db looks little bit different from what I have. This is the data that I've seen from internet tutorial.
((126.97688884274817 37.575650779448786, 126.9770344988775 37.569194530054546, 126.97597472821249 37.569336299425764, 126.97537470991254 37.569315567021562, 126.97433193562325 37.569261800517531, 126.96904837001854 37.568194417708312, 126.96854493603384 37.568427679612753, 126.9666499598212 37.569491655206569, 126.96628175024485 37.569700734798701, 126.9660973270804 37.569856509723699, 126.96572852922577 37.570183936115114, 126.96592699822128 37.570318805686199, 126.96601094018429 37.57154839557748, 126.96365922052196 37.575174660660359, 126.96308600434513 37.576485920015529, 126.96284099051198 37.576661586092726, 126.96281041047263 37.579448809656768, 126.96742431584332 37.579601537124489, 126.96742176302651 37.579263521441646, 126.9674300601846 37.579192577998612, 126.96745709009561 37.578975250585444, 126.96806604699626 37.578246780467865, 126.96895511695477 37.577935262340283, 126.96921284296906 37.577935299309395, 126.96941453886579 37.578121124142172, 126.96966442669471 37.578531136682209, 126.96966721914872 37.578736205134923, 126.96966877353309 37.578992879009881, 126.96966949910363 37.579112526749597, 126.96990457361626 37.579301753628719, 126.97135197544759 37.579513277939817, 126.97381925784454 37.579372140302631, 126.97391736338342 37.578487073041011, 126.97393961998088 37.578240429978088, 126.97433153835757 37.575749906299862, 126.97580378997804 37.575649468824203, 126.97688884274817 37.575650779448786 ))'
So the idea that I have is make polygon data into string and just replace the brackets using regex. However this methods will takes lot of time. So, I wonder if there is any solution to insert this data into mysql polygon field.

How to create a modified voronoi algorithm for ramdon points with physical restriction
Voronoi algorithm has no doubt provided a amenable approach to divide a plane into regions based on distance to points in a specific subset of the plane. Such the Voronoi diagram of a set of points is dual to its Delaunay triangulation.This goal now can be directly achieved by using the module scipy as
import scipy.spatial point_coordinate_array = np.array(point_coordinates) delaunay_mesh = scipy.spatial.Delaunay(point_coordinate_array) voronoi_diagram = scipy.spatial.Voronoi(point_coordinate_array) # plot(delaunay_mesh and voronoi_diagram using matplotlib)
when the given points beforehand. The results can be shown in Fig 1,
in which the areas bounded by green dashed lines are the delaunay triangles of all points and the closed region into blue solid lines is of course the voronoi cell of the center point(for a better Visualization, only the closed region is shown here)
Up to now, all things are seen to be perfect. But for actual application, all points may have their own physical meanings. (For example, these points may have 'radii' varible when they represent the natural particles). And the common voronoi algorithm above is to be more or less inappropriate for such the case in which the complex physical restriction may be considered. As shown in Fig 2, the ridges of voronoi cell may intersect the particle's boundary. It can not meet the physical requirment any more.
My question now is how to create a modified voronoi algorithm (maybe it can not called voronoi any more) to deal with this physical restriction. This purpose is shown roughly in Fig 3, the region closed by blue dashed lines is just what I want.
All the pip requirments are:
1.numpy1.13.3+mklcp36cp36mwin_amd64.whl
2.scipy0.19.1cp36cp36mwin_amd64.whl
3.matplotlib2.1.0cp36cp36mwin_amd64.whl
and all of them can be directly downloaded in http://www.lfd.uci.edu/~gohlke/pythonlibs/
My codes are updated for a better modifcation, they are as
import numpy as np import scipy.spatial import matplotlib as mpl import matplotlib.pyplot as plt from matplotlib.patches import Circle from matplotlib.collections import PatchCollection # give the pointcoordinate array for contribute the trinetwork. point_coordinate_array = np.array([[0,0.5],[8**0.5,8**0.5+0.5],[0,3.5],[np.sqrt(15),1.5]]) # give the physical restriction (radius array) here. point_radius_array = np.array([2.5,1.0,1.0,1.0]) # create the delaunay trimesh and voronoi diagram for the given points here. point_trimesh = scipy.spatial.Delaunay(point_coordinate_array) point_voronoi = scipy.spatial.Voronoi(point_coordinate_array) # show the results using matplotlib. # do the matplotlib setting here. fig_width = 8.0; fig_length = 8.0 mpl.rc('figure', figsize=((fig_width * 0.3937), (fig_length * 0.3937)), dpi=300) mpl.rc('axes', linewidth=0.0, edgecolor='red', labelsize=7.5, labelcolor='black', grid=0) mpl.rc('xtick.major', size=0.0, width=0.0, pad=0) mpl.rc('xtick.minor', size=0.0, width=0.0, pad=0) mpl.rc('ytick.major', size=0.0, width=0.0, pad=0) mpl.rc('ytick.minor', size=0.0, width=0.0, pad=0) mpl.rc('figure.subplot', left=0.0, right=1.0, bottom=0.065, top=0.995) mpl.rc('savefig', dpi=300) ax_1 = plt.figure().add_subplot(1, 1, 1) plt.gca().set_aspect('equal') ax_1.set_xlim(5.5, 8.5) ax_1.set_ylim(4.5, 7.5) ax_1.set_xticklabels([]) ax_1.set_yticklabels([]) # plot all the given points and vertices here. ax_1.scatter(point_coordinate_array[:,0],point_coordinate_array[:,1], s=7.0,c='black') ax_1.scatter(point_voronoi.vertices[:,0],point_voronoi.vertices[:,1], s=7.0,c='blue') # plot the delaunay trimesh here. ax_1.triplot(point_trimesh.points[:,0],point_trimesh.points[:,1], point_trimesh.vertices, linestyle='',dashes=[2.0]*4,color='green',lw=0.5) # plot the voronoi cell here.(only the closed one) ax_1.plot(point_voronoi.vertices[:,0],point_voronoi.vertices[:,1], lw=1.0,color='blue') ax_1.plot([point_voronoi.vertices[1][0],point_voronoi.vertices[0][0]], [point_voronoi.vertices[1][1],point_voronoi.vertices[0][1]], lw=1.0,color='blue') # plot all the particles here.(point+radius) patches1 = [Circle(point_coordinate_array[i], point_radius_array[i]) for i in range(len(point_radius_array))] ax_1.add_collection(PatchCollection(patches1, linewidths=1.0, edgecolor='black', facecolors='none', alpha=1.0)) # save the .png file. plt.savefig('Fig_a.png',dpi=300) plt.close()

Iterate over pixels along a rasterized circular arc
I want to iterate over pixels along a rasterized circular arc, given its radius, start and end angles in radians, eg:
template<typename Functor> void arc(float startRadians, float endRadians, int radius, Functor f);
To be used like:
arc(0.f, M_PI, 10, [](int x, int y) { std::cout << "got: " << x << " " << y << "\n"; });
There's a few catches:
 pixels have integer coordinates
radius
is also given as an integer the rasterised arc is effectively every pixel in a sector between the arc of radius
radius
and the arc of radiusradius1
In the picture below:
 blue pixels have been visited, red pixel is the next to be visited
 the arc is confined by the two radial lines defined by start/end angles, and the sector between the two arcs
radius
,radius1
.  finally, if every arc with radius 0 to 100 were to be drawn, angles 0 to 2*PI, then we'd get a filled disc/circle of radius 100 and no pixel would be visited twice.
I think Bresenham's circle algorithm doesn't directly apply to this problem, because of the angle constraints and visitation order.
In stackoverflow, I believe this is the most closely related question:
Finally, OpenCV has something similar/related in spirit, but only for lines: