suncasa.utils.DButil

Attributes

__author__

__email__

Classes

ButtonsPlayCTRL

Produce A play/stop button widget for bokeh plot

Functions

img2html_movie(imgprefix[, outname, img_fmt])

my_timer(orig_func)

spectrogram2wav(spec[, threshld, gama, fs, t_length, ...])

Convert spectrogram to audio in WAV format

smooth(x[, window_len, window])

smooth the data using a window with requested size.

img2movie([imgprefix, img_ext, outname, size, ...])

image_fill_gap(image)

getspwfromfreq(vis, freqrange)

initconfig(suncasa_dir)

ProgressBar(iteration, total[, prefix, suffix, ...])

Call in a loop to create terminal progress bar

getcurtimstr([prefix, suffix])

getlatestfile([directory, prefix, suffix])

loadjsonfile(jsonfile[, mustexist])

updatejsonfile(jsonfile, data)

getSDOdir(config, database_dir, suncasa_dir)

getsdodir(filename[, unique])

return a list of the data path relative to the SDOdir

FileNotInList(file2chk, filelist)

return the index of files not in the list

getfreeport()

normalize_aiamap(aiamap)

do expisure normalization of an aia map

tplt(mapcube)

sdo_aia_scale_hdr(amap[, sigma])

sdo_aia_scale_dict([wavelength, imagetype])

rescale the aia image

sdo_aia_scale([image, wavelength])

rescale the aia image

insertchar(source_str, insert_str, pos)

readsdofile([datadir, wavelength, trange, isexists, ...])

read sdo file from local database

readsdofileX([datadir, filelist, wavelength, trange, ...])

read sdo file from local database

findDist(x, y)

paramspline(x, y, length[, s])

polyfit(x, y, length, deg[, keepxorder])

htfit_warren2011(x, y, cutlength)

reference: https://ui.adsabs.harvard.edu/abs/2011ApJ...742...92W/abstract

spline(x, y, length[, s])

get_curve_grad(x, y)

get the grad of at data point

improfile(z, xi, yi[, interp])

Pixel-value cross-section along line segment in an image

canvaspix_to_data(smap, x, y)

data_to_mappixel(smap, x, y)

polsfromfitsheader(header)

get polarisation information from fits header

headerfix(header)

freqsfromfitsheader(header)

get frequency in GHz from fits header

transfitdict2DF(datain[, gaussfit, getcentroid])

convert the results from pimfit or pmaxfit tasks to pandas DataFrame structure.

getcolctinDF(dspecDF, col)

return the count of how many times of the element starts with col occurs in columns of dspecDF

dspecDFfilter(dspecDF, pol)

filter the unselect polarisation from dspecDF

dspecDF2text(DFfile[, outfile])

smapmeshgrid2(smap[, angle, rescale, origin])

map2wcsgrids(snpmap[, cell, antialiased])

smapradialfilter(sunpymap[, factor, grid])

regridimage(values, x, y[, grid, resize])

re-grid the data on a regular grid with uneven grid spacing to an uniform grid

regridspec(spec, x, y[, nxmax, nymax, interp])

get_contour_data(X, Y, Z[, levels])

c_correlate(a, v[, returnx])

c_correlateX(a, v[, returnx, returnav, s])

XCorrMap(z, x, y[, doxscale])

get the cross correlation map along y axis

Module Contents

suncasa.utils.DButil.__author__ = ['Sijie Yu'][source]
suncasa.utils.DButil.__email__ = 'sijie.yu@njit.edu'[source]
suncasa.utils.DButil.img2html_movie(imgprefix, outname='movie', img_fmt='png')[source]
suncasa.utils.DButil.my_timer(orig_func)[source]
suncasa.utils.DButil.spectrogram2wav(spec, threshld=None, gama=1, fs=1.0, t_length=None, w=1, wavfile='output.wav')[source]

Convert spectrogram to audio in WAV format :param spec: spec.shape (nfreq, ntime) :param threshld: below which is set to be threshold :param gama: :param fs: :param t_length: time duration of output WAV file :param w: width of the smooth window, if apply :param wavfile: :return:

suncasa.utils.DButil.smooth(x, window_len=11, window='hanning')[source]

smooth the data using a window with requested size.

This method is based on the convolution of a scaled window with the signal. The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the begining and end part of the output signal.

input:

x: the input signal window_len: the dimension of the smoothing window; should be an odd integer window: the type of window from ‘flat’, ‘hanning’, ‘hamming’, ‘bartlett’, ‘blackman’

