Exemplo n.º 1
0
def calculation(config, sprofile, circle):
	def _errmsg(obj_name, obj_type, Type):
		try:
			config.__dict__[obj_name] = Type(config.__dict__[obj_name])
		except:
			exit("{} can't be {}".format(obj_name, obj_type))
	
		
	general.verb(config.verbose, "Beginning Calculation of method: {}".format(config.method))
	if sprofile.ndim != 2: exit("Numpy array is wrong size, {}, needs to be 2."
	                            "".format(sprofile.ndim))
	if not isinstance(config.water_pressure, float) : _errmsg("water_pressure", type(config.water_pressure), float)
	if not isinstance(config.soil_cohesion, float)  : _errmsg("soil_cohesion", type(config.soil_cohesion), float)
	if not isinstance(config.internal_friction_angle, float): _errmsg("internal_friction_angle", type(config.internal_friction_angle), float)
	if not isinstance(config.num_of_slices, int)    : _errmsg("num_of_slices", type(config.num_of_slices), int)
	if not isinstance(config.bulk_density, float)   : _errmsg("bulk_density", type(config.bulk_density), float)
	if not isinstance(config.method, str)   : _errmsg("method", type(config.method), str)
	if not isinstance(config.vslice, int)   : _errmsg("vslice", type(config.vslice), int)
	if not isinstance(config.fos_trial, float): _errmsg("fos_trial", type(config.fos_trial), float)
	if not isinstance(circle, LineString)   : _errmsg("circle", type(circle), LineString)
	
	if config.method.lower() == 'general':
		return do_general(config, sprofile, circle)
	
	elif config.method.lower() == 'bishop':
		return do_bishop(config, sprofile, circle)
	else:
		raise StandardError("Method isn't recognized.")
Exemplo n.º 2
0
def shapely_circle(config):
	v = config.verbose
	x = config.ellipse_coordinates[0]
	y = config.ellipse_coordinates[1]
	a = config.ellipse_coordinates[2]
	b = config.ellipse_coordinates[3]
	
	g.verb(v, "Creating Shapely circle with ellipsoid data: {},{},{},{}."
	          "".format(x,y,a,b))
	
	circle = ellipse(config)
	return LineString(circle)
Exemplo n.º 3
0
def shapely_circle(config):
    v = config.verbose
    x = config.ellipse_coordinates[0]
    y = config.ellipse_coordinates[1]
    a = config.ellipse_coordinates[2]
    b = config.ellipse_coordinates[3]

    g.verb(
        v, "Creating Shapely circle with ellipsoid data: {},{},{},{}."
        "".format(x, y, a, b))

    circle = ellipse(config)
    return LineString(circle)
Exemplo n.º 4
0
def get_inter_points(config, circle, profile_data):
	g.verb(config.verbose, 'Finding Intersection between Circle and Profile')
	profile = LineString(profile_data)
	intsec_coor = list(circle.intersection(profile).bounds)
	
	if len(intsec_coor) == 0:
		exit("Error: Circle doesn't intersect the profile - please readjust circle coordinates in config file")
	
	if len(intsec_coor) != 4:
		exit("Error: Found more/less than two intersection coordinates\nNumber of intersections: {}"
		     "".format(len(intsec_coor)))
	
	return intsec_coor
Exemplo n.º 5
0
def working_space(config, profile_data):
    circle = shapely_circle(config)
    intsec_coords = format.get_inter_points(config, circle, profile_data)
    profile = shapely_line(config, profile_data)
    int1, int2 = format.fetch_intsec_coords(config, intsec_coords)

    g.verb(config.verbose, "Converting ellipse coordinates into Numpy Array.")
    circ_coords = np.array(list(circle.coords))

    g.verb(config.verbose, "Converting profile coordinates into Numpy Array.")
    profile = np.array(list(profile.coords))
    sprofile = sliced_profile(config, profile, int1, int2)

    return sprofile, circle, circ_coords
Exemplo n.º 6
0
def working_space(config, profile_data):
	circle = shapely_circle(config)
	intsec_coords = format.get_inter_points(config, circle, profile_data)
	profile = shapely_line(config, profile_data)
	int1, int2 = format.fetch_intsec_coords(config, intsec_coords)
	
	g.verb(config.verbose, "Converting ellipse coordinates into Numpy Array.")
	circ_coords = np.array(list(circle.coords))
	
	g.verb(config.verbose, "Converting profile coordinates into Numpy Array.")
	profile = np.array(list(profile.coords))
	sprofile = sliced_profile(config, profile, int1, int2)
	
	return sprofile, circle, circ_coords
