コード例 #1
0
ファイル: fields.py プロジェクト: california43/gattini
    def value(self, data, image=None):        
        cam = data['name']
        if type(cam) == N.recarray:
            cam = cam[0]
        pix_size = {"sky": N.sqrt(202000/4), "sbc": 11.3}[cam]        
        ex = data['exposure']
        sky = data['sky'].clip(0.0001, data['sky'].max())
        mean = data['mean'] 
        pix_mag = 2.5*log10(pix_size**2) 


        temp = data['temp'].copy()
        if type(cam) == N.recarray:
            temp[temp < -35] = -40
            temp[temp >= -35] = -30
            
            offset = ex.copy()
            offset[temp == -30] = 2.25*ex[temp == -30]
            offset[temp == -40] = 0.59*ex[temp == -40]
        else:
            offset = 0
        if cam == "sbc":
            offset = 68
        else:
            offset += 77.1
        return -2.5*log10(sky - offset) + data['zmag']  + pix_mag
コード例 #2
0
ファイル: foo.py プロジェクト: california43/gattini
def main():
    Z = 17.4
    pix_size = 11.3
    pix_mag = 2.5*log10(pix_size**2) 
    sky = 148
    offset = 68        
    print -2.5*log10(sky - offset) + Z  + pix_mag
コード例 #3
0
ファイル: galaxy_bios.py プロジェクト: tomczak724/mypy
def restore_logaxes_labels(subplot, xaxis=True, yaxis=True):
	'''
	This script reformats the default labeling scheme
	for logarithmic axis labels to the "regular" format.
	e.g. axis labels of "10**-1" and "10**3" will be
	changed to "0.1" and "1000" respectively.
	'''
	xticks = subplot.get_xticks() 
	yticks = subplot.get_yticks() 

	if xaxis:
		xticks_new = []
		for xi in xticks:
			base = pylab.log10(xi)
			if base >= 0:
				xi_new = '%i' % xi
			else:
				formatter = '%.' + str(int(abs(base))) + 'f'
				xi_new = formatter % xi
			xticks_new.append(xi_new)
		subplot.xaxis.set_ticklabels(xticks_new)

	if yaxis:
		yticks_new = []
		for yi in yticks:
			base = pylab.log10(yi)
			if base >= 0:
				yi_new = '%i' % yi
			else:
				formatter = '%.' + str(int(abs(base))) + 'f'
				yi_new = formatter % yi
			yticks_new.append(yi_new)
		subplot.yaxis.set_ticklabels(yticks_new)

	return subplot
コード例 #4
0
def get_Rplusmag_true(rflux_instr, iflux_instr):
	a = 1.
	b = 0.03185165
	c = 27.45145076
	if rflux_instr < 0 or iflux_instr < 0:
		return -99.
	else:
		rmag_instr = -2.5 * pylab.log10(rflux_instr)
		imag_instr = -2.5 * pylab.log10(iflux_instr)
		return a * rmag_instr + b * (rmag_instr - imag_instr) + c
コード例 #5
0
def get_Kmag_true(jflux_instr, kflux_instr):
	a = 1.
	b = -0.0257698323
	c = 29.4494709
	if jflux_instr < 0 or kflux_instr < 0:
		return -99.
	else:
		jmag_instr = -2.5 * pylab.log10(jflux_instr)
		kmag_instr = -2.5 * pylab.log10(kflux_instr)
		return a * kmag_instr + b * (jmag_instr - kmag_instr) + c
コード例 #6
0
def get_rmag_true(rflux_instr, iflux_instr):
	a = 1.
	b = 0.05033836
	c = 26.52083003
	if rflux_instr < 0 or iflux_instr < 0:
		return -99.
	else:
		rmag_instr = -2.5 * pylab.log10(rflux_instr)
		imag_instr = -2.5 * pylab.log10(iflux_instr)
		return a * rmag_instr + b * (rmag_instr - imag_instr) + c
コード例 #7
0
ファイル: test_eigenfre.py プロジェクト: anielsen001/spectrum
def create_figure():
    psd = test_eigenfre_music()
    f = linspace(-0.5, 0.5, len(psd))
    plot(f, 10 * log10(psd/max(psd)), '--',label='MUSIC 15')
    savefig('psd_eigenfre_music.png')

    psd = test_eigenfre_ev()
    f = linspace(-0.5, 0.5, len(psd))
    plot(f, 10 * log10(psd/max(psd)), '--',label='EV 15')
    savefig('psd_eigenfre_ev.png')
コード例 #8
0
def get_Iplusmag_true(rflux_instr, iflux_instr):
	a = 1.
	b = 0.00013198858
	c = 27.3378864
	if rflux_instr < 0 or iflux_instr < 0:
		return -99.
	else:
		rmag_instr = -2.5 * pylab.log10(rflux_instr)
		imag_instr = -2.5 * pylab.log10(iflux_instr)
		return a * imag_instr + b * (rmag_instr - imag_instr) + c
コード例 #9
0
def get_imag_true(rflux_instr, iflux_instr):
	a = 1.
	b = 0.021948947
	c = 26.2291181
	if rflux_instr < 0 or iflux_instr < 0:
		return -99.
	else:
		rmag_instr = -2.5 * pylab.log10(rflux_instr)
		imag_instr = -2.5 * pylab.log10(iflux_instr)
		return a * imag_instr + b * (rmag_instr - imag_instr) + c
コード例 #10
0
def get_zmag_true(iflux_instr, zflux_instr):
	a = 1.
	b = -0.03321189
	c = 25.02113495
	if iflux_instr < 0 or zflux_instr < 0:
		return -99.
	else:
		imag_instr = -2.5 * pylab.log10(iflux_instr)
		zmag_instr = -2.5 * pylab.log10(zflux_instr)
		return a * zmag_instr + b * (imag_instr - zmag_instr) + c
コード例 #11
0
def get_Jmag_true(jflux_instr, kflux_instr):
	a = 1.
	b = -0.04157139
	c = 29.07118567
	if jflux_instr < 0 or kflux_instr < 0:
		return -99.
	else:
		jmag_instr = -2.5 * pylab.log10(jflux_instr)
		kmag_instr = -2.5 * pylab.log10(kflux_instr)
		return a * jmag_instr + b * (jmag_instr - kmag_instr) + c
コード例 #12
0
ファイル: TeraData.py プロジェクト: DavidJahn86/terapy
 def getDR(self):
     #this function should return the dynamic range
     #this should be the noiselevel of the fft
     noiselevel=py.sqrt(py.mean(abs(py.fft(self._tdData.getAllPrecNoise()[0]))**2))
     #apply a moving average filter on log
     window_size=5
     window=py.ones(int(window_size))/float(window_size)
     hlog=py.convolve(20*py.log10(self.getFAbs()), window, 'valid')
     one=py.ones((2,))
     hlog=py.concatenate((hlog[0]*one,hlog,hlog[-1]*one))
     return hlog-20*py.log10(noiselevel)         
コード例 #13
0
ファイル: filterexplore.py プロジェクト: kghose/neurapy
  def on_release(self, event):
    """When we release the mouse, if we were dragging the line, recompute the filter and draw it."""
    if self.being_dragged is None: return

    self.being_dragged = None
    xy = self.design_line.get_data()
    self.wp = [xy[0][2], xy[0][3]]
    self.ws = [xy[0][1], xy[0][4]]
    self.gpass = -20*pylab.log10(xy[1][2])
    self.gstop = -20*pylab.log10(xy[1][1])
    self.update_design()
コード例 #14
0
    def _fetch_normalisation(self):
        # x is training
        # y is gold
        filename = self._pj([self._path2data, 'data', 'common_training.csv'])
        training = pd.read_csv(filename)

        filename = self._pj([self._path2data, 'data', 'common_gold.csv'])
        goldfile = pd.read_csv(filename)

        #"""function [m b rho] = fetch_normalization(jj)
        #%% jj is the index of the molecule (1-7)

        colnames = self.species

        self.norm_training = pylab.log10(training[colnames] + 1)
        self.norm_gold = pylab.log10(goldfile[colnames] + 1)
コード例 #15
0
ファイル: test_correlog.py プロジェクト: anielsen001/spectrum
def create_figure():
    psd = test_correlog()
    f = linspace(-0.5, 0.5, len(psd))

    psd = cshift(psd, len(psd)/2)
    plot(f, 10*log10(psd/max(psd)))
    savefig('psd_corr.png')
コード例 #16
0
ファイル: base.py プロジェクト: AllanRamsay/COMP34411
def hz2mel(hz):
    """Convert a value in Hertz to Mels

    :param hz: a value in Hz. This can also be a numpy array, conversion proceeds element-wise.
    :returns: a value in Mels. If an array was passed in, an identical sized array is returned.
    """
    return 2595 * pylab.log10(1+hz/700.0)
コード例 #17
0
ファイル: window.py プロジェクト: carlkl/spectrum
    def compute_response(self, **kargs):
        """Compute the window data frequency response

        :param norm: True by default. normalised the frequency data.
        :param int NFFT:       total length of the final data sets( 2048 by default. if less than data length, then
            NFFT is set to the data length*2).

        The response is stored in :attr:`response`.

        .. note:: Units are dB (20 log10) since we plot the frequency response)


        """
        from pylab import fft, fftshift, log10

        norm = kargs.get('norm', self.norm)

        # do some padding. Default is max(2048, data.len*2)
        NFFT = kargs.get('NFFT', 2048)
        if NFFT < len(self.data):
            NFFT = self.data.size * 2

        # compute the fft modulus
        A = fft(self.data, NFFT)
        mag = abs(fftshift(A))

        # do we want to normalise the data
        if norm is True:
            mag = mag / max(mag)
        response = 20. * log10(mag) # factor 20 we are looking at the response
                                    # not the powe
        #response = clip(response,mindB,100)
        self.__response = response
コード例 #18
0
ファイル: filterexplore.py プロジェクト: kghose/neurapy
  def update_design(self):
    ax = self.ax
    ax.cla()
    ax2 = self.ax2
    ax2.cla()

    wp = self.wp
    ws = self.ws
    gpass = self.gpass
    gstop = self.gstop
    b, a = ss.iirdesign(wp, ws, gpass, gstop, ftype=self.ftype, output='ba')
    self.a = a
    self.b = b
    #b = [1,2]; a = [1,2]
    #Print this on command line so we can use it in our programs
    print 'b = ', pylab.array_repr(b)
    print 'a = ', pylab.array_repr(a)

    my_w = pylab.logspace(pylab.log10(.1*self.ws[0]), 0.0, num=512)
    #import pdb;pdb.set_trace()
    w, h = freqz(b, a, worN=my_w*pylab.pi)
    gp = 10**(-gpass/20.)#Go from db to regular
    gs = 10**(-gstop/20.)
    self.design_line, = ax.plot([.1*self.ws[0], self.ws[0], wp[0], wp[1], ws[1], 1.0], [gs, gs, gp, gp, gs, gs], 'ko:', lw=2, picker=5)
    ax.semilogx(w/pylab.pi, pylab.absolute(h),lw=2)
    ax.text(.5,1.0, '{:d}/{:d}'.format(len(b), len(a)))
    pylab.setp(ax, 'xlim', [.1*self.ws[0], 1.2], 'ylim', [-.1, max(1.1,1.1*pylab.absolute(h).max())], 'xticklabels', [])

    ax2.semilogx(w/pylab.pi, pylab.unwrap(pylab.angle(h)),lw=2)
    pylab.setp(ax2, 'xlim', [.1*self.ws[0], 1.2])
    ax2.set_xlabel('Normalized frequency')

    pylab.draw()
コード例 #19
0
ファイル: makemask.py プロジェクト: pawel-kw/pyxsvs
 def toggle_logscale(self,label):
     self.log_flag = not self.log_flag
     if self.log_flag:
         self.data = log10(self.data+1e-9)
     else:
         self.data = self.raw_data
     self.update_img()
コード例 #20
0
ファイル: sc1a_tools.py プロジェクト: nagyistoce/dreamtools
    def pcolor(self, mode="mean", vmin=None, vmax=None):
        """

        If you loaded the pickle data sets with only mean and sigma, the D and
        pvalue mode cannot be used.

        """
        from pylab import clf, xticks, yticks, pcolor, colorbar, flipud, log10
        if mode == "mean":
            data = self.get_mean()
        elif mode == "sigma":
            data = self.get_sigma()
        elif mode == "D":
            data = self.get_ks()[0]
        elif mode == "pvalue":
            data = self.get_ks()[1]
        clf();

        if mode == "pvalue":
            pcolor(log10(flipud(data)), vmin=vmin, vmax=vmax);
        else:
            pcolor(flipud(data), vmin=vmin,vmax=vmax);

        colorbar()
        xticks([x+0.5 for x in range(0,8)], self.ligands, rotation=90)
        cellLines = self.cellLines[:]
        cellLines.reverse()
        yticks([x+0.5 for x in range(0,4)], cellLines, rotation=0)
コード例 #21
0
ファイル: test_modcovar.py プロジェクト: carlkl/spectrum
def create_figure():
    newpsd = test_modcovar()

    pylab.plot(pylab.linspace(-0.5, 0.5, 4096),
               10 * pylab.log10(newpsd/max(newpsd)))
    pylab.axis([-0.5,0.5,-60,0])
    pylab.savefig('psd_modcovar.png')
