Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- data1 = open('Training_wells.csv').read().split('\n')
- data2 = open('Empty_part.csv').read().split('\n')
- del data1[-1]
- del data2[-1]
- n1 = len(data1)
- n2 = len(data2)
- xs1 = []
- ys1 = []
- vals1 = []
- points1 = []
- for i in range(1, n1):
- line = data1[i].split(',')
- x, y, val = line[1], line[2], line[3]
- x, y, val = int(x), int(y), float(val)
- xs1.append(x)
- ys1.append(y)
- vals1.append(val)
- points1.append((x, y, val))
- xs2 = []
- ys2 = []
- vals2 = []
- points2 = []
- for i in range(1, n2):
- line = data2[i].split(',')
- x, y = line[1], line[2]
- val = 0
- x, y, val = int(x), int(y), float(val)
- xs2.append(x)
- ys2.append(y)
- vals2.append(val)
- points2.append((x, y, val))
- 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))
- for i in range(len(points1)):
- x, y, val = points1[i]
- x -= min_x
- y -= min_y
- points1[i] = (x, y, val)
- for i in range(len(points2)):
- x, y, val = points2[i]
- x -= min_x
- y -= min_y
- points2[i] = (x, y, val)
- 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))
- n = max_x - min_x + 1
- m = max_y - min_y + 1
- print(min_x, max_x, min_y, max_y)
- print(min(vals1), max(vals1))
- image = Image.new('RGB', (n, m))
- pixel_map = image.load()
- for x in range(n):
- for y in range(m):
- pixel_map[x, y] = (255, 255, 255)
- values = [[0 for y in range(m)] for x in range(n)]
- for (x, y, val) in points1:
- pixel_map[x, y] = (0, int(255 * val), 0)
- values[x][y] = val
- deltas = []
- for (x, y, val) in points2:
- pixel_map[x, y] = (255, 0, 0)
- k = min(800 // n, 800 // m)
- image.resize((n * k, m * k), resample=Image.BOX).show()
- # f(x, y) = sum(a[i][j] * x ** i * y ** j for i in range(n) for j in range(m)) = z
- # n, m
- # 0 <= f(x, y) <= 1
- # 1 <= n == m, n + m == 40
- # f(x, y) == value 138th times
- from random import random
- from math import *
- def generate(n, m, values):
- N = 4
- a = [[random() for y in range(N)] for x in range(N)]
- def relax(a, x, y, value):
- return a
- for itr in range(50):
- for x, y, value in values:
- a = relax(a, x, y, value)
- result = [[0 for y in range(m)] for x in range(n)]
- for x in range(n):
- for y in range(m):
- for i in range(N):
- for j in range(N):
- result[x][y] += a[i][j] * x ** i * y ** j
- return result
- def apply_to_pixel_map_and_show(res):
- n = len(res)
- m = len(res[0])
- img = Image.new('RGB', (n, m))
- pm = img.load()
- for x in range(n):
- for y in range(m):
- val = int(255 * res[x][y]) & 255
- print(val, end = ' ')
- pm[x, y] = (val, val, 0)
- print()
- img.resize((n * k, m * k), resample=Image.BOX).show()
- apply_to_pixel_map_and_show(values)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement