Esempio n. 1
0
    def hslice(self, value):
        """
        slice a spectrogram at a given position along the y axis, maintains
        variable names from spectrogram

        Parameters
        ==========
        value : float or datetime.datetime
            the value to slice the spectrogram at

        Returns
        =======
        out : datamodel.SpaceData
            spacedata containing the slice
        """
        # using bisect find the index of the spectrogram to use
        if isinstance(value, datetime.datetime):
            value = date2num(value)
        ind = bisect.bisect_right(self['spectrogram']['yedges'], value)
        ans = dm.SpaceData()
        ans[self['spectrogram'].attrs['variables']
            [0]] = tb.bin_edges_to_center(self['spectrogram']['xedges'])
        ans['yedges'] = self['spectrogram']['yedges'][ind:ind + 2].copy()
        ans['xedges'] = self['spectrogram']['xedges'].copy()
        ans[self['spectrogram'].attrs['variables']
            [2]] = self['spectrogram']['spectrogram'][ind, :]
        return ans
Esempio n. 2
0
    def hslice(self, value):
        """
        slice a spectrogram at a given position along the y axis, maintains
        variable names from spectrogram

        Parameters
        ==========
        value : float or datetime.datetime
            the value to slice the spectrogram at

        Returns
        =======
        out : datamodel.SpaceData
            spacedata containing the slice
        """
        # using bisect find the index of the spectrogram to use
        if isinstance(value, datetime.datetime):
            value = date2num(value)
        ind = bisect.bisect_right(self['spectrogram']['yedges'], value)
        ans = dm.SpaceData()
        ans[self['spectrogram'].attrs['variables'][0]] = tb.bin_edges_to_center(self['spectrogram']['xedges'])
        ans['yedges'] = self['spectrogram']['yedges'][ind:ind+2].copy()
        ans['xedges'] = self['spectrogram']['xedges'].copy()
        ans[self['spectrogram'].attrs['variables'][2]] = self['spectrogram']['spectrogram'][ind, :]
        return ans
Esempio n. 3
0
 def testBinEdgesToCenter(self):
     """Convert a set of bin edges to bin centers"""
     inputs = [[1, 2, 3, 4, 5],
               [1,2,3,7,10,20],
               ]
     outputs = [[1.5, 2.5, 3.5, 4.5],
                [1.5, 2.5, 5, 8.5, 15],]
     for i, val in enumerate(inputs):
         numpy.testing.assert_almost_equal(outputs[i], tb.bin_edges_to_center(val))
Esempio n. 4
0
 def testBinEdgesToCenter(self):
     """Convert a set of bin edges to bin centers"""
     inputs = [[1, 2, 3, 4, 5],
               [1,2,3,7,10,20],
               ]
     outputs = [[1.5, 2.5, 3.5, 4.5],
                [1.5, 2.5, 5, 8.5, 15],]
     for i, val in enumerate(inputs):
         numpy.testing.assert_almost_equal(outputs[i], tb.bin_edges_to_center(val))
Esempio n. 5
0
 def testBinEdgesToCenterToEdges_datetimeroundtrip(self):
     """Convert a set of datetime bin edges to centers and back to bin edges"""
     inputs = [datetime.datetime(2012,9,3,n) for n in range(10)]
     computedOut = tb.bin_edges_to_center(inputs)
     roundtripResults = tb.bin_center_to_edges(computedOut)
     self.assertTrue((inputs == roundtripResults).all())
Esempio n. 6
0
 def testBinEdgesToCenterToEdges_datetimeroundtrip(self):
     """Convert a set of datetime bin edges to centers and back to bin edges"""
     inputs = [datetime.datetime(2012,9,3,n) for n in range(10)]
     computedOut = tb.bin_edges_to_center(inputs)
     roundtripResults = tb.bin_center_to_edges(computedOut)
     self.assertTrue((inputs == roundtripResults).all())
Esempio n. 7
0
for npts in tqdm.tqdm_notebook(range(1,102,40)):
    d1 = sampledat[np.random.randint(0, len(sampledat), npts)]
    with pm.Model() as model:
        alpha = pm.Uniform('loc', -10, 10)
        #     beta = pm.Uniform('dist', 1, 1)
        x = pm.Cauchy(name='x', alpha=alpha, beta=1, observed=d1)
        trace = pm.sample(10000)
        hists[npts] = np.histogram(trace['loc'], bins)
        stats[npts] = np.percentile(trace['loc'], (1, 5, 25, 50, 75, 95, 99))


# In[40]:

keys = sorted(list(hists.keys()))
for k in keys:
    p = plt.plot(tb.bin_edges_to_center(bins), hists[k][0]/np.max(hists[k][0]), 
                 drawstyle='steps', label=str(k), lw=1)
    c = p[0].get_color()
    plt.axvline(stats[k][3], lw=3, color=c)
    print(k, stats[k][2:5], stats[k][3]/(stats[k][4]-stats[k][2]), )
plt.legend()
plt.xlim((-2,2))


# ## if both are unknown

# In[65]:

# generate some data
bins = np.linspace(-4,4,100)
hists2 = {}