def check_p32_targets(params): """ Check the number of polygons if stopCondition is set to 1, else check the p32 target parameters. Parameters ------------- params : dict parameter dictionary Returns --------- None Notes --------- Exits program is inconsistencies are found. """ # Check P32 inputs for ellipses if params['nFamEll']['value'] > 0: hf.check_none('e_p32Targets', params['e_p32Targets']['value']) hf.check_length('e_p32Targets', params['e_p32Targets']['value'],params['nFamEll']['value']) hf.check_values('e_p32Targets',params['e_p32Targets']['value'],0) # Check P32 inputs for rectangles if params['nFamRect']['value'] > 0: hf.check_none('r_p32Targets', params['r_p32Targets']['value']) hf.check_length('r_p32Targets', params['r_p32Targets']['value'],params['nFamRect']['value']) hf.check_values('r_p32Targets',params['r_p32Targets']['value'],0)
def check_regions_fracture(params, prefix): """ Checks that the number of regions is each family is correct. Checks that the region index is a known index. Parameters ------------- params : dict parameter dictionary prefix : string either 'e' or 'r' for ellipse or rectangle Returns --------- None Notes --------- Exits program is inconsistencies are found. """ key = prefix + "Region" shape = "ellipse" if prefix == 'e' else "rectangle" num_families = params['nFamEll']['value'] if prefix == 'e' else params[ 'nFamRect']['value'] hf.check_none(key, params[key]['value']) hf.check_length(key, params[key]['value'], num_families) hf.check_values(key, params[key]['value'], 0, params["numOfRegions"]['value'])
def check_aspect(params, prefix): """ Check the aspect of the rectangle or ellipse families matches the number of families requested and is a positive value Parameters ------------- params : dict parameter dictionary prefix : string either 'e' or 'r' for ellipse or rectangle Returns --------- None Notes --------- Exits program is inconsistencies are found. """ key = prefix + "aspect" shape = "ellipse" if prefix == 'e' else "rectangle" num_families = params['nFamEll']['value'] if prefix == 'e' else params[ 'nFamRect']['value'] hf.check_none(key, params[key]['value']) hf.check_length(key, params[key]['value'], num_families) hf.check_values(key, params[key]['value'], 0)
def check_aperture(params): """ Checks how apertures are being defined. This feature will be removed in the future and apertures will be defined by family.. Parameters ------------- params : dict parameter dictionary Returns --------- None Notes --------- Exits program is inconsistencies are found. """ if params['aperture']['value'] == 1: hf.check_none('meanAperture', params['meanAperture']['value']) hf.check_none('stdAperture', params['stdAperture']['value']) hf.check_values('stdAperture', params['stdAperture']['value'], 0) elif params['aperture']['value'] == 2: hf.check_none('apertureFromTransmissivity', params['apertureFromTransmissivity']['value']) hf.check_length('apertureFromTransmissivity', params['apertureFromTransmissivity']['value'], 2) if params['apertureFromTransmissivity']['value'][0] == 0: hf.print_error( "\"apertureFromTransmissivity\"'s first value cannot be 0.") if params['apertureFromTransmissivity']['value'][1] == 0: hf.print_warning( "\"apertureFromTransmissivity\"'s second value is 0, which will result in a constant aperture." ) elif params['aperture']['value'] == 3: hf.check_none('constantAperture', params['constantAperture']['value']) hf.check_values('constantAperture', params['constantAperture']['value'], 0) elif params['aperture']['value'] == 4: hf.check_none('lengthCorrelatedAperture', params['lengthCorrelatedAperture']['value']) hf.check_length('lengthCorrelatedAperture', params['lengthCorrelatedAperture']['value'], 2) if params['lengthCorrelatedAperture']['value'][0] == 0: hf.print_error( "\"lengthCorrelatedAperture\"'s first value cannot be 0.") if params['lengthCorrelatedAperture']['value'][1] == 0: hf.print_warning( "\"lengthCorrelatedAperture\"'s second value is 0, which will result in a constant aperture." ) else: hf.print_error("\"aperture\" must only be option 1 (log-normal), 2 (from transmissivity), "\ "3 (constant), or 4 (length correlated).")
def check_beta_distribution(params, prefix): """ Verifies both the "ebetaDistribution" and "rBetaDistribution". If either contain any flags indicating constant angle (1) then the corresponding "ebeta" and/or "rbeta" parameters are also verified. Parameters ------------- params : dict parameter dictionary prefix : string either 'e' or 'r' for ellipse or rectangle Returns --------- None Notes --------- Exits program is inconsistencies are found. """ shape = "ellipse" if prefix == 'e' else "rectangle" num_families = params['nFamEll']['value'] if prefix == 'e' else params[ 'nFamRect']['value'] angle_option_key = prefix + 'AngleOption' #check kappa key = prefix + 'betaDistribution' hf.check_none(key, params[key]['value']) hf.check_length(key, params[key]['value'], num_families) # check actual values of beta num_beta = params[key]['value'].count(1) if num_beta > 0: beta_key = prefix + "beta" hf.check_none(beta_key, params[beta_key]['value']) hf.check_length(beta_key, params[beta_key]['value'], num_beta) for i, val in enumerate(params[beta_key]['value']): if params[angle_option_key]['value'] == 0: if val < 0 or val > 2 * pi: hf.print_error( f"\"{key}\" entry {i+1} has value {val} which is outside of acceptable parameter range [0,2*pi). If you want to use degrees, please use {angle_option_key} = 1. " ) # check degrees else: if val < 0 or val > 365: hf.print_error( f"\"{key}\" entry {i+1} has value {val} which is outside of acceptable parameter range [0,365). " )
def check_user_defined(params): user_files = [("userEllipsesOnOff", "UserEll_Input_File_Path"), ("userRectanglesOnOff", "UserRect_Input_File_Path"), ("userRecByCoord", "RectByCoord_Input_File_Path"), ("userEllByCoord", "EllByCoord_Input_File_Path"), ("userPolygonByCoord", "PolygonByCoord_Input_File_Path")] for flag, path in user_files: # User Ellipse hf.check_none(flag, params[flag]['value']) if params[flag]['value']: hf.check_path(params[path]['value']) copy(params[path]['value'], "./")
def check_layers_general(params): """ Check the number of layers provided matching the requested number. Checks boundaries of layers that they are within the domain. Parameters ------------- params : dict parameter dictionary Returns --------- None Notes --------- Exits program is inconsistencies are found. """ hf.check_none('layers', params['layers']['value']) hf.check_length('layers', params['layers']['value'], params['numOfLayers']['value']) half_z_domain = params['domainSize']['value'][ 2] / 2.0 ## -index[2] becaue domainSize = [x,y,z] ## -center of z-domain at z = 0 so ## whole Zdomain is -zDomainSize to +zDomainSize for i, layer in enumerate(params['layers']['value']): if len(layer) != 2: hf.print_error( f"\"layers\" has defined layer #{i+1} to have {len(layer)} element(s) but each layer must have 2 elements, which define its upper and lower bounds" ) if params['layers']['value'].count(layer) > 1: hf.print_error( "\"layers\" has defined the same layer more than once.") minZ = layer[0] maxZ = layer[1] if maxZ <= minZ: hf.print_error( f"\"layers\" has defined layer #{i+1} where zmin: {minZ} is greater than zmax {maxZ}" ) if minZ <= -half_z_domain and maxZ <= -half_z_domain: hf.print_error( f"\"layers\" has defined layer #{i+1} to have both upper and lower bounds completely below the domain's z-dimensional range ({-half_z_domain} to {half_z_domain}). At least one boundary must be within the domain's range. The domain's range is half of 3rd value in \"domainSize (z-dimension) in both positive and negative directions." ) if minZ >= half_z_domain and maxZ >= half_z_domain: hf.print_error( f"\"layers\" has defined layer #{i+1} to have both upper and lower bounds completely above the domain's z-dimensional range ({-half_z_domain} to {half_z_domain}). At least one boundary must be within the domain's range. The domain's range is half of 3rd value in \"domainSize\" (z-dimension) in both positive and negative directions." )
def check_enum_points(params): """ Check that the value of enumPoints for each ellipse family is an integer greater than 4 Parameters ------------- params : dict parameter dictionary Returns --------- None Notes --------- Exits program is inconsistencies are found. """ key = 'enumPoints' hf.check_none(key, params[key]['value']) hf.check_length(key, params[key]['value'], params['nFamEll']['value']) hf.check_values(key, params[key]['value'], 4)
def check_permeability(params): """Verify the float used for permeability, if permOption is set to 1 Parameters ------------- params : dict parameter dictionary Returns --------- None Notes --------- Exits program is inconsistencies are found. """ if params['permOption']['value'] == 1: hf.check_none('constantPermeability', params['constantPermeability']['value']) hf.check_values('constantPermeability', params['constantPermeability']['value'], 0)
def check_distributions(params, prefix): """ Verifies "edistr" and "rdistr" making sure one distribution is defined per family and each distribution is either 1 (log-normal), 2 (Truncated Power Law), 3 (Exponential), or 4 (constant). Parameters ------------- params : dict parameter dictionary prefix : string either 'e' or 'r' for ellipse or rectangle Returns --------- None Notes --------- Exits program is inconsistencies are found. """ key = prefix + "distr" shape = "ellipse" if prefix == 'e' else "rectangle" num_families = params['nFamEll']['value'] if prefix == 'e' else params[ 'nFamRect']['value'] hf.check_none(key, params[key]['value']) hf.check_length(key, params[key]['value'], num_families) hf.check_values(key, params[key]['value'], 1, 4) #check lengths for i in params[key]['value']: cnt = params[key]['value'].count(i) if i == 1: ## logNormal dist_keys = [ prefix + name for name in ["LogMean", "sd", "LogMin", "LogMax"] ] for dist_key in dist_keys: hf.check_none(dist_key, params[dist_key]['value']) hf.check_length(dist_key, params[dist_key]['value'], cnt) check_lognormal_dist(params, prefix, shape, cnt) elif i == 2: # TPL dist_keys = [prefix + name for name in ["min", "max", "alpha"]] for dist_key in dist_keys: hf.check_none(dist_key, params[dist_key]['value']) hf.check_length(dist_key, params[dist_key]['value'], cnt) check_tpl_dist(params, prefix, shape, cnt) elif i == 3: # Exp dist_keys = [ prefix + name for name in ["ExpMean", "ExpMin", "ExpMax"] ] for dist_key in dist_keys: hf.check_none(dist_key, params[dist_key]['value']) hf.check_length(dist_key, params[dist_key]['value'], cnt) check_exponential_dist(params, prefix, shape, cnt) elif i == 4: # constant dist_keys = [prefix + name for name in ["const"]] for dist_key in dist_keys: hf.check_none(dist_key, params[dist_key]['value']) hf.check_length(dist_key, params[dist_key]['value'], cnt) check_constant_dist(params, prefix, shape, cnt)
def check_regions_general(params): """ Check the number of regions provided matching the requested number. Checks boundaries of regions that they are within the domain. Checks that region_min_value < region_max_value for all three spatial coordinates. Parameters ------------- params : dict parameter dictionary Returns --------- None Notes --------- Exits program is inconsistencies are found. """ hf.check_none('regions', params['regions']['value']) hf.check_length('regions', params['regions']['value'], params['numOfRegions']['value']) half_x_domain = params['domainSize']['value'][0] / 2.0 half_y_domain = params['domainSize']['value'][1] / 2.0 half_z_domain = params['domainSize']['value'][2] / 2.0 for i, region in enumerate(params['regions']['value']): if len(region) != 6: hf.print_error( f"\"regions\" has defined layer #{i+1} to have {len(region)} element(s) but each region must have 6 elements, which define its upper and lower bounds" ) if params['regions']['value'].count(region) > 1: hf.print_error( "\"regions\" has defined the same region more than once.") # X direction if region[1] <= region[0]: hf.print_error( f"\"regions\" has defined region #{i+1} where xmin: {region[0]} is greater than xmax: {region[1]}" ) if region[0] <= -half_x_domain and region[1] <= -half_x_domain: hf.print_error( f"\"regions\" has defined region #{i+1} to have both upper and lower x-bounds completely below the domain's x-dimensional range ({-half_x_domain} to {half_x_domain}). At least one boundary must be within the domain's range. The domain's range is half of 1st value in \"domainSize\" (x-dimension) in both positive and negative directions." ) if region[0] >= half_x_domain and region[1] >= half_x_domain: hf.print_error( f"\"regions\" has defined region #{i+1} to have both upper and lower x-bounds completely above the domain's x-dimensional range ({-half_x_domain} to {half_x_domain}). At least one boundary must be within the domain's range. The domain's range is half of 1st value in \"domainSize\" (x-dimension) in both positive and negative directions." ) # Y direction if region[3] <= region[2]: hf.print_error( f"\"regions\" has defined region #{i+1} where ymin: {region[2]} is greater than ymax: {region[3]}" ) if region[2] <= -half_y_domain and region[3] <= -half_y_domain: hf.print_error( f"\"regions\" has defined region #{i+1} to have both upper and lower y-bounds completely below the domain's y-dimensional range ({-half_y_domain} to {half_y_domain}). At least one boundary must be within the domain's range. The domain's range is half of 2nd value in \"domainSize\" (y-dimension) in both positive and negative directions." ) if region[2] >= half_y_domain and region[3] >= half_y_domain: hf.print_error( f"\"regions\" has defined region #{i+1} to have both upper and lower y-bounds completely above the domain's y-dimensional range ({-half_y_domain} to {half_y_domain}). At least one boundary must be within the domain's range. The domain's range is half of 2nd value in \"domainSize\" (y-dimension) in both positive and negative directions." ) # Z direction if region[5] <= region[4]: hf.print_error( f"\"regions\" has defined region #{i+1} where zmin: {region[4]} is greater than zmax: {region[5]}" ) if region[4] <= -half_z_domain and region[5] <= -half_z_domain: hf.print_error( f"\"regions\" has defined region #{i+1} to have both upper and lower z-bounds completely below the domain's y-dimensional range ({-half_z_domain} to {half_z_domain}). At least one boundary must be within the domain's range. The domain's range is half of 3rd value in \"domainSize\" (z-dimension) in both positive and negative directions." ) if region[4] >= half_z_domain and region[5] >= half_z_domain: hf.print_error( f"\"regions\" has defined region #{i+1} to have both upper and lower y-bounds completely above the domain's y-dimensional range ({-half_y_domain} to {half_z_domain}). At least one boundary must be within the domain's range. The domain's range is half of 3rd value in \"domainSize\" (z-dimension) in both positive and negative directions." )
def check_orientations(params, prefix): """ Checks orientation options. If using trend/plunge, degrees must be used. If using spherical, radians are okay as well. Checks that values are within acceptable ranges. Parameters ------------- params : dict parameter dictionary prefix : string either 'e' or 'r' for ellipse or rectangle Returns --------- None Notes --------- Exits program is inconsistencies are found. """ shape = "ellipse" if prefix == 'e' else "rectangle" num_families = params['nFamEll']['value'] if prefix == 'e' else params[ 'nFamRect']['value'] angle_option_key = prefix + 'AngleOption' if params["orientationOption"]["value"] == 0: #print("--> Using Spherical Coordinates") keys = [prefix + name for name in ["theta", "phi"]] elif params["orientationOption"]["value"] == 1: #print("--> Using Trend and Plunge") # 0 is radians, 1 is degrees if params[angle_option_key]['value'] == 0: hf.print_error( f"Using Trend and Plunge but {prefix + 'AngleOption'} is set to use radians. Trend and plunge must use degrees. Set {prefix + 'AngleOption'} = 1. " ) keys = [prefix + name for name in ["trend", "plunge"]] elif params["orientationOption"]["value"] == 2: # using dip / strike if params[angle_option_key]['value'] == 0: hf.print_error( f"Using Dip and Strike but {prefix + 'AngleOption'} is set to use radians. Trend and plunge must use degrees. Set {prefix + 'AngleOption'} = 1. " ) keys = [prefix + name for name in ["dip", "strike"]] else: hf.print_error(f"Unknown orientation option. Value must be 0,1, or 2.") for key in keys: hf.check_none(key, params[key]['value']) hf.check_length(key, params[key]['value'], num_families) for i, val in enumerate(params[key]['value']): # check radians if params[angle_option_key]['value'] == 0: if val < 0 or val > 2 * pi: hf.print_error( f"\"{key}\" entry {i+1} has value {val} which is outside of acceptable parameter range [0,2*pi). If you want to use degrees, please use {angle_option_key} = 1. " ) # check degrees else: if val < 0 or val > 365: hf.print_error( f"\"{key}\" entry {i+1} has value {val} which is outside of acceptable parameter range [0,365). " ) #check kappa key = prefix + 'kappa' hf.check_none(key, params[key]['value']) hf.check_length(key, params[key]['value'], num_families) hf.check_values(key, params[key]['value'], 0, 100)