python类in1d()的实例源码

segment.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def take_slice_of_analogsignalarray_by_channelindex(self,
                                                        channel_indexes=None):
        '''
        Return slices of the :class:`AnalogSignalArrays` in the
        :class:`Segment` that correspond to the :attr:`channel_indexes`
        provided.
        '''
        if channel_indexes is None:
            return []

        sliced_sigarrays = []
        for sigarr in self.analogsignals:
            if sigarr.get_channel_index() is not None:
                ind = np.in1d(sigarr.get_channel_index(), channel_indexes)
                sliced_sigarrays.append(sigarr[:, ind])

        return sliced_sigarrays
segment.py 文件源码 项目:NeoAnalysis 作者: neoanalysis 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def take_slice_of_analogsignalarray_by_channelindex(self,
                                                        channel_indexes=None):
        '''
        Return slices of the :class:`AnalogSignalArrays` in the
        :class:`Segment` that correspond to the :attr:`channel_indexes`
        provided.
        '''
        if channel_indexes is None:
            return []

        sliced_sigarrays = []
        for sigarr in self.analogsignals:
            if sigarr.get_channel_index() is not None:
                ind = np.in1d(sigarr.get_channel_index(), channel_indexes)
                sliced_sigarrays.append(sigarr[:, ind])

        return sliced_sigarrays
pre_sumstats.py 文件源码 项目:PleioPred 作者: yiminghu 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def get_1000G_snps(sumstats, out_file):
    sf = np.loadtxt(sumstats,dtype=str,skiprows=1)
    h5f = h5py.File('ref/Misc/1000G_SNP_info.h5','r')
    rf = h5f['snp_chr'][:]
    h5f.close()
    ind1 = np.in1d(sf[:,1],rf[:,2])
    ind2 = np.in1d(rf[:,2],sf[:,1])
    sf1 = sf[ind1]
    rf1 = rf[ind2]
    ### check order ###
    if sum(sf1[:,1]==rf1[:,2])==len(rf1[:,2]):
        print 'Good!'
    else:
        print 'Shit happens, sorting sf1 to have the same order as rf1'
        O1 = np.argsort(sf1[:,1])
        O2 = np.argsort(rf1[:,2])
        O3 = np.argsort(O2)
        sf1 = sf1[O1][O3]
    out = ['hg19chrc snpid a1 a2 bp or p'+'\n']
    for i in range(len(sf1[:,1])):
        out.append(sf1[:,0][i]+' '+sf1[:,1][i]+' '+sf1[:,2][i]+' '+sf1[:,3][i]+' '+rf1[:,1][i]+' '+sf1[:,5][i]+' '+sf1[:,6][i]+'\n')
    ff = open(out_file,"w")
    ff.writelines(out)
    ff.close()
common_funcs.py 文件源码 项目:model_sweeper 作者: akimovmike 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_multicollinearity(df, target_name, r2_threshold = 0.89):
    '''Tests if any of the features could be predicted from others with R2 >= 0.89

    input: dataframe, name of target (to exclude)

   '''
    r2s = pd.DataFrame()
    for feature in df.columns.difference([target_name]):
        model = sk.linear_model.Ridge()
        model.fit(df[df.columns.difference([target_name,feature])], df[feature])

        pos = np.in1d(model.coef_, np.sort(model.coef_)[-5:])

        r2s = r2s.append(pd.DataFrame({'r2':sk.metrics.r2_score(df[feature],\
            model.predict(df[df.columns.difference([target_name, feature])])),\
            'predictors' : str(df.columns.difference([target_name, feature])[np.ravel(np.argwhere(pos == True))].tolist())}, index = [feature]))
        print('Testing', feature)

    print('-----------------')

    if len(r2s[r2s['r2'] >= r2_threshold]) > 0:
        print('Multicollinearity detected')
        print(r2s[r2s['r2'] >= r2_threshold])
    else:
        print('No multicollinearity')
