Esempio n. 1
0
        old_title_list = mesh_dict['vertex_attribute_titles']

    if verbose:
        log.critical('tsh file %s loaded' % mesh_file)

    # load in the points file
    try:
        geo = Geospatial_data(point_file, verbose=verbose)
    except IOError, e:
        if display_errors:
            log.critical("Could not load bad file: %s" % str(e))
        raise IOError  #Re-raise exception  

    point_coordinates = geo.get_data_points(absolute=True)
    title_list, point_attributes = concatinate_attributelist( \
        geo.get_all_attributes())

    if mesh_dict.has_key('geo_reference') and \
           not mesh_dict['geo_reference'] is None:
        mesh_origin = mesh_dict['geo_reference'].get_origin()
    else:
        mesh_origin = None

    if verbose:
        log.critical("points file loaded")
    if verbose:
        log.critical("fitting to mesh")
    f = fit_to_mesh(point_coordinates,
                    vertex_coordinates,
                    triangles,
                    None,
Esempio n. 2
0
        old_title_list = mesh_dict['vertex_attribute_titles']

    if verbose:
        log.critical('tsh file %s loaded' % mesh_file)

    # load in the points file
    try:
        geo = Geospatial_data(point_file, verbose=verbose)
    except IOError, e:
        if display_errors:
            log.critical("Could not load bad file: %s" % str(e))
        raise IOError  #Re-raise exception

    point_coordinates = geo.get_data_points(absolute=True)
    title_list, point_attributes = concatinate_attributelist( \
        geo.get_all_attributes())

    if mesh_dict.has_key('geo_reference') and \
           not mesh_dict['geo_reference'] is None:
        mesh_origin = mesh_dict['geo_reference'].get_origin()
    else:
        mesh_origin = None

    if verbose:
        log.critical("points file loaded")
    if verbose:
        log.critical("fitting to mesh")
    f = fit_to_mesh(point_coordinates,
                    vertex_coordinates,
                    triangles,
                    None,
Esempio n. 3
0
def fit_to_mesh_file(mesh_file,
                     point_file,
                     mesh_output_file,
                     alpha=DEFAULT_ALPHA,
                     verbose=False,
                     expand_search=False,
                     precrop=False,
                     display_errors=True):
    """
    Given a mesh file (tsh) and a point attribute file, fit
    point attributes to the mesh and write a mesh file with the
    results.

    Note: the points file needs titles.  If you want anuga to use the tsh file,
    make sure the title is elevation.

    NOTE: Throws IOErrors, for a variety of file problems.

    """

    from anuga.load_mesh.loadASCII import import_mesh_file, \
        export_mesh_file, concatinate_attributelist

    try:
        mesh_dict = import_mesh_file(mesh_file)
    except IOError as e:
        if display_errors:
            log.critical("Could not load bad file: %s" % str(e))
        raise IOError  # Could not load bad mesh file.

    vertex_coordinates = mesh_dict['vertices']
    triangles = mesh_dict['triangles']
    if isinstance(mesh_dict['vertex_attributes'], num.ndarray):
        old_point_attributes = mesh_dict['vertex_attributes'].tolist()
    else:
        old_point_attributes = mesh_dict['vertex_attributes']

    if isinstance(mesh_dict['vertex_attribute_titles'], num.ndarray):
        old_title_list = mesh_dict['vertex_attribute_titles'].tolist()
    else:
        old_title_list = mesh_dict['vertex_attribute_titles']

    if verbose:
        log.critical('tsh file %s loaded' % mesh_file)

    # load in the points file
    try:
        geo = Geospatial_data(point_file, verbose=verbose)
    except IOError as e:
        if display_errors:
            log.critical("Could not load bad file: %s" % str(e))
        raise IOError  # Re-raise exception

    point_coordinates = geo.get_data_points(absolute=True)
    title_list, point_attributes = concatinate_attributelist(
        geo.get_all_attributes())

    if 'geo_reference' in mesh_dict and \
            not mesh_dict['geo_reference'] is None:
        mesh_origin = mesh_dict['geo_reference'].get_origin()
    else:
        mesh_origin = None

    if verbose:
        log.critical("points file loaded")
    if verbose:
        log.critical("fitting to mesh")
    f = fit_to_mesh(point_coordinates,
                    vertex_coordinates,
                    triangles,
                    None,
                    point_attributes,
                    alpha=alpha,
                    verbose=verbose,
                    data_origin=None,
                    mesh_origin=mesh_origin)
    if verbose:
        log.critical("finished fitting to mesh")

    # convert array to list of lists
    new_point_attributes = f.tolist()
    # FIXME have this overwrite attributes with the same title - DSG
    # Put the newer attributes last
    if old_title_list != []:
        old_title_list.extend(title_list)
        # FIXME can this be done a faster way? - DSG
        for i in range(len(old_point_attributes)):
            old_point_attributes[i].extend(new_point_attributes[i])
        mesh_dict['vertex_attributes'] = old_point_attributes
        mesh_dict['vertex_attribute_titles'] = old_title_list
    else:
        mesh_dict['vertex_attributes'] = new_point_attributes
        mesh_dict['vertex_attribute_titles'] = title_list

    if verbose:
        log.critical("exporting to file %s" % mesh_output_file)

    try:
        export_mesh_file(mesh_output_file, mesh_dict)
    except IOError as e:
        if display_errors:
            log.critical("Could not write file %s", str(e))
        raise IOError