コード例 #1
0
ファイル: ssnr.py プロジェクト: yichuanyanyu26/aitom
def ssnr_sequential___individual_data_collect(self, r, op):
    if (self is None):
        get_mrc_func = IV.get_mrc
    else:
        get_mrc_func = self.cache.get_mrc
    v = get_mrc_func(r['subtomogram'])
    if ('angle' in r):
        v = GR.rotate_pad_mean(v, angle=N.array(r['angle'], dtype=N.float), loc_r=N.array(r['loc'], dtype=N.float))
    if ((op is not None) and ('segmentation_tg' in op) and ('template' in r) and ('segmentation' in r['template'])):
        phi = IV.read_mrc_vol(r['template']['segmentation'])
        phi_m = (phi > 0.5)
        del phi
        (ang_inv, loc_inv) = AAL.reverse_transform_ang_loc(r['angle'], r['loc'])
        phi_mr = GR.rotate(phi_m, angle=ang_inv, loc_r=loc_inv, default_val=0)
        del phi_m
        del ang_inv, loc_inv
        import aitom.tomominer.pursuit.multi.util as PMU
        v_s = PMU.template_guided_segmentation(v=v, m=phi_mr, op=op['segmentation_tg'])
        del phi_mr
        if (v_s is not None):
            v_f = N.isfinite(v_s)
            if (v_f.sum() > 0):
                v_s[N.logical_not(v_f)] = v_s[v_f].mean()
                v = v_s
            del v_s
    v = NF.fftshift(NF.fftn(v))
    m = get_mrc_func(r['mask'])
    if ('angle' in r):
        m = GR.rotate_mask(m, angle=N.array(r['angle'], dtype=N.float))
    v[(m < op['mask_cutoff'])] = 0.0
    return {'v': v, 'm': m, }
コード例 #2
0
ファイル: ssnr.py プロジェクト: xut006/aitom
def var__local(self, data_json, labels=None, mask_cutoff=0.5, return_key=True, segmentation_tg_op=None):
    if labels is None:
        labels = ([0] * len(data_json))
    sum_v = {}
    prod_sum_v = {}
    mask_sum = {}
    for (i, r) in enumerate(data_json):
        if (self is not None) and (self.work_queue is not None) and self.work_queue.done_tasks_contains(
                self.task.task_id):
            raise Exception('Duplicated task')
        v = IV.read_mrc_vol(r['subtomogram'])
        v = GR.rotate_pad_mean(v, angle=N.array(r['angle'], dtype=N.float), loc_r=N.array(r['loc'], dtype=N.float))
        m = IV.read_mrc_vol(r['mask'])
        m = GR.rotate_mask(m, N.array(r['angle'], dtype=N.float))
        if (segmentation_tg_op is not None) and ('template' in r) and ('segmentation' in r['template']):
            phi = IV.read_mrc(r['template']['segmentation'])['value']
            import aitom.tomominer.pursuit.multi.util as PMU
            v_s = PMU.template_guided_segmentation(v=v, m=(phi > 0.5), op=segmentation_tg_op)
            if v_s is not None:
                v = v_s
                del v_s
                v_t = N.zeros(v.shape)
                v_f = N.isfinite(v)
                v_t[v_f] = v[v_f]
                v_t[N.logical_not(v_f)] = v[v_f].mean()
                v = v_t
                del v_f, v_t
        v = NF.fftshift(NF.fftn(v))
        v[(m < mask_cutoff)] = 0.0
        if labels[i] not in sum_v:
            sum_v[labels[i]] = v
        else:
            sum_v[labels[i]] += v
        if labels[i] not in prod_sum_v:
            prod_sum_v[labels[i]] = (v * N.conj(v))
        else:
            prod_sum_v[labels[i]] += (v * N.conj(v))
        if labels[i] not in mask_sum:
            mask_sum[labels[i]] = N.zeros(m.shape, dtype=N.int)
        mask_sum[labels[i]][(m >= mask_cutoff)] += 1
    re = {'sum': sum_v, 'prod_sum': prod_sum_v, 'mask_sum': mask_sum, }
    if return_key:
        re_key = self.cache.save_tmp_data(re, fn_id=self.task.task_id)
        assert (re_key is not None)
        return {'key': re_key, }
    else:
        return re