task.py 文件源码 项目:Crossworder 作者: olety 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __init__(self, **kwargs):
        logging.info('Crossword __init__: Initializing crossword...')
        logging.debug('kwargs:', kwargs)
        # Reading kwargs
        self.setup = kwargs
        self.rows = int(kwargs.get('n', 5))
        self.cols = int(kwargs.get('m', 5))
        self.words_file = str(kwargs.get('word_file', 'lemma.num.txt'))
        self.sort = bool(kwargs.get('sort', False))
        self.maximize_len = bool(kwargs.get('maximize_len', False))
        self.repeat_words = bool(kwargs.get('repeat_words', False))
        logging.debug('Crossword __init__: n={}, m={}, fname={}'.format(self.rows, self.cols, self.words_file))
        # Loading words
        logging.debug('Crossword __init__: Started loading words from {}'.format(self.words_file))
        arr = np.genfromtxt(self.words_file, dtype='str', delimiter=' ')
        self.words = arr[np.in1d(arr[:, 3], ['v', 'n', 'adv', 'a'])][:, 2].tolist()
        # Number of words loaded
        logging.debug('Crossword __init__: Number of words loaded: {}'.format(len(self.words)))
        self.words = list(set(x for x in self.words if len(x) <= self.rows and len(x) <= self.cols))
        if self.sort:
            self.words = sorted(self.words, key=len, reverse=self.maximize_len)
        # After filter logging
        logging.debug('Crossword __init__: Number of words after filter: {}, maxlen = {}'.format(len(self.words), len(
            max(self.words, key=len))))
list_builder.py 文件源码 项目:seniority_list 作者: rubydatasystems 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def test_df_col_or_idx_equivalence(df1,
                                   df2,
                                   col=None):
    '''check whether two dataframes contain the same elements (but not
    necessarily in the same order) in either the indexes or a selected column

    inputs
        df1, df2
            the dataframes to check
        col
            if not None, test this dataframe column for equivalency, otherwise
            test the dataframe indexes

    Returns True or False
    '''
    if not col:
        result = all(np.in1d(df1.index, df2.index,
                             assume_unique=True,
                             invert=False))
    else:
        result = all(np.in1d(df1[col], df2[col],
                             assume_unique=False,
                             invert=False))

    return result
text_classifier.py 文件源码 项目:textar 作者: datosgobar 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def make_classifier(self, name, ids, labels):
        """Entrenar un clasificador SVM sobre los textos cargados.

        Crea un clasificador que se guarda en el objeto bajo el nombre `name`.

        Args:
            name (str): Nombre para el clasidicador.
            ids (list): Se espera una lista de N ids de textos ya almacenados
                en el TextClassifier.
            labels (list): Se espera una lista de N etiquetas. Una por cada id
                de texto presente en ids.
        Nota:
            Usa el clasificador de `Scikit-learn <http://scikit-learn.org/>`_
        """
        if not all(np.in1d(ids, self.ids)):
            raise ValueError("Hay ids de textos que no se encuentran \
                              almacenados.")
        setattr(self, name, SGDClassifier())
        classifier = getattr(self, name)
        indices = np.searchsorted(self.ids, ids)
        classifier.fit(self.tfidf_mat[indices, :], labels)
text_classifier.py 文件源码 项目:textar 作者: datosgobar 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def retrain(self, name, ids, labels):
        """Reentrenar parcialmente un clasificador SVM.

        Args:
            name (str): Nombre para el clasidicador.
            ids (list): Se espera una lista de N ids de textos ya almacenados
                en el TextClassifier.
            labels (list): Se espera una lista de N etiquetas. Una por cada id
                de texto presente en ids.
        Nota:
            Usa el clasificador de `Scikit-learn <http://scikit-learn.org/>`_
        """
        if not all(np.in1d(ids, self.ids)):
            raise ValueError("Hay ids de textos que no se encuentran \
                              almacenados.")
        try:
            classifier = getattr(self, name)
        except AttributeError:
            raise AttributeError("No hay ningun clasificador con ese nombre.")
        indices = np.in1d(self.ids, ids)
        if isinstance(labels, str):
            labels = [labels]
        classifier.partial_fit(self.tfidf_mat[indices, :], labels)
