Ejemplo n.º 1
0
def executeMacro(compositeDataWraper, value):
    #TODO: Docs
    path = "macros"
    macro = (importlib.import_module(path + '.' + value + '.start'))
    [points, wave] = macro.execute(compositeDataWraper)
    setOfPoints = []
    setOfWaves = []
    if (len(points) > 0):
        for p in points:
            newPoints = sm.Points(p[0], p[1], p[2])
            if (p[2] in compositeDataWraper.points.keys()):
                dictType, color, axis, offset, status = DataActionWidgets.DataSettingsDialog.getDataSettings(
                    forbiddenNames=compositeDataWraper.points.keys(),
                    title=p[2])
                if status is DataActionStatus.Cancel:
                    return
            else:
                dictType = p[2]
                color = DefaultColors.getColor(p[2])
                axis = -1
            setOfPoints.append((newPoints, dictType, color, axis))
    if (len(wave) > 0):
        for w in wave:
            setOfWaves.append((w, w.type, DefaultColors.getColor(w.type), -1))

    return setOfPoints, setOfWaves
Ejemplo n.º 2
0
def _import_point_dat(file_name, point_type):
    """Importuje współrzędne punktów z pliku .dat i zwraca odpowiadający
    im sm.Points.
    """
    x, y = _import_dat(file_name)    
    return sm.Points(x, y, 
                          point_type = point_type)
Ejemplo n.º 3
0
def find_points(waves, points, begin_time, end_time, procedure, arguments):
    """Runs a `points` procedure and returns a `Points` instance
    corresponding to its output.
    """
    if (procedure.required_waves
            and not all(wave in waves for wave in procedure.required_waves)):
        raise ValueError('Not all waves from {} provided.'.format(
            procedure.required_waves))
    if (procedure.required_points
            and not all(points_ in points
                        for points_ in procedure.required_points)):
        raise ValueError('Not all points from {} provided.'.format(
            procedure.required_points))
    found_points_x, found_points_y = procedure.execute(waves, points,
                                                       begin_time, end_time,
                                                       arguments)
    return sm.Points(found_points_x, found_points_y, procedure.output_type)
Ejemplo n.º 4
0
def find_points(waves, points, begin_time, end_time, 
                procedure, arguments):
    """Odnajduje punkty na danym zakresie czasu za pomocą podanej 
    procedury.
    """
    if (procedure.required_waves
        and not all(wave in waves for wave in procedure.required_waves)):
        raise ValueError('Nie podano wymaganych przebiegów z %s'
                         % procedure.required_waves)
    if (procedure.required_points
        and not all(points_ in points for points_ in procedure.required_points)):
        raise ValueError('Nie podano wymaganych punktów z %s'
                         % procedure.required_points)
    found_points_x, found_points_y = procedure.execute(
        waves, points,
        begin_time, end_time, 
        arguments)
    return sm.Points(found_points_x, found_points_y, procedure.output_type)
Ejemplo n.º 5
0
def test_composite_data_management(bp_wave, r_points):
    composite_data = sm.Composite_data(
        waves={
            'bp':bp_wave},
        points={
            'r':r_points})
    composite_data.delete_wave('bp')
    composite_data.add_wave(bp_wave, 'bp')
    with pytest.raises(ValueError):
        composite_data.add_wave(bp_wave, 'bp')
    composite_data.add_wave(bp_wave, 'bp', replace=True)
    composite_data.delete_points('r')
    composite_data.add_points(r_points, 'r')
    with pytest.raises(ValueError):
        composite_data.add_points(r_points, 'r')
    slice_ = composite_data.points['r'].data_slice(20, 30)
    slice_points = sm.Points(slice_[0], slice_[1], 'r')
    assert slice_points[0][0] == 20.618680000000001
    assert composite_data.points['r'][22][0] == 20.618680000000001
    composite_data.points['r'].delete_slice(20, 30)
    assert composite_data.points['r'][22][0] != 20.618680000000001
    composite_data.add_points(slice_points, 'r', join=True)
    assert composite_data.points['r'][22][0] == 20.618680000000001
Ejemplo n.º 6
0
def _import_point_dat(file_name, point_type):
    """Imports coordinates from a .dat file and returns a corresponding
    `Points` instance."""
    x, y = _import_dat(file_name)    
    return sm.Points(x, y, 
                          point_type = point_type)
Ejemplo n.º 7
0
def import_modelflow_data(file_name, reference_points, reference_points_type):
    """Imports and aligns Finapres Modeflow data to already existing 
    points.
    
    Args:
        base_data - sm.Points to align to
        base_data_type - can be 'sbp', 'dbp' or 'r'
    """
    if reference_points_type not in ['sbp', 'dbp', 'r']:
        raise ValueError("Invlaid reference data type")
    x = []
    y = None
    names = None
    # Data retrieval
    with open(file_name) as f:
        if '.A00' in file_name:
            data_section = False
            for line in f:
                if not data_section and "END preamble" in line:
                    data_section = True 
                    continue
                if data_section:
                    data = line.split()
                    if len(data) > 2:
                        if names is None:
                            # trim " characters
                            names = [name[1:-1] for name in data[1:]]
                            continue
                        try:
                            x.append(float(data[0]))
                            if y is None:
                                y = [[float(str_)] for str_ in data[1:]]
                            else:
                                for i in range(1, len(data)):
                                    y[i-1].append(float(data[i]))
                        except ValueError: # If values are strings
                            continue
        else:
           i = 0
           for line in f:
               i = i + 1
               if i == 8:
                   pom = line.split(';')
                   if '\n' in pom:
                       del pom[pom.index('\n')]
                   pom[0] = 'HR'
                   names = pom
               if i > 8:
                   pom = line.split(';') 
                   if '\n' in pom:
                       del pom[pom.index('\n')]
                   if len(pom) > 2:
                       if is_number(pom[0]):
                           x.append(float(pom[0]))  
                           if y is None:
                                 y = [[0 for k in range(1)] for j in range(len(pom))]
                                 for k in range(1, len(pom)):
                                     if (is_number(pom[k])):
                                         y[k][0]=(float(pom[k]))   
                                     else:
                                         y[k][0] = 0
                           else:
                               for k in range(1, len(pom)):
                                    if (is_number(pom[k])):
                                         y[k].append(float(pom[k]))   
                                    else:
                                         y[k].append (0)
           y[0] =  _hr_from_r(x)         
    # Alignment and object initialization
    # modelflow_data[0] -> fiSYS -> SBP
    # modelflow_data[1] -> fiDIA -> DBP
    # modelflow_data[6] -> HR -> can be calculated from R
    points_list = []
    hr_points = None
    offset = 0
    for y_vals, name in zip(y, names):
        points = sm.Points(x, y_vals, name)
        points_list.append(points)
        if offset == 0:
            if reference_points_type == 'sbp' and name =='fiSYS':
                offset = _estimate_points_offset(points, reference_points)
            elif reference_points_type == 'dbp' and name == 'fiDIA':
                offset = _estimate_points_offset(points, reference_points)
            elif reference_points_type == 'r' and name == 'HR':
                hr_from_r = _hr_from_r(reference_points.data_x)
                hr_points = sm.Points(reference_points.data_x, hr_from_r,
                                      'HRfromR')
                offset = _estimate_points_offset(points, hr_points)
            

    for points in points_list:
        points.move_in_time(offset)
    
    if hr_points is not None:
        points_list.append(hr_points)
        names.append('HRfromR')


    return points_list, names