flat window will produce a moving average smoothing.

output:

the smoothed signal

example:

t=linspace(-2,2,0.1) x=sin(t)+randn(len(t))*0.1 y=smooth(x)

see also:

numpy.hanning, numpy.hamming, numpy.bartlett, numpy.blackman, numpy.convolve scipy.signal.lfilter

NOTE: length(output) != length(input), to correct this: return y[(window_len/2-1):-(window_len/2)] instead of just y.

suncasa.utils.DButil.img2movie(imgprefix='', img_ext='png', outname='movie', size=None, start_num=0, crf=15, fps=10, overwrite=False, crop=[], title=[], dpi=200, keeptmp=False, usetmp=False, autorotate=True)[source]
Parameters:
  • imgprefix

  • img_ext

  • outname

  • size

  • start_num

  • crf

  • fps

  • overwrite

  • title – the timestamp on each frame

  • crop – 4-tuple of integer specifies the cropping pixels [x0, x1, y0, y1]

  • dpi

  • keeptmp

  • usetmp – use the image in the default tmp folder

Returns:

suncasa.utils.DButil.image_fill_gap(image)[source]
suncasa.utils.DButil.getspwfromfreq(vis, freqrange)[source]
suncasa.utils.DButil.initconfig(suncasa_dir)[source]
suncasa.utils.DButil.ProgressBar(iteration, total, prefix='', suffix='', decimals=1, length=100, empfill=' ', fill='#')[source]

Call in a loop to create terminal progress bar @params:

iteration - Required : current iteration (Int) total - Required : total iterations (Int) prefix - Optional : prefix string (Str) suffix - Optional : suffix string (Str) decimals - Optional : positive number of decimals in percent complete (Int) length - Optional : character length of bar (Int) fill - Optional : bar fill character (Str) empfill - Optional : empty bar fill character (Str)

suncasa.utils.DButil.getcurtimstr(prefix='CleanID_', suffix='')[source]
suncasa.utils.DButil.getlatestfile(directory='./', prefix='CleanID_', suffix='')[source]
suncasa.utils.DButil.loadjsonfile(jsonfile, mustexist=True)[source]
suncasa.utils.DButil.updatejsonfile(jsonfile, data)[source]
suncasa.utils.DButil.getSDOdir(config, database_dir, suncasa_dir)[source]
suncasa.utils.DButil.getsdodir(filename, unique=True)[source]

return a list of the data path relative to the SDOdir :param filename: :return:

suncasa.utils.DButil.FileNotInList(file2chk, filelist)[source]

return the index of files not in the list :param file2chk: files to be check :param filelist: the list :return:

suncasa.utils.DButil.getfreeport()[source]
suncasa.utils.DButil.normalize_aiamap(aiamap)[source]

do expisure normalization of an aia map :param aia map made from sunpy.map: :return: normalised aia map

suncasa.utils.DButil.tplt(mapcube)[source]
suncasa.utils.DButil.sdo_aia_scale_hdr(amap, sigma=None)[source]
suncasa.utils.DButil.sdo_aia_scale_dict(wavelength=None, imagetype='image')[source]

rescale the aia image :param image: normalised aia image data :param wavelength: :return: byte scaled image data

suncasa.utils.DButil.sdo_aia_scale(image=None, wavelength=None)[source]

rescale the aia image :param image: normalised aia image data :param wavelength: :return: byte scaled image data

suncasa.utils.DButil.insertchar(source_str, insert_str, pos)[source]
suncasa.utils.DButil.readsdofile(datadir=None, wavelength=None, trange=None, isexists=False, timtol=1)[source]

read sdo file from local database :param datadir: :param wavelength: :param trange: the timestamp or timerange in Julian days. if is timerange, return a list of files in the timerange :param isexists: check if file exist. if files exist, return file name :param timtol: time difference tolerance in days for considering data as the same timestamp :return:

suncasa.utils.DButil.readsdofileX(datadir=None, filelist=None, wavelength=None, trange=None, isexists=False, timtol=1)[source]

read sdo file from local database :param datadir: :param wavelength: :param trange: time object. the timestamp or timerange. if is timerange, return a list of files in the timerange :param isexists: check if file exist. if files exist, return file name :param timtol: time difference tolerance in days for considering data as the same timestamp :return:

suncasa.utils.DButil.findDist(x, y)[source]
suncasa.utils.DButil.paramspline(x, y, length, s=0)[source]
suncasa.utils.DButil.polyfit(x, y, length, deg, keepxorder=False)[source]
suncasa.utils.DButil.htfit_warren2011(x, y, cutlength)[source]

reference: https://ui.adsabs.harvard.edu/abs/2011ApJ…742…92W/abstract

suncasa.utils.DButil.spline(x, y, length, s=0)[source]
suncasa.utils.DButil.get_curve_grad(x, y)[source]

get the grad of at data point :param x: :param y: :return: grad,posang

suncasa.utils.DButil.improfile(z, xi, yi, interp='cubic')[source]

Pixel-value cross-section along line segment in an image :param z: an image array :param xi and yi: equal-length vectors specifying the pixel coordinates of the endpoints of the line segment :param interp: interpolation type to sampling, ‘nearest’ or ‘cubic’ :return: the intensity values of pixels along the line

suncasa.utils.DButil.canvaspix_to_data(smap, x, y)[source]
suncasa.utils.DButil.data_to_mappixel(smap, x, y)[source]
suncasa.utils.DButil.polsfromfitsheader(header)[source]

get polarisation information from fits header :param header: fits header :return pols: polarisation stokes

suncasa.utils.DButil.headerfix(header)[source]
suncasa.utils.DButil.freqsfromfitsheader(header)[source]

get frequency in GHz from fits header :param header: fits header :return pols: polarisation stokes

suncasa.utils.DButil.transfitdict2DF(datain, gaussfit=True, getcentroid=False)[source]

convert the results from pimfit or pmaxfit tasks to pandas DataFrame structure. :param datain: The component list from pimfit or pmaxfit tasks :param gaussfit: True if the results is from pimfit, otherwise False. :param getcentroid: If True returns the centroid :return: the pandas DataFrame structure.

suncasa.utils.DButil.getcolctinDF(dspecDF, col)[source]

return the count of how many times of the element starts with col occurs in columns of dspecDF :param dspecDF: :param col: the start string :return: the count and items

suncasa.utils.DButil.dspecDFfilter(dspecDF, pol)[source]

filter the unselect polarisation from dspecDF :param dspecDF: the original dspecDF :param pol: selected polarisation, dtype = string :return: the output dspecDF

suncasa.utils.DButil.dspecDF2text(DFfile, outfile=None)[source]
suncasa.utils.DButil.smapmeshgrid2(smap, angle=None, rescale=1.0, origin=1)[source]
suncasa.utils.DButil.map2wcsgrids(snpmap, cell=True, antialiased=True)[source]
Parameters:
  • snpmap

  • cell – if True, return the coordinates of the pixel centers. if False, return the coordinates of the pixel boundaries

Returns:

suncasa.utils.DButil.smapradialfilter(sunpymap, factor=5, grid=None)[source]
suncasa.utils.DButil.regridimage(values, x, y, grid=None, resize=[1.0, 1.0])[source]

re-grid the data on a regular grid with uneven grid spacing to an uniform grid :param values: The image data on the regular grid :param x: the points defining the regular grid in x :param y: the points defining the regular grid in y :param grid: new uniform mesh grid [gridx,gridy] :param resize: list of re-size ratio factors of x and y. if resize is not [1.0,1.0], grid is neglected. :return: re-gridded image

suncasa.utils.DButil.regridspec(spec, x, y, nxmax=None, nymax=None, interp=False)[source]
Parameters:
  • spec – ndarray of float or complex, shape (npol,nbl,nf,nt) Data values.

  • x – Data point x coordinates.

  • y – Data point y coordinates.

  • nxmax

  • nymax

Returns:

suncasa.utils.DButil.get_contour_data(X, Y, Z, levels=[0.5, 0.7, 0.9])[source]
suncasa.utils.DButil.c_correlate(a, v, returnx=False)[source]
suncasa.utils.DButil.c_correlateX(a, v, returnx=False, returnav=False, s=0)[source]
Parameters:
  • a

  • v – a and v can be a dict in following format {‘x’:[],’y’:[]}. The length of a and v can be different.

  • returnx

Returns:

suncasa.utils.DButil.XCorrMap(z, x, y, doxscale=True)[source]

get the cross correlation map along y axis :param z: data :param x: x axis :param y: y axis :return:

class suncasa.utils.DButil.ButtonsPlayCTRL(plot_width=None, *args, **kwargs)[source]

Produce A play/stop button widget for bokeh plot

__slots__ = ['buttons'][source]
buttons[source]