models.py 文件源码 项目:polara 作者: Evfro 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def get_feedback_data(self, on_level=None):
        feedback = self.data.fields.feedback
        eval_data = self.data.test.evalset[feedback].values
        holdout = self.data.holdout_size
        feedback_data = eval_data.reshape(-1, holdout)

        if on_level is not None:
            try:
                iter(on_level)
            except TypeError:
                feedback_data = np.ma.masked_not_equal(feedback_data, on_level)
            else:
                mask_level = np.in1d(feedback_data.ravel(),
                                     on_level,
                                     invert=True).reshape(feedback_data.shape)
                feedback_data = np.ma.masked_where(mask_level, feedback_data)
        return feedback_data
precluster.py 文件源码 项目:texta 作者: texta-tk 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _find_optimal_clustering(self,clusterings):

        max_score = float('-inf')
        max_clustering = None

        for clustering in clusterings:
            labeled_vectors = [(node.vector,cluster_idx) for cluster_idx in range(len(clustering)) for node in _get_cluster_nodes(clustering[cluster_idx][1]) ]
            vectors,labels = [np.array(x) for x in zip(*labeled_vectors)]
            if np.in1d([1],labels)[0]:
                score = silhouette_score(vectors,labels,metric='cosine')
            else:
                continue # silhouette doesn't work with just one cluster
            if score > max_score:
                max_score = score
                max_clustering = clustering

        return zip(*max_clustering)[1] if max_clustering else zip(*clusterings[0])[1]
preprocess.py 文件源码 项目:sequence-based-recommendations 作者: rdevooght 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def remove_rare_elements(data, min_user_activity, min_item_popularity):
    '''Removes user and items that appears in too few interactions.
    min_user_activity is the minimum number of interaction that a user should have.
    min_item_popularity is the minimum number of interaction that an item should have.
    NB: the constraint on item might not be strictly satisfied because rare users and items are removed in alternance, 
    and the last removal of inactive users might create new rare items.
    '''

    print('Remove inactive users and rare items...')

    #Remove inactive users a first time
    user_activity = data.groupby('u').size()
    data = data[np.in1d(data.u, user_activity[user_activity >= min_user_activity].index)]
    #Remove unpopular items
    item_popularity = data.groupby('i').size()
    data = data[np.in1d(data.i, item_popularity[item_popularity >= min_item_popularity].index)]
    #Remove users that might have passed below the activity threshold due to the removal of rare items
    user_activity = data.groupby('u').size()
    data = data[np.in1d(data.u, user_activity[user_activity >= min_user_activity].index)]

    return data
loading.py 文件源码 项目:l3 作者: jacobandreas 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def reconstruct_goal(world):
    # pdb.set_trace()
    world = world.copy()
    ## indices for grass and puddle
    background_inds = [obj['index'] for (name, obj) in library.objects.iteritems() if obj['background']]
    ## background mask
    background = np.in1d(world, background_inds)
    background = background.reshape( (world.shape) )
    ## set backgronud to 0
    world[background] = 0
    ## subtract largest background ind
    ## so indices of objects begin at 1
    world[~background] -= max(background_inds)
    world = np.expand_dims(np.expand_dims(world, 0), 0)
    # pdb.set_trace()
    return world
core.py 文件源码 项目:rTensor 作者: erichson 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def check_multiplication_dims(dims, N, M, vidx=False, without=False):
    dims = array(dims, ndmin=1)
    if len(dims) == 0:
        dims = arange(N)
    if without:
        dims = setdiff1d(range(N), dims)
    if not np.in1d(dims, arange(N)).all():
        raise ValueError('Invalid dimensions')
    P = len(dims)
    sidx = np.argsort(dims)
    sdims = dims[sidx]
    if vidx:
        if M > N:
            raise ValueError('More multiplicants than dimensions')
        if M != N and M != P:
            raise ValueError('Invalid number of multiplicants')
        if P == M:
            vidx = sidx
        else:
            vidx = sdims
        return sdims, vidx
    else:
        return sdims
