コード例 #1
0
ファイル: mean_field_ising.py プロジェクト: SaraMati/coniii
def fightPossibilities(ell, minSize=0):
    fightNumbers = range(2**ell)
    fp = [ [ int(x) for x in scipy.binary_repr(fN,ell) ]                  \
             for fN in fightNumbers ]
    if minSize > 0:
        fp = scipy.array(filter(lambda x: sum(x) >= minSize, fp))
    return fp
コード例 #2
0
def fightPossibilities(ell, minSize=0):
    fightNumbers = list(range(2**ell))
    fp = [ [ int(x) for x in scipy.binary_repr(fN,ell) ]                  \
             for fN in fightNumbers ]
    if minSize > 0:
        fp = scipy.array([x for x in fp if sum(x) >= minSize])
    return fp
コード例 #3
0
ファイル: modisread.py プロジェクト: anjaroesel/modis-mpf
def modisread_day_of_year(folder):
    print ' '
    print '____________Read Modis Day_of_Year_____________'
    print ' '
    d = {}
    cs_clouds = 1000
    granules = modis_granules(folder)
    #Chose one File
    k = granules.keys()[0]
    filename_doy = granules[k]['day_of_year']
    print 'read day_of_year: ' + folder + filename_doy
    f_doy = SD(folder + filename_doy)
    print ' '
    for key in ['day_of_year', 'Latitude', 'Longitude']:
        d[key] = sp.array(f_doy.select(key).get(), sp.int16)
        if key == 'day_of_year':
            day_of_year = []
            for n in d[key][0].flatten():
                #flag=convert_decimal_to_8bit(n)
                flag = sp.binary_repr(n, width=16)
                day_of_year.append(int(flag))  #0->cloudy, 1->clear
            doy = sp.array(day_of_year).reshape(d[key].shape[1:3])
            d[key] = doy

    print ' done.'
    d['day_of_year'] = d['day_of_year'][:, :-1000 / cs_clouds]
    d['Latitude'] = d[
        'Latitude'][:, :-1000 /
                    cs_clouds]  #remove the right-hand-side edge pixels
    d['Longitude'] = d['Longitude'][:, :-1000 / cs_clouds]
    print 'image shape: ' + str(d['day_of_year'].shape)
    print ' '
    return d['day_of_year'], d['Longitude'], d['Latitude']
コード例 #4
0
ファイル: makeHam.py プロジェクト: RZachLamberty/Husimi
def binaryRep(i, gen):
    """
    given an integer and a generation, return the representation of that
    configuration i in the site basis, as a string of 0's and 1's
    
    Basically, at gen we should have numberOfNodes points in our binary rep of
    i.
    """

    length = numberOfNodes(gen)
    b = scipy.binary_repr(i, length)

    return b
コード例 #5
0
ファイル: kl_tools.py プロジェクト: yoanyomba123/neuro-kl
def spikes2indep_dict(spikes, npoints=None, fractions=[1,2,4]):
    """Return dictionary with distribution over states assuming independence.

    This function works like `states2dict`, but takes as input an array of
    spikes, and return a dictionary of states by removing all dependencies
    between channels.

    The distributions are *not* normalized, as required by other routines
    (e.g., KL estimation routines).
    
    Input arguments:
    spikes -- spikes trains: 2D binary array, each column a different unit,
              each row a time point
    nchannels -- total number of channels (used to determine the maximum number
                 of states)
    npoints -- number of data points Default: None, meaning the full length of states
    fractions -- fractions of the data. For example, fractions=[1,2,4] will create
                 3 entries in the dictionary, based on the full data (N datapoints),
                 half the data (2 x N/2 points), and one quarter of the data
                 (4 x N/4 points). Default: [1,2,4]
    shuffle -- If True, data points are shuffled before computing the dictionaries
               to avoid trends in the data

    Output:
    Dictionary distr[fraction][distr_nr]. Keys are fractions (as given by input
    argument), values are lists of distributions.
    """
    if npoints is None:
        npoints = spikes.shape[0]
    nchannels = spikes.shape[1]

    # p1[i] = p(channel_i = 1)
    p1 = spikes.sum(0).astype('d')/spikes.shape[0]
    # distribution over states given independence
    nbins = 2**nchannels
    indep_distr = zeros((nbins,))
    # cycle over states
    for s in range(nbins):
        # get binary pattern
        s_bin = scipy.binary_repr(s, width=nchannels) if s>0 else '0'*nchannels
        # compute probability for independent case
        prob = [(p1[k] if s_bin[k]=='1' else 1.-p1[k]) for k in range(nchannels) ]
        indep_distr[s] = scipy.prod(prob)
    # construct dictionary as for normal case
    distr = {}
    for d in fractions:
        l = npoints/d
        distr[d] = [indep_distr*l] * d
    _check_dict_consistency(distr, npoints)
    return distr
コード例 #6
0
ファイル: modisread.py プロジェクト: anjaroesel/modis-mpf
def modisread_clouds(folder):
    print ' '
    print '____________Read Modis Cloudmask - kann etwas dauern_____________'
    print ' '
    d = {}
    cs_clouds = 1000
    granules = modis_granules(folder)
    #Chose one File
    k = granules.keys()[0]
    #
    # Read Cloudmask
    #
    filename_clouds = granules[k]['clouds']
    print 'read clouds: ' + folder + filename_clouds
    f_clouds = SD(folder + filename_clouds)
    print ' '
    for key in ['Cloud_Mask', 'Latitude', 'Longitude']:
        d[key] = sp.array(f_clouds.select(key).get(), sp.int8)
        if key == 'Cloud_Mask':
            cloud_mask = []
            land_mask = []
            for n in d[key][0].flatten():
                #flag=convert_decimal_to_8bit(n)
                flag = sp.binary_repr(n, width=8)
                cloud_mask.append(int(flag[5]))  #0->cloudy, 1->clear
                land_mask.append(int(flag[0]))  #0->water 1->coast,desert,land
            clouds = sp.array(cloud_mask, sp.int8).reshape(d[key].shape[1:3])
            land = abs(
                sp.array(land_mask, sp.int8).reshape(d[key].shape[1:3]) -
                1)  #1->water 0->coast,desert,land
            d[key] = land * clouds

    print ' done.'
    d['Cloud_Mask'] = d['Cloud_Mask'][:, :-1000 / cs_clouds]
    d['Latitude'] = d[
        'Latitude'][:, :-1000 /
                    cs_clouds]  #remove the right-hand-side edge pixels
    d['Longitude'] = d['Longitude'][:, :-1000 / cs_clouds]
    print 'image shape: ' + str(d['Cloud_Mask'].shape)
    print ' '
    return d['Cloud_Mask'], d['Longitude'], d['Latitude']
コード例 #7
0
def number2fight(stateList, numIndividuals):
    """
    Returns the 'base-2 fight' corresponding to the base-10 number.
    """
    return [ [int(bit) for bit in scipy.binary_repr(state,numIndividuals)]  \
        for state in stateList ]