In [1]:
%pylab inline

import pandas as pd

import csv

import shapely.affinity as af
# import shapely.geometry as sh

from scipy.optimize import fsolve, basinhopping

from equivalent_ellipse import *

from scaled_figures import *


Populating the interactive namespace from numpy and matplotlib

In [2]:
x_list = list()
y_list = list()

with open('../data/cutout_x.csv', 'r') as x_csvfile:
    with open('../data/cutout_y.csv', 'r') as y_csvfile:
        
        x_reader = csv.reader(x_csvfile, delimiter=',', lineterminator='\n')
        y_reader = csv.reader(y_csvfile, delimiter=',', lineterminator='\n')
        
        for row in x_reader:
            x_list += [row]
  
        for row in y_reader:
            y_list += [row]

In [3]:
x_array = list()
y_array = list()

for i in range(len(x_list)):

    x_array += [array(x_list[i], dtype='float')]
    y_array += [array(y_list[i], dtype='float')]

In [4]:
cutout = shapely_cutout(x_array[0],y_array[0])
#cutout

In [13]:
output = eq_ellipse_calc(cutout,3,10)


success at: [a,b] = [0.0718, -0.7461], [width, length] = [6.3799, 7.4510], theta = 4.0079
success at: [a,b] = [0.0718, -0.7461], [width, length] = [6.3799, 7.4510], theta = 4.0079
success at: [a,b] = [0.0718, -0.7461], [width, length] = [6.3799, 7.4510], theta = 4.0079
success at: [a,b] = [0.0718, -0.7461], [width, length] = [6.3799, 7.4510], theta = 4.0079
success at: [a,b] = [0.0718, -0.7461], [width, length] = [6.3799, 7.4510], theta = 4.0079
success at: [a,b] = [0.0718, -0.7461], [width, length] = [6.3799, 7.4510], theta = 4.0079
success at: [a,b] = [0.0718, -0.7461], [width, length] = [6.3799, 7.4510], theta = 4.0079
success at: [a,b] = [0.0718, -0.7461], [width, length] = [6.3799, 7.4510], theta = 4.0078
success at: [a,b] = [0.0718, -0.7461], [width, length] = [6.3799, 7.4510], theta = 4.0080
success at: [a,b] = [0.0718, -0.7461], [width, length] = [6.3799, 7.4510], theta = 4.0081

In [6]:
a = output.x[0]
b = output.x[1]

if (output.x[3] > output.x[2]):
    width = output.x[2]
    length = output.x[3]
    theta = mod(output.x[4],360)
else:
    width = output.x[3]
    length = output.x[2]
    theta = mod(output.x[4]+90,180)

In [7]:
ellipse = create_ellipse(output.x)
#ellipse

In [8]:
scaled_fig_start(12,12)

plot(cutout.exterior.xy[0],cutout.exterior.xy[1])
plot(ellipse.exterior.xy[0],ellipse.exterior.xy[1],'r')

plot(ellipse.centroid.xy[0],ellipse.centroid.xy[1],'go')

scaled_fig_end(12,12)



In [9]:
sh.box(*cutout.bounds).difference(cutout)


Out[9]:

In [10]:
boxBound = max(array([cutout.bounds[2]-cutout.bounds[0],cutout.bounds[3]-cutout.bounds[1]]))
boxBound


Out[10]:
7.3000000000000007

In [11]:
# x_list_optimised = x_list
# y_list_optimised = y_list

In [12]:
# with open('../data/cutout_width.csv', 'w') as cutout_width:
#     with open('../data/cutout_length.csv', 'w') as cutout_length:
#         with open('../data/cutout_box_bound.csv', 'w') as cutout_box_bound:
        
#             x_writer = csv.writer(x_csvfile, delimiter=',', lineterminator='\n')
#             y_writer = csv.writer(y_csvfile, delimiter=',', lineterminator='\n')


#             for i in range(len(x_list_optimised)):

#                 x_writer.writerow(x_list_optimised[i])
#                 y_writer.writerow(y_list_optimised[i])