Exemplo n.º 7
0
def get_inter_points(config, circle, profile_data):
    g.verb(config.verbose, 'Finding Intersection between Circle and Profile')
    profile = LineString(profile_data)
    intsec_coor = list(circle.intersection(profile).bounds)

    if len(intsec_coor) == 0:
        exit(
            "Error: Circle doesn't intersect the profile - please readjust circle coordinates in config file"
        )

    if len(intsec_coor) != 4:
        exit(
            "Error: Found more/less than two intersection coordinates\nNumber of intersections: {}"
            "".format(len(intsec_coor)))

    return intsec_coor
Exemplo n.º 8
0
def ellipse(config):
    def _deg2rad(degree):
        return degree * np.pi / 180.

    if len(config.ellipse_coordinates) < 4:
        exit("Ellipse Coordinates are not formatted correctly."
             " '{}'".format(config.ellipse_coordinates))

    v = config.verbose
    x = config.ellipse_coordinates[0]
    y = config.ellipse_coordinates[1]
    a = config.ellipse_coordinates[2]
    b = config.ellipse_coordinates[3]
    if len(config.ellipse_coordinates) == 5: c = config.ellipse_coordinates[4]
    else: c = None

    g.verb(v,
           "Generating ellipsoid coordinates: {},{},{},{}.".format(x, y, a, b))
    x_coords, y_coords = [], []
    degree = 0
    while degree <= 360:
        c_x = (a * np.cos(_deg2rad(degree)))
        c_y = (b * np.sin(_deg2rad(degree)))
        x_coords.append(c_x), y_coords.append(c_y)
        degree += 0.5

    x_coords, y_coords = np.array(x_coords), np.array(y_coords)

    if c is None:
        xy_ellipse = np.stack((x_coords + x, y_coords + y), axis=-1)
        return xy_ellipse

    x_coords = (x_coords * np.cos(_deg2rad(c))) - (y_coords *
                                                   np.sin(_deg2rad(c)))
    y_coords = (x_coords * np.sin(_deg2rad(c))) + (y_coords *
                                                   np.cos(_deg2rad(c)))
    xy_ellipse = np.stack((x_coords + x, y_coords + y), axis=-1)

    return xy_ellipse
Exemplo n.º 9
0
def calculation(config, sprofile, circle):
    def _errmsg(obj_name, obj_type, Type):
        try:
            config.__dict__[obj_name] = Type(config.__dict__[obj_name])
        except:
            exit("{} can't be {}".format(obj_name, obj_type))

    general.verb(config.verbose,
                 "Beginning Calculation of method: {}".format(config.method))
    if sprofile.ndim != 2:
        exit("Numpy array is wrong size, {}, needs to be 2."
             "".format(sprofile.ndim))
    if not isinstance(config.water_pressure, float):
        _errmsg("water_pressure", type(config.water_pressure), float)
    if not isinstance(config.soil_cohesion, float):
        _errmsg("soil_cohesion", type(config.soil_cohesion), float)
    if not isinstance(config.internal_friction_angle, float):
        _errmsg("internal_friction_angle",
                type(config.internal_friction_angle), float)
    if not isinstance(config.num_of_slices, int):
        _errmsg("num_of_slices", type(config.num_of_slices), int)
    if not isinstance(config.bulk_density, float):
        _errmsg("bulk_density", type(config.bulk_density), float)
    if not isinstance(config.method, str):
        _errmsg("method", type(config.method), str)
    if not isinstance(config.vslice, int):
        _errmsg("vslice", type(config.vslice), int)
    if not isinstance(config.fos_trial, float):
        _errmsg("fos_trial", type(config.fos_trial), float)
    if not isinstance(circle, LineString):
        _errmsg("circle", type(circle), LineString)

    if config.method.lower() == 'general':
        return do_general(config, sprofile, circle)

    elif config.method.lower() == 'bishop':
        return do_bishop(config, sprofile, circle)
    else:
        raise StandardError("Method isn't recognized.")