halo_objects.py 文件源码 项目:yt 作者: yt-project 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def particle_mask(self):
        # Dynamically create the masking array for particles, and get
        # the data using standard yt methods.
        if self._particle_mask is not None:
            return self._particle_mask
        # This is from disk.
        pid = self.__getitem__('particle_index')
        # This is from the sphere.
        if self._name == "RockstarHalo":
            ds = self.ds.sphere(self.CoM, self._radjust * self.max_radius)
        elif self._name == "LoadedHalo":
            ds = self.ds.sphere(self.CoM, np.maximum(self._radjust * \
            self.ds.quan(self.max_radius, 'code_length'), \
            self.ds.index.get_smallest_dx()))
        sp_pid = ds['particle_index']
        self._ds_sort = sp_pid.argsort()
        sp_pid = sp_pid[self._ds_sort]
        # This matches them up.
        self._particle_mask = np.in1d(sp_pid, pid)
        return self._particle_mask
metrics.py 文件源码 项目:skggm 作者: skggm 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def has_approx_support(m, m_hat, prob=0.01):
    """Returns 1 if model selection error is less than or equal to prob rate,
    0 else.

    NOTE: why does np.nonzero/np.flatnonzero create so much problems?
    """
    m_nz = np.flatnonzero(np.triu(m, 1))
    m_hat_nz = np.flatnonzero(np.triu(m_hat, 1))

    upper_diagonal_mask = np.flatnonzero(np.triu(np.ones(m.shape), 1))
    not_m_nz = np.setdiff1d(upper_diagonal_mask, m_nz)

    intersection = np.in1d(m_hat_nz, m_nz)  # true positives
    not_intersection = np.in1d(m_hat_nz, not_m_nz)  # false positives

    true_positive_rate = 0.0
    if len(m_nz):
        true_positive_rate = 1. * np.sum(intersection) / len(m_nz)
        true_negative_rate = 1. - true_positive_rate

    false_positive_rate = 0.0
    if len(not_m_nz):
        false_positive_rate = 1. * np.sum(not_intersection) / len(not_m_nz)

    return int(np.less_equal(true_negative_rate + false_positive_rate, prob))
matrix.py 文件源码 项目:ottertune 作者: cmu-db 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_membership_mask(self, labels, rows_or_columns):
        from .util import array_tostring

        assert rows_or_columns in ['rows', 'columns']
        assert isinstance(labels, np.ndarray)
        assert labels.size > 0

        if rows_or_columns == "rows":
            filter_labels = self.rowlabels
        else:
            filter_labels = self.columnlabels

        labels = array_tostring(labels)
        filter_labels = array_tostring(filter_labels)

        return np.in1d(filter_labels.ravel(),
                       labels).reshape(filter_labels.shape)
information_value.py 文件源码 项目:score_card_base_python 作者: zzstrwolf 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def discrete(self, x, bin=5):
        #res = np.array([0] * x.shape[-1], dtype=int)
        #?????????????????????WOE?????????????<=?WOE??
        x_copy = pd.Series.copy(x)
        x_copy = x_copy.astype(str)
        #x_copy = x_copy.astype(np.str_)
        #x_copy = x
        x_gt0 = x[x>=0]
        #if x.name == 'TD_PLTF_CNT_1M':
            #bin = 5
            #x_gt0 = x[(x>=0) & (x<=24)]

        for i in range(bin):
            point1 = stats.scoreatpercentile(x_gt0, i * (100.0/bin))
            point2 = stats.scoreatpercentile(x_gt0, (i + 1) * (100.0/bin))
            x1 = x[(x >= point1) & (x <= point2)]
            mask = np.in1d(x, x1)
            #x_copy[mask] = i + 1
            x_copy[mask] = '%s-%s' % (point1,point2)
            #x_copy[mask] = point1
            #print x_copy[mask]
            #print x
        #print x
        return x_copy
