Skip to content

Instantly share code, notes, and snippets.

View bhishanpdl's full-sized avatar

Bhishan Poudel bhishanpdl

View GitHub Profile
@bhishanpdl
bhishanpdl / gist_scatter_plot.py
Last active August 28, 2018 19:56
Plotting #plot #matplotlib
# Imports
from __future__ import print_function, division,with_statement
import sys
import numpy as np
import matplotlib.pyplot as plt
import os
args = sys.argv[1]
ifile, c0, c1 = args.split(' ')
c0 = int(c0)
@bhishanpdl
bhishanpdl / ipython_pandas_display.py
Last active August 28, 2018 19:58
Display multiple dataframes in ipython #ipython
import numpy as np
import pandas as pd
class display(object):
"""Display HTML representation of multiple objects
Usage: display('df', "df.groupby('key').std()")
"""
template = """<div style="float: left; padding: 10px;">
<p style='font-family:"Courier New", Courier, monospace'>{0}</p>{1}
</div>"""
@bhishanpdl
bhishanpdl / ipydisplay.py
Last active August 28, 2018 19:57
[ipython display function] # ipython
import pandas as pd
import numpy as np
class display(object):
"""Display HTML representation of multiple objects"""
template = """<div style="float: left; padding: 10px;">
<p style='font-family:"Courier New", Courier, monospace'>{0}</p>{1}
</div>"""
def __init__(self, *args):
self.args = args
@bhishanpdl
bhishanpdl / plot_dmstack_four_text_files.py
Created August 28, 2018 16:53
Plot src.csv files obtained from obs_file module for
# %%writefile compare_plots_for_txt_with_comment_head.py
# Plot the files
# Date: Jul 10, 2018
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import os,sys,argparse
import glob
"""
@bhishanpdl
bhishanpdl / dmstack_parameters.md
Last active August 28, 2018 19:46
[DMSTACK parameters] dmstack parameters from obs_file #dmstack #obs_file

The DMSTACK module obs_file will ingest a cluster fitsfile and do the CCD processing to give the fits table output src.fits with 77 parameters.

id (0)                                       coord_ra (1)
coord_dec (2)                                parent (3)                                   
deblend_nChild  (4)                          deblend_psfCenter_x (5)
deblend_psfCenter_y (6)                      deblend_psfFlux (7)                          
base_GaussianCentroid_x (8)                  base_GaussianCentroid_y (9)                  
base_NaiveCentroid_x  (10)                   base_NaiveCentroid_y (11)
@bhishanpdl
bhishanpdl / click_sub_menu.applescript
Last active August 29, 2018 00:53
[Applescript to activate second google chrome] #applescript
tell application "System Events" to tell process "Google Chrome"
perform action "AXRaise" of window 2
set frontmost to true
end tell
@bhishanpdl
bhishanpdl / utility_function_assert.py
Created August 29, 2018 12:12
[utility function assert] #assert
def norm_scale(X, axis=0):
mx = np.max(X, axis=axis)
mi = np.min(X, axis=axis)
epsilon = 10**-32
return (X — mi) / (np.abs(mi) + mx + epsilon)
norm = norm_scale(X)
assert np.min(norm) >= 0
assert np.max(norm) <= 1
@bhishanpdl
bhishanpdl / ipython_memory_cache.py
Created August 29, 2018 12:13
[ipython_memory_cache] #ipython #memory #cache
from sklearn.externals.joblib import Memory
memory = Memory(cachedir='/tmp', verbose=0)
@memory.cache
def computation(p1, p2):
return p1 * p2
# example 2
@bhishanpdl
bhishanpdl / ipython_interactive_all.py
Created August 29, 2018 12:14
[ipython_interactive_all] #ipython
from IPython.core.interactiveshell import InteractiveShell
# pretty print all cell's output and not just the last one
InteractiveShell.ast_node_interactivity = "all"
# pretty print only the last output of the cell
# InteractiveShell.ast_node_interactivity = "last_expr"