Skip to content

Instantly share code, notes, and snippets.

# how to pool processes for arima
# given chunked data from data_chunker.py
# https://gist.github.com/justinhchae/13d246e8e2e2d521a8d2cce20eb09a09
# given arima function from run_arima.py
# https://gist.github.com/justinhchae/d2a2dc8b71b5f5fbbb0f7eabf68b6850
# dependencies
from tqdm import tqdm
from fbprophet import Prophet
import pandas as pd
import os
# https://stackoverflow.com/questions/2125702/how-to-suppress-console-output-in-python
# https://medium.com/spikelab/forecasting-multiples-time-series-using-prophet-in-parallel-2515abd1a245
# https://facebook.github.io/prophet/docs/quick_start.html#python-api
class suppress_stdout_stderr(object):
# how to pool processes for prophet
# given chunked data from data_chunker.py
# https://gist.github.com/justinhchae/13d246e8e2e2d521a8d2cce20eb09a09
# given prophet function wrapper
# https://gist.github.com/justinhchae/8ef78743f13f50051ad1aca2106eaa1a
# dependencies
from tqdm import tqdm
@justinhchae
justinhchae / fc.py
Last active March 4, 2021 22:06
A do nothing functio to demonstrate a function call to a function that does a progress bar with tqdm.
# solution reference:
# https://stackoverflow.com/questions/41707229/tqdm-printing-to-newline
def fc(x, param):
# inject some waiting to see progress unfold
time.sleep(1)
# set up pbar
pbar = tqdm(x.items(), desc='Exp:', position=0)
# init a variable for output
yhat = 0
@justinhchae
justinhchae / main.py
Created March 4, 2021 22:05
A made up function that calls another function to demonstrate multiprocessing with tqdm progress bar.
# given a function from fc.py
# https://gist.github.com/justinhchae/a2efee420330a985286e7b88fd049ce5
# in a file called main.py
import pandas as pd
# using the pytorch version of mp
import torch.multiprocessing as mp
# we need partial
from functools import partial
# progress bar
@justinhchae
justinhchae / config.py
Created March 14, 2021 17:49
schema generator for alchemy
def get_vars_main(filename):
"""
a helper function for creating the code for the main table of an sql alchemy schema
bases on a csv file, extract necessary column names and tables and print the code to terminal
copy and paste the code into the schema section
"""
logging.info('get_vars_main() Producing code to make main data table in alchemy.')
class_name = f'class {db_table_name.title()}({db_class_name}):'
full_path = os.sep.join([data_folder, filename])
@justinhchae
justinhchae / sample_schema.py
Created March 14, 2021 17:53
sample_schema.py
class Budget2021(BudgetDB.base):
__tablename__ = "budget2021"
# uncomment the following line to print out this class as text
# df = get_vars_main('budget_main.csv')
id = Column(Integer, primary_key=True)
fund_type = Column(String)
# the code is a value like 4355 that means "Department A" -> F key to the table the name of the dept.
department_code = Column(Integer, ForeignKey("departmentDescription.department_code"))
fund_code = Column(String, ForeignKey("fundDescription.fund_code"))
organization_code = Column(Integer)
@justinhchae
justinhchae / Numpy4PointClouds.py
Created May 3, 2022 23:25
A simple working example of how to use compressed numpy storage for data such as point clouds and classes.
'''https://numpy.org/doc/stable/reference/generated/numpy.savez_compressed.html#numpy.savez_compressed
'''
import numpy as np
import os
# number of points in the point cloud
num_points = 10
@justinhchae
justinhchae / install_import_pytorch3d_high_precision.py
Last active June 22, 2023 13:44
Example Install and Import for Esri PyTorch3D Fork
# install direct from our forked repository: https://github.com/Esri/pytorch3d/tree/multitexture-obj-high-precision
!pip install 'git+https://github.com/Esri/pytorch3d.git@multitexture-obj-high-precision'
# import the forked pytorch3d library and new functions
from pytorch3d.io import load_obj
from pytorch3d.ops import sample_points_from_obj
from pytorch3d.io import subset_obj, save_obj
@justinhchae
justinhchae / load_obj_pytorch3d_high_precision.py
Last active June 22, 2023 03:49
Example Usage for PyTorch3D Load Obj with High Precision
# install direct from our forked repository: https://github.com/Esri/pytorch3d/tree/multitexture-obj-high-precision
!pip install 'git+https://github.com/Esri/pytorch3d.git@multitexture-obj-high-precision'
from pytorch3d.io import load_obj
# the current pytorch3d API for load_obj
obj = load_obj(
path_to_obj_file,
load_textures=True,
)