Sunday, September 9, 2018

Sunday Funday - Code Kata - MS Paint program

Code Kata is a quick software challenge you can do to warm up your brain.  You are only supposed to work on the challenge for 30 minutes or less.  If you need more time, continue the challenge the next day.  I wanted to make a drawing program with an old school spray paint brush like MS paint.  I made one in less than 30 minutes and 50 lines of code (including white space and comments).  

I loved MS Paint.  I thought I was going to be an online artist using it.  But then I quickly found out its limitations (and my own).  The spray can only let you have one color.  I wanted 3 or more all mixed together for better blending.  So that is the focus of my code kata today.

I picked out three colors in the same spectrum that blended well.  Then every time I click and hole it starts adding dots in random points around my mouse.  The slower I drag my mouse the denser the dots like a spray can.  

Try out making up your own code kata, this one or send me your ideas.  I'll try them out as well!

Aaaaaannnnnd some source code.  I made the paint dots 4 pixels wide and my spray brush 32 coverage 32 pixels.  Copy and paste this into your own python file.

# Have a paintbrush you can control with your mouse that sprays like the old
# MS Paint spray paint brush.  But instead of one color, use three different
# colors all at once.  That way there is no dominant color.  This will help
# blend colors together.

from tkinter import *
import random

class View:

    def __init__(self, master):
        self.root = master
        self.frame = Frame(self.root, width = 800, height = 800)
        self.canvas = Canvas(self.frame, width = 800, height = 800)
        self.colors = [ '#113d84', '#68768e', '#609bff' ]  # blues
        self.brush_size = 16 = 2
        self.num = len(self.colors) * 3
        self.draw = False
        self.canvas.bind('', self.mouse_button_1_click)
        self.canvas.bind('', self.mouse_button_1_release)
        self.canvas.bind('', self.mouse_button_1_motion)
        self.root.bind('', self.key_pressed)
    def add_points(self, x, y):
        for i in range(0, self.num):
            x1 = random.randint(-self.brush_size, self.brush_size) + x
            y1 = random.randint(-self.brush_size, self.brush_size) + y
            self.canvas.create_oval(,,,, outline = self.colors[i%3], fill = self.colors[i%3], tags = 'dot')
    def mouse_button_1_click(self, event):
        self.add_points(event.x, event.y)
    def mouse_button_1_motion(self, event):
        if self.draw == True:
            self.add_points(event.x, event.y)

    def mouse_button_1_release(self, event):
        self.draw = False

    def key_pressed(self, event):
        if key == 'R':

master = Tk()
view = View(master)

Thursday, August 23, 2018

Log Viewer Update - depth shifting

The last year I've primarily focused on Reservoir Engineering instead of Petrophysics and Geology.  I've lacked in my documentation of new software development but fully intend of showing off different techniques for production decline interpretation in later posts.  This post highlights a small feature I added to my Log Viewer where I can do a single linear depth shift to a curve.  Curves can be off depth straight from the logging engineer or, more likely, off depth because they were digitized from raster logs.  Getting curves on depth is crucial before running any calculations.  

There is another kind of depth shift I need to incorporate.  This would be a non-linear stretch and squeeze.  This would be due to a logging tool having a stick and pull making curves off depth from each other.  As the math is slightly harder and I don't run across this very often I omitted this update for the time being.  

Below I've produced some snapshots from my test well where I depth shift the neutron porosity curve.  This isn't any ground breaking new idea by any means.  Just documenting new functionality.  

Let's start off with my Roswell, New Mexico test well.

I added a menu for depth shifting and the first thing it does is ask which curve you would like to shift.  

After I pick my curve I click my marker where I want to start shifting (orange horizontal line) and the second click is where I want to move it to (green horizontal line).  In this instance I want my neutron porosity to move up 50' to be in line with the inflections from my bulk density.  

I (intentionally) missed my mark and need to move my green line down some, so I  merely click and drag it down the green line.  My intermediate changes are seen by a grey line that is interactive with the motion of the mouse.  

When I let got of the mouse button I can see the lines are just as I would like them.  

I right click to save changes.  And BOOM!  Now I can run calculations.  

My original curve is still there.  The data is backed up to a new curve called NPHI_N_ORIG.  

Well that's all for today folks.  I hope everyone has had a pleasurable summer.