idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
52,200 | def add_to_package_numpy ( self , root , ndarray , node_path , target , source_path , transform , custom_meta ) : filehash = self . save_numpy ( ndarray ) metahash = self . save_metadata ( custom_meta ) self . _add_to_package_contents ( root , node_path , [ filehash ] , target , source_path , transform , metahash ) | Save a Numpy array to the store . |
52,201 | def add_to_package_package_tree ( self , root , node_path , pkgnode ) : if node_path : ptr = root for node in node_path [ : - 1 ] : ptr = ptr . children . setdefault ( node , GroupNode ( dict ( ) ) ) ptr . children [ node_path [ - 1 ] ] = pkgnode else : if root . children : raise PackageException ( "Attempting to overw... | Adds a package or sub - package tree from an existing package to this package s contents . |
52,202 | def _install_interrupt_handler ( ) : import os import sys import signal import pkg_resources from . tools import const quilt = pkg_resources . get_distribution ( 'quilt' ) executable = os . path . basename ( sys . argv [ 0 ] ) entry_points = quilt . get_entry_map ( ) . get ( 'console_scripts' , [ ] ) if executable == '... | Suppress KeyboardInterrupt traceback display in specific situations |
52,203 | def _data_keys ( self ) : return [ name for name , child in iteritems ( self . _children ) if not isinstance ( child , GroupNode ) ] | every child key referencing a dataframe |
52,204 | def _group_keys ( self ) : return [ name for name , child in iteritems ( self . _children ) if isinstance ( child , GroupNode ) ] | every child key referencing a group that is not a dataframe |
52,205 | def _data ( self , asa = None ) : hash_list = [ ] stack = [ self ] alldfs = True store = None while stack : node = stack . pop ( ) if isinstance ( node , GroupNode ) : stack . extend ( child for _ , child in sorted ( node . _items ( ) , reverse = True ) ) else : if node . _target ( ) != TargetType . PANDAS : alldfs = F... | Merges all child dataframes . Only works for dataframes stored on disk - not in memory . |
52,206 | def _set ( self , path , value , build_dir = '' ) : assert isinstance ( path , list ) and len ( path ) > 0 if isinstance ( value , pd . DataFrame ) : metadata = { SYSTEM_METADATA : { 'target' : TargetType . PANDAS . value } } elif isinstance ( value , np . ndarray ) : metadata = { SYSTEM_METADATA : { 'target' : TargetT... | Create and set a node by path |
52,207 | def handle_api_exception ( error ) : _mp_track ( type = "exception" , status_code = error . status_code , message = error . message , ) response = jsonify ( dict ( message = error . message ) ) response . status_code = error . status_code return response | Converts an API exception into an error response . |
52,208 | def api ( require_login = True , schema = None , enabled = True , require_admin = False , require_anonymous = False ) : if require_admin : require_login = True if schema is not None : Draft4Validator . check_schema ( schema ) validator = Draft4Validator ( schema ) else : validator = None assert not ( require_login and ... | Decorator for API requests . Handles auth and adds the username as the first argument . |
52,209 | def _private_packages_allowed ( ) : if not HAVE_PAYMENTS or TEAM_ID : return True customer = _get_or_create_customer ( ) plan = _get_customer_plan ( customer ) return plan != PaymentPlan . FREE | Checks if the current user is allowed to create private packages . |
52,210 | def _create_auth ( team , timeout = None ) : url = get_registry_url ( team ) contents = _load_auth ( ) auth = contents . get ( url ) if auth is not None : if auth [ 'expires_at' ] < time . time ( ) + 60 : try : auth = _update_auth ( team , auth [ 'refresh_token' ] , timeout ) except CommandException as ex : raise Comma... | Reads the credentials updates the access token if necessary and returns it . |
52,211 | def _create_session ( team , auth ) : session = requests . Session ( ) session . hooks . update ( dict ( response = partial ( _handle_response , team ) ) ) session . headers . update ( { "Content-Type" : "application/json" , "Accept" : "application/json" , "User-Agent" : "quilt-cli/%s (%s %s) %s/%s" % ( VERSION , platf... | Creates a session object to be used for push install etc . |
52,212 | def _get_session ( team , timeout = None ) : global _sessions session = _sessions . get ( team ) if session is None : auth = _create_auth ( team , timeout ) _sessions [ team ] = session = _create_session ( team , auth ) assert session is not None return session | Creates a session or returns an existing session . |
52,213 | def _check_team_login ( team ) : contents = _load_auth ( ) for auth in itervalues ( contents ) : existing_team = auth . get ( 'team' ) if team and team != existing_team : raise CommandException ( "Can't log in as team %r; log out first." % team ) elif not team and existing_team : raise CommandException ( "Can't log in ... | Disallow simultaneous public cloud and team logins . |
52,214 | def _check_team_exists ( team ) : if team is None : return hostname = urlparse ( get_registry_url ( team ) ) . hostname try : socket . gethostbyname ( hostname ) except IOError : try : socket . gethostbyname ( 'quiltdata.com' ) except IOError : message = "Can't find quiltdata.com. Check your internet connection." else ... | Check that the team registry actually exists . |
52,215 | def login_with_token ( refresh_token , team = None ) : _check_team_id ( team ) auth = _update_auth ( team , refresh_token ) url = get_registry_url ( team ) contents = _load_auth ( ) contents [ url ] = auth _save_auth ( contents ) _clear_session ( team ) | Authenticate using an existing token . |
52,216 | def generate ( directory , outfilename = DEFAULT_BUILDFILE ) : try : buildfilepath = generate_build_file ( directory , outfilename = outfilename ) except BuildException as builderror : raise CommandException ( str ( builderror ) ) print ( "Generated build-file %s." % ( buildfilepath ) ) | Generate a build - file for quilt build from a directory of source files . |
52,217 | def build ( package , path = None , dry_run = False , env = 'default' , force = False , build_file = False ) : team , _ , _ , subpath = parse_package ( package , allow_subpath = True ) _check_team_id ( team ) logged_in_team = _find_logged_in_team ( ) if logged_in_team is not None and team is None and force is False : a... | Compile a Quilt data package either from a build file or an existing package node . |
52,218 | def build_from_node ( package , node ) : team , owner , pkg , subpath = parse_package ( package , allow_subpath = True ) _check_team_id ( team ) store = PackageStore ( ) pkg_root = get_or_create_package ( store , team , owner , pkg , subpath ) if not subpath and not isinstance ( node , nodes . GroupNode ) : raise Comma... | Compile a Quilt data package from an existing package node . |
52,219 | def build_from_path ( package , path , dry_run = False , env = 'default' , outfilename = DEFAULT_BUILDFILE ) : team , owner , pkg , subpath = parse_package ( package , allow_subpath = True ) if not os . path . exists ( path ) : raise CommandException ( "%s does not exist." % path ) try : if os . path . isdir ( path ) :... | Compile a Quilt data package from a build file . Path can be a directory in which case the build file will be generated automatically . |
52,220 | def log ( package ) : team , owner , pkg = parse_package ( package ) session = _get_session ( team ) response = session . get ( "{url}/api/log/{owner}/{pkg}/" . format ( url = get_registry_url ( team ) , owner = owner , pkg = pkg ) ) table = [ ( "Hash" , "Pushed" , "Author" , "Tags" , "Versions" ) ] for entry in revers... | List all of the changes to a package on the server . |
52,221 | def push ( package , is_public = False , is_team = False , reupload = False , hash = None ) : team , owner , pkg , subpath = parse_package ( package , allow_subpath = True ) _check_team_id ( team ) session = _get_session ( team ) store , pkgroot = PackageStore . find_package ( team , owner , pkg , pkghash = hash ) if p... | Push a Quilt data package to the server |
52,222 | def version_list ( package ) : team , owner , pkg = parse_package ( package ) session = _get_session ( team ) response = session . get ( "{url}/api/version/{owner}/{pkg}/" . format ( url = get_registry_url ( team ) , owner = owner , pkg = pkg ) ) for version in response . json ( ) [ 'versions' ] : print ( "%s: %s" % ( ... | List the versions of a package . |
52,223 | def version_add ( package , version , pkghash , force = False ) : team , owner , pkg = parse_package ( package ) session = _get_session ( team ) try : Version ( version ) except ValueError : url = "https://www.python.org/dev/peps/pep-0440/#examples-of-compliant-version-schemes" raise CommandException ( "Invalid version... | Add a new version for a given package hash . |
52,224 | def tag_list ( package ) : team , owner , pkg = parse_package ( package ) session = _get_session ( team ) response = session . get ( "{url}/api/tag/{owner}/{pkg}/" . format ( url = get_registry_url ( team ) , owner = owner , pkg = pkg ) ) for tag in response . json ( ) [ 'tags' ] : print ( "%s: %s" % ( tag [ 'tag' ] , ... | List the tags of a package . |
52,225 | def tag_add ( package , tag , pkghash ) : team , owner , pkg = parse_package ( package ) session = _get_session ( team ) session . put ( "{url}/api/tag/{owner}/{pkg}/{tag}" . format ( url = get_registry_url ( team ) , owner = owner , pkg = pkg , tag = tag ) , data = json . dumps ( dict ( hash = _match_hash ( package , ... | Add a new tag for a given package hash . |
52,226 | def install_via_requirements ( requirements_str , force = False ) : if requirements_str [ 0 ] == '@' : path = requirements_str [ 1 : ] if os . path . isfile ( path ) : yaml_data = load_yaml ( path ) if 'packages' not in yaml_data . keys ( ) : raise CommandException ( 'Error in {filename}: missing "packages" node' . for... | Download multiple Quilt data packages via quilt . xml requirements file . |
52,227 | def access_list ( package ) : team , owner , pkg = parse_package ( package ) session = _get_session ( team ) lookup_url = "{url}/api/access/{owner}/{pkg}/" . format ( url = get_registry_url ( team ) , owner = owner , pkg = pkg ) response = session . get ( lookup_url ) data = response . json ( ) users = data [ 'users' ]... | Print list of users who can access a package . |
52,228 | def delete ( package ) : team , owner , pkg = parse_package ( package ) answer = input ( "Are you sure you want to delete this package and its entire history? " "Type '%s' to confirm: " % package ) if answer != package : print ( "Not deleting." ) return 1 session = _get_session ( team ) session . delete ( "%s/api/packa... | Delete a package from the server . |
52,229 | def search ( query , team = None ) : if team is None : team = _find_logged_in_team ( ) if team is not None : session = _get_session ( team ) response = session . get ( "%s/api/search/" % get_registry_url ( team ) , params = dict ( q = query ) ) print ( "* Packages in team %s" % team ) packages = response . json ( ) [ '... | Search for packages |
52,230 | def ls ( ) : for pkg_dir in PackageStore . find_store_dirs ( ) : print ( "%s" % pkg_dir ) packages = PackageStore ( pkg_dir ) . ls_packages ( ) for package , tag , pkghash in sorted ( packages ) : print ( "{0:30} {1:20} {2}" . format ( package , tag , pkghash ) ) | List all installed Quilt data packages |
52,231 | def inspect ( package ) : team , owner , pkg = parse_package ( package ) store , pkgroot = PackageStore . find_package ( team , owner , pkg ) if pkgroot is None : raise CommandException ( "Package {package} not found." . format ( package = package ) ) def _print_children ( children , prefix , path ) : for idx , ( name ... | Inspect package details |
52,232 | def load ( pkginfo , hash = None ) : node , pkgroot , info = _load ( pkginfo , hash ) for subnode_name in info . subpath : node = node [ subnode_name ] return node | functional interface to from quilt . data . USER import PKG |
52,233 | def c_ideal_gas ( T , k , MW ) : r Rspecific = R * 1000. / MW return ( k * Rspecific * T ) ** 0.5 | r Calculates speed of sound c in an ideal gas at temperature T . |
52,234 | def Reynolds ( V , D , rho = None , mu = None , nu = None ) : r if rho and mu : nu = mu / rho elif not nu : raise Exception ( 'Either density and viscosity, or dynamic viscosity, \ is needed' ) return V * D / nu | r Calculates Reynolds number or Re for a fluid with the given properties for the specified velocity and diameter . |
52,235 | def Peclet_heat ( V , L , rho = None , Cp = None , k = None , alpha = None ) : r if rho and Cp and k : alpha = k / ( rho * Cp ) elif not alpha : raise Exception ( 'Either heat capacity and thermal conductivity and\ density, or thermal diffusivity is needed' ) return V * L / alpha | r Calculates heat transfer Peclet number or Pe for a specified velocity V characteristic length L and specified properties for the given fluid . |
52,236 | def Fourier_heat ( t , L , rho = None , Cp = None , k = None , alpha = None ) : r if rho and Cp and k : alpha = k / ( rho * Cp ) elif not alpha : raise Exception ( 'Either heat capacity and thermal conductivity and \density, or thermal diffusivity is needed' ) return t * alpha / L ** 2 | r Calculates heat transfer Fourier number or Fo for a specified time t characteristic length L and specified properties for the given fluid . |
52,237 | def Graetz_heat ( V , D , x , rho = None , Cp = None , k = None , alpha = None ) : r if rho and Cp and k : alpha = k / ( rho * Cp ) elif not alpha : raise Exception ( 'Either heat capacity and thermal conductivity and\ density, or thermal diffusivity is needed' ) return V * D ** 2 / ( x * alpha ) | r Calculates Graetz number or Gz for a specified velocity V diameter D axial distance x and specified properties for the given fluid . |
52,238 | def Schmidt ( D , mu = None , nu = None , rho = None ) : r if rho and mu : return mu / ( rho * D ) elif nu : return nu / D else : raise Exception ( 'Insufficient information provided for Schmidt number calculation' ) | r Calculates Schmidt number or Sc for a fluid with the given parameters . |
52,239 | def Lewis ( D = None , alpha = None , Cp = None , k = None , rho = None ) : r if k and Cp and rho : alpha = k / ( rho * Cp ) elif alpha : pass else : raise Exception ( 'Insufficient information provided for Le calculation' ) return alpha / D | r Calculates Lewis number or Le for a fluid with the given parameters . |
52,240 | def Confinement ( D , rhol , rhog , sigma , g = g ) : r return ( sigma / ( g * ( rhol - rhog ) ) ) ** 0.5 / D | r Calculates Confinement number or Co for a fluid in a channel of diameter D with liquid and gas densities rhol and rhog and surface tension sigma under the influence of gravitational force g . |
52,241 | def Morton ( rhol , rhog , mul , sigma , g = g ) : r mul2 = mul * mul return g * mul2 * mul2 * ( rhol - rhog ) / ( rhol * rhol * sigma * sigma * sigma ) | r Calculates Morton number or Mo for a liquid and vapor with the specified properties under the influence of gravitational force g . |
52,242 | def Prandtl ( Cp = None , k = None , mu = None , nu = None , rho = None , alpha = None ) : r if k and Cp and mu : return Cp * mu / k elif nu and rho and Cp and k : return nu * rho * Cp / k elif nu and alpha : return nu / alpha else : raise Exception ( 'Insufficient information provided for Pr calculation' ) | r Calculates Prandtl number or Pr for a fluid with the given parameters . |
52,243 | def Grashof ( L , beta , T1 , T2 = 0 , rho = None , mu = None , nu = None , g = g ) : r if rho and mu : nu = mu / rho elif not nu : raise Exception ( 'Either density and viscosity, or dynamic viscosity, \ is needed' ) return g * beta * abs ( T2 - T1 ) * L ** 3 / nu ** 2 | r Calculates Grashof number or Gr for a fluid with the given properties temperature difference and characteristic length . |
52,244 | def Froude ( V , L , g = g , squared = False ) : r Fr = V / ( L * g ) ** 0.5 if squared : Fr *= Fr return Fr | r Calculates Froude number Fr for velocity V and geometric length L . If desired gravity can be specified as well . Normally the function returns the result of the equation below ; Froude number is also often said to be defined as the square of the equation below . |
52,245 | def Stokes_number ( V , Dp , D , rhop , mu ) : r return rhop * V * ( Dp * Dp ) / ( 18.0 * mu * D ) | r Calculates Stokes Number for a given characteristic velocity V particle diameter Dp characteristic diameter D particle density rhop and fluid viscosity mu . |
52,246 | def Suratman ( L , rho , mu , sigma ) : r return rho * sigma * L / ( mu * mu ) | r Calculates Suratman number Su for a fluid with the given characteristic length density viscosity and surface tension . |
52,247 | def nu_mu_converter ( rho , mu = None , nu = None ) : r if ( nu and mu ) or not rho or ( not nu and not mu ) : raise Exception ( 'Inputs must be rho and one of mu and nu.' ) if mu : return mu / rho elif nu : return nu * rho | r Calculates either kinematic or dynamic viscosity depending on inputs . Used when one type of viscosity is known as well as density to obtain the other type . Raises an error if both types of viscosity or neither type of viscosity is provided . |
52,248 | def Engauge_2d_parser ( lines , flat = False ) : z_values = [ ] x_lists = [ ] y_lists = [ ] working_xs = [ ] working_ys = [ ] new_curve = True for line in lines : if line . strip ( ) == '' : new_curve = True elif new_curve : z = float ( line . split ( ',' ) [ 1 ] ) z_values . append ( z ) if working_xs and working_ys :... | Not exposed function to read a 2D file generated by engauge - digitizer ; for curve fitting . |
52,249 | def isothermal_work_compression ( P1 , P2 , T , Z = 1 ) : r return Z * R * T * log ( P2 / P1 ) | r Calculates the work of compression or expansion of a gas going through an isothermal process . |
52,250 | def isentropic_T_rise_compression ( T1 , P1 , P2 , k , eta = 1 ) : r dT = T1 * ( ( P2 / P1 ) ** ( ( k - 1.0 ) / k ) - 1.0 ) / eta return T1 + dT | r Calculates the increase in temperature of a fluid which is compressed or expanded under isentropic adiabatic conditions assuming constant Cp and Cv . The polytropic model is the same equation ; just provide n instead of k and use a polytropic efficienty for eta instead of a isentropic efficiency . |
52,251 | def isentropic_efficiency ( P1 , P2 , k , eta_s = None , eta_p = None ) : r if eta_s is None and eta_p : return ( ( P2 / P1 ) ** ( ( k - 1.0 ) / k ) - 1.0 ) / ( ( P2 / P1 ) ** ( ( k - 1.0 ) / ( k * eta_p ) ) - 1.0 ) elif eta_p is None and eta_s : return ( k - 1.0 ) * log ( P2 / P1 ) / ( k * log ( ( eta_s + ( P2 / P1 ) ... | r Calculates either isentropic or polytropic efficiency from the other type of efficiency . |
52,252 | def P_isothermal_critical_flow ( P , fd , D , L ) : r lambert_term = float ( lambertw ( - exp ( ( - D - L * fd ) / D ) , - 1 ) . real ) return P * exp ( ( D * ( lambert_term + 1.0 ) + L * fd ) / ( 2.0 * D ) ) | r Calculates critical flow pressure Pcf for a fluid flowing isothermally and suffering pressure drop caused by a pipe s friction factor . |
52,253 | def P_upstream_isothermal_critical_flow ( P , fd , D , L ) : lambertw_term = float ( lambertw ( - exp ( - ( fd * L + D ) / D ) , - 1 ) . real ) return exp ( - 0.5 * ( D * lambertw_term + fd * L + D ) / D ) * P | Not part of the public API . Reverses P_isothermal_critical_flow . |
52,254 | def is_critical_flow ( P1 , P2 , k ) : r Pcf = P_critical_flow ( P1 , k ) return Pcf > P2 | r Determines if a flow of a fluid driven by pressure gradient P1 - P2 is critical for a fluid with the given isentropic coefficient . This function calculates critical flow pressure and checks if this is larger than P2 . If so the flow is critical and choked . |
52,255 | def one_phase_dP ( m , rho , mu , D , roughness = 0 , L = 1 , Method = None ) : r D2 = D * D V = m / ( 0.25 * pi * D2 * rho ) Re = Reynolds ( V = V , rho = rho , mu = mu , D = D ) fd = friction_factor ( Re = Re , eD = roughness / D , Method = Method ) dP = fd * L / D * ( 0.5 * rho * V * V ) return dP | r Calculates single - phase pressure drop . This is a wrapper around other methods . |
52,256 | def discharge_coefficient_to_K ( D , Do , C ) : r beta = Do / D beta2 = beta * beta beta4 = beta2 * beta2 return ( ( 1.0 - beta4 * ( 1.0 - C * C ) ) ** 0.5 / ( C * beta2 ) - 1.0 ) ** 2 | r Converts a discharge coefficient to a standard loss coefficient for use in computation of the actual pressure drop of an orifice or other device . |
52,257 | def dn ( self , fraction , n = None ) : r if fraction == 1.0 : fraction = 1.0 - epsilon if fraction < 0 : raise ValueError ( 'Fraction must be more than 0' ) elif fraction == 0 : if self . truncated : return self . d_min return 0.0 elif fraction > 1 : raise ValueError ( 'Fraction less than 1' ) return brenth ( lambda d... | r Computes the diameter at which a specified fraction of the distribution falls under . Utilizes a bounded solver to search for the desired diameter . |
52,258 | def fit ( self , x0 = None , distribution = 'lognormal' , n = None , ** kwargs ) : dist = { 'lognormal' : PSDLognormal , 'GGS' : PSDGatesGaudinSchuhman , 'RR' : PSDRosinRammler } [ distribution ] if distribution == 'lognormal' : if x0 is None : d_characteristic = sum ( [ fi * di for fi , di in zip ( self . fractions , ... | Incomplete method to fit experimental values to a curve . It is very hard to get good initial guesses which are really required for this . Differential evolution is promissing . This API is likely to change in the future . |
52,259 | def Dis ( self ) : return [ self . di_power ( i , power = 1 ) for i in range ( self . N ) ] | Representative diameters of each bin . |
52,260 | def SA_tank ( D , L , sideA = None , sideB = None , sideA_a = 0 , sideB_a = 0 , sideA_f = None , sideA_k = None , sideB_f = None , sideB_k = None , full_output = False ) : r if sideA == 'conical' : sideA_SA = SA_conical_head ( D = D , a = sideA_a ) elif sideA == 'ellipsoidal' : sideA_SA = SA_ellipsoidal_head ( D = D , ... | r Calculates the surface are of a cylindrical tank with optional heads . In the degenerate case of being provided with only D and L provides the surface area of a cylinder . |
52,261 | def pitch_angle_solver ( angle = None , pitch = None , pitch_parallel = None , pitch_normal = None ) : r if angle is not None and pitch is not None : pitch_normal = pitch * sin ( radians ( angle ) ) pitch_parallel = pitch * cos ( radians ( angle ) ) elif angle is not None and pitch_normal is not None : pitch = pitch_no... | r Utility to take any two of angle pitch pitch_parallel and pitch_normal and calculate the other two . This is useful for applications with tube banks as in shell and tube heat exchangers or air coolers and allows for a wider range of user input . |
52,262 | def A_hollow_cylinder ( Di , Do , L ) : r side_o = pi * Do * L side_i = pi * Di * L cap_circle = pi * Do ** 2 / 4 * 2 cap_removed = pi * Di ** 2 / 4 * 2 return side_o + side_i + cap_circle - cap_removed | r Returns the surface area of a hollow cylinder . |
52,263 | def A_multiple_hole_cylinder ( Do , L , holes ) : r side_o = pi * Do * L cap_circle = pi * Do ** 2 / 4 * 2 A = cap_circle + side_o for Di , n in holes : side_i = pi * Di * L cap_removed = pi * Di ** 2 / 4 * 2 A = A + side_i * n - cap_removed * n return A | r Returns the surface area of a cylinder with multiple holes . Calculation will naively return a negative value or other impossible result if the number of cylinders added is physically impossible . Holes may be of different shapes but must be perpendicular to the axis of the cylinder . |
52,264 | def V_from_h ( self , h , method = 'full' ) : r if method == 'full' : return V_from_h ( h , self . D , self . L , self . horizontal , self . sideA , self . sideB , self . sideA_a , self . sideB_a , self . sideA_f , self . sideA_k , self . sideB_f , self . sideB_k ) elif method == 'chebyshev' : if not self . chebyshev :... | r Method to calculate the volume of liquid in a fully defined tank given a specified height h . h must be under the maximum height . If the method is chebyshev and the coefficients have not yet been calculated they are created by calling set_chebyshev_approximators . |
52,265 | def h_from_V ( self , V , method = 'spline' ) : r if method == 'spline' : if not self . table : self . set_table ( ) return float ( self . interp_h_from_V ( V ) ) elif method == 'chebyshev' : if not self . chebyshev : self . set_chebyshev_approximators ( ) return self . h_from_V_cheb ( V ) elif method == 'brenth' : to_... | r Method to calculate the height of liquid in a fully defined tank given a specified volume of liquid in it V . V must be under the maximum volume . If the method is spline and the interpolation table is not yet defined creates it by calling the method set_table . If the method is chebyshev and the coefficients have no... |
52,266 | def set_table ( self , n = 100 , dx = None ) : r if dx : self . heights = np . linspace ( 0 , self . h_max , int ( self . h_max / dx ) + 1 ) else : self . heights = np . linspace ( 0 , self . h_max , n ) self . volumes = [ self . V_from_h ( h ) for h in self . heights ] from scipy . interpolate import UnivariateSpline ... | r Method to set an interpolation table of liquids levels versus volumes in the tank for a fully defined tank . Normally run by the h_from_V method this may be run prior to its use with a custom specification . Either the number of points on the table or the vertical distance between steps may be specified . |
52,267 | def _V_solver_error ( self , Vtarget , D , L , horizontal , sideA , sideB , sideA_a , sideB_a , sideA_f , sideA_k , sideB_f , sideB_k , sideA_a_ratio , sideB_a_ratio ) : a = TANK ( D = float ( D ) , L = float ( L ) , horizontal = horizontal , sideA = sideA , sideB = sideB , sideA_a = sideA_a , sideB_a = sideB_a , sideA... | Function which uses only the variables given and the TANK class itself to determine how far from the desired volume Vtarget the volume produced by the specified parameters in a new TANK instance is . Should only be used by solve_tank_for_V method . |
52,268 | def plate_exchanger_identifier ( self ) : s = ( 'L' + str ( round ( self . wavelength * 1000 , 2 ) ) + 'A' + str ( round ( self . amplitude * 1000 , 2 ) ) + 'B' + '-' . join ( [ str ( i ) for i in self . chevron_angles ] ) ) return s | Method to create an identifying string in format L + wavelength + A + amplitude + B + chevron angle - chevron angle . Wavelength and amplitude are specified in units of mm and rounded to two decimal places . |
52,269 | def linspace ( start , stop , num = 50 , endpoint = True , retstep = False , dtype = None ) : num = int ( num ) start = start * 1. stop = stop * 1. if num <= 0 : return [ ] if endpoint : if num == 1 : return [ start ] step = ( stop - start ) / float ( ( num - 1 ) ) if num == 1 : step = nan y = [ start ] for _ in range ... | Port of numpy s linspace to pure python . Does not support dtype and returns lists of floats . |
52,270 | def derivative ( func , x0 , dx = 1.0 , n = 1 , args = ( ) , order = 3 ) : if order < n + 1 : raise ValueError if order % 2 == 0 : raise ValueError weights = central_diff_weights ( order , n ) tot = 0.0 ho = order >> 1 for k in range ( order ) : tot += weights [ k ] * func ( x0 + ( k - ho ) * dx , * args ) return tot /... | Reimplementation of SciPy s derivative function with more cached coefficients and without using numpy . If new coefficients not cached are needed they are only calculated once and are remembered . |
52,271 | def polyder ( c , m = 1 , scl = 1 , axis = 0 ) : c = list ( c ) cnt = int ( m ) if cnt == 0 : return c n = len ( c ) if cnt >= n : c = c [ : 1 ] * 0 else : for i in range ( cnt ) : n = n - 1 c *= scl der = [ 0.0 for _ in range ( n ) ] for j in range ( n , 0 , - 1 ) : der [ j - 1 ] = j * c [ j ] c = der return c | not quite a copy of numpy s version because this was faster to implement . |
52,272 | def horner_log ( coeffs , log_coeff , x ) : tot = 0.0 for c in coeffs : tot = tot * x + c return tot + log_coeff * log ( x ) | Technically possible to save one addition of the last term of coeffs is removed but benchmarks said nothing was saved |
52,273 | def implementation_optimize_tck ( tck ) : if IS_PYPY : return tck else : if len ( tck ) == 3 : tck [ 0 ] = np . array ( tck [ 0 ] ) tck [ 1 ] = np . array ( tck [ 1 ] ) elif len ( tck ) == 5 : tck [ 0 ] = np . array ( tck [ 0 ] ) tck [ 1 ] = np . array ( tck [ 1 ] ) tck [ 2 ] = np . array ( tck [ 2 ] ) else : raise Not... | Converts 1 - d or 2 - d splines calculated with SciPy s splrep or bisplrep to a format for fastest computation - lists in PyPy and numpy arrays otherwise . Only implemented for 3 and 5 length tck s . |
52,274 | def py_bisect ( f , a , b , args = ( ) , xtol = _xtol , rtol = _rtol , maxiter = _iter , ytol = None , full_output = False , disp = True ) : fa = f ( a , * args ) fb = f ( b , * args ) if fa * fb > 0.0 : raise ValueError ( "f(a) and f(b) must have different signs" ) elif fa == 0.0 : return a elif fb == 0.0 : return b d... | Port of SciPy s C bisect routine . |
52,275 | def is_choked_turbulent_l ( dP , P1 , Psat , FF , FL = None , FLP = None , FP = None ) : r if FLP and FP : return dP >= ( FLP / FP ) ** 2 * ( P1 - FF * Psat ) elif FL : return dP >= FL ** 2 * ( P1 - FF * Psat ) else : raise Exception ( 'Either (FLP and FP) or FL is needed' ) | r Calculates if a liquid flow in IEC 60534 calculations is critical or not for use in IEC 60534 liquid valve sizing calculations . Either FL may be provided or FLP and FP depending on the calculation process . |
52,276 | def is_choked_turbulent_g ( x , Fgamma , xT = None , xTP = None ) : r if xT : return x >= Fgamma * xT elif xTP : return x >= Fgamma * xTP else : raise Exception ( 'Either xT or xTP is needed' ) | r Calculates if a gas flow in IEC 60534 calculations is critical or not for use in IEC 60534 gas valve sizing calculations . Either xT or xTP must be provided depending on the calculation process . |
52,277 | def Reynolds_valve ( nu , Q , D1 , FL , Fd , C ) : r return N4 * Fd * Q / nu / ( C * FL ) ** 0.5 * ( FL ** 2 * C ** 2 / ( N2 * D1 ** 4 ) + 1 ) ** 0.25 | r Calculates Reynolds number of a control valve for a liquid or gas flowing through it at a specified Q for a specified D1 FL Fd C and with kinematic viscosity nu according to IEC 60534 calculations . |
52,278 | def Reynolds_factor ( FL , C , d , Rev , full_trim = True ) : r if full_trim : n1 = N2 / ( min ( C / d ** 2 , 0.04 ) ) ** 2 FR_1a = 1 + ( 0.33 * FL ** 0.5 ) / n1 ** 0.25 * log10 ( Rev / 10000. ) FR_2 = 0.026 / FL * ( n1 * Rev ) ** 0.5 if Rev < 10 : FR = FR_2 else : FR = min ( FR_2 , FR_1a ) else : n2 = 1 + N32 * ( C / ... | r Calculates the Reynolds number factor FR for a valve with a Reynolds number Rev diameter d flow coefficient C liquid pressure recovery factor FL and with either full or reduced trim all according to IEC 60534 calculations . |
52,279 | def func_args ( func ) : try : return tuple ( inspect . signature ( func ) . parameters ) except : return tuple ( inspect . getargspec ( func ) . args ) | Basic function which returns a tuple of arguments of a function or method . |
52,280 | def cast_scalar ( method ) : @ wraps ( method ) def new_method ( self , other ) : if np . isscalar ( other ) : other = type ( self ) ( [ other ] , self . domain ( ) ) return method ( self , other ) return new_method | Cast scalars to constant interpolating objects |
52,281 | def dct ( data ) : N = len ( data ) // 2 fftdata = fftpack . fft ( data , axis = 0 ) [ : N + 1 ] fftdata /= N fftdata [ 0 ] /= 2. fftdata [ - 1 ] /= 2. if np . isrealobj ( data ) : data = np . real ( fftdata ) else : data = fftdata return data | Compute DCT using FFT |
52,282 | def _cutoff ( self , coeffs , vscale ) : bnd = self . _threshold ( vscale ) inds = np . nonzero ( abs ( coeffs ) >= bnd ) if len ( inds [ 0 ] ) : N = inds [ 0 ] [ - 1 ] else : N = 0 return N + 1 | Compute cutoff index after which the coefficients are deemed negligible . |
52,283 | def same_domain ( self , fun2 ) : return np . allclose ( self . domain ( ) , fun2 . domain ( ) , rtol = 1e-14 , atol = 1e-14 ) | Returns True if the domains of two objects are the same . |
52,284 | def restrict ( self , subinterval ) : if ( subinterval [ 0 ] < self . _domain [ 0 ] ) or ( subinterval [ 1 ] > self . _domain [ 1 ] ) : raise ValueError ( "Can only restrict to subinterval" ) return self . from_function ( self , subinterval ) | Return a Polyfun that matches self on subinterval . |
52,285 | def basis ( self , n ) : if n == 0 : return self ( np . array ( [ 1. ] ) ) vals = np . ones ( n + 1 ) vals [ 1 : : 2 ] = - 1 return self ( vals ) | Chebyshev basis functions T_n . |
52,286 | def sum ( self ) : ak = self . coefficients ( ) ak2 = ak [ : : 2 ] n = len ( ak2 ) Tints = 2 / ( 1 - ( 2 * np . arange ( n ) ) ** 2 ) val = np . sum ( ( Tints * ak2 . T ) . T , axis = 0 ) a_ , b_ = self . domain ( ) return 0.5 * ( b_ - a_ ) * val | Evaluate the integral over the given interval using Clenshaw - Curtis quadrature . |
52,287 | def integrate ( self ) : coeffs = self . coefficients ( ) a , b = self . domain ( ) int_coeffs = 0.5 * ( b - a ) * poly . chebyshev . chebint ( coeffs ) antiderivative = self . from_coeff ( int_coeffs , domain = self . domain ( ) ) return antiderivative - antiderivative ( a ) | Return the object representing the primitive of self over the domain . The output starts at zero on the left - hand side of the domain . |
52,288 | def differentiate ( self , n = 1 ) : ak = self . coefficients ( ) a_ , b_ = self . domain ( ) for _ in range ( n ) : ak = self . differentiator ( ak ) return self . from_coeff ( ( 2. / ( b_ - a_ ) ) ** n * ak , domain = self . domain ( ) ) | n - th derivative default 1 . |
52,289 | def sample_function ( self , f , N ) : x = self . interpolation_points ( N + 1 ) return f ( x ) | Sample a function on N + 1 Chebyshev points . |
52,290 | def interpolator ( self , x , values ) : p = Bary ( [ 0. ] ) N = len ( values ) weights = np . ones ( N ) weights [ 0 ] = .5 weights [ 1 : : 2 ] = - 1 weights [ - 1 ] *= .5 p . wi = weights p . xi = x p . set_yi ( values ) return p | Returns a polynomial with vector coefficients which interpolates the values at the Chebyshev points x |
52,291 | def drag_sphere ( Re , Method = None , AvailableMethods = False ) : r def list_methods ( ) : methods = [ ] for key , ( func , Re_min , Re_max ) in drag_sphere_correlations . items ( ) : if ( Re_min is None or Re > Re_min ) and ( Re_max is None or Re < Re_max ) : methods . append ( key ) return methods if AvailableMetho... | r This function handles calculation of drag coefficient on spheres . Twenty methods are available all requiring only the Reynolds number of the sphere . Most methods are valid from Re = 0 to Re = 200 000 . A correlation will be automatically selected if none is specified . The full list of correlations valid for a give... |
52,292 | def v_terminal ( D , rhop , rho , mu , Method = None ) : r v_lam = g * D * D * ( rhop - rho ) / ( 18 * mu ) Re_lam = Reynolds ( V = v_lam , D = D , rho = rho , mu = mu ) if Re_lam < 0.01 or Method == 'Stokes' : return v_lam Re_almost = rho * D / mu main = 4 / 3. * g * D * ( rhop - rho ) / rho V_max = 1E6 / rho / D * mu... | r Calculates terminal velocity of a falling sphere using any drag coefficient method supported by drag_sphere . The laminar solution for Re < 0 . 01 is first tried ; if the resulting terminal velocity does not put it in the laminar regime a numerical solution is used . |
52,293 | def integrate_drag_sphere ( D , rhop , rho , mu , t , V = 0 , Method = None , distance = False ) : r laminar_initial = Reynolds ( V = V , rho = rho , D = D , mu = mu ) < 0.01 v_laminar_end_assumed = v_terminal ( D = D , rhop = rhop , rho = rho , mu = mu , Method = Method ) laminar_end = Reynolds ( V = v_laminar_end_ass... | r Integrates the velocity and distance traveled by a particle moving at a speed which will converge to its terminal velocity . |
52,294 | def bend_rounded_Ito ( Di , angle , Re , rc = None , bend_diameters = None , roughness = 0.0 ) : if not rc : if bend_diameters is None : bend_diameters = 5.0 rc = Di * bend_diameters radius_ratio = rc / Di angle_rad = radians ( angle ) De2 = Re * ( Di / rc ) ** 2.0 if rc > 50.0 * Di : alpha = 1.0 else : alpha_45 = 1.0 ... | Ito method as shown in Blevins . Curved friction factor as given in Blevins with minor tweaks to be more accurate to the original methods . |
52,295 | def geopy_geolocator ( ) : global geolocator if geolocator is None : try : from geopy . geocoders import Nominatim except ImportError : return None geolocator = Nominatim ( user_agent = geolocator_user_agent ) return geolocator return geolocator | Lazy loader for geocoder from geopy . This currently loads the Nominatim geocode and returns an instance of it taking ~2 us . |
52,296 | def heating_degree_days ( T , T_base = F2K ( 65 ) , truncate = True ) : r dd = T - T_base if truncate and dd < 0.0 : dd = 0.0 return dd | r Calculates the heating degree days for a period of time . |
52,297 | def cooling_degree_days ( T , T_base = 283.15 , truncate = True ) : r dd = T_base - T if truncate and dd < 0.0 : dd = 0.0 return dd | r Calculates the cooling degree days for a period of time . |
52,298 | def get_station_year_text ( WMO , WBAN , year ) : if WMO is None : WMO = 999999 if WBAN is None : WBAN = 99999 station = str ( int ( WMO ) ) + '-' + str ( int ( WBAN ) ) gsod_year_dir = os . path . join ( data_dir , 'gsod' , str ( year ) ) path = os . path . join ( gsod_year_dir , station + '.op' ) if os . path . exist... | Basic method to download data from the GSOD database given a station identifier and year . |
52,299 | def _Stichlmair_flood_f ( inputs , Vl , rhog , rhol , mug , voidage , specific_area , C1 , C2 , C3 , H ) : Vg , dP_irr = float ( inputs [ 0 ] ) , float ( inputs [ 1 ] ) dp = 6.0 * ( 1.0 - voidage ) / specific_area Re = Vg * rhog * dp / mug f0 = C1 / Re + C2 / Re ** 0.5 + C3 dP_dry = 0.75 * f0 * ( 1.0 - voidage ) / void... | Internal function which calculates the errors of the two Stichlmair objective functions and their jacobian . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.