コード例 #22
0
ファイル: fastq.py プロジェクト: WMGoBuffs/biokit
    def quality_from_error_probability(pe):
        """

        A quality value Q is an integer mapping of :math:`pe` (i.e., the probability 
        that the corresponding base call is incorrect). Two different equations have 
        been in use but we will only use the standard Sanger variant 
        otherwise known as Phred quality score:

        The PHRED software assigns a non-negative quality value 
        to each base using a logged transformation of the error probability:
        
        :math:`Q = -10 \log_{10}( P_e )`
        
        ::

            >>> Pe = 1e-9
            >>> Q = quality_from_error_probability(Pe)
            >>> Q
            90
            >>> quality_from_error_probability(0.1)
            0.1
            >>> quality_from_error_probability(0)
            1
            

        """
        assert pe >=0 and pe <= 1, "probability expected to be between 0 and 1"
        return -10 * pylab.log10(pe)
コード例 #23
0
ファイル: test_yulewalker.py プロジェクト: strawlab/spectrum
def create_figure():
    psd = test_yule()
    psd = cshift(psd, len(psd)/2) # switch positive and negative freq

    plot(linspace(-0.5, 0.5, 4096),
               10 * log10(psd/max(psd)))
    axis([-0.5,0.5,-60,0])
    savefig('psd_yulewalker.png')
コード例 #24
0
ファイル: test_filtering.py プロジェクト: schevalier/pyspace
def plot_freqz_response(b,a=1):
    w,h = scipy.signal.freqz(b,a)
    h_dB = 20 * pylab.log10 (abs(h))
    pylab.plot(w/max(w),h_dB)
    pylab.ylim(-150, 5)
    pylab.ylabel('Magnitude (db)')
    pylab.xlabel(r'Normalized Frequency (x$\pi$rad/sample)')
    pylab.title(r'Frequency response')
コード例 #25
0
    def process(self):
        """rearranges the ping data into a matrix of max amplitude of
        dimensions corrisponding to the power, gain and beam sections."""
        MINSAMPLES = 5
        datadim = self.pingdata.shape
        self.pingmax = pl.zeros((len(self.settings['power']), len(self.settings['gain']), datadim[2]))

        for i, power in enumerate(self.settings['power']):
            for j, gain in enumerate(self.settings['gain']):
                for k in xrange(datadim[2]):
                    sampleindx = pl.find((self.pingdata[:, 1, k]  == power) & (self.pingdata[:, 2, k] == gain))
                    if len(sampleindx)  >  MINSAMPLES:
                        temp = self.pingdata[sampleindx[-MINSAMPLES:], 0, k]
                        tempmax = temp.max()
                        if tempmax == 0:
                            self.pingmax[i, j, k] = pl.NaN
                        else:
                            self.pingmax[i, j, k] = temp.max()
                    else:
                        self.pingmax[i, j, k] = pl.NaN

        #The following section removes settings that were collected erroniously.
        #gain settings first
        null = pl.zeros((len(self.settings['gain']), datadim[2]))
        powershortlist = []
        self.havedata = True  # this is an ugly workaround...
        for i, power in enumerate(self.settings['power']):
            test = pl.isnan(self.pingmax[i, :, :] )
            if test.all():
                powershortlist.append(i)
                print 'removing ' + str(power) + ' power setting.'
        for i in powershortlist:
            try:
                self.settings['power'].pop(i)
            except IndexError:
                self.havedata = False
        if self.havedata:
            self.pingmax = pl.delete(self.pingmax, powershortlist, 0)
            #then power settings
            null = pl.zeros((len(self.settings['power']), datadim[2]))
            gainshortlist = []
            for i, gain in enumerate(self.settings['gain']):
                test = pl.isnan(self.pingmax[:, i, :])
                if test.all():
                    gainshortlist.append(i)
                    print 'removing ' + str(gain) + ' gain setting.'
            for i in gainshortlist:
                try:
                    self.settings['gain'].pop(i)
                except IndexError:
                    self.havedata = False
            if self.havedata:
                self.pingmax = pl.delete(self.pingmax, gainshortlist, 1)
                #remove the power and gain to normalize
                self.pingmax = 20*pl.log10(self.pingmax)
                for i, power in enumerate(self.settings['power']):
                    for j, gain in enumerate(self.settings['gain']):
                        self.pingmax[i, j, :] = self.pingmax[i, j, :] - power - gain