information_value.py 文件源码 项目:score_card_base_python 作者: zzstrwolf 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def grade(self, x, bin=5):
        #res = np.array([0] * x.shape[-1], dtype=int)
        #?????????????????????WOE?????????????<=?WOE??
        x_copy = np.copy(x)
        #x_copy = x_copy.astype(str)
        #x_copy = x_copy.astype(np.str_)
        #x_copy = x
        x_gt0 = x[x>=0]

        for i in range(bin):
            point1 = stats.scoreatpercentile(x_gt0, i * (100.0/bin))
            point2 = stats.scoreatpercentile(x_gt0, (i + 1) * (100.0/bin))
            x1 = x[(x >= point1) & (x <= point2)]
            mask = np.in1d(x, x1)
            #x_copy[mask] = i + 1
            x_copy[mask] = i + 1
            #x_copy[mask] = point1
            #print x_copy[mask]
            #print x
            print point1,point2
        #print x
        return x_copy
dcpg_data.py 文件源码 项目:deepcpg 作者: cangermueller 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def map_values(values, pos, target_pos, dtype=None, nan=dat.CPG_NAN):
    """Maps `values` array at positions `pos` to `target_pos`.

    Inserts `nan` for uncovered positions.
    """
    assert len(values) == len(pos)
    assert np.all(pos == np.sort(pos))
    assert np.all(target_pos == np.sort(target_pos))

    values = values.ravel()
    pos = pos.ravel()
    target_pos = target_pos.ravel()
    idx = np.in1d(pos, target_pos)
    pos = pos[idx]
    values = values[idx]
    if not dtype:
        dtype = values.dtype
    target_values = np.empty(len(target_pos), dtype=dtype)
    target_values.fill(nan)
    idx = np.in1d(target_pos, pos).nonzero()[0]
    assert len(idx) == len(values)
    assert np.all(target_pos[idx] == pos)
    target_values[idx] = values
    return target_values
test_learn_d_z.py 文件源码 项目:alphacsc 作者: alphacsc 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_learn_codes():
    """Test learning of codes."""
    thresh = 0.25

    X, ds, z = simulate_data(n_trials, n_times, n_times_atom, n_atoms)

    for solver in ('l_bfgs', 'ista', 'fista'):
        z_hat = update_z(X, ds, reg, n_times_atom, solver=solver,
                         solver_kwargs=dict(factr=1e11, max_iter=50))

        X_hat = construct_X(z_hat, ds)
        assert_true(np.corrcoef(X.ravel(), X_hat.ravel())[1, 1] > 0.99)
        assert_true(np.max(X - X_hat) < 0.1)

        # Find position of non-zero entries
        idx = np.ravel_multi_index(z[0].nonzero(), z[0].shape)
        loc_x, loc_y = np.where(z_hat[0] > thresh)
        # shift position by half the length of atom
        idx_hat = np.ravel_multi_index((loc_x, loc_y), z_hat[0].shape)
        # make sure that the positions are a subset of the positions
        # in the original z
        mask = np.in1d(idx_hat, idx)
        assert_equal(np.sum(mask), len(mask))
angles.py 文件源码 项目:coordinates 作者: markovmodel 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __init__(self, topology, selstr=None, deg=False, cossin=False, periodic=True):
        indices = indices_phi(topology)

        if not selstr:
            self._phi_inds = indices
        else:
            self._phi_inds = indices[np.in1d(indices[:, 1],
                                             topology.select(selstr), assume_unique=True)]

        indices = indices_psi(topology)
        if not selstr:
            self._psi_inds = indices
        else:
            self._psi_inds = indices[np.in1d(indices[:, 1],
                                             topology.select(selstr), assume_unique=True)]

        # alternate phi, psi pairs (phi_1, psi_1, ..., phi_n, psi_n)
        dih_indexes = np.array(list(phi_psi for phi_psi in
                                    zip(self._phi_inds, self._psi_inds))).reshape(-1, 4)

        super(BackboneTorsionFeature, self).__init__(topology, dih_indexes,
                                                     deg=deg, cossin=cossin,
                                                     periodic=periodic)
data_sources_test.py 文件源码 项目:speech_ml 作者: coopie 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_ttv_array_like_data_source(self):
        dummy_data_source = DummyDataSource()
        subject_info_dir = os.path.join('test', 'dummy_data', 'metadata')
        ttv = yaml_to_dict(os.path.join(subject_info_dir, 'dummy_ttv.yaml'))

        array_ds = TTVArrayLikeDataSource(dummy_data_source, ttv)

        self.assertEqual(len(array_ds), 3)

        all_values = np.fromiter((x for x in array_ds[:]), dtype='int16')

        self.assertTrue(
            np.all(
                np.in1d(
                    all_values,
                    np.array([1, 2, 3])
                )
            )
        )
