コード例 #1
0
ファイル: utils.py プロジェクト: fenglb/nmrpro
def make_uc_pipe(dic, data, dim=-1):
    if dim == -1:
        dim = data.ndim - 1     # last dimention

    fn = "FDF" + str(int(dic["FDDIMORDER"][data.ndim - 1 - dim]))
    size = float(data.shape[dim])

    # check for quadrature in indirect dimentions
    if (dic[fn + "QUADFLAG"] != 1) and (dim != data.ndim - 1):
        size = size / 2.
        cplx = True
    else:
        cplx = False

    sw = dic[fn + "SW"]
    if sw == 0.0:
        sw = 1.0
    obs = dic[fn + "OBS"]
    if obs == 0.0:
        obs = 1.0

    car = dic[fn + "CAR"] * obs
    # NMRPipe keeps the carrier constant during extractions storing the
    # location of this point as CENTER.  This may not be the actual "center" of
    # the spectrum and may not even be a valid index in that dimension. We need
    # to re-center the carrier value so that actually represents the
    # frequency of the central point in the dimension.
    if dic[fn + "X1"] != 0. or dic[fn + "XN"] != 0.:
        car = car + sw / size * (dic[fn + "CENTER"] - 1. - size / 2.)
    return unit_conversion(size, cplx, sw, obs, car)
コード例 #2
0
ファイル: NMRSpectrum.py プロジェクト: fenglb/nmrpro
    def __new__(cls, input_array, udic, parent=None, uc=None):
        if input_array.ndim == 1:
            cls = NMRSpectrum1D
        elif input_array.ndim == 2:
            cls = NMRSpectrum2D
        obj = np.asarray(input_array).view(cls)

        
        if parent is None:
            history = Workflow()
            original = DataUdic(input_array, udic)
            flags = {}
            annotation = []
        else:
            history = parent.history
            original = parent.original
            flags = parent.spec_flags
            annotation = parent.annotation
            
            if uc is None: uc = parent.uc
        
        # add the new attribute to the created instance
        if uc is None:
            uc = [unit_conversion(udic[i]['size'],
                                    udic[i]['complex'],
                                    udic[i]['sw'],
                                    udic[i]['obs'],
                                    udic[i]['car'])
                for i in range(0, udic['ndim'])]

        if hasattr(input_array, 'annotation'):
            obj.annotation = input_array.annotation
        
        obj.udic = udic
        obj.uc = uc
        obj.history = history
        obj.original = original
        obj.spec_flags = flags
        obj.annotation = annotation
        return obj