This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ogr | |
__author__ = 'Jwely' | |
class Shape: | |
""" | |
Helps read data from shapefiles with ogr | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# quick overview of function definitions and function calls. | |
import some_module | |
# this below is a function definition, use it to generalize code to repeatedly do something. | |
# dnppy is full of function definitions | |
def my_function(argument1, argument2, default_argument3="some_default_string") | |
""" | |
this is a function DEFINITION , and this docstring should tell you | |
something about how it works. This docstring will be displayed if someone |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'Jwely' | |
import numpy | |
# in order to handle Nodata values, we must use floats, not integer datatypes. | |
array = numpy.array([0, 5, 6, 3, 0, 11, 5, 2, 3, 6, 4, 1, 2, 5, 12], "float32") | |
# mask this array, where all "0" values are masked | |
# see also: https://docs.scipy.org/doc/numpy/reference/maskedarray.generic.html | |
masked_array = numpy.ma.masked_equal(array, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# in the input expression | |
#from osgeo import gdal, gdalconst, gdalnumeric | |
import gdal | |
import gdalconst | |
import gdalnumeric | |
import numpy | |
import os | |
import math # imported so it is available to the users expression evaluation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# super barebones list to csv | |
list = ["some", "kind", "of", "data"] | |
with open("myfile.csv", "w+") as f: | |
for item in list: | |
f.write(str(item) + "\n") | |
# same deal but with lists of lists | |
list_of_lists = [["bob", "20"], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'Jwely' | |
class Butt(): | |
def __init__(self): | |
self.times_farted = 0 | |
def fart(self, times): | |
self.times_farted += times |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ftplib | |
import os | |
import re | |
""" | |
MIT license: 2017 - Jwely | |
Example usage: | |
``` python | |
import ftplib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
class AmbiguousArgs(BaseException): | |
pass | |
def remove_png_alpha(image_path, overwrite=False, color=(255, 255, 255), out_path=None): | |
""" | |
Removes the alpha layer form an input png (probably works with other filetypes as well) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from queue import Queue | |
import threading | |
import os | |
from datetime import datetime | |
import time | |
def updater(): | |
for i in range(10): | |
time.sleep(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from contextlib import contextmanager | |
@contextmanager | |
def manage_something(something): | |
""" this is the general structure of a contextmanager """ | |
try: | |
# prepare the something | |
yield something | |
except Exception as e: |
OlderNewer