previous.py 文件源码 项目:hax 作者: XENON1T 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_data(self, dataset, event_list=None):
        # Load Basics for this dataset and shift it by 1
        data = hax.minitrees.load_single_minitree(dataset, 'Basics')
        df = data.shift(1)

        # Add previous_ prefix to all columns
        df = df.rename(columns=lambda x: 'previous_' + x)

        # Add (unshifted) event number and run number, to support merging
        df['event_number'] = data['event_number']
        df['run_number'] = data['run_number']

        # Support for event list (lame)
        if event_list is not None:
            df = df[np.in1d(df['event_number'].values, event_list)]

        return df
halo_objects.py 文件源码 项目:yt_astro_analysis 作者: yt-project 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def particle_mask(self):
        # Dynamically create the masking array for particles, and get
        # the data using standard yt methods.
        if self._particle_mask is not None:
            return self._particle_mask
        # This is from disk.
        pid = self.__getitem__('particle_index')
        # This is from the sphere.
        if self._name == "RockstarHalo":
            ds = self.ds.sphere(self.CoM, self._radjust * self.max_radius)
        elif self._name == "LoadedHalo":
            ds = self.ds.sphere(self.CoM, np.maximum(self._radjust * \
            self.ds.quan(self.max_radius, 'code_length'), \
            self.ds.index.get_smallest_dx()))
        sp_pid = ds['particle_index']
        self._ds_sort = sp_pid.argsort()
        sp_pid = sp_pid[self._ds_sort]
        # This matches them up.
        self._particle_mask = np.in1d(sp_pid, pid)
        return self._particle_mask
roi_cache.py 文件源码 项目:Waskom_PNAS_2017 作者: WagnerLabPapers 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def extract_from_volume(vol_data, vox_ijk):
    """Extract data values (broadcasting across time if relevant)."""
    i, j, k = vox_ijk.T
    ii, jj, kk = vol_data.shape[:3]
    fov = (np.in1d(i, np.arange(ii)) &
           np.in1d(j, np.arange(jj)) &
           np.in1d(k, np.arange(kk)))

    if len(vol_data.shape) == 3:
        ntp = 1
    else:
        ntp = vol_data.shape[-1]

    roi_data = np.empty((len(i), ntp))
    roi_data[:] = np.nan
    roi_data[fov] = vol_data[i[fov], j[fov], k[fov]]
    return roi_data
loglike.py 文件源码 项目:ugali 作者: DarkEnergySurvey 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def clip_catalog(self):
        # ROI-specific catalog
        logger.debug("Clipping full catalog...")
        cut_observable = self.mask.restrictCatalogToObservableSpace(self.catalog_full)

        # All objects within disk ROI
        logger.debug("Creating roi catalog...")
        self.catalog_roi = self.catalog_full.applyCut(cut_observable)
        self.catalog_roi.project(self.roi.projector)
        self.catalog_roi.spatialBin(self.roi)

        # All objects interior to the background annulus
        logger.debug("Creating interior catalog...")
        cut_interior = numpy.in1d(ang2pix(self.config['coords']['nside_pixel'], self.catalog_roi.lon, self.catalog_roi.lat), 
                                  self.roi.pixels_interior)
        #cut_interior = self.roi.inInterior(self.catalog_roi.lon,self.catalog_roi.lat)
        self.catalog_interior = self.catalog_roi.applyCut(cut_interior)
        self.catalog_interior.project(self.roi.projector)
        self.catalog_interior.spatialBin(self.roi)

        # Set the default catalog
        #logger.info("Using interior ROI for likelihood calculation")
        self.catalog = self.catalog_interior
        #self.pixel_roi_cut = self.roi.pixel_interior_cut
