Skip to content

Instantly share code, notes, and snippets.

View rcgalbo's full-sized avatar

Rick Galbo rcgalbo

View GitHub Profile
import matplotlib.pyplot as plt
import numpy as np
# set seed for reproduceable
np.random.seed(123)
ind = np.arange(1, 40_001)
x = np.random.random(40_000)
y = np.random.random(40_000)
radius = (x**2 + y**2)**.5
@rcgalbo
rcgalbo / selector_heatmap.py
Created October 4, 2019 01:02 — forked from mandieq/selector_heatmap.py
Heatmap example - python / dash
import plotly.plotly as py
import plotly.graph_objs as go
import plotly.figure_factory as ff
import plotly.offline as offline
import pandas as pd
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
@rcgalbo
rcgalbo / convert_pdf_image.py
Last active August 24, 2018 14:18
convert a pdf file to an image
from pdf2image import convert_from_path
image = convert_from_path("path_to_pdf.pdf")
@rcgalbo
rcgalbo / cols_to_datetime.py
Last active August 22, 2018 15:50
Converting list of columns to date time
def convert_to_datetime(df, columns):
return df[columns].apply(pd.to_datetime, axis=1)
@rcgalbo
rcgalbo / list_blobs.py
Last active August 21, 2018 18:23
list the contents of a gcs bucket
from google.cloud import storage
def list_blobs(bucket, prefix):
"""
Lists all the blobs in the bucket
make sure prefix ends with '/'
"""
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket)
@rcgalbo
rcgalbo / structure_keras_dir.py
Created August 8, 2018 14:20
move images into sub directories for keras ImageDataGenerator
import os
with open('../data/labels.csv','r') as labels:
lines = [line.split(',') for line in labels.readlines()][1:]
for line in lines:
image = line[0]
label = line[1].split('/')[-1].replace('\n','')
if not os.path.exists('../data/train/'+label):
os.mkdir('../data/train/'+label)
os.rename('../data/train/'+image+'.jpg', '../data/train/'+label+'/'+image+'.jpg')
@rcgalbo
rcgalbo / ploy_heatmap.py
Created July 25, 2018 21:50
Plotting an interactive heatmap of lat, long
import folium
def plot_heatmap(data):
'''
Args:
takes a list of lists [[lat, long]]
Returns:
Folium map object with heatmap overlay
'''
heatmap = folium.Map(tiles="CartoDBpositron", prefer_canvas=True)
@rcgalbo
rcgalbo / install_jupyter.txt
Last active August 30, 2018 16:17
Install conda package in jupyter notebook into environment
import sys
!conda install --yes --prefix={sys.prefix} numpy
@rcgalbo
rcgalbo / condaenv.txt
Created April 16, 2018 14:51 — forked from pratos/condaenv.txt
To package a conda environment (Requirement.txt and virtual environment)
# For Windows users# Note: <> denotes changes to be made
#Create a conda environment
conda create --name <environment-name> python=<version:2.7/3.5>
#To create a requirements.txt file:
conda list #Gives you list of packages used for the environment
conda list -e > requirements.txt #Save all the info about packages to your folder
@rcgalbo
rcgalbo / pytorch_keras_gcloud.txt
Created April 12, 2018 15:21 — forked from motiur/pytorch_keras_gcloud.txt
Keras and Pytorch in Google Cloud VM
# This script is designed to work with ubuntu 16.04 LTS
# with keras 1.2.2 and the latest Pytorch with CUDA 8 support
##########################################################################
#This is used to install CUDA 8 driver for Tesla K80
##########################################################################
#!/bin/bash
echo "Checking for CUDA and installing."
# Check for CUDA and try to install.
if ! dpkg-query -W cuda-8-0; then