Exemplo n.º 10
0
def ellipse(config):
	def _deg2rad(degree):
		return degree * np.pi / 180.
	
	if len(config.ellipse_coordinates) < 4:
		exit("Ellipse Coordinates are not formatted correctly."
		     " '{}'".format(config.ellipse_coordinates))
	
	v = config.verbose
	x = config.ellipse_coordinates[0]
	y = config.ellipse_coordinates[1]
	a = config.ellipse_coordinates[2]
	b = config.ellipse_coordinates[3]
	if len(config.ellipse_coordinates) == 5: c = config.ellipse_coordinates[4]
	else: c = None
	
	g.verb(v, "Generating ellipsoid coordinates: {},{},{},{}.".format(x,y,a,b))
	x_coords, y_coords = [], []
	degree = 0
	while degree <= 360:
		c_x = (a * np.cos(_deg2rad(degree)))
		c_y = (b * np.sin(_deg2rad(degree)))
		x_coords.append(c_x), y_coords.append(c_y)
		degree += 0.5
		
	x_coords, y_coords = np.array(x_coords), np.array(y_coords)
	
	if c is None:
		xy_ellipse = np.stack((x_coords + x, y_coords + y), axis=-1)
		return xy_ellipse
	
	x_coords = (x_coords*np.cos(_deg2rad(c))) - (y_coords * np.sin(_deg2rad(c)))
	y_coords = (x_coords * np.sin(_deg2rad(c))) + (y_coords * np.cos(_deg2rad(c)))
	xy_ellipse = np.stack((x_coords + x, y_coords +y), axis=-1)
	
	return xy_ellipse
Exemplo n.º 11
0
def fetch_intsec_coords(config, intsec_coords):
	g.verb(config.verbose, "'Isolating section of profile: Length of element is correct.'")
	int1, int2 = (intsec_coords[0], intsec_coords[1]), (intsec_coords[2], intsec_coords[3])
	
	g.verb(config.verbose, "'Cross-checking intersection coordinates.'")
	if int1 == int2:
		g.verb(config.verbose,  "Error: Circle only intersects the profile in one "
	                            "place - please readjust circle coordinates "
	                            "in config file")
	
	return int1, int2
Exemplo n.º 12
0
def fetch_intsec_coords(config, intsec_coords):
    g.verb(config.verbose,
           "'Isolating section of profile: Length of element is correct.'")
    int1, int2 = (intsec_coords[0], intsec_coords[1]), (intsec_coords[2],
                                                        intsec_coords[3])

    g.verb(config.verbose, "'Cross-checking intersection coordinates.'")
    if int1 == int2:
        g.verb(
            config.verbose, "Error: Circle only intersects the profile in one "
            "place - please readjust circle coordinates "
            "in config file")

    return int1, int2
Exemplo n.º 13
0
def load_profile_data(config):
	g.verb(config.verbose, 'Loading data from file. {}'.format(config.f_data))
	data = np.loadtxt(config.f_data, delimiter=config.delimiter)
	
	g.verb(config.verbose, "Checking if number of slices is lower than actual length of data.")
	if config.num_of_slices < len(data):
		g.verb(config.verbose, "num_of_slices is set to a lower value"
		                       " than the total amount of data points."
		                       " Changing num_of_slices to '{}'"
		                       "".format(len(data)))
		
		config.num_of_slices = len(data)
	
	return data
Exemplo n.º 14
0
def load_profile_data(config):
    g.verb(config.verbose, 'Loading data from file. {}'.format(config.f_data))
    data = np.loadtxt(config.f_data, delimiter=config.delimiter)

    g.verb(
        config.verbose,
        "Checking if number of slices is lower than actual length of data.")
    if config.num_of_slices < len(data):
        g.verb(
            config.verbose, "num_of_slices is set to a lower value"
            " than the total amount of data points."
            " Changing num_of_slices to '{}'"
            "".format(len(data)))

        config.num_of_slices = len(data)

    return data
Exemplo n.º 15
0
def sliced_profile(config, profile, int1, int2):
	g.verb(config.verbose, "Creating Numpy array of sliced profile bounded within circle.")
	elevp = format.linspace2d(profile, config.num_of_slices)
	elevp = format.slice_array(elevp, int1, int2, config.num_of_slices)
	return elevp
Exemplo n.º 16
0
def sliced_profile(config, profile, int1, int2):
    g.verb(config.verbose,
           "Creating Numpy array of sliced profile bounded within circle.")
    elevp = format.linspace2d(profile, config.num_of_slices)
    elevp = format.slice_array(elevp, int1, int2, config.num_of_slices)
    return elevp
Exemplo n.º 17
0
def shapely_line(config, profile_data):
    g.verb(config.verbose, "Creating Shapely Line with Elevation Profile")
    return LineString(profile_data)
Exemplo n.º 18
0
def shapely_line(config, profile_data):
	g.verb(config.verbose, "Creating Shapely Line with Elevation Profile")
	return LineString(profile_data)