Skip to content

Instantly share code, notes, and snippets.

View ipashchenko's full-sized avatar

Ilya ipashchenko

  • LPI ASC
View GitHub Profile
@ipashchenko
ipashchenko / one-hot.py
Created May 7, 2017 06:03 — forked from ramhiser/one-hot.py
Apply one-hot encoding to a pandas DataFrame
import pandas as pd
import numpy as np
from sklearn.feature_extraction import DictVectorizer
def encode_onehot(df, cols):
"""
One-hot encoding is applied to columns specified in a pandas DataFrame.
Modified from: https://gist.github.com/kljensen/5452382
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
def model1(x, k):
return k * x
def model2(x, k, a):
return k * x + x * np.sin(a * x)
import os
import json
import time
import numpy as np
import scipy as sp
import corner
from uv_data import UVData
from spydiff import import_difmap_model
from model import Model
from stats import LnLikelihood
def create_mask(shape, region):
"""
Function that creates rectangular or circular or elliptic gaussian mask.
:param shape:
Shape of the image.
:param region:
Tuple (blc[0], blc[1], trc[0], trc[1],) or (center[0], center[1], r,
None,) or (center[0], center[1], bmaj, e, bpa). Where ``bpa`` [rad].
from cfx import CFX
from utils import find_file
from raw_data import M5
cfx_file = '/home/ilya/code/frb/data/cfx/RADIOASTRON_RAKS12ER_L_20151105T130000_ASC_V1.cfx'
cfx = CFX(cfx_file)
cfx_data = cfx.parse_cfx('raks12er')
fname = 'rk12er_tr_no0001'
params = cfx_data[fname]
@ipashchenko
ipashchenko / final_clean_nw
Created November 10, 2015 14:48
Dan Homan's difmap CLEAN script
! final_clean_rms -- revised version of old 'final_clean' script
!
! Version: 2011_05_09
! Change Log:
! 2011_05_09 - limit maximum clean iter in natural clean to 500
!
! Script revised -- May 2011 by D. Homan to improve stopping
! criteria and not overclean images. See 'deep_map_residual'
! macro below for how this works in detail. The idea is to
! compare the residual map rms in the frame to a target RMS which
@ipashchenko
ipashchenko / clean_difmap.py
Created November 10, 2015 14:46
Using difmap's CLEAN from python
def clean_difmap(fname, outfname, stokes, mapsize_clean, path=None,
path_to_script=None, mapsize_restore=None, beam_restore=None,
outpath=None, shift=None, show_difmap_output=False):
"""
Map self-calibrated uv-data in difmap.
:param fname:
Filename of uv-data to clean.
:param outfname:
Filename with CCs.
@ipashchenko
ipashchenko / core_sims.py
Created October 19, 2015 19:50
script for core shif simulation
import os
import numpy as np
from components import CGComponent, EGComponent
from from_fits import (create_uvdata_from_fits_file,
create_image_from_fits_file,
create_clean_image_from_fits_file)
from model import Model
from spydiff import clean_difmap
from data_io import get_fits_image_info
from utils import mas_to_rad, degree_to_rad
from collections import OrderedDict, Callable
class DefaultOrderedDict(OrderedDict):
# Source: http://stackoverflow.com/a/6190500/562769
def __init__(self, default_factory=None, *a, **kw):
if (default_factory is not None and
not isinstance(default_factory, Callable)):
raise TypeError('first argument must be callable')
OrderedDict.__init__(self, *a, **kw)
self.default_factory = default_factory
@ipashchenko
ipashchenko / de_dispersion.py
Created July 19, 2015 12:44
De-dispersion using cumulative sums of dynamical spectra
import numpy as np
vint = np.vectorize(int)
vround = np.vectorize(round)
def de_disperse(image, nu_0, d_nu, d_t, dm_values):
"""
De-disperse dynamical spestra with grid of user specifies values of DM.