999ms

Untitled

Feb 24th, 2021
743
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from PIL import Image
  2.  
  3. data1 = open('Training_wells.csv').read().split('\n')
  4. data2 = open('Empty_part.csv').read().split('\n')
  5. del data1[-1]
  6. del data2[-1]
  7.  
  8. n1 = len(data1)
  9. n2 = len(data2)
  10. xs1 = []
  11. ys1 = []
  12. vals1 = []
  13. points1 = []
  14. for i in range(1, n1):
  15.     line = data1[i].split(',')
  16.     x, y, val = line[1], line[2], line[3]
  17.     x, y, val = int(x), int(y), float(val)
  18.     xs1.append(x)
  19.     ys1.append(y)
  20.     vals1.append(val)
  21.     points1.append((x, y, val))
  22.  
  23. xs2 = []
  24. ys2 = []
  25. vals2 = []
  26. points2 = []
  27. for i in range(1, n2):
  28.     line = data2[i].split(',')
  29.     x, y = line[1], line[2]
  30.     val = 0
  31.     x, y, val = int(x), int(y), float(val)
  32.     xs2.append(x)
  33.     ys2.append(y)
  34.     vals2.append(val)
  35.     points2.append((x, y, val))
  36.    
  37.    
  38. min_x, max_x, min_y, max_y = min(min(xs1), min(xs2)), max(max(xs1), max(xs2)), min(min(ys1), min(ys2)), max(max(ys1), max(ys2))
  39.  
  40. for i in range(len(points1)):
  41.     x, y, val = points1[i]
  42.     x -= min_x
  43.     y -= min_y
  44.     points1[i] = (x, y, val)
  45.    
  46. for i in range(len(points2)):
  47.     x, y, val = points2[i]
  48.     x -= min_x
  49.     y -= min_y
  50.     points2[i] = (x, y, val)
  51.  
  52. min_x, max_x, min_y, max_y = min(min(xs1), min(xs2)), max(max(xs1), max(xs2)), min(min(ys1), min(ys2)), max(max(ys1), max(ys2))
  53.  
  54.  
  55. n = max_x - min_x + 1
  56. m = max_y - min_y + 1
  57. print(min_x, max_x, min_y, max_y)
  58. print(min(vals1), max(vals1))
  59. image = Image.new('RGB', (n, m))
  60. pixel_map = image.load()
  61. for x in range(n):
  62.     for y in range(m):
  63.         pixel_map[x, y] = (255, 255, 255)
  64.  
  65. values = [[0 for y in range(m)] for x in range(n)]
  66. for (x, y, val) in points1:
  67.     pixel_map[x, y] = (0, int(255 * val), 0)
  68.     values[x][y] = val
  69.    
  70. deltas = []
  71. for (x, y, val) in points2:
  72.     pixel_map[x, y] = (255, 0, 0)
  73.  
  74. k = min(800 // n, 800 // m)
  75. image.resize((n * k, m * k), resample=Image.BOX).show()
  76.  
  77.  
  78. # f(x, y) = sum(a[i][j] * x ** i * y ** j for i in range(n) for j in range(m)) = z
  79. # n, m
  80. # 0 <= f(x, y) <= 1
  81. # 1 <= n == m, n + m == 40
  82. # f(x, y) == value 138th times
  83. from random import random
  84. from math import *
  85.  
  86. def generate(n, m, values):
  87.     N = 4
  88.    
  89.     a = [[random() for y in range(N)] for x in range(N)]
  90.  
  91.     def relax(a, x, y, value):
  92.        
  93.         return a
  94.    
  95.     for itr in range(50):
  96.         for x, y, value in values:
  97.             a = relax(a, x, y, value)
  98.     result = [[0 for y in range(m)] for x in range(n)]
  99.  
  100.     for x in range(n):
  101.         for y in range(m):
  102.             for i in range(N):
  103.                 for j in range(N):
  104.                     result[x][y] += a[i][j] * x ** i * y ** j
  105.     return result
  106.  
  107.  
  108. def apply_to_pixel_map_and_show(res):
  109.     n = len(res)
  110.     m = len(res[0])
  111.     img = Image.new('RGB', (n, m))
  112.     pm = img.load()
  113.     for x in range(n):
  114.         for y in range(m):
  115.             val = int(255 * res[x][y]) & 255
  116.             print(val, end = ' ')
  117.             pm[x, y] = (val, val, 0)
  118.     print()
  119.     img.resize((n * k, m * k), resample=Image.BOX).show()
  120.    
  121. apply_to_pixel_map_and_show(values)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×