idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
42,200 | def plot_iso ( axis , step , var ) : xmesh , ymesh , fld = get_meshes_fld ( step , var ) if conf . field . shift : fld = np . roll ( fld , conf . field . shift , axis = 0 ) axis . contour ( xmesh , ymesh , fld , linewidths = 1 ) | Plot isocontours of scalar field . |
42,201 | def plot_vec ( axis , step , var ) : xmesh , ymesh , vec1 , vec2 = get_meshes_vec ( step , var ) dipz = step . geom . nztot // 10 if conf . field . shift : vec1 = np . roll ( vec1 , conf . field . shift , axis = 0 ) vec2 = np . roll ( vec2 , conf . field . shift , axis = 0 ) if step . geom . spherical or conf . plot . ... | Plot vector field . |
42,202 | def cmd ( ) : sdat = StagyyData ( conf . core . path ) sovs = set_of_vars ( conf . field . plot ) minmax = { } if conf . plot . cminmax : conf . plot . vmin = None conf . plot . vmax = None for step in sdat . walk . filter ( snap = True ) : for var , _ in sovs : if var in step . fields : if var in phyvars . FIELD : dim... | Implementation of field subcommand . |
42,203 | def _sub ( cmd , * sections ) : cmd_func = cmd if isfunction ( cmd ) else cmd . cmd return Subcmd ( baredoc ( cmd ) , * sections , func = cmd_func ) | Build Subcmd instance . |
42,204 | def _steps_to_slices ( ) : if not ( conf . core . timesteps or conf . core . snapshots ) : conf . core . timesteps = None conf . core . snapshots = slice ( - 1 , None , None ) return elif conf . core . snapshots : conf . core . timesteps = None steps = conf . core . snapshots else : conf . core . snapshots = None steps... | parse timesteps and snapshots arguments and return slices |
42,205 | def parse_args ( arglist = None ) : climan = CLIManager ( conf , ** SUB_CMDS ) create_complete_files ( climan , CONFIG_DIR , 'stagpy' , 'stagpy-git' , zsh_sourceable = True ) cmd_args , all_subs = climan . parse_args ( arglist ) sub_cmd = cmd_args . loam_sub_name if sub_cmd is None : return cmd_args . func if sub_cmd !... | Parse cmd line arguments . |
42,206 | def plot_plate_limits ( axis , ridges , trenches , ymin , ymax ) : for trench in trenches : axis . axvline ( x = trench , ymin = ymin , ymax = ymax , color = 'red' , ls = 'dashed' , alpha = 0.4 ) for ridge in ridges : axis . axvline ( x = ridge , ymin = ymin , ymax = ymax , color = 'green' , ls = 'dashed' , alpha = 0.4... | plot lines designating ridges and trenches |
42,207 | def plot_plate_limits_field ( axis , rcmb , ridges , trenches ) : for trench in trenches : xxd = ( rcmb + 1.02 ) * np . cos ( trench ) yyd = ( rcmb + 1.02 ) * np . sin ( trench ) xxt = ( rcmb + 1.35 ) * np . cos ( trench ) yyt = ( rcmb + 1.35 ) * np . sin ( trench ) axis . annotate ( '' , xy = ( xxd , yyd ) , xytext = ... | plot arrows designating ridges and trenches in 2D field plots |
42,208 | def io_surface ( timestep , time , fid , fld ) : fid . write ( "{} {}" . format ( timestep , time ) ) fid . writelines ( [ "%10.2e" % item for item in fld [ : ] ] ) fid . writelines ( [ "\n" ] ) | Output for surface files |
42,209 | def set_of_vars ( arg_plot ) : return set ( var for var in arg_plot . split ( ',' ) if var in phyvars . PLATES ) | Build set of needed variables . |
42,210 | def _check_config ( ) : config . CONFIG_DIR . mkdir ( parents = True , exist_ok = True ) verfile = config . CONFIG_DIR / '.version' uptodate = verfile . is_file ( ) and verfile . read_text ( ) == __version__ if not uptodate : verfile . write_text ( __version__ ) if not ( uptodate and config . CONFIG_FILE . is_file ( ) ... | Create config files as necessary . |
42,211 | def load_mplstyle ( ) : plt = importlib . import_module ( 'matplotlib.pyplot' ) if conf . plot . mplstyle : for style in conf . plot . mplstyle . split ( ) : stfile = config . CONFIG_DIR / ( style + '.mplstyle' ) if stfile . is_file ( ) : style = str ( stfile ) try : plt . style . use ( style ) except OSError : print (... | Try to load conf . plot . mplstyle matplotlib style . |
42,212 | def dtime ( sdat , tstart = None , tend = None ) : tseries = sdat . tseries_between ( tstart , tend ) time = tseries [ 't' ] . values return time [ 1 : ] - time [ : - 1 ] , time [ : - 1 ] | Time increment dt . |
42,213 | def dt_dt ( sdat , tstart = None , tend = None ) : tseries = sdat . tseries_between ( tstart , tend ) time = tseries [ 't' ] . values temp = tseries [ 'Tmean' ] . values dtdt = ( temp [ 1 : ] - temp [ : - 1 ] ) / ( time [ 1 : ] - time [ : - 1 ] ) return dtdt , time [ : - 1 ] | Derivative of temperature . |
42,214 | def ebalance ( sdat , tstart = None , tend = None ) : tseries = sdat . tseries_between ( tstart , tend ) rbot , rtop = misc . get_rbounds ( sdat . steps . last ) if rbot != 0 : coefsurf = ( rtop / rbot ) ** 2 volume = rbot * ( ( rtop / rbot ) ** 3 - 1 ) / 3 else : coefsurf = 1. volume = 1. dtdt , time = dt_dt ( sdat , ... | Energy balance . |
42,215 | def mobility ( sdat , tstart = None , tend = None ) : tseries = sdat . tseries_between ( tstart , tend ) steps = sdat . steps [ tseries . index [ 0 ] : tseries . index [ - 1 ] ] time = [ ] mob = [ ] for step in steps . filter ( rprof = True ) : time . append ( step . timeinfo [ 't' ] ) mob . append ( step . rprof . ilo... | Plates mobility . |
42,216 | def r_edges ( step ) : rbot , rtop = misc . get_rbounds ( step ) centers = step . rprof . loc [ : , 'r' ] . values + rbot edges = ( centers [ : - 1 ] + centers [ 1 : ] ) / 2 edges = np . insert ( edges , 0 , rbot ) edges = np . append ( edges , rtop ) return edges , edges | Cell border . |
42,217 | def _scale_prof ( step , rprof , rad = None ) : rbot , rtop = misc . get_rbounds ( step ) if rbot == 0 : return rprof if rad is None : rad = step . rprof [ 'r' ] . values + rbot return rprof * ( 2 * rad / ( rtop + rbot ) ) ** 2 | Scale profile to take sphericity into account |
42,218 | def diffs_prof ( step ) : diff , rad = diff_prof ( step ) return _scale_prof ( step , diff , rad ) , rad | Scaled diffusion . |
42,219 | def energy_prof ( step ) : diff , rad = diffs_prof ( step ) adv , _ = advts_prof ( step ) return ( diff + np . append ( adv , 0 ) ) , rad | Energy flux . |
42,220 | def advth ( step ) : rbot , rtop = misc . get_rbounds ( step ) rmean = 0.5 * ( rbot + rtop ) rad = step . rprof [ 'r' ] . values + rbot radio = step . timeinfo [ 'H_int' ] if rbot != 0 : th_adv = - ( rtop ** 3 - rad ** 3 ) / rmean ** 2 / 3 else : th_adv = rad - rtop th_adv *= radio th_adv += step . timeinfo [ 'Nutop' ]... | Theoretical advection . |
42,221 | def init_c_overturn ( step ) : rbot , rtop = misc . get_rbounds ( step ) xieut = step . sdat . par [ 'tracersin' ] [ 'fe_eut' ] k_fe = step . sdat . par [ 'tracersin' ] [ 'k_fe' ] xi0l = step . sdat . par [ 'tracersin' ] [ 'fe_cont' ] xi0s = k_fe * xi0l xired = xi0l / xieut rsup = ( rtop ** 3 - xired ** ( 1 / ( 1 - k_f... | Initial concentration . |
42,222 | def c_overturned ( step ) : rbot , rtop = misc . get_rbounds ( step ) cinit , rad = init_c_overturn ( step ) radf = ( rtop ** 3 + rbot ** 3 - rad ** 3 ) ** ( 1 / 3 ) return cinit , radf | Theoretical overturned concentration . |
42,223 | def last ( self ) : if self . _last is UNDETERMINED : self . _last = self . sdat . tseries . index [ - 1 ] return self [ self . _last ] | Last time step available . |
42,224 | def filter ( self , ** filters ) : for flt , val in self . _flt . items ( ) : self . _flt [ flt ] = filters . pop ( flt , val ) if filters : raise error . UnknownFiltersError ( filters . keys ( ) ) return self | Update filters with provided arguments . |
42,225 | def hdf5 ( self ) : if self . _rundir [ 'hdf5' ] is UNDETERMINED : h5_folder = self . path / self . par [ 'ioin' ] [ 'hdf5_output_folder' ] if ( h5_folder / 'Data.xmf' ) . is_file ( ) : self . _rundir [ 'hdf5' ] = h5_folder else : self . _rundir [ 'hdf5' ] = None return self . _rundir [ 'hdf5' ] | Path of output hdf5 folder if relevant None otherwise . |
42,226 | def tseries ( self ) : if self . _stagdat [ 'tseries' ] is UNDETERMINED : timefile = self . filename ( 'TimeSeries.h5' ) self . _stagdat [ 'tseries' ] = stagyyparsers . time_series_h5 ( timefile , list ( phyvars . TIME . keys ( ) ) ) if self . _stagdat [ 'tseries' ] is not None : return self . _stagdat [ 'tseries' ] ti... | Time series data . |
42,227 | def files ( self ) : if self . _rundir [ 'ls' ] is UNDETERMINED : out_stem = pathlib . Path ( self . par [ 'ioin' ] [ 'output_file_stem' ] + '_' ) out_dir = self . path / out_stem . parent if out_dir . is_dir ( ) : self . _rundir [ 'ls' ] = set ( out_dir . iterdir ( ) ) else : self . _rundir [ 'ls' ] = set ( ) return s... | Set of found binary files output by StagYY . |
42,228 | def walk ( self ) : if conf . core . snapshots is not None : return self . snaps [ conf . core . snapshots ] elif conf . core . timesteps is not None : return self . steps [ conf . core . timesteps ] return self . snaps [ - 1 : ] | Return view on configured steps slice . |
42,229 | def scale ( self , data , unit ) : if self . par [ 'switches' ] [ 'dimensional_units' ] or not conf . scaling . dimensional or unit == '1' : return data , '' scaling = phyvars . SCALES [ unit ] ( self . scales ) factor = conf . scaling . factors . get ( unit , ' ' ) if conf . scaling . time_in_y and unit == 's' : scali... | Scales quantity to obtain dimensionful quantity . |
42,230 | def tseries_between ( self , tstart = None , tend = None ) : if self . tseries is None : return None ndat = self . tseries . shape [ 0 ] if tstart is None : istart = 0 else : igm = 0 igp = ndat - 1 while igp - igm > 1 : istart = igm + ( igp - igm ) // 2 if self . tseries . iloc [ istart ] [ 't' ] >= tstart : igp = ista... | Return time series data between requested times . |
42,231 | def filename ( self , fname , timestep = None , suffix = '' , force_legacy = False ) : if timestep is not None : fname += '{:05d}' . format ( timestep ) fname += suffix if not force_legacy and self . hdf5 : fpath = self . hdf5 / fname else : fpath = self . par [ 'ioin' ] [ 'output_file_stem' ] + '_' + fname fpath = sel... | Return name of StagYY output file . |
42,232 | def binfiles_set ( self , isnap ) : possible_files = set ( self . filename ( fstem , isnap , force_legacy = True ) for fstem in phyvars . FIELD_FILES ) return possible_files & self . files | Set of existing binary files at a given snap . |
42,233 | def _tidy_names ( names , nnames , extra_names = None ) : if len ( names ) < nnames and extra_names is not None : names . extend ( extra_names ) names . extend ( range ( nnames - len ( names ) ) ) del names [ nnames : ] | Truncate or extend names so that its len is nnames . |
42,234 | def time_series ( timefile , colnames ) : if not timefile . is_file ( ) : return None data = pd . read_csv ( timefile , delim_whitespace = True , dtype = str , header = None , skiprows = 1 , index_col = 0 , engine = 'c' , memory_map = True , error_bad_lines = False , warn_bad_lines = False ) data = data . apply ( pd . ... | Read temporal series text file . |
42,235 | def time_series_h5 ( timefile , colnames ) : if not timefile . is_file ( ) : return None with h5py . File ( timefile , 'r' ) as h5f : dset = h5f [ 'tseries' ] _ , ncols = dset . shape ncols -= 1 h5names = map ( bytes . decode , h5f [ 'names' ] [ len ( colnames ) + 1 : ] ) _tidy_names ( colnames , ncols , h5names ) data... | Read temporal series HDF5 file . |
42,236 | def _extract_rsnap_isteps ( rproffile ) : step_regex = re . compile ( r'^\*+step:\s*(\d+) ; time =\s*(\S+)' ) isteps = [ ] rows_to_del = set ( ) line = ' ' with rproffile . open ( ) as stream : while line [ 0 ] != '*' : line = stream . readline ( ) match = step_regex . match ( line ) istep = int ( match . group ( 1 ) )... | Extract istep and compute list of rows to delete |
42,237 | def _readbin ( fid , fmt = 'i' , nwords = 1 , file64 = False , unpack = True ) : if fmt in 'if' : fmt += '8' if file64 else '4' elts = np . fromfile ( fid , fmt , nwords ) if unpack and len ( elts ) == 1 : elts = elts [ 0 ] return elts | Read n words of 4 or 8 bytes with fmt format . |
42,238 | def tracers ( tracersfile ) : if not tracersfile . is_file ( ) : return None tra = { } with tracersfile . open ( 'rb' ) as fid : readbin = partial ( _readbin , fid ) magic = readbin ( ) if magic > 8000 : magic -= 8000 readbin ( ) readbin = partial ( readbin , file64 = True ) if magic < 100 : raise ParsingError ( tracer... | Extract tracers data . |
42,239 | def _read_group_h5 ( filename , groupname ) : with h5py . File ( filename , 'r' ) as h5f : data = h5f [ groupname ] [ ( ) ] return data | Return group content . |
42,240 | def _make_3d ( field , twod ) : shp = list ( field . shape ) if twod and 'X' in twod : shp . insert ( 1 , 1 ) elif twod : shp . insert ( 0 , 1 ) return field . reshape ( shp ) | Add a dimension to field if necessary . |
42,241 | def _ncores ( meshes , twod ) : nnpb = len ( meshes ) nns = [ 1 , 1 , 1 ] if twod is None or 'X' in twod : while ( nnpb > 1 and meshes [ nns [ 0 ] ] [ 'X' ] [ 0 , 0 , 0 ] == meshes [ nns [ 0 ] - 1 ] [ 'X' ] [ - 1 , 0 , 0 ] ) : nns [ 0 ] += 1 nnpb -= 1 cpu = lambda icy : icy * nns [ 0 ] if twod is None or 'Y' in twod : ... | Compute number of nodes in each direction . |
42,242 | def _conglomerate_meshes ( meshin , header ) : meshout = { } npc = header [ 'nts' ] // header [ 'ncs' ] shp = [ val + 1 if val != 1 else 1 for val in header [ 'nts' ] ] x_p = int ( shp [ 0 ] != 1 ) y_p = int ( shp [ 1 ] != 1 ) for coord in meshin [ 0 ] : meshout [ coord ] = np . zeros ( shp ) for icore in range ( np . ... | Conglomerate meshes from several cores into one . |
42,243 | def _get_field ( xdmf_file , data_item ) : shp = _get_dim ( data_item ) h5file , group = data_item . text . strip ( ) . split ( ':/' , 1 ) icore = int ( group . split ( '_' ) [ - 2 ] ) - 1 fld = _read_group_h5 ( xdmf_file . parent / h5file , group ) . reshape ( shp ) return icore , fld | Extract field from data item . |
42,244 | def _maybe_get ( elt , item , info , conversion = None ) : maybe_item = elt . find ( item ) if maybe_item is not None : maybe_item = maybe_item . get ( info ) if conversion is not None : maybe_item = conversion ( maybe_item ) return maybe_item | Extract and convert info if item is present . |
42,245 | def read_geom_h5 ( xdmf_file , snapshot ) : header = { } xdmf_root = xmlET . parse ( str ( xdmf_file ) ) . getroot ( ) if snapshot is None : return None , xdmf_root elt_snap = xdmf_root [ 0 ] [ 0 ] [ snapshot ] header [ 'ti_ad' ] = float ( elt_snap . find ( 'Time' ) . get ( 'Value' ) ) header [ 'mo_lambda' ] = _maybe_g... | Extract geometry information from hdf5 files . |
42,246 | def _to_spherical ( flds , header ) : cth = np . cos ( header [ 't_mesh' ] [ : , : , : - 1 ] ) sth = np . sin ( header [ 't_mesh' ] [ : , : , : - 1 ] ) cph = np . cos ( header [ 'p_mesh' ] [ : , : , : - 1 ] ) sph = np . sin ( header [ 'p_mesh' ] [ : , : , : - 1 ] ) fout = np . copy ( flds ) fout [ 0 ] = cth * cph * fld... | Convert vector field to spherical . |
42,247 | def _flds_shape ( fieldname , header ) : shp = list ( header [ 'nts' ] ) shp . append ( header [ 'ntb' ] ) if fieldname == 'Velocity' : shp . insert ( 0 , 3 ) header [ 'xp' ] = int ( header [ 'nts' ] [ 0 ] != 1 ) shp [ 1 ] += header [ 'xp' ] header [ 'yp' ] = int ( header [ 'nts' ] [ 1 ] != 1 ) shp [ 2 ] += header [ 'y... | Compute shape of flds variable . |
42,248 | def _post_read_flds ( flds , header ) : if flds . shape [ 0 ] >= 3 and header [ 'rcmb' ] > 0 : header [ 'p_mesh' ] = np . roll ( np . arctan2 ( header [ 'y_mesh' ] , header [ 'x_mesh' ] ) , - 1 , 1 ) for ibk in range ( header [ 'ntb' ] ) : flds [ ... , ibk ] = _to_spherical ( flds [ ... , ibk ] , header ) header [ 'p_m... | Process flds to handle sphericity . |
42,249 | def read_field_h5 ( xdmf_file , fieldname , snapshot , header = None ) : if header is None : header , xdmf_root = read_geom_h5 ( xdmf_file , snapshot ) else : xdmf_root = xmlET . parse ( str ( xdmf_file ) ) . getroot ( ) npc = header [ 'nts' ] // header [ 'ncs' ] flds = np . zeros ( _flds_shape ( fieldname , header ) )... | Extract field data from hdf5 files . |
42,250 | def read_tracers_h5 ( xdmf_file , infoname , snapshot , position ) : xdmf_root = xmlET . parse ( str ( xdmf_file ) ) . getroot ( ) tra = { } tra [ infoname ] = [ { } , { } ] if position : for axis in 'xyz' : tra [ axis ] = [ { } , { } ] for elt_subdomain in xdmf_root [ 0 ] [ 0 ] [ snapshot ] . findall ( 'Grid' ) : ibk ... | Extract tracers data from hdf5 files . |
42,251 | def _init_shape ( self ) : shape = self . _par [ 'geometry' ] [ 'shape' ] . lower ( ) aspect = self . _header [ 'aspect' ] if self . rcmb is not None and self . rcmb >= 0 : self . _shape [ 'cyl' ] = self . twod_xz and ( shape == 'cylindrical' or aspect [ 0 ] >= np . pi ) self . _shape [ 'sph' ] = not self . _shape [ 'c... | Determine shape of geometry |
42,252 | def _get_raw_data ( self , name ) : filestem = '' for filestem , list_fvar in self . _files . items ( ) : if name in list_fvar : break fieldfile = self . step . sdat . filename ( filestem , self . step . isnap , force_legacy = True ) if not fieldfile . is_file ( ) : fieldfile = self . step . sdat . filename ( filestem ... | Find file holding data and return its content . |
42,253 | def geom ( self ) : if self . _header is UNDETERMINED : binfiles = self . step . sdat . binfiles_set ( self . step . isnap ) if binfiles : self . _header = stagyyparsers . fields ( binfiles . pop ( ) , only_header = True ) elif self . step . sdat . hdf5 : xmf = self . step . sdat . hdf5 / 'Data.xmf' self . _header , _ ... | Geometry information . |
42,254 | def timeinfo ( self ) : if self . istep not in self . sdat . tseries . index : return None return self . sdat . tseries . loc [ self . istep ] | Time series data of the time step . |
42,255 | def rprof ( self ) : if self . istep not in self . sdat . rprof . index . levels [ 0 ] : return None return self . sdat . rprof . loc [ self . istep ] | Radial profiles data of the time step . |
42,256 | def isnap ( self ) : if self . _isnap is UNDETERMINED : istep = None isnap = - 1 while ( istep is None or istep < self . istep ) and isnap < 99999 : isnap += 1 istep = self . sdat . snaps [ isnap ] . istep self . sdat . snaps . bind ( isnap , istep ) if istep != self . istep : self . _isnap = None return self . _isnap | Snapshot index corresponding to time step . |
42,257 | def from_json_dict ( dct , validate = True ) : if validate : validate_schema_dict ( dct ) version = dct [ 'version' ] if version == 1 : dct = convert_v1_to_v2 ( dct ) if validate : validate_schema_dict ( dct ) elif version != 2 : msg = ( 'Schema version {} is not supported. ' 'Consider updating clkhash.' ) . format ( v... | Create a Schema for v1 or v2 according to dct |
42,258 | def _get_master_schema ( version ) : try : file_name = MASTER_SCHEMA_FILE_NAMES [ version ] except ( TypeError , KeyError ) as e : msg = ( 'Schema version {} is not supported. ' 'Consider updating clkhash.' ) . format ( version ) raise_from ( SchemaError ( msg ) , e ) try : schema_bytes = pkgutil . get_data ( 'clkhash'... | Loads the master schema of given version as bytes . |
42,259 | def validate_schema_dict ( schema ) : if not isinstance ( schema , dict ) : msg = ( 'The top level of the schema file is a {}, whereas a dict is ' 'expected.' . format ( type ( schema ) . __name__ ) ) raise SchemaError ( msg ) if 'version' in schema : version = schema [ 'version' ] else : raise SchemaError ( 'A format ... | Validate the schema . |
42,260 | def compute_hash_speed ( num , quiet = False ) : namelist = NameList ( num ) os_fd , tmpfile_name = tempfile . mkstemp ( text = True ) schema = NameList . SCHEMA header_row = ',' . join ( [ f . identifier for f in schema . fields ] ) with open ( tmpfile_name , 'wt' ) as f : f . write ( header_row ) f . write ( '\n' ) f... | Hash time . |
42,261 | def hash ( pii_csv , keys , schema , clk_json , quiet , no_header , check_header , validate ) : schema_object = clkhash . schema . from_json_file ( schema_file = schema ) header = True if not check_header : header = 'ignore' if no_header : header = False try : clk_data = clk . generate_clk_from_csv ( pii_csv , keys , s... | Process data to create CLKs |
42,262 | def status ( server , output , verbose ) : if verbose : log ( "Connecting to Entity Matching Server: {}" . format ( server ) ) service_status = server_get_status ( server ) if verbose : log ( "Status: {}" . format ( service_status [ 'status' ] ) ) print ( json . dumps ( service_status ) , file = output ) | Connect to an entity matching server and check the service status . |
42,263 | def create_project ( type , schema , server , name , output , verbose ) : if verbose : log ( "Entity Matching Server: {}" . format ( server ) ) if schema is not None : schema_json = json . load ( schema ) clkhash . schema . validate_schema_dict ( schema_json ) else : raise ValueError ( "Schema must be provided when cre... | Create a new project on an entity matching server . |
42,264 | def create ( server , name , project , apikey , output , threshold , verbose ) : if verbose : log ( "Entity Matching Server: {}" . format ( server ) ) if threshold is None : raise ValueError ( "Please provide a threshold" ) try : response = run_create ( server , project , apikey , threshold , name ) except ServiceError... | Create a new run on an entity matching server . |
42,265 | def upload ( clk_json , project , apikey , server , output , verbose ) : if verbose : log ( "Uploading CLK data from {}" . format ( clk_json . name ) ) log ( "To Entity Matching Server: {}" . format ( server ) ) log ( "Project ID: {}" . format ( project ) ) log ( "Uploading CLK data to the server" ) response = project_... | Upload CLK data to entity matching server . |
42,266 | def results ( project , apikey , run , watch , server , output ) : status = run_get_status ( server , project , run , apikey ) log ( format_run_status ( status ) ) if watch : for status in watch_run_status ( server , project , run , apikey , 24 * 60 * 60 ) : log ( format_run_status ( status ) ) if status [ 'state' ] ==... | Check to see if results are available for a particular mapping and if so download . |
42,267 | def generate ( size , output , schema ) : pii_data = randomnames . NameList ( size ) if schema is not None : raise NotImplementedError randomnames . save_csv ( pii_data . names , [ f . identifier for f in pii_data . SCHEMA . fields ] , output ) | Generate fake PII data for testing |
42,268 | def generate_default_schema ( output ) : original_path = os . path . join ( os . path . dirname ( __file__ ) , 'data' , 'randomnames-schema.json' ) shutil . copyfile ( original_path , output ) | Get default schema for fake PII |
42,269 | def docx_extraction ( docx , cloud = None , batch = False , api_key = None , version = None , ** kwargs ) : docx = docx_preprocess ( docx , batch = batch ) url_params = { "batch" : batch , "api_key" : api_key , "version" : version } results = api_handler ( docx , cloud = cloud , api = "docxextraction" , url_params = ur... | Given a . docx file returns the raw text associated with the given . docx file . The . docx file may be provided as base64 encoded data or as a filepath . |
42,270 | def docx_preprocess ( docx , batch = False ) : if batch : return [ docx_preprocess ( doc , batch = False ) for doc in docx ] if os . path . isfile ( docx ) : return b64encode ( open ( docx , 'rb' ) . read ( ) ) else : return docx | Load docx files from local filepath if not already b64 encoded |
42,271 | def LAMBDA ( self , node ) : self . handleNode , self . deferHandleNode = self . deferHandleNode , self . handleNode super ( ) . LAMBDA ( node ) self . handleNode , self . deferHandleNode = self . deferHandleNode , self . handleNode | This is likely very brittle currently works for pyflakes 1 . 3 . 0 . |
42,272 | def double_hash_encode_ngrams ( ngrams , keys , ks , l , encoding ) : key_sha1 , key_md5 = keys bf = bitarray ( l ) bf . setall ( False ) for m , k in zip ( ngrams , ks ) : sha1hm = int ( hmac . new ( key_sha1 , m . encode ( encoding = encoding ) , sha1 ) . hexdigest ( ) , 16 ) % l md5hm = int ( hmac . new ( key_md5 , ... | Computes the double hash encoding of the ngrams with the given keys . |
42,273 | def double_hash_encode_ngrams_non_singular ( ngrams , keys , ks , l , encoding ) : key_sha1 , key_md5 = keys bf = bitarray ( l ) bf . setall ( False ) for m , k in zip ( ngrams , ks ) : m_bytes = m . encode ( encoding = encoding ) sha1hm_bytes = hmac . new ( key_sha1 , m_bytes , sha1 ) . digest ( ) md5hm_bytes = hmac .... | computes the double hash encoding of the n - grams with the given keys . |
42,274 | def blake_encode_ngrams ( ngrams , keys , ks , l , encoding ) : key , = keys log_l = int ( math . log ( l , 2 ) ) if not 2 ** log_l == l : raise ValueError ( 'parameter "l" has to be a power of two for the BLAKE2 encoding, ' 'but was: {}' . format ( l ) ) bf = bitarray ( l ) bf . setall ( False ) for m , k in zip ( ngr... | Computes the encoding of the ngrams using the BLAKE2 hash function . |
42,275 | def fold_xor ( bloomfilter , folds ) : if len ( bloomfilter ) % 2 ** folds != 0 : msg = ( 'The length of the bloom filter is {length}. It is not ' 'divisible by 2 ** {folds}, so it cannot be folded {folds} ' 'times.' . format ( length = len ( bloomfilter ) , folds = folds ) ) raise ValueError ( msg ) for _ in range ( f... | Performs XOR folding on a Bloom filter . |
42,276 | def crypto_bloom_filter ( record , tokenizers , schema , keys ) : hash_l = schema . l * 2 ** schema . xor_folds bloomfilter = bitarray ( hash_l ) bloomfilter . setall ( False ) for ( entry , tokenize , field , key ) in zip ( record , tokenizers , schema . fields , keys ) : fhp = field . hashing_properties if fhp : ngra... | Computes the composite Bloom filter encoding of a record . |
42,277 | def re_compile_full ( pattern , flags = 0 ) : assert type ( pattern ) is str or type ( pattern ) is unicode return re . compile ( r'(?:{})\Z' . format ( pattern ) , flags = flags ) | Create compiled regular expression such that it matches the entire string . Calling re . match on the output of this function is equivalent to calling re . fullmatch on its input . |
42,278 | def _p2_unicode_reader ( unicode_csv_data , dialect = csv . excel , ** kwargs ) : utf8_csv_data = _utf_8_encoder ( unicode_csv_data ) csv_reader = csv . reader ( utf8_csv_data , dialect = dialect , ** kwargs ) return ( [ unicode ( cell , 'utf-8' ) for cell in row ] for row in csv_reader ) | Encode Unicode as UTF - 8 and parse as CSV . |
42,279 | def get_list_dimensions ( _list ) : if isinstance ( _list , list ) or isinstance ( _list , tuple ) : return [ len ( _list ) ] + get_list_dimensions ( _list [ 0 ] ) return [ ] | Takes a nested list and returns the size of each dimension followed by the element type in the list |
42,280 | def get_element_type ( _list , dimens ) : elem = _list for _ in range ( len ( dimens ) ) : elem = elem [ 0 ] return type ( elem ) | Given the dimensions of a nested list and the list returns the type of the elements in the inner list . |
42,281 | def image_recognition ( image , cloud = None , batch = False , api_key = None , version = None , ** kwargs ) : image = data_preprocess ( image , batch = batch , size = 144 , min_axis = True ) url_params = { "batch" : batch , "api_key" : api_key , "version" : version } return api_handler ( image , cloud = cloud , api = ... | Given an input image returns a dictionary of image classifications with associated scores |
42,282 | def spec_from_json_dict ( json_dict ) : if 'ignored' in json_dict : return Ignore ( json_dict [ 'identifier' ] ) type_str = json_dict [ 'format' ] [ 'type' ] spec_type = cast ( FieldSpec , FIELD_TYPE_MAP [ type_str ] ) return spec_type . from_json_dict ( json_dict ) | Turns a dictionary into the appropriate object . |
42,283 | def replace_missing_value ( self , str_in ) : if self . missing_value is None : return str_in elif self . missing_value . sentinel == str_in : return self . missing_value . replace_with else : return str_in | returns str_in if it is not equals to the sentinel as defined in the missingValue section of the schema . Else it will return the replaceWith value . |
42,284 | def from_json_dict ( cls , json_dict ) : result = cast ( StringSpec , super ( ) . from_json_dict ( json_dict ) ) format_ = json_dict [ 'format' ] if 'encoding' in format_ and result . hashing_properties : result . hashing_properties . encoding = format_ [ 'encoding' ] if 'pattern' in format_ : pattern = format_ [ 'patt... | Make a StringSpec object from a dictionary containing its properties . |
42,285 | def from_json_dict ( cls , json_dict ) : result = cast ( IntegerSpec , super ( ) . from_json_dict ( json_dict ) ) format_ = json_dict [ 'format' ] result . minimum = format_ . get ( 'minimum' ) result . maximum = format_ . get ( 'maximum' ) return result | Make a IntegerSpec object from a dictionary containing its properties . |
42,286 | def from_json_dict ( cls , json_dict ) : result = cast ( DateSpec , super ( ) . from_json_dict ( json_dict ) ) format_ = json_dict [ 'format' ] result . format = format_ [ 'format' ] return result | Make a DateSpec object from a dictionary containing its properties . |
42,287 | def from_json_dict ( cls , json_dict ) : result = cast ( EnumSpec , super ( ) . from_json_dict ( json_dict ) ) format_ = json_dict [ 'format' ] result . values = set ( format_ [ 'values' ] ) return result | Make a EnumSpec object from a dictionary containing its properties . |
42,288 | def standardize_input_data ( data ) : if type ( data ) == bytes : data = data . decode ( 'utf-8' ) if type ( data ) == list : data = [ el . decode ( 'utf-8' ) if type ( data ) == bytes else el for el in data ] return data | Ensure utf - 8 encoded strings are passed to the indico API |
42,289 | def api_handler ( input_data , cloud , api , url_params = None , batch_size = None , ** kwargs ) : url_params = url_params or { } input_data = standardize_input_data ( input_data ) cloud = cloud or config . cloud host = "%s.indico.domains" % cloud if cloud else config . host if not ( host . endswith ( 'indico.domains' ... | Sends finalized request data to ML server and receives response . If a batch_size is specified breaks down a request into smaller component requests and aggregates the results . |
42,290 | def collect_api_results ( input_data , url , headers , api , batch_size , kwargs ) : if batch_size : results = [ ] for batch in batched ( input_data , size = batch_size ) : try : result = send_request ( batch , api , url , headers , kwargs ) if isinstance ( result , list ) : results . extend ( result ) else : results .... | Optionally split up a single request into a series of requests to ensure timely HTTP responses . |
42,291 | def send_request ( input_data , api , url , headers , kwargs ) : data = { } if input_data != None : data [ 'data' ] = input_data serializer = kwargs . pop ( "serializer" , config . serializer ) data [ 'serializer' ] = serializer data . update ( ** kwargs ) json_data = json . dumps ( data ) response = requests . post ( ... | Use the requests library to send of an HTTP call to the indico servers |
42,292 | def create_url ( url_protocol , host , api , url_params ) : is_batch = url_params . pop ( "batch" , None ) apis = url_params . pop ( "apis" , None ) version = url_params . pop ( "version" , None ) or url_params . pop ( "v" , None ) method = url_params . pop ( 'method' , None ) host_url_seg = url_protocol + "://%s" % ho... | Generate the proper url for sending off data for analysis |
42,293 | def keywords ( text , cloud = None , batch = False , api_key = None , version = 2 , batch_size = None , ** kwargs ) : if kwargs . get ( "language" , "english" ) != "english" : version = 1 url_params = { "batch" : batch , "api_key" : api_key , "version" : version } return api_handler ( text , cloud = cloud , api = "keyw... | Given input text returns series of keywords and associated scores |
42,294 | def personas ( text , cloud = None , batch = False , api_key = None , version = None , ** kwargs ) : url_params = { "batch" : batch , "api_key" : api_key , "version" : version } kwargs [ 'persona' ] = True return api_handler ( text , cloud = cloud , api = "personality" , url_params = url_params , ** kwargs ) | Given input text returns the authors likelihood of being 16 different personality types in a dict . |
42,295 | def pdf_extraction ( pdf , cloud = None , batch = False , api_key = None , version = None , ** kwargs ) : pdf = pdf_preprocess ( pdf , batch = batch ) url_params = { "batch" : batch , "api_key" : api_key , "version" : version } results = api_handler ( pdf , cloud = cloud , api = "pdfextraction" , url_params = url_param... | Given a pdf returns the text and metadata associated with the given pdf . PDFs may be provided as base64 encoded data or as a filepath . Base64 image data and formatted table is optionally returned by setting images = True or tables = True . |
42,296 | def get_tokenizer ( fhp ) : def dummy ( word , ignore = None ) : return ( '' for i in range ( 0 ) ) if not fhp : return dummy n = fhp . ngram if n < 0 : raise ValueError ( '`n` in `n`-gram must be non-negative.' ) positional = fhp . positional def tok ( word , ignore = None ) : if ignore is not None : word = word . rep... | Get tokeniser function from the hash settings . |
42,297 | def pdf_preprocess ( pdf , batch = False ) : if batch : return [ pdf_preprocess ( doc , batch = False ) for doc in pdf ] if os . path . isfile ( pdf ) : return b64encode ( open ( pdf , 'rb' ) . read ( ) ) else : return pdf | Load pdfs from local filepath if not already b64 encoded |
42,298 | def update ( self , x ) : if any ( math . isnan ( float ( i ) ) or math . isinf ( float ( i ) ) for i in x ) : raise ValueError ( 'input contains non-finite numbers like "nan" or "+/- inf"' ) t = sum ( x ) m = float ( len ( x ) ) norm_t = t / m S = sum ( ( xi - norm_t ) ** 2 for xi in x ) if self . n == 0 : self . S = ... | updates the statistics with the given list of numbers |
42,299 | def generate_clk_from_csv ( input_f , keys , schema , validate = True , header = True , progress_bar = True ) : if header not in { False , True , 'ignore' } : raise ValueError ( "header must be False, True or 'ignore' but is {}." . format ( header ) ) log . info ( "Hashing data" ) reader = unicode_reader ( input_f ) if... | Generate Bloom filters from CSV file then serialise them . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.