takes in PTRM data in this format: [temp, dec, inc, moment, ZI or IZ] -- and PTRM_check data in this format: [temp, dec, inc, moment].  Returns them in vector form (cartesian).
162600
def get_delta_pal_vectors(PTRMS, PTRM_Checks, NRM):
    
    PTRMS = numpy.array(PTRMS)
    PTRM_Checks = numpy.array(PTRM_Checks)
    TRM_1 = lib_direct.dir2cart(PTRMS[0,1:3])
    PTRMS_cart = []
    Checks_cart = []
    for num, ptrm in enumerate(PTRMS):
        ptrm_cart = lib_direct.dir2cart([PTRMS[num][1], PTRMS[num][2], old_div(PTRMS[num][3], NRM)])
        PTRMS_cart.append(ptrm_cart)
    for num, check in enumerate(PTRM_Checks):
        check_cart = lib_direct.dir2cart([PTRM_Checks[num][1], PTRM_Checks[num][2], old_div(PTRM_Checks[num][3], NRM)])
        Checks_cart.append(check_cart)
    return PTRMS_cart, Checks_cart, TRM_1
1107664
def returnData(self, dsptr):
        
        dataPtr = dsptr & 0x00FFFFFFL
        dataLen = (dsptr >> 24) & 0xFF

        self.__f.seek(dataPtr)

        data = self.__f.read(dataLen)
        result = data[4:].split('|')
        location = Location(self.getLong(data, 0), result[0], result[1], result[2], result[3], result[4])

        return location
204892
def format_geometry_in
      output = ""
      if self.lattice_vectors
        output << self.lattice_vectors.collect{|v| "lattice_vector #{v[0]} #{v[1]} #{v[2]}"}.join("\n")
        output << "\n"
      end
      output << self.atoms.collect{|a| a.format_geometry_in}.join("\n")

      output
    end
476374
def zcr(data):
    """"""
    data = np.mean(data, axis=1)

    count = len(data)
    countZ = np.sum(np.abs(np.diff(np.sign(data)))) / 2
    return (np.float64(countZ) / np.float64(count - 1.0))
999681
def pt_rotate(pt=(0.0, 0.0), angle=[0.0], center=(0.0, 0.0)):
    '''
    '''
    assert isinstance(pt, tuple)
    l_pt = len(pt)
    assert l_pt > 1
    for i in pt:
        assert isinstance(i, float)
    assert isinstance(angle, list)
    l_angle = len(angle)
    assert l_angle == l_pt-1
    for i in angle:
        assert isinstance(i, float)
        assert abs(i) <= 2*pi
    assert isinstance(center, tuple)
    assert len(center) == l_pt
    for i in center:
        assert isinstance(i, float)

    # Get vector from center to point and use to get relative polar coordinate.
    v_cart = [pt[i] - center[i] for i in range(l_pt)]

    # Length of vector needs to stay constant for new point.
    v_pol_l = [sqrt(v_cart[i]**2 + v_cart[i+1]**2) for i in range(l_angle)]
    v_pol_a = [(atan(v_cart[i+1] / v_cart[i]) if v_cart[i] != 0.0 else pi/2) + pi*int(pt[i] < center[i]) \
               for i in range(l_angle)]

    # Add rotation angle then convert back to cartesian vector.
    n_pol_a = [v_pol_a[i] + angle[i] for i in range(l_angle)]
    n_cart = [v_pol_l[0] * cos(n_pol_a[0])] + [v_pol_l[i] * sin(n_pol_a[i])\
                                               for i in range(l_angle)]

    # Add in the centre offset to get original offset from c.
    r = [n_cart[i] + center[i] for i in range(l_pt)]
    return tuple(r)
618941
def map_tqdm(self):
        
        with Pool(self.cpu_count) as pool:
            vals = [v for v in tqdm(pool.imap_unordered(self._func, self._iterable), total=len(self._iterable))]
            pool.close()
            return vals
652616
def write_pt(idx, value) # :nodoc:
      return unless value

      attributes = [ ['idx', idx] ]

      @writer.tag_elements('c:pt', attributes) { write_v(value) }
    end
529839
def parsedate_tz(data):
    
    res = _parsedate_tz(data)
    if not res:
        return
    if res[9] is None:
        res[9] = 0
    return tuple(res)
1022597
def _wmi_to_ts(self, wmi_ts):
        ''' 
        '''
        year, month, day, hour, minute, second, microsecond, tz = to_time(wmi_ts)
        tz_delta = timedelta(minutes=int(tz))
        if '+' in wmi_ts:
            tz_delta = -tz_delta

        dt = (
            datetime(year=year, month=month, day=day, hour=hour, minute=minute, second=second, microsecond=microsecond)
            + tz_delta
        )
        return int(calendar.timegm(dt.timetuple()))
1000596
def imm_params(imm):
    '''
    
    '''
    return {p: getattr(imm, p) for p in six.iterkeys(_imm_param_data(imm))}
