SHARE
TWEET

Delta No Threading

distrtedpuppy Dec 13th, 2016 (edited) 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import mysql.connector
  2. import numpy as np
  3. from colormath.color_objects import LabColor
  4. from colormath.color_diff import delta_e_cie2000
  5. import pandas as pd
  6.  
  7. cnx = mysql.connector.connect(user='user', password='pass', host='localhost', database='database')
  8. cursor = cnx.cursor()
  9.  
  10. def delta(cie_Lab1, cie_Lab2):
  11.     cie_Lab1 = cie_Lab1[1:]
  12.     cie_Lab1 = cie_Lab1[:-1]
  13.     cie_Lab2 = cie_Lab2[1:]
  14.     cie_Lab2 = cie_Lab2[:-1]
  15.     CIE_list1 = cie_Lab1.split(",")
  16.     CIE_list2 = cie_Lab2.split(",")
  17.     #print CIE_list1
  18.     CIE_L1 = CIE_list1[0]
  19.     CIE_a1 = CIE_list1[1]
  20.     CIE_b1 = CIE_list1[2]
  21.     CIE_L2 = CIE_list2[0]
  22.     CIE_a2 = CIE_list2[1]
  23.     CIE_b2 = CIE_list2[2]
  24.     color1 = LabColor(lab_l=CIE_L1, lab_a=CIE_a1, lab_b=CIE_b1)
  25.     color2 = LabColor(lab_l=CIE_L2, lab_a=CIE_a2, lab_b=CIE_b2)
  26.     deltae = delta_e_cie2000(color1, color2, Kl=1, Kc=1, Kh=1)
  27.     return deltae
  28.  
  29.  
  30.  
  31. selectstmt = 'SELECT CIE_Lab, ID FROM `database`.`table` LIMIT 1000'
  32. cursor.execute(selectstmt)
  33. color = cursor.fetchall()
  34.  
  35. df = pd.DataFrame(columns = color, index = color)
  36. headers = df.dtypes.index
  37. sides = df.index
  38. print headers[1][0]
  39. print sides[0][0]
  40. nums = df.shape[0]
  41. for num in range(nums):
  42.     for mun in range(nums):
  43.         df.ix[mun][num] = delta(headers[num][0], sides[mun][0])
  44. print df
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top