farm.py 文件源码 项目:ugali 作者: DarkEnergySurvey 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def inFootprint(self, pixels, nside=None):
        """
        Open each valid filename for the set of pixels and determine the set 
        of subpixels with valid data.
        """
        if numpy.isscalar(pixels): pixels = numpy.array([pixels])
        if nside is None: nside = self.nside_likelihood

        inside = numpy.zeros( len(pixels), dtype='bool')
        if not self.nside_catalog:
            catalog_pix = [0]
        else:
            catalog_pix = superpixel(pixels,nside,self.nside_catalog)
            catalog_pix = numpy.intersect1d(catalog_pix,self.catalog_pixels)

        for filenames in self.filenames[catalog_pix]:
            #logger.debug("Loading %s"%filenames['mask_1'])
            subpix_1,val_1 = ugali.utils.skymap.readSparseHealpixMap(filenames['mask_1'],'MAGLIM',construct_map=False)
            #logger.debug("Loading %s"%filenames['mask_2'])
            subpix_2,val_2 = ugali.utils.skymap.readSparseHealpixMap(filenames['mask_2'],'MAGLIM',construct_map=False)
            subpix = numpy.intersect1d(subpix_1,subpix_2)
            superpix = numpy.unique(ugali.utils.skymap.superpixel(subpix,self.nside_pixel,nside))
            inside |= numpy.in1d(pixels, superpix)

        return inside
healpix.py 文件源码 项目:ugali 作者: DarkEnergySurvey 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def index_pixels(lon,lat,pixels,nside):
   """
   Find the index for object amoung a subset of healpix pixels.
   Set index of objects outside the pixel subset to -1

   # ADW: Not really safe to set index = -1 (accesses last entry); 
   # -np.inf would be better, but breaks other code...
   """
   pix = ang2pix(nside,lon,lat)
   # pixels should be pre-sorted, otherwise...???
   index = np.searchsorted(pixels,pix)
   if np.isscalar(index):
       if not np.in1d(pix,pixels).any(): index = -1
   else:
       # Find objects that are outside the roi
       #index[np.take(pixels,index,mode='clip')!=pix] = -1
       index[~np.in1d(pix,pixels)] = -1
   return index

############################################################
stats.py 文件源码 项目:ugali 作者: DarkEnergySurvey 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get(self, names=None, burn=None, clip=None):
        if names is None: names = list(self.dtype.names)
        names = np.array(names,ndmin=1)

        missing = names[~np.in1d(names,self.dtype.names)]
        if len(missing):
            msg = "field(s) named %s not found"%(missing)
            raise ValueError(msg)
        #idx = np.where(np.in1d(self.dtype.names,names))[0]
        idx = np.array([self.dtype.names.index(n) for n in names])

        # Remove zero entries
        zsel = ~np.all(self.ndarray==0,axis=1)
        # Remove burn entries
        bsel = np.zeros(len(self),dtype=bool)
        bsel[slice(burn,None)] = 1

        data = self.ndarray[:,idx][bsel&zsel]
        if clip is not None:
            from astropy.stats import sigma_clip
            mask = sigma_clip(data,sig=clip,copy=False,axis=0).mask
            data = data[np.where(~mask.any(axis=1))]

        return data
simulator.py 文件源码 项目:ugali 作者: DarkEnergySurvey 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def _setup_subpix(self,nside=2**16):
        """
        Subpixels for random position generation.
        """
        # Only setup once...
        if hasattr(self,'subpix'): return

        # Simulate over full ROI
        self.roi_radius  = self.config['coords']['roi_radius']

        # Setup background spatial stuff
        logger.info("Setup subpixels...")
        self.nside_pixel = self.config['coords']['nside_pixel']
        self.nside_subpixel = self.nside_pixel * 2**4 # Could be config parameter
        epsilon = np.degrees(healpy.max_pixrad(self.nside_pixel)) # Pad roi radius to cover edge healpix
        subpix = ugali.utils.healpix.query_disc(self.nside_subpixel,self.roi.vec,self.roi_radius+epsilon)
        superpix = ugali.utils.healpix.superpixel(subpix,self.nside_subpixel,self.nside_pixel)
        self.subpix = subpix[np.in1d(superpix,self.roi.pixels)]


问题


面经


文章

微信
公众号

扫码关注公众号