コード例 #26
0
ファイル: on_key.py プロジェクト: nbigaouette/libpotentials
def on_key(event):
    #print 'you pressed', event.key, event.xdata, event.ydata
    if   (event.key == 'q'):
        sys.exit(0)
    #
    elif (event.key == 'w'):
        pylab.close(event.canvas.figure)
    #
    elif (event.key == 'd'):
        print "##############################################################"
        print "Please click two points to get the distance and slope."
        from matplotlib.widgets import Cursor
        cursor = Cursor(event.inaxes, useblit=False, color='red', linewidth=1)
        points = pylab.ginput(n=2, show_clicks=True, timeout=0)
        xs  = pylab.array([points[0][0], points[1][0]])
        ys  = pylab.array([points[0][1], points[1][1]])
        dx = xs[1] - xs[0]
        dy = ys[1] - ys[0]
        dy_log = pylab.log10(ys[0]) - pylab.log10(ys[1])
        dy_ln = pylab.log(ys[0]) - pylab.log(ys[1])
        angle = pylab.arctan2(dy, dx)
        print "points = ", points
        print "distance (x) =", dx
        print "distance (y) =", dy
        print "distance =", pylab.sqrt( dx**2 + dy**2 )
        print "Ratio: x0/x1 =", xs[0] / xs[1], "   x1/x0 =", xs[1] / xs[0], "  y0/y1 =", ys[0] / ys[1], "  y1/y0 =", ys[1] / ys[0]
        print "dy/y0 = ", dy/ys[0]
        print "dx/x0 = ", dx/xs[0]
        print "Angle: theta = atan2(y/x) =", angle, "rad =", angle*180.0/pylab.pi, "deg"
        print "Slope: ", dy/dx, "  1/slope =", dx/dy
        print "Slope (log10 scale):", dy_log/dx
        print "Slope (ln scale):",    dy_ln/dx
        event.inaxes.plot([points[0][0], points[1][0]], [points[0][1], points[1][1]], '--r', lw=1.0)
        event.inaxes.plot([points[0][0], points[1][0]], [points[0][1], points[1][1]],  '+r', lw=1.0)
        pylab.draw()
    #
    elif (event.key == 'a'):
        print "##############################################################"
        print "Please click a point to get the position."
        from matplotlib.widgets import Cursor
        cursor = Cursor(event.inaxes, useblit=False, color='red', linewidth=1)
        point = pylab.ginput(n=1, show_clicks=False, timeout=0)
        print "point = ", point
        event.inaxes.plot(point[0][0], point[0][1],  '+r', lw=1.0)
        pylab.draw()
コード例 #27
0
ファイル: pt.py プロジェクト: jizhi/project_TL
    def deltac(self, z):
        """
        calculate delta_collapse (the number that's ~1.686 for E-dS)
        Taken from Nakamura and Suto, 1997
        """
        deltac0 = 3.0 * (12.0 * M.pi) ** (2.0 / 3.0) / 20.0 * (1.0 + 0.0123 * M.log10(self.om0z(z)))
        deltac = deltac0 * self.d1(0) / self.d1(z)

        return deltac
コード例 #28
0
 def _set_scatter(self):
     filename = self.caller.prefix + "results.csv"
     df = pd.read_csv(filename)
     df["log_ttest"] = -pylab.log10(df["ttest"])
     df["markersize"] = 20
     js = ScatterJS(df, x="Rp", y="log_ttest", color="bayes", size="markersize" )
     js.xlabel = "Regression coefficient"
     js.ylabel = "log10(ttest pvalue)"
     self.jinja['volcano_jsdata'] = js.get_html()
コード例 #29
0
ファイル: TeraData.py プロジェクト: DavidJahn86/terapy
    def getBandwidth(self,dbDistancetoNoise=15):
        #this function should return the lowest trustable and highest trustable
        #frequency, along with the resulting bandwidth
        
        absdata=-20*py.log10(self.getFAbs()/max(self.getFAbs()))
        ix=self.maxDR-dbDistancetoNoise>absdata #dangerous, due to sidelobes, there might be some high freq component!
        tfr=self.getfreqs()[ix]

        return min(tfr),max(tfr)
コード例 #30
0
def plot_fit(pop1, pop2):
    pop_fraction_selected = [ [pop,fraction] for pop,fraction in zip(bins,n) if pop > pop1 and pop < pop2]
    pop_selected = [ p for p,f in pop_fraction_selected ]
    fraction_selected = [ f for p,f in pop_fraction_selected ]

    pop_selected = pop_selected[1:]
    fraction_selected = fraction_selected[1:]

    x = P.log10(pop_selected)
    y = P.log10(fraction_selected)

    a,b = np.polyfit(x,y,1)
    print a,b

    x = pop_selected
    y = [10**b*xx**a for xx in x]

    P.loglog(x,y)