188687
def getBytes(self) -> list:
        ''''''
        tmpList = []
        tmpList.extend(_FIRST_INDEX)
        # first append the high byte from the Flags and Length
        # high 4 bit: 0x7 then the bits 8-11(indexes) from _length
        length = self.length - 16
        tmpList.append((0x7 << 4) + (length >> 8))
        # Then append the lower 8 bits from _length
        tmpList.append(length & 0xFF)

        tmpList.extend(self._vector)
        tmpList.extend(self._cid)
        return tmpList
216406
def vector_str(p, decimal_places=2, print_zero=True):
    ''''''
    style = '{0:.' + str(decimal_places) + 'f}'
    return '[{0}]'.format(", ".join([' ' if not print_zero and a == 0 else style.format(a) for a in p]))
1226225
def tpm(tpm, check_independence=True):
    
    see_tpm_docs = (
        'See the documentation on TPM conventions and the `pyphi.Network` '
        'object for more information on TPM forms.'
    )
    # Cast to np.array.
    tpm = np.array(tpm)
    # Get the number of nodes from the state-by-node TPM.
    N = tpm.shape[-1]
    if tpm.ndim == 2:
        if not ((tpm.shape[0] == 2**N and tpm.shape[1] == N) or
                (tpm.shape[0] == tpm.shape[1])):
            raise ValueError(
                'Invalid shape for 2-D TPM: {}\nFor a state-by-node TPM, '
                'there must be ' '2^N rows and N columns, where N is the '
                'number of nodes. State-by-state TPM must be square. '
                '{}'.format(tpm.shape, see_tpm_docs))
        if tpm.shape[0] == tpm.shape[1] and check_independence:
            conditionally_independent(tpm)
    elif tpm.ndim == (N + 1):
        if tpm.shape != tuple([2] * N + [N]):
            raise ValueError(
                'Invalid shape for multidimensional state-by-node TPM: {}\n'
                'The shape should be {} for {} nodes. {}'.format(
                    tpm.shape, ([2] * N) + [N], N, see_tpm_docs))
    else:
        raise ValueError(
            'Invalid TPM: Must be either 2-dimensional or multidimensional. '
            '{}'.format(see_tpm_docs))
    return True
461083
def get_ptrms_angle(ptrms_best_fit_vector, B_lab_vector):
    
    ptrms_angle = math.degrees(math.acos(old_div(numpy.dot(ptrms_best_fit_vector,B_lab_vector),(numpy.sqrt(sum(ptrms_best_fit_vector**2)) * numpy.sqrt(sum(B_lab_vector**2))))))  # from old thellier_gui.py code  
    return ptrms_angle
40407
def load_data(self):
        
        data = []
        valid_dates = []
        mrms_files = np.array(sorted(os.listdir(self.path + self.variable + "/")))
        mrms_file_dates = np.array([m_file.split("_")[-2].split("-")[0]
            for m_file in mrms_files])
        old_mrms_file = None
        file_obj = None
        for t in range(self.all_dates.shape[0]):
            file_index = np.where(mrms_file_dates == self.all_dates[t].strftime("%Y%m%d"))[0]
            if len(file_index) > 0:
                mrms_file = mrms_files[file_index][0]
                if mrms_file is not None:
                    if file_obj is not None:
                        file_obj.close()
                    file_obj = Dataset(self.path + self.variable + "/" + mrms_file)
                    #old_mrms_file = mrms_file
                    
                    if "time" in file_obj.variables.keys():
                        time_var = "time"
                    else:
                        time_var = "date"
                    file_valid_dates = pd.DatetimeIndex(num2date(file_obj.variables[time_var][:],
                                                                 file_obj.variables[time_var].units))
                else:
                    file_valid_dates = pd.DatetimeIndex([])
                time_index = np.where(file_valid_dates.values == self.all_dates.values[t])[0]
                if len(time_index) > 0:
                    data.append(file_obj.variables[self.variable][time_index[0]])
                    valid_dates.append(self.all_dates[t])
        if file_obj is not None:
            file_obj.close()
        self.data = np.array(data)
        self.data[self.data < 0] = 0
        self.data[self.data > 150] = 150
        self.valid_dates = pd.DatetimeIndex(valid_dates)
1231098
def imm_values(imm):
    '''
    
    '''
    return {p: getattr(imm, p) for p in six.iterkeys(_imm_value_data(imm))}
275941
def _get_tdm(self, m):
        
        m = np.atleast_2d(m)
        assert len(m.shape) == 2
        tdm = crtomo.tdMan(grid=self.grid, tempdir=self.tempdir)
        tdm.configs.add_to_configs(self.configs)

        pid_mag = tdm.parman.add_data(m[0, :])
        tdm.register_magnitude_model(pid_mag)
        if m.shape[0] == 2:
            pid_pha = tdm.parman.add_data(m[1, :])
        else:
            pid_pha = tdm.parman.add_data(np.zeros(m.shape[1]))
        tdm.register_phase_model(pid_pha)
        return tdm