def ART2(X, a=10, b=10, c=0.3, d=0.75, theta=0.1, rho=0.997, output=None, e=1E-8): if a <= 0: print('a should > 0, but a is ', str(a)) raise if b <= 0: print('b should > 0, but is ', str(b)) raise if d < 0 or d > 1: print('0 <= d <= 1, but d is ', str(d)) raise if c * d / (1 - d) > 1: print('c*d/(1-d) <= 1, but c*d/(1-d) is ', str(c * d / (1 - d))) if rho <= 0 or rho > 1: print('0 < rho <= 1, but rho is ', str(rho)) raise if e > 1E-1: warnings('e << 1, but e is ', str(e)) X = np.array(X) m, n = X.shape if output is None: output = m WF1_F2 = np.dot(np.ones((output,n)),0.5/((1-d)*math.sqrt(n))) WF2_F1 = np.zeros((n, output)) w = np.zeros(m) for j in range(m): Input = X[j,:] u,J = ART_Process(Input, output,a,b,c,d,WF1_F2,WF2_F1, rho,theta,e) WF2_F1[:,J] = np.transpose((u/(1-d))[0]) WF1_F2[J,:] = (u/(1-d))[0] w[j] = J return w
def window_args(self, val): # If future value is not available, force to set the labels at the # right end of the window to avoid data leakage. if not self.future_value_available and "center" in val and val[ "center"] is True: val["center"] = False warnings("window_args['center'] is set to False, because " "future_value_available is False") self._window_args = val
def get_min_cost(features, label): Xs = np.array(features) ys = np.array(label) Xs_multiply = np.dot(Xs.T, Xs) try: inverse = np.linalg.inv(Xs_multiply) except np.linalg.LinAlgError: warnings("looks like matrix is non-inverable") min_cost = np.dot(inverse, np.dot(Xs.T, ys)) return min_cost
def __call__(self, inputs): axes = self.get_axes() for axe in axes: try: f = axe.get_figure() f.clf() except: import warnings warnings('a figure could not be selected or deleted.') axe.get_figure().canvas.draw() return self.get_input('axes')
def getFile(filename, commentPrefix='#', lowercase=False, unique=False): retVal = list() if not unique else OrderedDict() if filename: filename = filename.strip('"\'') checkFile(filename) try: with open(filename, 'r') as f: for l in f: if commentPrefix: if l.find(commentPrefix) != -1: l = l[:l.find(commentPrefix)] line = line.strip() if line: if lowercase: line = line.lower() if unique and line in retVal: continue if unique: retVal[line] = True else: retVal.append(line) except (IOError, OSError, MemoryError) as ex: errMsg = "something went wrong while trying " errMsg += "to read the content of file '%s' ('%s')" % (filename, (ex)) raise warnings(errMsg) return retVal if not unique else list(retVal.keys())
def culledLegForwardTransform(orders, locations, functionVals, threshold=None): # inspired by : A Simple Regularization of the Polynomial Interpolation For the Runge Phenomemenon if len(locations.shape)==1: vandermonde=leg.legvander(locations, orders[0]) elif locations.shape[1]==2: vandermonde=leg.legvander2d(locations[:,0], locations[:,1], orders) elif locations.shape[1]==3: vandermonde=leg.legvander3d(locations[:,0],locations[:,1],locations[:,2], orders) elif locations.shape[1]==4: vandermonde=legvander4d(locations,orders) elif locations.shape[1]==5: vandermonde=legvander5d(locations,orders) else: raise NotImplementedError # there's a bad startup joke about this being good enough for the paper. # preconditioner = np.diag((0.94) ** (2* (np.arange(vandermonde.shape[0])))) # vandermonde=np.dot(preconditioner, vandermonde) U,S,Vh=np.linalg.svd(vandermonde) numTake=0 filtS=S if threshold is None: Eps= np.finfo(functionVals.dtype).eps Neps = np.prod(cmn.numpyze(orders)) * Eps * S[0] #truncation due to ill-conditioning Nt = max(np.argmax(Vh, axis=0)) #"Automatic" determination of threshold due to Runge's phenomenon threshold=min(Neps, Nt) while numTake<=0: filter=S>threshold numTake=filter.sum() if numTake>0: filtU=U[:,:numTake]; filtS=S[:numTake]; filtVh=Vh[:numTake, :] else: if threshold>1e-13: threshold=threshold/2 warnings.warn('cutting threshold for eigenvalues to '+str(threshold)) else: warnings('seems all eigenvalues are zero (<1e-13), setting to zero and breaking') filtS=np.zeros_like(S) truncVander=np.dot(filtU,np.dot(np.diag(filtS),filtVh)) ret, _, _, _=npl.lstsq(truncVander, functionVals, rcond=None) return np.reshape(ret, np.array(orders).flatten()+1)
def k_nearest_neighbors(data, predict, k=3): if len(data) > k: warnings( "The dataset is larger than the K parameter. Increase the size of K" ) distance = [] for group in data: for feature in data[group]: euclidean_distance = np.linalg.norm( np.array(feature) - np.array(predict)) distance.append([euclidean_distance, group]) for i in sorted(distance)[:k]: votes = i[1] vote_result = Counter(votes).most_common(1)[0][0] return vote_result
def __init__(self, jobdir=None, jobid=None, ram_dir=None): """Declare a Ramses instance for a given job. The job can be specified by one of the following options: 1. r = Ramses(`job_dir`), where `job_dir` is the path to the job directory. 2. r = Ramses(jobid = `_id`, ram_dir = `ram_dir`), where `ram_dir` is the directory where all the RAMSES jobs are stored, and `_id` is the string after "Job". This is equivalent to Ramses(`ram_dir/Job_id`) 3. ramtools.set_RAM_DIR(`ram_dir`); r = Ramses(jobid = `_id`). Args: jobdir : str relative/absolute path to the job directory jobid : str jobid, postfix to 'Job' to get the job directory name (in `ram_dir`) ram_dir : str the base directory for the RAMSES jobs """ if jobdir is not None: self.jobPath = jobdir self.jobid = os.path.basename(jobdir)[3:] elif jobid is None: warnings("Need to specify either jobdir or jobid") return else: if ram_dir is None: if RAM_DIR is None: warnings("Need to define ram_dir. Either specify" "ram_dir as a parameter, or define a global RAM_DIR" "by calling ramtools.set_RAM_DIR(`ram_dir`)") return else: ram_dir = RAM_DIR self.jobPath = f"{ram_dir}/Job{jobid}" self.jobid = jobid self.ds1 = None if self.get_units() == 0: self.tRelax = self.get_trelax() self.ramses_dir = os.path.dirname(self.jobPath if self.jobPath[-1] != '/' else self.jobPath[:-1]) self.data_dir = os.path.join(self.ramses_dir, "h5_data")
def truncatedVandermondeForwardTransform(freqs, locations, functionVals, threshold=None): freqProd=freqTuples(freqs) if len(locations.shape)==1: pointLoc=locations[:,np.newaxis] else: pointLoc=locations # TODO: noncomplex evaluation of vandermonde exponentTerm=2*np.pi*1j*np.dot(pointLoc,freqProd) # no transpose? pseudoVander=np.exp(exponentTerm) U,S,Vh=np.linalg.svd(pseudoVander) numTake=0 filtS=S if threshold is None: Eps= np.finfo(functionVals.dtype).eps Neps = np.prod(cmn.numpyze(freqs.shape)) * Eps * S[0] #truncation due to ill-conditioning # Nt = max(np.argmax(Vh, axis=0)) #"Automatic" determination of threshold due to Runge's phenomenon # threshold=min(Neps, Nt) threshold=Neps while numTake<=0: filter=S>threshold numTake=filter.sum() if numTake>0: filtU=U[:,:numTake]; filtS=S[:numTake]; filtVh=Vh[:numTake, :] else: if threshold>1e-13: threshold=threshold/2 warnings.warn('cutting threshold for eigenvalues to '+str(threshold)) else: warnings('seems all eigenvalues are zero (<1e-13), setting to zero and breaking') filtS=np.zeros_like(S) truncVander=np.dot(filtU,np.dot(np.diag(filtS),filtVh)) ret, _, _, _=npl.lstsq(truncVander, functionVals, rcond=None) if len(freqs.shape)>1: numFreqs=list(map(len, freqs)) else: numFreqs=len(freqs) return np.reshape(ret, numFreqs)
def setRandomAgent(): userAgents = open('data/txt/random_agents.txt', 'r') if not userAgents: debugMsg = info + "loading random HTTP User-Agent header(s) from " debugMsg += "file 'data/txt/random_agents.txt'" logging.debug(debugMsg) try: userAgents = getFile('data/txt/random_agents.txt') except IOError: errMsg = "unable to read HTTP User-Agent file " errMsg += "file 'data/txt/random_agents.txt'" raise warnings(errMsg) return random.sample(userAgents, 1)[0]
def checkFile(filename, raiseOnError=True): valid = True if filename: filename = filename.strip('"\'') else: try: if filename is None or not os.path.isfile(filename): valid = False except: valid = False if valid: try: with open(filename, "rb"): pass except: valid = False if not valid and raiseOnError: raise warnings("unable to read file '%s'" % filename) return valid
try: from setuptools import setup except ImportError: from distutils import setup import warnings warnings('Please install setuptools or distribute!') # Workaround for http://bugs.python.org/issue15881#msg170215 try: import multiprocessing # noqa except ImportError: pass long_description = open('README.rst').read() setup( name='requirements-parser', version='0.1.0', description='Parses Pip requirement files', long_description=long_description, author='David Fischer', author_email='*****@*****.**', url='https://github.com/davidfischer/requirements-parser', license='BSD', platforms=['OS Independent'], packages=['requirements'], classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent',
# GromacsWrapper # Copyright (c) 2009-2010 Oliver Beckstein <*****@*****.**> # Released under the GNU Public License 3 (or higher, your choice) # See the file COPYING for details. """ :mod:`gromacs` -- GromacsWrapper Package Overview ================================================= **GromacsWrapper** (package :mod:`gromacs`) is a thin shell around the `Gromacs`_ tools for light-weight integration into python scripts or interactive use in `ipython`_. .. _`Gromacs`: http://www.gromacs.org .. _`ipython`: http://ipython.scipy.org Modules ------- :mod:`gromacs` The top level module contains all gromacs tools; each tool can be run directly or queried for its documentation. It also defines the root logger class (name *gromacs* by default). :mod:`gromacs.config` Configuration options. Not really used much at the moment. :mod:`gromacs.cbook` The Gromacs cook book contains typical applications of the tools. In many cases this not more than just an often-used combination of parameters for
def assert_equal_objects(obj1, obj2, attributes_dict=None, logger=None): def print_not_equal_message(attr, logger): # logger.error("\n\nValueError: Original and read object field "+ attr + " not equal!") # raise ValueError("\n\nOriginal and read object field " + attr + " not equal!") warning("Original and read object field " + attr + " not equal!", logger) if isinstance(obj1, dict): get_field1 = lambda obj, key: obj[key] if not (isinstance(attributes_dict, dict)): attributes_dict = dict() for key in obj1.keys(): attributes_dict.update({key: key}) else: get_field1 = lambda obj, attribute: getattr(obj, attribute) if not (isinstance(attributes_dict, dict)): attributes_dict = dict() for key in obj1.__dict__.keys(): attributes_dict.update({key: key}) if isinstance(obj2, dict): get_field2 = lambda obj, key: obj.get(key, None) else: get_field2 = lambda obj, attribute: getattr(obj, attribute, None) equal = True for attribute in attributes_dict: #print attributes_dict[attribute] field1 = get_field1(obj1, attributes_dict[attribute]) field2 = get_field2(obj2, attributes_dict[attribute]) try: #TODO: a better hack for the stupid case of an ndarray of a string, such as model.zmode or pmode # For non numeric types if isinstance(field1, basestring) or isinstance(field1, list) or isinstance(field1, dict) \ or (isinstance(field1, np.ndarray) and field1.dtype.kind in 'OSU'): if np.any(field1 != field2): print_not_equal_message(attributes_dict[attribute], logger) equal = False # For numeric types elif isinstance(field1, (int, float, long, complex, np.number, np.ndarray)) \ and not (isinstance(field1, np.ndarray) and field1.dtype.kind in 'OSU'): # TODO: handle better accuracy differences and complex numbers... if np.any(np.float32(field1) - np.float32(field2) > 0): print_not_equal_message(attributes_dict[attribute], logger) equal = False else: warning( "Comparing str(objects) for field " + attributes_dict[attribute] + " because it is of unknown type!", logger) if np.any(str(field1) != str(field2)): print_not_equal_message(attributes_dict[attribute], logger) equal = False except: try: warnings( "Comparing str(objects) for field " + attributes_dict[attribute] + " because there was an error!", logger) if np.any(str(field1) != str(field2)): print_not_equal_message(attributes_dict[attribute], logger) equal = False except: raise_value_error( "ValueError: Something went wrong when trying to compare " + attributes_dict[attribute] + " !", logger) if equal: return True else: return False
def index_doc(self, doc): _id = doc[0] d = doc[1] status = self.es.index(index='nssd', doc_type='doc', body=d, id=_id) if not status['created']: warnings('Document {} not created'.format(status['_id']))
from enchant.errors import * from enchant.utils import EnchantStr, get_default_language, UTF16EnchantStr from enchant.pypwl import PyPWL # Due to the unfortunate name collision between the enchant "tokenize" module # and the stdlib "tokenize" module, certain values of sys.path can cause # the former to override the latter and break the "warnings" module. # This hacks around it by making a dummy "warnings" module. try: import warnings except ImportError: class warnings(object): def warn(self,*args,**kwds): pass warnings = warnings() class ProviderDesc(object): """Simple class describing an Enchant provider. Each provider has the following information associated with it: * name: Internal provider name (e.g. "aspell") * desc: Human-readable description (e.g. "Aspell Provider") * file: Location of the library containing the provider """ _DOC_ERRORS = ["desc"] def __init__(self,name,desc,file):
try: from setuptools import setup except ImportError: from distutils import setup import warnings warnings('Please install setuptools or distribute!') # Workaround for http://bugs.python.org/issue15881#msg170215 try: import multiprocessing # noqa except ImportError: pass long_description = open('README.rst').read() setup( name='requirements-parser', version='0.2.0', description='Parses Pip requirement files', long_description=long_description, author='David Fischer', author_email='*****@*****.**', url='https://github.com/davidfischer/requirements-parser', license='BSD', platforms=['OS Independent'], packages=['requirements'], classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License',
try: from setuptools import setup except ImportError: from distutils import setup import warnings warnings("Please install setuptools or distribute!") # Workaround for http://bugs.python.org/issue15881#msg170215 try: import multiprocessing # noqa except ImportError: pass long_description = open("README.rst").read() setup( name="requirements-parser", version="0.0.6", description="Parses Pip requirement files", long_description=long_description, author="David Fischer", author_email="*****@*****.**", url="https://github.com/davidfischer/requirements-parser", license="BSD", platforms=["OS Independent"], packages=["requirements"], classifiers=[ "Development Status :: 4 - Beta", "Intended Audience :: Developers",
# GromacsWrapper # Copyright (c) 2009-2010 Oliver Beckstein <*****@*****.**> # Released under the GNU Public License 3 (or higher, your choice) # See the file COPYING for details. """:mod:`gromacs` -- GromacsWrapper Package Overview ================================================= **GromacsWrapper** (package :mod:`gromacs`) is a thin shell around the `Gromacs`_ tools for light-weight integration into python scripts or interactive use in `ipython`_. .. _`Gromacs`: http://www.gromacs.org .. _`ipython`: http://ipython.scipy.org Modules ------- :mod:`gromacs` The top level module contains all gromacs tools; each tool can be run directly or queried for its documentation. It also defines the root logger class (name *gromacs* by default). :mod:`gromacs.config` Configuration options. Not really used much at the moment. :mod:`gromacs.cbook` The Gromacs cook book contains typical applications of the tools. In many cases this not more than just an often-used combination of parameters for a tool.
# -*- coding: utf-8 -*- import os, sys import configparser import warnings # # Look for a global .ini in the current directory. If none is # there, raise an exception and exit. Look for a local .ini # in the same directory. If that isn't present, issue a warning # but carry on and use the global values # global_filepath = os.path.abspath("piwars.ini") if not os.path.isfile(global_filepath): warnings("No global ini found at %s" % global_filepath) local_filepath = os.path.join(os.path.dirname(global_filepath), "piwars.local.ini") if not os.path.isfile(local_filepath): warnings.warn("No local ini found at %s" % local_filepath) ini = configparser.ConfigParser() ini.read([global_filepath, local_filepath]) # # Since we already have code which expects to find a set of simple # module constants, keep that approach alive. This does however preclude # the easy possibility of a reload-while-running # LISTEN_ON_IP = ini["network"]["listen_on_ip"] LISTEN_ON_PORT = ini["network"]["listen_on_port"] PUBSUB_LISTEN_ON_IP = ini["pubsub"]["listen_on_ip"] PUBSUB_LISTEN_ON_PORT = ini["pubsub"]["listen_on_port"] CODEC = ini["i18n"]["codec"]
def which_file(cls, filename=None, deep=True): """ Which file is class method . List of files are the typical files able to read by pyCSAMT softwares. Sensitive class method. Parameters ---------- **filename** :str corresponding file to read , pathLike **deep** : bool , control reading : False for just control the extension file , not opening file . True control in deeper file and find which file were inputted. Returns --------- str FileType could be [`avg` | `j` | `edi` | `resp` | `mesh` | `occamdat` | `stn` | `model` | `iter` | `logfile` | `startup`] List of files read by pyCSAMT : ============== ======================================================= CodeFile Description ============== ======================================================= *avg* Zonge Engineering file Plainty file of ASTATIC file. *j* A.G .Jonhson J=Format file. *edi* SEG (Society of Exploration Geophysics) Electrical Data Interchange file (SEG-EDI) *stn* Zonge Engineering station file *occamdat* deGroot-Hedlin, C., and S. Constable, Occam file. *mesh* Constable, S. C., R. L. Parker, and C. G. Constable mesh file *model* Occam Model file *startup* Occam startup file *iter* Occam iteration file get after Inversion *resp* Occam response file , Get after inversion *logfile* Occam Logfile, Get after inverson (Inversion file ) ============== ======================================================= :Example: >>> files = ['K1_exp.bln','LCS01.avg' ,'LCS01_2_to_1.avg', 'K1.stn', ... 'csi000.dat','csa250.edi','LogFile.logfile', ... 'Occam2DMesh','Occam2DModel', 'OccamDataFile.dat', ... 'S00_ss.edi', 'Startup','RESP13.resp', ... 'ITER02.iter'] >>> for ii in files : >>> path = os.path.join(os.environ["pyCSAMT"], ... 'csamtpy','data', ii) ... try : ... print(_sensitive.which_file(path,deep=True)) ... except :pass """ _code = { 'edi': cls._edi, 'j': cls._j, 'startup': cls._occam_startup, 'occamdat': cls._occam_datafile, 'model': cls._occam_modelfile, 'mesh': cls._occam_meshfile, 'iter': cls._occam_startup, 'avg': cls._avg, 'stn': cls._stn, 'logfile': cls._occam_logfile, 'resp': ['none', 'none'], } _filename = filename if _filename is None: pyCSAMTError_file_handling( 'Error file: NoneType can not be computed. Check your right path.' ) if _filename is not None: if os.path.basename(_filename).split('.')[-1].lower() in list( _code.keys()): #code file recognized _flag = os.path.basename(_filename).split('.')[-1].lower() if deep == False: return _flag else: _flag = 0 #file not recognized # Open the file now with open(_filename, 'r', encoding='utf8') as _f: _data_lines = _f.readlines() if _flag != 0: # file extension has been recognized on dict code keys. cls._logger.info('Reading %s file' % os.path.basename(_filename)) _value_code = _code[_flag] if _flag == 'edi': #avoid expensive function then controle 2thing before continue if _value_code[0] not in _data_lines[0]: warnings.warn('File probably is incorrect. Please consult EDI_Main file components : {0}'.\ format(''.join(cls._edi))) raise pyCSAMTError_file_handling( "Wrong SEG-EDI file. It'seems -File provided doesnt include '>HEAD. Please provide the right EDI-FORMAT" ) elif _value_code[-1] not in _data_lines[-1]: warnings.warn('File probably incorrect. Please consult EDI_Main file composents : {0}'.\ format(''.join(cls._edi))) raise pyCSAMTError_file_handling( "Wrong SEG-EDI file. It'seems -File provided doesnt include '>END. Please provide the right EDI-FORMAT" ) elif _flag == 'resp': # control quick response file #check if the len of resp= 7 if len(_data_lines[0].strip().split()) != 7: raise pyCSAMTError_file_handling( "Wrong OCCAM-RESPONSE file. Please provide the right response file." ) else: return _flag elif _flag == 'avg': _reason = cls.validate_avg(avg_data_lines=_data_lines)[0] if _reason not in ['yesAST', 'yes']: warnings( 'File <{0}> does not match Zonge AVGfile. Get info to {1}' .format(os.path.basename(_filename), notion.AVG)) raise pyCSAMTError_file_handling( "Wrong <{0}>Zonge AVG-file. Please provide the right file." .format(os.path.basename(_filename))) return _flag elif _flag == 'mesh': try: [float(ss) for ss in _data_lines[1].strip().split() ] #check the first occam layer except: warnings.warn( 'Wrong OCCAM-MESH file.Get more info on that site :https://marineemlab.ucsd.edu/Projects/Occam/index.html' ) raise pyCSAMTError_file_handling("Wrong OCCAM-MESH <%s>file .We don't find the characteristic of thefirst layer."\ "Please provide the right OCCAM meshfile." % os.path.basename(_filename)) for _meshcodec in _value_code: if _meshcodec in _data_lines[-1]: return _flag else: warnings.warn( 'Trouble occurs while reading the "OCCAM-params specs.More details in :{0}.\n {1}' .format(notion.occam_mesh_parameter_specs_info, notion.occam_mesh_parameter_specs_meaning)) raise pyCSAMTError_file_handling( 'We do not find a "Parameter specs" in your <{0}>'. format(os.path.basename(_filename))) #once both thing has already been controled . then continue . avoid avg because already has deep controlled # with special static method then pass _ccounter = 0 # threshold control is match to 7 except stn. for _codec in _value_code: # loop the dict value of code #loop now all the if _flag not in ['avg', 'resp', 'mesh']: for num, _data_item in enumerate(_data_lines): if _codec in _data_item: _ccounter += 1 if _flag == 'stn': if _ccounter >= 3: return _flag elif _flag == 'j': if _ccounter >= 5: return _flag if _ccounter >= 7: return _flag if _ccounter < 7: raise pyCSAMTError_file_handling('ERROR occurs while reading file !<{0}>. '\ 'File doesnt not match the typical <{1}> Format.'.format(os.path.basename(_filename), _flag)) elif _flag == 0: #file not recognized in _codekeys , #then try to read and to find which file mastch the best. _ccounter = 0 for _keycode, _value_code in _code.items(): for num, valueitem in enumerate(_data_lines): for codec in _value_code: #read value in code if codec.lower() in valueitem.lower(): _ccounter += 1 if _keycode == 'j': if _ccounter >= 4: return _keycode if _ccounter >= 7: if _keycode == 'startup': if all([ float(val) for val in _data_lines[len(_value_code) + 1].strip().split() ]) == False: return 'iter' else: return _keycode return _keycode #Now we assune that the file must be the response file then read according response control try: resp0 = [float(ss) for ss in _data_lines[0]] resp_end = [float(ss) for ss in _data_lines[-1]] resp_mid = [ float(ss) for ss in _data_lines[int(len(_data_lines) / 2)] ] # get the middele of file and try float converter assert (len(resp0) == len(resp_end)) and (len(resp_end)==len(resp_mid)),\ pyCSAMTError_file_handling('We presume that RESP <{0}> file doesnt not match a OCCAM-RESPONSE file.'.format(os.path.basename(_filename))) except: message = ''.join( 'Error reading File. pyCSAMT can read only <{0}> Format file.', 'Format file. Program can not find the type of that file : <{1}>.', 'You may use script <rewriteXXX> of pyCSAMT to try to rewrite file', 'either to SEG-EDI |j|STN|AVG| or OCCAM{DAT, RESP,MODEL,ITER} files.' ) cls._logger.error( message.format('|'.join(list(_code.keys())), os.path.basename(_filename))) warnings.warn( message.format('|'.join(list(_code.keys())), os.path.basename(_filename))) return return 'resp'
def execute_method(methodName, inGraph, graphName, distances=True, distFunction="default", methodParams="default"): print "Executing " + methodName method = method_dispatcher(methodName) if methodName.startswith("panos_sim"): if methodParams == "default" or methodParams == None: signatures = method(inGraph, graphName) else: eigs, strategy, compressed, sigma = methodParams signatures = method(inGraph, graphName, eigs, strategy, compressed, sigma) elif is_spectral(methodName): if methodParams == "default" or methodParams == None: signatures = method(inGraph, graphName) else: eigs, energies, strategy = methodParams print "Using " + str( eigs ) + " eigenvalues for a %d-dimensional embedding via the eigenvalue strategy \'%s\'" % ( energies, strategy) signatures = method(inGraph, graphName, eigs, energies, strategy) elif methodName == "refex_sim": signatures = method(graphName) elif methodName == "cycle_sim": cycleLength, matrixType, keepEven, clearConverged = methodParams if clearConverged and distances: assert (distFunction == calc_emd) signatures = method(inGraph, cycleLength, matrixType, keepEven, clearConverged) elif methodName in [ "sim_rank", "role_sim", "vertex_sim", "commute_time_dist" ]: if distances == False: # These methods only return a distance per pair of nodes. warnings('%s only provides a distance matrix.' % (methodName, )) if methodName == "vertex_sim": distanceMatrix = method(inGraph, dist=True) elif methodName == "commute_time_dist": distanceMatrix = method(inGraph) else: distanceMatrix = method(graphName) distanceMatrix[abs(distanceMatrix) < 1e-9] = 0.0 # Safeguarding against floating point numerical errors. return distanceMatrix else: assert (False) if distances: distanceMatrix = pairwise_distances_(signatures, methodName, distFunction=distFunction) return distanceMatrix else: return signatures
def CommitNewContainer(self, containerName, commitmessage, authtoken, BASE): self.containerName = containerName self.containerId = containerName # self.tempFrame.description = self.descriptionText.toPlainText() self.workingFrame.commitMessage = commitmessage commitContainer = self.dictify() commitFrame = self.workingFrame.dictify() url = BASE + 'CONTAINERS/newContainer' payload = { 'containerdictjson': json.dumps(commitContainer), 'framedictjson': json.dumps(commitFrame) } filesToUpload = {} for fileheader, filetrack in self.workingFrame.filestrack.items(): if filetrack.style in [typeOutput, typeRequired]: filepath = os.path.join(self.containerworkingfolder, filetrack.file_name) filesToUpload[fileheader] = open(filepath, 'rb') fileb = open(filepath, 'rb') filetrack.md5 = hashlib.md5(fileb.read()).hexdigest() headers = {'Authorization': 'Bearer ' + authtoken['auth_token']} response = requests.request("POST", url, headers=headers, data=payload, files=filesToUpload) if 'Container Made' == response.headers['response']: resp = response.json() returncontdict = resp['containerdictjson'] returnframedict = resp['framedictjson'] self.allowedUser = returncontdict['allowedUser'] self.workingFrame.FrameInstanceId = returnframedict[ 'FrameInstanceId'] self.workingFrame.commitMessage = returnframedict['commitMessage'] self.workingFrame.commitUTCdatetime = returnframedict[ 'commitUTCdatetime'] for filetrack in returnframedict['filestrack']: fileheader = filetrack['FileHeader'] self.workingFrame.filestrack[ fileheader].commitUTCdatetime = filetrack[ 'commitUTCdatetime'] if not self.workingFrame.filestrack[ fileheader].md5 == filetrack['md5']: warnings('MD5 changed') self.workingFrame.filestrack[ fileheader].committedby = filetrack['committedby'] self.workingFrame.filestrack[fileheader].file_id = filetrack[ 'file_id'] frameyamlfn = os.path.join(self.containerworkingfolder, self.currentbranch, self.workingFrame.FrameName + '.yaml') self.workingFrame.writeoutFrameYaml(frameyamlfn) self.save() return True else: return False
from enchant.errors import * from enchant.utils import EnchantStr, get_default_language from enchant.pypwl import PyPWL # Due to the unfortunate name collision between the enchant "tokenize" module # and the stdlib "tokenize" module, certain values of sys.path can cause # the former to override the latter and break the "warnings" module. # This hacks around it by making a dummy "warnings" module. try: import warnings except ImportError: class warnings(object): def warn(self,*args,**kwds): pass warnings = warnings() class ProviderDesc(object): """Simple class describing an Enchant provider. Each provider has the following information associated with it: * name: Internal provider name (e.g. "aspell") * desc: Human-readable description (e.g. "Aspell Provider") * file: Location of the library containing the provider """ _DOC_ERRORS = ["desc"] def __init__(self,name,desc,file):
def copy(self): warnings(NotImplemented) return self