content
stringlengths
1
1.05M
input_ids
listlengths
1
883k
ratio_char_token
float64
1
22.9
token_count
int64
1
883k
""" Processes a folder of .txt files to Spacy docs then saves the docs """ # first import standard modules import glob import os from pathlib import Path # then import third-party modules import spacy # finally import my own code (PEP-8 convention) from askdir import whichdir nlp = spacy.load("en_core_web_lg") source_directory = whichdir() os.chdir(source_directory) filelist = glob.glob("*") output_directory = whichdir() for filename in filelist: with open(filename, "r", encoding="utf-8") as f: novel = f.read() # the novel is too long for the default, so increase allocated memory nlp.max_length = len(novel) + 100 # Process a text doc = nlp(novel) short_name = Path(filename).stem # r for raw string--no escape characters # f for format string--allow me to pass in variable doc.to_disk(rf"{output_directory}\{short_name}")
[ 37811, 198, 18709, 274, 257, 9483, 286, 764, 14116, 3696, 284, 1338, 1590, 34165, 788, 16031, 262, 34165, 198, 37811, 198, 2, 717, 1330, 3210, 13103, 198, 11748, 15095, 198, 11748, 28686, 198, 6738, 3108, 8019, 1330, 10644, 198, 198, 2,...
2.99322
295
from output.models.nist_data.list_pkg.nmtoken.schema_instance.nistschema_sv_iv_list_nmtoken_max_length_2_xsd.nistschema_sv_iv_list_nmtoken_max_length_2 import NistschemaSvIvListNmtokenMaxLength2 __all__ = [ "NistschemaSvIvListNmtokenMaxLength2", ]
[ 6738, 5072, 13, 27530, 13, 77, 396, 62, 7890, 13, 4868, 62, 35339, 13, 77, 16762, 4233, 13, 15952, 2611, 62, 39098, 13, 77, 1023, 2395, 2611, 62, 21370, 62, 452, 62, 4868, 62, 77, 16762, 4233, 62, 9806, 62, 13664, 62, 17, 62, 87...
2.258929
112
# -*- coding:utf-8 -*- """ file: src/sample.py Sample Source file ================== Description ----------- Sample description ... Content ------- - say_hello_sikuli Status ------ Test with: tests/sample.py last verification date: xx/xx/xxxx last verification status: XX """ from sikuli import * def say_hello_sikuli(): """ :return: """ popup("Hello World !", title="Sikuli")
[ 2, 532, 9, 12, 19617, 25, 40477, 12, 23, 532, 9, 12, 198, 198, 37811, 198, 220, 220, 220, 2393, 25, 12351, 14, 39873, 13, 9078, 628, 220, 220, 220, 27565, 8090, 2393, 198, 220, 220, 220, 36658, 28, 628, 220, 220, 220, 12489, 198...
2.581006
179
from allauth.socialaccount import providers from allauth.socialaccount.providers.base import ProviderAccount from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider providers.registry.register(ChaHubProvider)
[ 6738, 477, 18439, 13, 14557, 23317, 1330, 9549, 198, 6738, 477, 18439, 13, 14557, 23317, 13, 15234, 4157, 13, 8692, 1330, 32549, 30116, 198, 6738, 477, 18439, 13, 14557, 23317, 13, 15234, 4157, 13, 12162, 1071, 17, 13, 15234, 1304, 1330...
3.741935
62
# Copyright 2017 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import os import shutil import tempfile from telemetry import decorators from telemetry.testing import options_for_unittests from telemetry.testing import page_test_test_case from telemetry.util import image_util from contrib.cluster_telemetry import screenshot
[ 2, 15069, 2177, 383, 18255, 1505, 46665, 13, 1439, 2489, 10395, 13, 198, 2, 5765, 286, 428, 2723, 2438, 318, 21825, 416, 257, 347, 10305, 12, 7635, 5964, 326, 460, 307, 198, 2, 1043, 287, 262, 38559, 24290, 2393, 13, 198, 198, 11748...
3.837838
111
from pcradmin import views from django.conf.urls import url, include urlpatterns = [ url(r'^(?P<pagename>\w+)/', views.index), #url(r'^sendmail$', views.sendmail), #url(r'^sentmail$', views.sentmail), url(r'^changelimit$', views.change_team_limits), url(r'^change_team_limit$', views.change_team_limit_list), url(r'^limit_changed$', views.change_limits), url(r'^changesportslimit$', views.change_sports_limits), url(r'^sports_limits_changed$', views.save_sports_limits), url(r'^setstatus', views.set_status), url(r'^showstatus', views.save_status), url(r'^emailsend', views.send_mail), url(r'^compose', views.compose), ]
[ 6738, 279, 6098, 28482, 1330, 5009, 198, 6738, 42625, 14208, 13, 10414, 13, 6371, 82, 1330, 19016, 11, 2291, 198, 6371, 33279, 82, 796, 685, 198, 220, 220, 220, 19016, 7, 81, 6, 61, 7, 30, 47, 27, 79, 11286, 480, 29, 59, 86, 10,...
2.432836
268
a = input('digite algo :') print('O tipo primitivo desswe valor ', type(a)) print("S tem espaos? ", a.isspace()) print(' um nmero? ', a.isnumeric()) print('E alfabetico?', a.isalpha()) print(' alphanumerico?', a.isalnum()) print('Esta em maisculas?', a.isupper()) print('Esta em minsculas?', a.islower()) print('Est capitalizada', a.istitle())
[ 64, 796, 5128, 10786, 12894, 578, 435, 2188, 1058, 11537, 198, 198, 4798, 10786, 46, 8171, 78, 2684, 270, 23593, 288, 408, 732, 1188, 273, 220, 46083, 2099, 7, 64, 4008, 198, 4798, 7203, 50, 2169, 15024, 7495, 30, 33172, 257, 13, 74...
2.574627
134
""" Examples of authenticating to the API. Usage: login <username> <password> <server> login -h Arguments: username ID to provide for authentication password Password corresponding to specified userid. server API endpoint. Options: -h --help Show this screen. --version Show version. Description: There are two ways that you can authenticate to the Web Services API. Both options are viable and are demonstrated below with examples. Basic-Authentication is probably the most popular option, especially for shorter/simpler usages of the API, mostly because of its simplicity. The credentials are simply provided with each request. There is a login endpoint (POST /devmgr/utils/login), that will allow you to explicitly authenticate with the API. Upon authenticating, a JSESSIONID will be provided in the Response headers and as a Cookie that can be utilized to create a persistent session (that will eventually timeout). """ import logging import docopt import requests LOG = logging.getLogger(__name__) if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG, format='%(relativeCreated)dms %(levelname)s %(module)s.%(funcName)s:%(lineno)d\n %(message)s') args = docopt.docopt(__doc__) login(args.get('<server>'), args.get('<username>'), args.get('<password>'))
[ 37811, 198, 27730, 286, 8323, 12364, 284, 262, 7824, 13, 198, 198, 28350, 25, 198, 220, 17594, 1279, 29460, 29, 1279, 28712, 29, 1279, 15388, 29, 198, 220, 17594, 532, 71, 198, 28100, 2886, 25, 198, 220, 20579, 220, 4522, 284, 2148, ...
3.24
425
# -*- coding: utf-8 -*- ''' ''' from PyQt5.QtWidgets import QApplication, QLabel ,QWidget, QVBoxLayout , QPushButton, QMainWindow from PyQt5.QtGui import QPalette , QBrush , QPixmap from PyQt5.QtCore import Qt import sys app = QApplication(sys.argv) win = QMainWindow() win.setWindowTitle("") win.resize(350, 250) palette = QPalette() palette.setColor(QPalette.Background , Qt.red ) win.setPalette(palette) win.show() sys.exit(app.exec_())
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 7061, 6, 198, 220, 220, 220, 220, 198, 197, 198, 220, 220, 220, 220, 198, 7061, 6, 198, 198, 6738, 9485, 48, 83, 20, 13, 48, 83, 54, 312, 11407, 1330, 1195, ...
2.26699
206
import csv
[ 11748, 269, 21370, 628, 628 ]
2.8
5
import numpy as np from tensorflow.keras.preprocessing.image import Iterator import time import os import xml.etree.ElementTree as ET import cv2 import pydicom as dicom from os.path import join as opjoin import json from tqdm import tqdm def parseXML(scan_path): ''' parse xml file args: xml file path output: nodule list [{nodule_id, roi:[{z, sop_uid, xy:[[x1,y1],[x2,y2],...]}]}] ''' file_list = os.listdir(scan_path) xml_file = None for file in file_list: if '.' in file and file.split('.')[1] == 'xml': xml_file = file break prefix = "{http://www.nih.gov}" if xml_file is None: print('SCAN PATH: {}'.format(scan_path)) tree = ET.parse(scan_path + '/' + xml_file) root = tree.getroot() readingSession_list = root.findall(prefix + "readingSession") nodules = [] for session in readingSession_list: # print(session) unblinded_list = session.findall(prefix + "unblindedReadNodule") for unblinded in unblinded_list: nodule_id = unblinded.find(prefix + "noduleID").text edgeMap_num = len(unblinded.findall(prefix + "roi/" + prefix + "edgeMap")) if edgeMap_num >= 1: # it's segmentation label nodule_info = {} nodule_info['nodule_id'] = nodule_id nodule_info['roi'] = [] roi_list = unblinded.findall(prefix + "roi") for roi in roi_list: roi_info = {} # roi_info['z'] = float(roi.find(prefix + "imageZposition").text) roi_info['sop_uid'] = roi.find(prefix + "imageSOP_UID").text roi_info['xy'] = [] edgeMap_list = roi.findall(prefix + "edgeMap") for edgeMap in edgeMap_list: x = float(edgeMap.find(prefix + "xCoord").text) y = float(edgeMap.find(prefix + "yCoord").text) xy = [x, y] roi_info['xy'].append(xy) nodule_info['roi'].append(roi_info) nodules.append(nodule_info) return nodules
[ 11748, 299, 32152, 355, 45941, 198, 6738, 11192, 273, 11125, 13, 6122, 292, 13, 3866, 36948, 13, 9060, 1330, 40806, 1352, 198, 11748, 640, 198, 11748, 28686, 198, 11748, 35555, 13, 316, 631, 13, 20180, 27660, 355, 12152, 198, 11748, 269...
1.945662
1,141
from hexagon.support.hooks import HexagonHooks from hexagon.support.execute.tool import select_and_execute_tool from hexagon.support.update.cli import check_for_cli_updates import sys from hexagon.support.args import fill_args from hexagon.domain import cli, tools, envs from hexagon.support.help import print_help from hexagon.support.tracer import tracer from hexagon.support.printer import log from hexagon.support.update.hexagon import check_for_hexagon_updates from hexagon.support.storage import ( HexagonStorageKeys, store_user_data, ) from hexagon.plugins import collect_plugins if __name__ == "__main__": main()
[ 6738, 17910, 1840, 13, 11284, 13, 25480, 82, 1330, 22212, 1840, 39, 31085, 198, 6738, 17910, 1840, 13, 11284, 13, 41049, 13, 25981, 1330, 2922, 62, 392, 62, 41049, 62, 25981, 198, 6738, 17910, 1840, 13, 11284, 13, 19119, 13, 44506, 13...
3.233503
197
""" Misc utility functions required by several modules in the ligpy program. """ import os import numpy as np from constants import GAS_CONST, MW def set_paths(): """ Set the absolute path to required files on the current machine. Returns ------- reactionlist_path : str path to the file `complete_reactionlist.dat` rateconstantlist_path : str path to the file `complete_rateconstantlist.dat` compositionlist_path : str path to the file `compositionlist.dat` """ module_dir = os.path.abspath(__file__).split('ligpy_utils')[0] reactionlist_path = module_dir + 'data/complete_reaction_list.dat' rateconstantlist_path = module_dir + 'data/complete_rateconstant_list.dat' compositionlist_path = module_dir + 'data/compositionlist.dat' return reactionlist_path, rateconstantlist_path, compositionlist_path def get_specieslist(completereactionlist): """ Make a list of all the molecular species involved in the kinetic scheme. Parameters ---------- completereactionlist : str the path to the `complete_reaction_list.dat` file Returns ------- specieslist : list a list of all the species in the kinetic scheme """ specieslist = [] for line in open(completereactionlist, 'r').readlines(): for spec in line.split(','): # If the species has already been added to the list then move on. if spec.split('_')[1].split()[0] in specieslist: continue else: specieslist.append(spec.split('_')[1].split()[0]) specieslist.sort() return specieslist def get_speciesindices(specieslist): """ Create a dictionary to assign an arbitrary index to each of the species in the kinetic scheme. Parameters ---------- specieslist : list a list of all the species in the model Returns ------- speciesindices : dict a dictionary of arbitrary indices with the species from specieslist as keys indices_to_species : dict the reverse of speciesindices (keys are the indices and values are the species) """ speciesindices = {} index = 0 for x in specieslist: speciesindices[x] = index index += 1 indices_to_species = dict(zip(speciesindices.values(), speciesindices.keys())) return speciesindices, indices_to_species def define_initial_composition(compositionlist, species): """ Read the plant ID specified and define the initial composition of the lignin polymer in terms of the three model components (PLIGC, PLIGH, PLIGO). Parameters ---------- compositionlist : str the path of the `compositionlist.dat` file species : str the name of a lignin species that exists in the `compositionlist.dat` file Returns ------- pligc_0 : float The initial composition (mol/L) of PLIGC pligh_0 : float The initial composition (mol/L) of PLIGH pligo_0 : float The initial composition (mol/L) of PLIGO """ for line in open(compositionlist, 'rb').readlines(): if line.split(',')[0] == species: # Initial compositions [mole fraction] pligc_mol = float(line.split(',')[1]) pligh_mol = float(line.split(',')[2]) pligo_mol = float(line.split(',')[3]) # The weighted average molar mass of mixture [kg/mol] weighted_m = (301*pligc_mol + 423*pligh_mol + 437*pligo_mol)/1000 # the density of the condensed phase [kg/L] density = 0.75 # Initial compositions [mol/L] pligc_0 = density/weighted_m * pligc_mol pligh_0 = density/weighted_m * pligh_mol pligo_0 = density/weighted_m * pligo_mol break return pligc_0, pligh_0, pligo_0 def build_k_matrix(rateconsts): """ Build a matrix of all the rate constant parameters (A, n, E). Parameters ---------- rateconsts : str the path to the file `complete_rateconstant_list.dat` Returns ------- kmatrix : list a list of lists that defines a matrix. Each entry in the list is A, n, E for a given reaction """ num_lines = sum(1 for line in open(rateconsts)) kmatrix = [None]*num_lines for i, line in enumerate(open(rateconsts, 'r').readlines()): kmatrix[i] = [line.split(' ')[0], line.split(' ')[1], line.split(' ')[2].split()[0]] return kmatrix def get_k_value(T, reaction_index, kmatrix): """ Returns the value of the rate constant for a particular reaction index. Parameters ---------- T : float temperature in Kelvin reaction_index : int the index of the reaction for which you want the rate kmatrix : list the kmatrix generated by build_k_matrix() Returns ------- k : float the value of the rate constant for the given reaction at the given temperature. """ k = (eval(kmatrix[reaction_index][0]) * T**eval(kmatrix[reaction_index][1]) * np.exp(-1 * eval(kmatrix[reaction_index][2]) /(GAS_CONST * T))) return k def get_k_value_list(T, kmatrix): """ Returns a list of all the k-values for a given temperature. Parameters ---------- T : float temperature in Kelvin kmatrix : list the kmatrix generated by build_k_matrix() Returns ------- kvaluelist : list a list of all the rate constant values for a given temperature """ kvaluelist = [] for index, row in enumerate(kmatrix): kvaluelist.append(get_k_value(T, index, kmatrix)) return kvaluelist def build_reactant_dict(completereactionlist, speciesindices): """ Build a dictionary of the reactants involved in each reaction, along with their stoichiometric coefficients. The keys of the dictionary are the reaction numbers, the values are lists of lists [[reactant1index, -1*coeff1],...] Parameters ---------- completereactionlist : str path to the file `complete_reaction_list.dat` speciesindices : dict the dictionary speciesindices from get_speciesindices() Returns ------- reactant_dict : dict a dictionary where keys are reaction numbers and values are lists of lists with the reactants and their stoichiometric coefficients for each reaction """ reactant_dict = {} for rxnindex, reaction in enumerate(open(completereactionlist, 'rb') .readlines()): reactants = [] # x is each coefficient_species set for x in reaction.split(','): # if the species is a reactant if float(x.split('_')[0]) < 0: reactants.append([speciesindices[x.split('_')[1].split()[0]], -1*float(x.split('_')[0])]) # in preceding line: *-1 because I want the |stoich coeff| reactant_dict[rxnindex] = reactants return reactant_dict def build_species_rxns_dict(completereactionlist): """ Build a dictionary where keys are species and values are lists with the reactions that species is involved in, that reaction's sign in the net rate equation, and the stoichiometric coefficient of the species in that reaction. Parameters ---------- completereactionlist : str path to the file `complete_reaction_list.dat` Returns ------- species_rxns : dict keys are the species in the model; values are lists of [reaction that species is involved in, sign of that species in the net rate equation, stoichiometric coefficient] """ specieslist = get_specieslist(set_paths()[0]) species_rxns = {} for species in specieslist: # This loop makes a list of which reactions "species" takes part in # and what sign that term in the net rate eqn has # and what the stoichiometric coefficient is reactions_involved = [] for rxnindex, line in enumerate(open(completereactionlist, 'rb') .readlines()): # example of x = '-1_ADIO' for x in line.split(','): # If the species being iterated over is part of this reaction if species == x.split('_')[1].split()[0]: # if the species is a reactant if float(x.split('_')[0]) < 0: reactions_involved.append( [rxnindex, -1, x.split('_')[0]]) # if the species is a product if float(x.split('_')[0]) > 0: reactions_involved.append( [rxnindex, 1, '+' + x.split('_')[0]]) species_rxns[species] = reactions_involved return species_rxns def build_rates_list(rateconstlist, reactionlist, speciesindices, indices_to_species, human='no'): """ This function writes the list of rate expressions for each reaction. Parameters ---------- rateconstlist : str the path to the file `complete_rateconstant_list.dat` reactionlist : str the path to the file `complete_reaction_list.dat` speciesindices : dict a dictionary of arbitrary indices with the species from specieslist as keys indices_to_species : dict the reverse of speciesindices (keys are the indices and values are the species) human : str, optional indicate whether the output of this function should be formatted for a human to read ('yes'). Default is 'no' Returns ------- rates_list : list a list of the rate expressions for all the reactions in the model """ kmatrix = build_k_matrix(rateconstlist) reactant_dict = build_reactant_dict(reactionlist, speciesindices) rates_list = [] for i, line in enumerate(kmatrix): rate = 'rate[%s] = kvalue(T,%s) ' % (i, i) concentrations = '' for entry in reactant_dict[i]: if entry == 'n': # if there is no reaction concentrations = '* 0' break else: if human == 'no': concentrations += '* y[%s]**%s ' % (entry[0], entry[1]) elif human == 'yes': concentrations += '* [%s]**%s ' % \ (indices_to_species[entry[0]], entry[1]) else: raise ValueError('human must be a string: yes or no') rate += concentrations rates_list.append(rate) return rates_list def build_dydt_list(rates_list, specieslist, species_rxns, human='no'): """This function returns the list of dydt expressions generated for all the reactions from rates_list. Parameters ---------- rates_list : list the output of build_rates_list() specieslist : list a list of all the species in the kinetic scheme species_rxns : dict dictionary where keys that are the model species and values are the reactions they are involved in human : str, optional indicate whether the output of this function should be formatted for a human to read ('yes'). Default is 'no' Returns ------- dydt_expressions : list expressions for the ODEs expressing the concentration of each species with time """ dydt_expressions = [] for species in specieslist: rate_formation = 'd[%s]/dt = ' % (species) # "entry" is [reaction#, sign of that reaction, coefficient] for entry in species_rxns[species]: if human == 'no': rate_formation += '%s*%s ' % \ (entry[2], rates_list[entry[0]].split(' = ')[1]) elif human == 'yes': rate_formation += '%s*rate[%s] ' % (entry[2], entry[0]) else: raise ValueError('human must be a string: yes or no') dydt_expressions.append(rate_formation) return dydt_expressions def write_rates_and_odes(filename, rates, odes): """ Writes a file that contains the model equations to be solved (a list of rate expressions, followed by a list of ODEs for each species). This file is just for reference for humans to be able to look at the specific reactions that are modeled, it is not actually used by the program. Users should only need to generate this file if they've changed anything about the kinetic scheme (it already exists in the data folder). Parameters ---------- filename : str the filename (including relative path if appropriate) of the ratesandodes file to write rates : list the output of build_rates_list() with human='yes' odes : list the output of build_dydt_list() with human='yes' Returns ------- None """ with open(filename, 'wb') as initialize: initialize.write('Reaction Rates:\n') with open(filename, 'ab') as writer: for line in rates: writer.write(line+'\n') writer.write('\n\nODE''s:\n') for line in odes: writer.write(line+'\n') # These are some functions for checking the integrity of some model # components, but they are not used except for exploratory or verification # purposes def check_species_in_MW(specieslist=None): """ Check to make sure that everything in the specieslist is in the MW dictionary from `constants.py`. Parameters ---------- specieslist : list, optional a list of species to check against. If no list is specified then the function get_specieslist() will be used to generate the default list Returns ------- None """ if specieslist == None: specieslist = get_specieslist(set_paths()[0]) for item in MW.keys(): if item in specieslist: print '%s is in specieslist' % ('{: <20}'.format(item)) else: print '********'+item for item in specieslist: if item in MW.keys(): print '%s is in MW dictionary' % ('{: <20}'.format(item)) else: print '********'+item print '\n%s should equal %s' % (len(MW.keys()), len(specieslist)) def check_mass_balance(): """ Check for conservation of mass, and if mass is not conserved, see which reactions are creating or losing mass. Note that mass will not be wholly conserved in this model because protons are not accounted for when radicals are involved in non-Hydrogen-abstraction reactions, but all other reactions should conserve mass. Parameters ---------- None Returns ------- total_mass_balance : numpy array an array with the amount of mass gained or lost in each reaction """ specieslist = get_specieslist(set_paths()[0]) speciesindices = get_speciesindices(specieslist)[0] kmatrix = build_k_matrix(set_paths()[1]) species_rxns = build_species_rxns_dict(set_paths()[0]) # Make vector of the MW's of each species, in the order from speciesindices mw_vector = np.zeros((len(MW), 1)) for species in MW: mw_vector[speciesindices[species]] = MW[species][0] mw_vector = mw_vector.transpose() # In this stoichiometric matrix, rows are species, columns are reactions stoicmatrix = np.zeros((len(speciesindices), len(kmatrix)), dtype='float') for species in species_rxns: i = speciesindices[species] for reaction in species_rxns[species]: j = reaction[0] stoicmatrix[i, j] += float(reaction[2]) # The result of this dot product should be a vector full of zeros. # This will not be the case because protons are not accounted for when # radicals are involved in non-H-abstraction rxns, # but all other reactions should be 0 total_mass_balance = np.dot(mw_vector, stoicmatrix[:, :]) # Use this to look at which reactions are creating or losing mass # (from missing Hydrogen) h_sum = 0 for i, value in enumerate(total_mass_balance[0, :]): if value != 0: print i, value h_sum += value print '\nNet mass change = %s' % h_sum return total_mass_balance def check_species_fate(): """ Check to see which species (if any) are only produced, but never consumed in the model reactions (assuming that all reactions occur). Parameters ---------- None Returns ------- fate_dict : dictionary a dictionary with the fate of model species """ specieslist = get_specieslist(set_paths()[0]) species_rxns = build_species_rxns_dict(set_paths()[0]) fate_dict = {} for species in specieslist: fate_dict[species] = 'produced only' for entry in species_rxns[species]: if entry[1] < 0: fate_dict[species] = 'consumed' for species in specieslist: if fate_dict[species] == 'consumed': del fate_dict[species] return fate_dict
[ 37811, 198, 44, 2304, 10361, 5499, 2672, 416, 1811, 13103, 287, 262, 26106, 9078, 1430, 13, 198, 37811, 198, 11748, 28686, 198, 198, 11748, 299, 32152, 355, 45941, 198, 198, 6738, 38491, 1330, 402, 1921, 62, 10943, 2257, 11, 29961, 198,...
2.298871
7,970
#!/usr/bin/python # -*- coding: utf-8 -*- import os import sys import random import tempfile import shutil mayan_debug = 1 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) sys.path.append(BASE_DIR) sys.path.append(os.path.dirname(BASE_DIR)) from global_variables import * from caffe_utils import * ''' @brief: extract labels from rendered images @input: xxx/03790512_13a245da7b0567509c6d15186da929c5_a035_e009_t-01_d004.png @output: (35,9,359) ''' def outspath2label(path): ''' :param path: input_labels+=bookshelf_16_a007_e023_t359_d002px_216.00_py_499.00_bbwidth_280.00_bbheight_485.00.jpg=== =====0======1==2=====3===4=====5======6====7===8=======9=======10======11======12========= :return: ''' parts = os.path.basename(path).split('_') class_name = str(parts[0]) cad_index = str(parts[1]) azimuth = int(parts[2][1:]) elevation = int(parts[3][1:]) tilt = -int(parts[4][1:]) distance = float(parts[5][1:-2]) px = float(parts[6]) py = float(parts[8]) bbox_width = float(parts[10]) bbox_height = float(parts[12][:-4]) return (class_name, cad_index, azimuth, elevation, tilt, distance, px, py, bbox_width, bbox_height) ''' @brief: get rendered image filenames and annotations, save to specified files. @input: shape_synset - like '02958343' for car [train,test]_image_label_file - output file list filenames train_ratio - ratio of training images vs. all images @output: save "<image_filepath> <class_idx> <azimuth> <elevation> <tilt>" to files. ''' no_bkg = 0 ''' @brief: combine lines from input files and save the shuffled version to output file. @input: input_file_list - a list of input file names output_file - output filename ''' ''' @brief: convert 360 view degree to view estimation label e.g. for bicycle with class_idx 1, label will be 360~719 ''' ''' @brief: generate LMDB from files containing image filenames and labels @input: image_label_file - each line is <image_filepath> <class_idx> <azimuth> <elelvation> <tilt> output_lmdb: LMDB pathname-prefix like xxx/xxxx_lmdb image_resize_dim (D): resize image to DxD square @output: write TWO LMDB corresponding to images and labels, i.e. xxx/xxxx_lmdb_label (each item is class_idx, azimuth, elevation, tilt) and xxx/xxxx_lmdb_image '''
[ 2, 48443, 14629, 14, 8800, 14, 29412, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 11748, 28686, 198, 11748, 25064, 198, 11748, 4738, 198, 11748, 20218, 7753, 198, 11748, 4423, 346, 198, 198, 11261, 272, ...
2.405622
996
# -*- coding: utf-8 -*- """ PyVisio visDocuments - Visio Document manipulation library See docstring for class VisDocument for usage """ #TODO docstring __author__ = 'Ivo Velcovsky' __email__ = 'velcovsky@email.cz' __copyright__ = "Copyright (c) 2015" __license__ = "MIT" __status__ = "Development" from .visCOM import * from .documents import * from .stencils import * from .shapes import * if __name__ == "__main__": import doctest doctest.testmod()
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 201, 198, 37811, 201, 198, 20519, 15854, 952, 1490, 38354, 532, 6911, 952, 16854, 17512, 5888, 201, 198, 201, 198, 6214, 2205, 8841, 329, 1398, 6911, 24941, 329, 8748, 201, 1...
2.627027
185
#!/usr/bin/env python3 # Pi-Ware main UI from tkinter import * from tkinter.ttk import * import tkinter as tk import os import webbrowser from functools import partial import getpass #Set global var username global username username = getpass.getuser() #Set global install/uninstall scripts global install_script global uninstall_script #Import custom pi-ware functions #import function import classes window = tk.Tk() #Functions #Check if dev files exist filepath = f"/home/{username}/pi-ware/.dev" try: file_tst = open(filepath) file_tst.close() except FileNotFoundError: IsDev = "False" else: IsDev = "True" #Set window icon p1 = PhotoImage(file = f'/home/{username}/pi-ware/icons/logo.png') window.iconphoto(False, p1) #Main window.resizable(0, 0) window.geometry("330x500") window.eval('tk::PlaceWindow . center') window.title("Pi-Ware") # Window tabs tab_control = Notebook(window) apps_tab = Frame(tab_control) news_tab = Frame(tab_control) credits_tab = Frame(tab_control) DEV_tab = Frame(tab_control) tab_control.add(apps_tab, text="Apps") tab_control.add(news_tab, text="News") tab_control.add(credits_tab, text="Credits") #Show dev tab if dev files are found if IsDev == "True": tab_control.add(DEV_tab, text="Dev") tab_control.pack(expand=0, fill="both") #Show DEV stuff PiWareVersionFile = open(f"/home/{username}/.local/share/pi-ware/version", "r") PiWareVersioncontent = PiWareVersionFile.read() files = folders = 0 for _, dirnames, filenames in os.walk(f"/home/{username}/pi-ware/apps"): files += len(filenames) folders += len(dirnames) InstallibleApps = "{:,} installible Apps".format(folders) PiWareVersion = tk.Label(DEV_tab, text=f"Pi-Ware Version:\n{PiWareVersioncontent}", font="Arial 11 bold") PiWareInstallableApps = tk.Label(DEV_tab, text=f"{InstallibleApps}", font="Arial 11 bold") PiWareVersion.pack() PiWareInstallableApps.pack() #Show latest news message NewsMessagefile = open(f"/home/{username}/pi-ware/func/info/latestnewsmessage", "r") NewsMessagecontent = NewsMessagefile.read() NewsMessage = tk.Label(news_tab, text=f"Latest news:\n{NewsMessagecontent}", font="Arial 11 bold") NewsMessage.pack() #Show info message InfoMessagefile = open(f"/home/{username}/pi-ware/func/info/infomessage", "r") InfoMessagecontent = InfoMessagefile.read() InfoMessage = tk.Label(credits_tab, text=f"{InfoMessagecontent}", font="Arial 11 bold") InfoMessage.pack() #Show commit links commitmessage = tk.Label(credits_tab, text=f"To see commits, please go to the link below.", font="Arial 11 bold") commitmessage.pack() commit = classes.HyperLink(credits_tab, f"""https://github.com/piware14/pi-ware/graphs/contributors"""); commit.pack() #Add pi-ware website piwarewebsite = tk.Label(credits_tab, text=f"To vist the pi-ware website, click the link below.", font="Arial 11 bold") piwarewebsite.pack() Website = classes.HyperLink(credits_tab, f"""https://pi-ware.ml"""); Website.pack() tree = Treeview(apps_tab) tree.pack(expand=YES, fill=BOTH) tree.column("#0", minwidth=0, width=330, stretch=NO) s = Style() s.configure('Treeview', rowheight=35) ap = next(os.walk(f"/home/{username}/pi-ware/apps"))[1] applist = sorted(ap) print("Current apps:\n") for app in applist: print(app) appb = "" for a in app: if(a == " "): appb += "_" else: appb += a tree.bind("<<TreeviewSelect>>", partial(show_desc,app)) exec(appb + """_button = PhotoImage(file=f'/home/{username}/pi-ware/apps/{app}/icon.png')""") exec("""tree.insert('', 'end', text=f"{app}",image=""" + appb + """_button)""") ScrollForMore = tk.Label(apps_tab, text="Scroll down for more apps.", font="Arial 11 bold") ScrollForMore.pack() quitbutton = tk.Button(window, text="Quit", font="Arial 11 bold", width=200, bg="grey", fg="white", command=quit) quitbutton.pack(side="bottom") window.mainloop()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 13993, 12, 38824, 1388, 12454, 198, 6738, 256, 74, 3849, 1330, 1635, 198, 6738, 256, 74, 3849, 13, 926, 74, 1330, 1635, 198, 11748, 256, 74, 3849, 355, 256, 74, 198, 11748, ...
2.713189
1,433
from __future__ import division # This file implements a RenderVolumeVisual class. It is derived from the # VolumeVisual class in vispy.visuals.volume, which is released under a BSD # license included here: # # =========================================================================== # Vispy is licensed under the terms of the (new) BSD license: # # Copyright (c) 2015, authors of Vispy # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of Vispy Development Team nor the names of its # contributors may be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # =========================================================================== # # This modified version is released under the (new) BSD license: # # Copyright (c) 2015, Dany Vohl # All rights reserved. # # A copy of the license is available in the root directory of this project. # from ..extern.vispy.gloo import Texture3D, TextureEmulated3D, VertexBuffer, IndexBuffer from ..extern.vispy.visuals import Visual from ..extern.vispy.visuals.shaders import Function from ..extern.vispy.color import get_colormap from ..extern.vispy.scene.visuals import create_visual_node from ..extern.vispy.io import load_spatial_filters import numpy as np # Vertex shader VERT_SHADER = """ attribute vec3 a_position; // attribute vec3 a_texcoord; uniform vec3 u_shape; // varying vec3 v_texcoord; varying vec3 v_position; varying vec4 v_nearpos; varying vec4 v_farpos; void main() { // v_texcoord = a_texcoord; v_position = a_position; // Project local vertex coordinate to camera position. Then do a step // backward (in cam coords) and project back. Voila, we get our ray vector. vec4 pos_in_cam = $viewtransformf(vec4(v_position, 1)); // intersection of ray and near clipping plane (z = -1 in clip coords) pos_in_cam.z = -pos_in_cam.w; v_nearpos = $viewtransformi(pos_in_cam); // intersection of ray and far clipping plane (z = +1 in clip coords) pos_in_cam.z = pos_in_cam.w; v_farpos = $viewtransformi(pos_in_cam); gl_Position = $transform(vec4(v_position, 1.0)); } """ # noqa # Fragment shader FRAG_SHADER = """ // uniforms uniform $sampler_type u_volumetex; uniform vec3 u_shape; uniform vec3 u_resolution; uniform float u_threshold; uniform float u_relative_step_size; //uniform int u_color_scale; //uniform float u_data_min; //uniform float u_data_max; // Moving box filter variables uniform int u_filter_size; uniform float u_filter_coeff; uniform int u_filter_arm; uniform int u_filter_type; uniform int u_use_gaussian_filter; uniform int u_gaussian_filter_size; //uniform int u_log_scale; // Volume Stats uniform float u_volume_mean; uniform float u_volume_std; //uniform float u_volume_madfm; uniform float u_high_discard_filter_value; uniform float u_low_discard_filter_value; uniform float u_density_factor; uniform int u_color_method; //varyings // varying vec3 v_texcoord; varying vec3 v_position; varying vec4 v_nearpos; varying vec4 v_farpos; // uniforms for lighting. Hard coded until we figure out how to do lights const vec4 u_ambient = vec4(0.2, 0.4, 0.2, 1.0); const vec4 u_diffuse = vec4(0.8, 0.2, 0.2, 1.0); const vec4 u_specular = vec4(1.0, 1.0, 1.0, 1.0); const float u_shininess = 40.0; //varying vec3 lightDirs[1]; // global holding view direction in local coordinates vec3 view_ray; float rand(vec2 co) {{ // Create a pseudo-random number between 0 and 1. // http://stackoverflow.com/questions/4200224 return fract(sin(dot(co.xy ,vec2(12.9898, 78.233))) * 43758.5453); }} float colorToVal(vec4 color1) {{ return color1.g; }} vec4 movingAverageFilter_line_of_sight(vec3 loc, vec3 step) {{ // Initialise variables vec4 partial_color = vec4(0.0, 0.0, 0.0, 0.0); for ( int i=1; i<=u_filter_arm; i++ ) {{ partial_color += $sample(u_volumetex, loc-i*step); partial_color += $sample(u_volumetex, loc+i*step); }} partial_color += $sample(u_volumetex, loc); // Evaluate mean partial_color *= u_filter_coeff; return partial_color; }} vec4 Gaussian_5(vec4 color_original, vec3 loc, vec3 direction) {{ vec4 color = vec4(0.0); vec3 off1 = 1.3333333333333333 * direction; color += color_original * 0.29411764705882354; color += $sample(u_volumetex, loc + (off1 * u_resolution)) * 0.35294117647058826; color += $sample(u_volumetex, loc - (off1 * u_resolution)) * 0.35294117647058826; return color; }} vec4 Gaussian_9(vec4 color_original, vec3 loc, vec3 direction) {{ vec4 color = vec4(0.0); vec3 off1 = 1.3846153846 * direction; vec3 off2 = 3.2307692308 * direction; color += color_original * 0.2270270270; color += $sample(u_volumetex, loc + (off1 * u_resolution)) * 0.3162162162; color += $sample(u_volumetex, loc - (off1 * u_resolution)) * 0.3162162162; color += $sample(u_volumetex, loc + (off2 * u_resolution)) * 0.0702702703; color += $sample(u_volumetex, loc - (off2 * u_resolution)) * 0.0702702703; return color; }} vec4 Gaussian_13(vec4 color_original, vec3 loc, vec3 direction) {{ vec4 color = vec4(0.0); vec3 off1 = 1.411764705882353 * direction; vec3 off2 = 3.2941176470588234 * direction; vec3 off3 = 5.176470588235294 * direction; color += color_original * 0.1964825501511404; color += $sample(u_volumetex, loc + (off1 * u_resolution)) * 0.2969069646728344; color += $sample(u_volumetex, loc - (off1 * u_resolution)) * 0.2969069646728344; color += $sample(u_volumetex, loc + (off2 * u_resolution)) * 0.09447039785044732; color += $sample(u_volumetex, loc - (off2 * u_resolution)) * 0.09447039785044732; color += $sample(u_volumetex, loc + (off3 * u_resolution)) * 0.010381362401148057; color += $sample(u_volumetex, loc - (off3 * u_resolution)) * 0.010381362401148057; return color; }} // ---------------------------------------------------------------- // ---------------------------------------------------------------- // Edge detection Pass // (adapted from https://www.shadertoy.com/view/MscSzf#) // ---------------------------------------------------------------- float checkSame(vec4 center, vec4 sample, vec3 resolution) {{ vec2 centerNormal = center.xy; float centerDepth = center.z; vec2 sampleNormal = sample.xy; float sampleDepth = sample.z; vec2 sensitivity = (vec2(0.3, 1.5) * resolution.y / 50.0); vec2 diffNormal = abs(centerNormal - sampleNormal) * sensitivity.x; bool isSameNormal = (diffNormal.x + diffNormal.y) < 0.1; float diffDepth = abs(centerDepth - sampleDepth) * sensitivity.y; bool isSameDepth = diffDepth < 0.1; return (isSameNormal && isSameDepth) ? 1.0 : 0.0; }} vec4 edge_detection(vec4 color_original, vec3 loc, vec3 step, vec3 resolution) {{ vec4 sample1 = $sample(u_volumetex, loc + (vec3(1., 1., 0.) / resolution)); vec4 sample2 = $sample(u_volumetex, loc + (vec3(-1., -1., 0.) / resolution)); vec4 sample3 = $sample(u_volumetex, loc + (vec3(-1., 1., 0.) / resolution)); vec4 sample4 = $sample(u_volumetex, loc + (vec3(1., -1., 0.) / resolution)); float edge = checkSame(sample1, sample2, resolution) * checkSame(sample3, sample4, resolution); return vec4(color_original.rgb, 1-edge); }} // ---------------------------------------------------------------- // ---------------------------------------------------------------- // Used with iso surface vec4 calculateColor(vec4 betterColor, vec3 loc, vec3 step) {{ // Calculate color by incorporating lighting vec4 color1; vec4 color2; // View direction vec3 V = normalize(view_ray); // calculate normal vector from gradient vec3 N; // normal color1 = $sample( u_volumetex, loc+vec3(-step[0],0.0,0.0) ); color2 = $sample( u_volumetex, loc+vec3(step[0],0.0,0.0) ); N[0] = colorToVal(color1) - colorToVal(color2); betterColor = max(max(color1, color2),betterColor); color1 = $sample( u_volumetex, loc+vec3(0.0,-step[1],0.0) ); color2 = $sample( u_volumetex, loc+vec3(0.0,step[1],0.0) ); N[1] = colorToVal(color1) - colorToVal(color2); betterColor = max(max(color1, color2),betterColor); color1 = $sample( u_volumetex, loc+vec3(0.0,0.0,-step[2]) ); color2 = $sample( u_volumetex, loc+vec3(0.0,0.0,step[2]) ); N[2] = colorToVal(color1) - colorToVal(color2); betterColor = max(max(color1, color2),betterColor); float gm = length(N); // gradient magnitude N = normalize(N); // Flip normal so it points towards viewer float Nselect = float(dot(N,V) > 0.0); N = (2.0*Nselect - 1.0) * N; // == Nselect * N - (1.0-Nselect)*N; // Get color of the texture (albeido) color1 = betterColor; color2 = color1; // todo: parametrise color1_to_color2 // Init colors vec4 ambient_color = vec4(0.0, 0.0, 0.0, 0.0); vec4 diffuse_color = vec4(0.0, 0.0, 0.0, 0.0); vec4 specular_color = vec4(0.0, 0.0, 0.0, 0.0); vec4 final_color; // todo: allow multiple light, define lights on viewvox or subscene int nlights = 1; for (int i=0; i<nlights; i++) {{ // Get light direction (make sure to prevent zero devision) vec3 L = normalize(view_ray); //lightDirs[i]; float lightEnabled = float( length(L) > 0.0 ); L = normalize(L+(1.0-lightEnabled)); // Calculate lighting properties float lambertTerm = clamp( dot(N,L), 0.0, 1.0 ); vec3 H = normalize(L+V); // Halfway vector float specularTerm = pow( max(dot(H,N),0.0), u_shininess); // Calculate mask float mask1 = lightEnabled; // Calculate colors ambient_color += mask1 * u_ambient; // * gl_LightSource[i].ambient; diffuse_color += mask1 * lambertTerm; specular_color += mask1 * specularTerm * u_specular; }} // Calculate final color by componing different components final_color = color2 * ( ambient_color + diffuse_color) + specular_color; final_color.a = color2.a; // Done return final_color; }} // for some reason, this has to be the last function in order for the // filters to be inserted in the correct place... void main() {{ vec3 farpos = v_farpos.xyz / v_farpos.w; vec3 nearpos = v_nearpos.xyz / v_nearpos.w; // Calculate unit vector pointing in the view direction through this // fragment. view_ray = normalize(farpos.xyz - nearpos.xyz); // Compute the distance to the front surface or near clipping plane float distance = dot(nearpos-v_position, view_ray); distance = max(distance, min((-0.5 - v_position.x) / view_ray.x, (u_shape.x - 0.5 - v_position.x) / view_ray.x)); distance = max(distance, min((-0.5 - v_position.y) / view_ray.y, (u_shape.y - 0.5 - v_position.y) / view_ray.y)); //distance = max(distance, min((-0.5 - v_position.z) / view_ray.z, // (u_shape.z - 0.5 - v_position.z) / view_ray.z)); // Now we have the starting position on the front surface vec3 front = v_position + view_ray * distance; // Decide how many steps to take int nsteps = int(-distance / u_relative_step_size + 0.5); if( nsteps < 1 ) discard; // Get starting location and step vector in texture coordinates vec3 step = ((v_position - front) / u_shape) / nsteps; vec3 start_loc = front / u_shape; // For testing: show the number of steps. This helps to establish // whether the rays are correctly oriented //gl_FragColor = vec4(0.0, nsteps / 3.0 / u_shape.x, 1.0, 1.0); //return; {before_loop} vec3 loc = start_loc; int iter = 0; float discard_ratio = 1.0 / (u_high_discard_filter_value - u_low_discard_filter_value); float low_discard_ratio = 1.0 / u_low_discard_filter_value; for (iter=0; iter<nsteps; iter++) {{ // Get sample color vec4 color; if (u_filter_size == 1) color = $sample(u_volumetex, loc); else {{ color = movingAverageFilter_line_of_sight(loc, step); }} if (u_use_gaussian_filter==1) {{ vec4 temp_color; vec3 direction; if (u_gaussian_filter_size == 5){{ // horizontal direction = vec3(1., 0., 0.); temp_color = Gaussian_5(color, loc, direction); // vertical direction = vec3(0., 1., 0.); temp_color = Gaussian_5(temp_color, loc, direction); // depth direction = vec3(0., 0., 1.); temp_color = Gaussian_5(temp_color, loc, direction); }} if (u_gaussian_filter_size == 9){{ // horizontal direction = vec3(1., 0., 0.); temp_color = Gaussian_9(color, loc, direction); // vertical direction = vec3(0., 1., 0.); temp_color = Gaussian_9(temp_color, loc, direction); // depth direction = vec3(0., 0., 1.); temp_color = Gaussian_9(temp_color, loc, direction); }} if (u_gaussian_filter_size == 13){{ // horizontal direction = vec3(1., 0., 0.); temp_color = Gaussian_13(color, loc, direction); // vertical direction = vec3(0., 1., 0.); temp_color = Gaussian_13(temp_color, loc, direction); // depth direction = vec3(0., 0., 1.); temp_color = Gaussian_13(temp_color, loc, direction); }} color = temp_color; }} float val = color.g; // To force activating the uniform - this should be done differently float density_factor = u_density_factor; if (u_filter_type == 1) {{ // Get rid of very strong signal values if (val > u_high_discard_filter_value) {{ val = 0.; }} // Don't consider noisy values //if (val < u_volume_mean - 3*u_volume_std) if (val < u_low_discard_filter_value) {{ val = 0.; }} if (u_low_discard_filter_value == u_high_discard_filter_value) {{ if (u_low_discard_filter_value != 0.) {{ val *= low_discard_ratio; }} }} else {{ val -= u_low_discard_filter_value; val *= discard_ratio; }} }} else {{ if (val > u_high_discard_filter_value) {{ val = 0.; }} if (val < u_low_discard_filter_value) {{ val = 0.; }} }} {in_loop} // Advance location deeper into the volume loc += step; }} {after_loop} //gl_FragColor = edge_detection(gl_FragColor, loc, step, u_shape); /* Set depth value - from visvis TODO int iter_depth = int(maxi); // Calculate end position in world coordinates vec4 position2 = vertexPosition; position2.xyz += ray*shape*float(iter_depth); // Project to device coordinates and set fragment depth vec4 iproj = gl_ModelViewProjectionMatrix * position2; iproj.z /= iproj.w; gl_FragDepth = (iproj.z+1.0)/2.0; */ }} """ # noqa MIP_SNIPPETS = dict( before_loop=""" float maxval = -99999.0; // The maximum encountered value int maxi = 0; // Where the maximum value was encountered """, in_loop=""" if( val > maxval ) { maxval = val; maxi = iter; } """, after_loop=""" // Refine search for max value loc = start_loc + step * (float(maxi) - 0.5); for (int i=0; i<10; i++) { maxval = max(maxval, $sample(u_volumetex, loc).g); loc += step * 0.1; } if (maxval > u_high_discard_filter_value || maxval < u_low_discard_filter_value) {{ maxval = 0.; }} // Color is associated to voxel intensity // Moment 0 if (u_color_method == 0) { gl_FragColor = $cmap(maxval); } // Moment 1 else if (u_color_method == 1) { gl_FragColor = $cmap(loc.y); gl_FragColor.a = maxval; } // Color is associated to RGB cube else if (u_color_method == 2) { gl_FragColor.r = loc.y; gl_FragColor.g = loc.z; gl_FragColor.b = loc.x; gl_FragColor.a = maxval; } // Color by sigma values else if (u_color_method == 3) { if ( (maxval < (u_volume_mean + (3.0 * u_volume_std))) ) { gl_FragColor = vec4(0., 0., 1., maxval); } // < 3 sigmas if ( (maxval >= (u_volume_mean + (3.0 * u_volume_std))) && (maxval < (u_volume_mean + (4.0 * u_volume_std))) ) { gl_FragColor = vec4(0., 1., 0., maxval); } if ( (maxval >= (u_volume_mean + (4.0 * u_volume_std))) && (maxval < (u_volume_mean + (5.0 * u_volume_std))) ) { gl_FragColor = vec4(1., 0., 0., maxval); } if ( (maxval >= (u_volume_mean + (5.0 * u_volume_std))) ) { gl_FragColor = vec4(1., 1., 1., maxval); } } else { // Moment 2 // TODO: verify implementation of MIP-mom2. gl_FragColor = $cmap((maxval * ((maxval - loc.y) * (maxval - loc.y))) / maxval); } """, ) MIP_FRAG_SHADER = FRAG_SHADER.format(**MIP_SNIPPETS) LMIP_SNIPPETS = dict( before_loop=""" float maxval = -99999.0; // The maximum encountered value float local_maxval = -99999.0; // The local maximum encountered value int maxi = 0; // Where the maximum value was encountered int local_maxi = 0; // Where the local maximum value was encountered bool local_max_found = false; """, in_loop=""" if( val > u_threshold && !local_max_found ) { local_maxval = val; local_maxi = iter; local_max_found = true; } if( val > maxval) { maxval = val; maxi = iter; } """, after_loop=""" if (!local_max_found) { local_maxval = maxval; local_maxi = maxi; } // Refine search for max value loc = start_loc + step * (float(local_maxi) - 0.5); for (int i=0; i<10; i++) { local_maxval = max(local_maxval, $sample(u_volumetex, loc).g); loc += step * 0.1; } if (local_maxval > u_high_discard_filter_value) { local_maxval = 0.; } if (local_maxval < u_low_discard_filter_value) { local_maxval = 0.; } // Color is associated to voxel intensity if (u_color_method == 0) { gl_FragColor = $cmap(local_maxval); gl_FragColor.a = local_maxval; } // Color is associated to redshift/velocity else { gl_FragColor = $cmap(loc.y); gl_FragColor.a = local_maxval; } """, ) LMIP_FRAG_SHADER = FRAG_SHADER.format(**LMIP_SNIPPETS) TRANSLUCENT_SNIPPETS = dict( before_loop=""" vec4 integrated_color = vec4(0., 0., 0., 0.); float mom0 = 0.; float mom1 = 0.; float ratio = 1/nsteps; // final average float a1 = 0.; float a2 = 0.; """, in_loop=""" float alpha; // Case 1: Color is associated to voxel intensity if (u_color_method == 0) { /*color = $cmap(val); a1 = integrated_color.a; a2 = val * density_factor * (1 - a1); alpha = max(a1 + a2, 0.001); integrated_color *= a1 / alpha; integrated_color += color * a2 / alpha;*/ color = $cmap(val); a1 = integrated_color.a; a2 = val * density_factor * (1 - a1); alpha = max(a1 + a2, 0.001); integrated_color *= a1 / alpha; integrated_color += color * a2 / alpha; } else{ // Case 2: Color is associated to redshift/velocity if (u_color_method == 1) { color = $cmap(loc.y); a1 = integrated_color.a; a2 = val * density_factor * (1 - a1); alpha = max(a1 + a2, 0.001); integrated_color *= a1 / alpha; integrated_color.rgb += color.rgb * a2 / alpha; } // Case 3: Color is associated to RGB cube else { if (u_color_method == 2){ color.r = loc.y; color.g = loc.z; color.b = loc.x; a1 = integrated_color.a; a2 = val * density_factor * (1 - a1); alpha = max(a1 + a2, 0.001); integrated_color *= a1 / alpha; integrated_color.rgb += color.rgb * a2 / alpha; } // Case 4: Mom2 // TODO: Finish implementation of mom2 (not correct in its present form). else { // mom0 a1 = mom0; a2 = val * density_factor * (1 - a1); alpha = max(a1 + a2, 0.001); mom0 *= a1 / alpha; mom0 += val * a2 / alpha; // mom1 a1 = mom1; a2 = val * density_factor * (1 - a1); alpha = max(a1 + a2, 0.001); mom1 *= a1 / alpha; mom1 += loc.y * a2 / alpha; } } } integrated_color.a = alpha; // stop integrating if the fragment becomes opaque if( alpha > 0.99 ){ iter = nsteps; } """, after_loop=""" if (u_color_method != 3){ gl_FragColor = integrated_color; } else { gl_FragColor = $cmap((mom0 * (mom0-mom1 * mom0-mom1)) / mom0); } """, ) TRANSLUCENT_FRAG_SHADER = FRAG_SHADER.format(**TRANSLUCENT_SNIPPETS) TRANSLUCENT2_SNIPPETS = dict( before_loop=""" vec4 integrated_color = vec4(0., 0., 0., 0.); float ratio = 1/nsteps; // final average """, in_loop=""" float alpha; // Case 1: Color is associated to voxel intensity if (u_color_method == 0) { color = $cmap(val); integrated_color = (val * density_factor + integrated_color.a * (1 - density_factor)) * color; alpha = integrated_color.a; //alpha = a1+a2; // integrated_color *= a1 / alpha; // integrated_color += color * a2 / alpha; } else{ // Case 2: Color is associated to redshift/velocity if (u_color_method == 1) { color = $cmap(loc.y); float a1 = integrated_color.a; float a2 = val * density_factor * (1 - a1); alpha = max(a1 + a2, 0.001); integrated_color *= a1 / alpha; integrated_color.rgb += color.rgb * a2 / alpha; } // Case 3: Color is associated to RGB cube else { color.r = loc.x; color.g = loc.z; color.b = loc.y; float a1 = integrated_color.a; float a2 = val * density_factor * (1 - a1); alpha = max(a1 + a2, 0.001); integrated_color *= a1 / alpha; integrated_color.rgb += color.rgb * a2 / alpha; } } integrated_color.a = alpha; // stop integrating if the fragment becomes opaque if( alpha > 0.99 ){ iter = nsteps; } """, after_loop=""" gl_FragColor = integrated_color; """, ) TRANSLUCENT2_FRAG_SHADER = FRAG_SHADER.format(**TRANSLUCENT2_SNIPPETS) ADDITIVE_SNIPPETS = dict( before_loop=""" vec4 integrated_color = vec4(0., 0., 0., 0.); """, in_loop=""" color = $cmap(val); integrated_color = 1.0 - (1.0 - integrated_color) * (1.0 - color); """, after_loop=""" gl_FragColor = integrated_color; """, ) ADDITIVE_FRAG_SHADER = FRAG_SHADER.format(**ADDITIVE_SNIPPETS) ISO_SNIPPETS = dict( before_loop=""" vec4 color3 = vec4(0.0); // final color vec3 dstep = 1.5 / u_shape; // step to sample derivative gl_FragColor = vec4(0.0); """, in_loop=""" if (val > u_threshold-0.2) { // Take the last interval in smaller steps vec3 iloc = loc - step; for (int i=0; i<10; i++) { val = $sample(u_volumetex, iloc).g; if (val > u_threshold) { color = $cmap(val); gl_FragColor = calculateColor(color, iloc, dstep); iter = nsteps; break; } iloc += step * 0.1; } } """, after_loop=""" """, ) ISO_FRAG_SHADER = FRAG_SHADER.format(**ISO_SNIPPETS) MINIP_SNIPPETS = dict( before_loop=""" float maxval = -99999.0; // maximum encountered float minval = 99999.0; // The minimum encountered value int mini = 0; // Where the minimum value was encountered """, in_loop=""" if( val > maxval ) { maxval = val; } if( val < minval ) { minval = val; mini = iter; } """, after_loop=""" // Refine search for min value loc = start_loc + step * (float(mini) - 0.5); for (int i=0; i<10; i++) { minval = min(minval, $sample(u_volumetex, loc).g); loc += step * 0.1; } if (minval > u_high_discard_filter_value || minval < u_low_discard_filter_value) {{ minval = 0.; }} // Color is associated to voxel intensity if (u_color_method == 0) { gl_FragColor = $cmap(minval); //gl_FragColor.a = minval; } else{ // Color is associated to redshift/velocity if (u_color_method == 1) { gl_FragColor = $cmap(loc.y); //if (minval == 0) gl_FragColor.a = 1-minval; } // Color is associated to RGB cube else { if (u_color_method == 2) { gl_FragColor.r = loc.y; gl_FragColor.g = loc.z; gl_FragColor.b = loc.x; gl_FragColor.a = minval; } // Color by sigma values else if (u_color_method == 3) { if ( (1-minval < (u_volume_mean + (3.0 * u_volume_std))) ) { gl_FragColor = vec4(0., 0., 1., 1-minval); } // < 3 sigmas if ( (1-minval >= (u_volume_mean + (3.0 * u_volume_std))) && (1-minval < (u_volume_mean + (4.0 * u_volume_std))) ) { gl_FragColor = vec4(0., 1., 0., 1-minval); } if ( (1-minval >= (u_volume_mean + (4.0 * u_volume_std))) && (1-minval < (u_volume_mean + (5.0 * u_volume_std))) ) { gl_FragColor = vec4(1., 0., 0., 1-minval); } if ( (1-minval >= (u_volume_mean + (5.0 * u_volume_std))) ) { gl_FragColor = vec4(1., 1., 1., 1-minval); } } // Case 4: Mom2 // TODO: verify implementation of MIP-mom2. else { gl_FragColor = $cmap((minval * ((minval - loc.y) * (minval - loc.y))) / minval); } } } """, ) MINIP_FRAG_SHADER = FRAG_SHADER.format(**MINIP_SNIPPETS) frag_dict = { 'mip': MIP_FRAG_SHADER, 'lmip': LMIP_FRAG_SHADER, 'iso': ISO_FRAG_SHADER, 'avip': TRANSLUCENT_FRAG_SHADER, 'minip': MINIP_FRAG_SHADER, 'translucent2': TRANSLUCENT2_FRAG_SHADER, 'additive': ADDITIVE_FRAG_SHADER, } # _interpolation_template = """ # #include "misc/spatial-filters.frag" # vec4 texture_lookup_filtered(vec2 texcoord) { # if(texcoord.x < 0.0 || texcoord.x > 1.0 || # texcoord.y < 0.0 || texcoord.y > 1.0) { # discard; # } # return %s($texture, $shape, texcoord); # }""" # # _texture_lookup = """ # vec4 texture_lookup(vec2 texcoord) { # if(texcoord.x < 0.0 || texcoord.x > 1.0 || # texcoord.y < 0.0 || texcoord.y > 1.0) { # discard; # } # return texture2D($texture, texcoord); # }""" RenderVolume = create_visual_node(RenderVolumeVisual)
[ 6738, 11593, 37443, 834, 1330, 7297, 198, 198, 2, 770, 2393, 23986, 257, 46722, 31715, 36259, 1398, 13, 632, 318, 10944, 422, 262, 198, 2, 14701, 36259, 1398, 287, 1490, 9078, 13, 41464, 82, 13, 29048, 11, 543, 318, 2716, 739, 257, ...
2.041195
15,366
# Copyright (c) 2019-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. # #TOFILL if __name__ == '__main__': param = [ (29,), (13,), (25,), (65,), (27,), (42,), (19,), (50,), (59,), (13,) ] n_success = 0 for i, parameters_set in enumerate(param): if f_filled(*parameters_set) == f_gold(*parameters_set): n_success+=1 print("#Results: %i, %i" % (n_success, len(param)))
[ 2, 15069, 357, 66, 8, 13130, 12, 25579, 11, 3203, 11, 3457, 13, 198, 2, 1439, 2489, 10395, 13, 198, 2, 198, 2, 770, 2723, 2438, 318, 11971, 739, 262, 5964, 1043, 287, 262, 198, 2, 38559, 24290, 2393, 287, 262, 6808, 8619, 286, 4...
2.22093
258
import os import shutil from textwrap import dedent import argparse import subprocess parser = argparse.ArgumentParser(description='This is a script to create 3D model folder structure') parser.add_argument('-p', '--project', help='3D project name', required=True) parser.add_argument('-wd', '--wd', help='Working directory', required=True) args = parser.parse_args() os.chdir(args.wd) root_dir = os.path.join(args.wd, args.project) if os.path.exists(root_dir) and os.listdir(root_dir): # If the path already exists and it is not empty, raise an error err_msg = ''' {directory} already exists and it is not empty. Please try a different project name or root directory. '''.format(directory=root_dir) raise IOError(000, dedent(err_msg)) else: os.mkdir(root_dir) # Create the root directory dirnames = ('images', 'masks', 'models') # Create all the other directories for item in dirnames: path3D = os.path.join(args.wd, args.project, item) os.mkdir(path3D) write_readme(args.project, root_dir) write_license(root_dir) write_ignore(root_dir)
[ 11748, 28686, 198, 11748, 4423, 346, 198, 6738, 2420, 37150, 1330, 4648, 298, 198, 11748, 1822, 29572, 198, 11748, 850, 14681, 198, 198, 48610, 796, 1822, 29572, 13, 28100, 1713, 46677, 7, 11213, 11639, 1212, 318, 257, 4226, 284, 2251, ...
2.813131
396
# # Copyright (c) 2015 - 2022, Intel Corporation # SPDX-License-Identifier: BSD-3-Clause # ''' Common command line arguments for experiments. ''' def setup_run_args(parser): """Add common arguments for all run scripts: --output-dir --node-count --trial-count --cool-off-time """ add_output_dir(parser) add_node_count(parser) add_trial_count(parser) add_cool_off_time(parser) add_enable_traces(parser) add_enable_profile_traces(parser)
[ 2, 198, 2, 220, 15069, 357, 66, 8, 1853, 532, 33160, 11, 8180, 10501, 198, 2, 220, 30628, 55, 12, 34156, 12, 33234, 7483, 25, 347, 10305, 12, 18, 12, 2601, 682, 198, 2, 198, 198, 7061, 6, 198, 17227, 3141, 1627, 7159, 329, 10256...
2.604167
192
import requests import json import chess import chess.pgn import io from collections import Counter from openpyxl import load_workbook import numpy #API link: https://api.chess.com/pub/player/{user}/games/{year}/{month}/pgn baseUrl='https://api.chess.com/pub/player/' users=['Mazrouai'] # You can add one or more chess.com profile/s, make sure to type the prfile name/s as it's/they're written in chess.com. for user in users: years = range(2000,2022) # Add the range of the years you want this code to analyze (from,to). months = ['01','02','03','04','05','06','07','08','09','10','11','12'] # Keep this as it is. count=0 winBlackKingPos=[] # Array to collect King position in the games won as black. lossBlackKingPos=[] # Array to collect King position in the games lost as black. winWhiteKingPos=[] # Array to collect King position in the games won as white. lossWhiteKingPos=[] # Array to collect King position in the games lost as white. for i in years: # For loop to irritate through the specified years range. for j in months: # For loop to irritate through the monthes of the specified years. extension=str(str(user)+'/games/'+str(i)+'/'+str(j)+'/pgn') # Creates the extension for the baseUrl. url=baseUrl+extension # Merges baseUrl with the extension. response = requests.get(url) pgns = io.StringIO(response.text) if response.text == '': # Checks if pgn file is empty and if it is, it jumps to the next PGN file. continue while True: games=chess.pgn.read_game(pgns) # Reads PGN file. if games == None: # Checks if there is a game available to read inside the pgn file, if not it exits this loop to the next PGN file. break if games.headers['Black'] == '?': # Checks if game data is missing, if true it jumps to the next game. continue if games.headers['White'] == '?': # Checks if game data is missing, if true it jumps to the next game. continue board=games.board() for move in games.mainline_moves(): # Moves to the last position in the game. board.push(move) map=board.piece_map() # Collect the position of the pieces in thier last move. if games.headers['Black']== str(user): # Checks if the specified user is playing as black for x,y in map.items(): if str(y) == 'k': kingPos=chess.square_name(x) # Gets the black king postion. if games.headers['Result'] == '0-1': # Collects the king position in the games won as black. winBlackKingPos.append(kingPos) if games.headers['Result'] == '1-0': # Collects the king position in the games lost as black. lossBlackKingPos.append(kingPos) else: # If the if condition is not satisfied then the specificed user is playing as white. for x,y in map.items(): if str(y) == 'K': kingPos=chess.square_name(x) # Gets the white king postion. if games.headers['Result'] == '0-1': # Collects the king position in the games lost as white. lossWhiteKingPos.append(kingPos) if games.headers['Result'] == '1-0': # Collects the king position in the games won as white. winWhiteKingPos.append(kingPos) gamesWon=len(winBlackKingPos)+len(winWhiteKingPos) # Counts # of won games. gamesLost=len(lossBlackKingPos)+len(lossWhiteKingPos) # Counts # of lost games. gamesPlayed=gamesWon+gamesLost # counts # of analyzed games print("Player: ",user) # Prints the name of the player. print("games played: ",gamesPlayed) # Prints # of won games. print("games won: ",gamesWon) # Prints # of lost games. print("games lost: ",gamesLost) # Prints # of analyzed games print("\n") winWhiteKingPosCount= Counter(winWhiteKingPos) # Creates a list with a position and the number of times the wining white king was in that position. lossWhiteKingPosCount= Counter(lossWhiteKingPos) # Creates a list with a position and the number of times the losing white king was in that position. winBlackKingPosCount= Counter(winBlackKingPos) # Creates a list with a position and the number of times the wining black king was in that position. lossBlackKingPosCount= Counter(lossBlackKingPos) # Creates a list with a position and the number of times the losing black king was in that position. posCounts=[winWhiteKingPosCount,lossWhiteKingPosCount,winBlackKingPosCount,lossBlackKingPosCount] # Merges the lists into an array. Data = load_workbook(filename='Data_Template.xlsx') # Opens the template excel file . sheets=Data.sheetnames # Register the sheets name. cellLetters=[] # Array for the cell letters in the excel file. cellNum=[] # Array for the cell numbers in the excel file. for j in range(8): # Generates cell letters to get the cells this code will work . for i in range(66, 74): cellLetters.append(chr(i)) for i in [10,9,8,7,6,5,4,3]: # Generates cell numbers to get the cells this code will work . for j in range(8): cellNum.append(i) c = 0 # This variable will be used as an index to go thorugh the lists that have been merged into an array. for sheet in sheets: # For loop to irritate through the excel sheets. workSheet=Data[sheet] posCount=posCounts[c] # Gets the postion list. c=c+1 for i in range(64): # For loop to go through the sheet cells and assign them the king recurrence value. cell=str(cellLetters[i])+str(cellNum[i]) # Constructs the excel cell name (e.g. A12). count=posCount[chess.square_name(i)] # Gets the king postion count that correlates with the cell name. if count== 0: # If king recurrence equals 0 set the cell to None. count= None workSheet[cell] = count # Makes the cell value equales the king recurrence in that position. Data.save(filename='Data_'+str(user)+'.xlsx') # Saves the data into a new xlsx file
[ 11748, 7007, 198, 11748, 33918, 198, 11748, 19780, 198, 11748, 19780, 13, 79, 4593, 198, 11748, 33245, 198, 6738, 17268, 1330, 15034, 198, 6738, 1280, 9078, 87, 75, 1330, 3440, 62, 1818, 2070, 198, 11748, 299, 32152, 198, 198, 2, 17614,...
1.595427
6,560
import csv import numpy as np
[ 11748, 269, 21370, 198, 11748, 299, 32152, 355, 45941, 198 ]
3
10
# coding=utf-8 # Copyright, 2021 Ontocord, LLC, All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from datasets import load_dataset import os import re import itertools from re import finditer import glob import random import fsspec import json from random import randint, choice from collections import Counter import spacy, itertools import langid from nltk.corpus import stopwords import fsspec, os, gzip from faker import Faker from faker.providers import person, company, geo, address from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer, MarianMTModel, AutoTokenizer, pipeline import torch import sys from tqdm import tqdm model_name = 'Helsinki-NLP/opus-mt-en-hi' model = MarianMTModel.from_pretrained(model_name) tokenizer = AutoTokenizer.from_pretrained(model_name) model_name = 'Helsinki-NLP/opus-mt-en-ar' model = MarianMTModel.from_pretrained(model_name) tokenizer = AutoTokenizer.from_pretrained(model_name) model_name = 'Helsinki-NLP/opus-mt-en-zh' model = MarianMTModel.from_pretrained(model_name) tokenizer = AutoTokenizer.from_pretrained(model_name) model = M2M100ForConditionalGeneration.from_pretrained("facebook/m2m100_418M") tokenizer = M2M100Tokenizer.from_pretrained("facebook/m2m100_418M") nlp = spacy.load('en_core_web_lg') stopwords_en = set(stopwords.words('english'))
[ 2, 19617, 28, 40477, 12, 23, 198, 2, 15069, 11, 33448, 9463, 420, 585, 11, 11419, 11, 1439, 2489, 10395, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, ...
3.194444
576
## Send data to a Graphite/Carbon Server import traceback import sys, time, socket, datetime from datetime import datetime
[ 2235, 16290, 1366, 284, 257, 29681, 578, 14, 9914, 4189, 9652, 198, 198, 11748, 12854, 1891, 198, 11748, 25064, 11, 640, 11, 17802, 11, 4818, 8079, 198, 6738, 4818, 8079, 1330, 4818, 8079, 198, 220, 220, 220, 220, 220, 220, 220, 220, ...
2.914894
47
from b_bot import BBot from rand_str import *
[ 198, 6738, 275, 62, 13645, 1330, 12597, 313, 198, 6738, 43720, 62, 2536, 1330, 1635 ]
3.066667
15
"""Samples negative pairs from run.""" import argparse from utils import load_qrels, load_run import numpy as np if __name__ == "__main__": main()
[ 37811, 50, 12629, 4633, 14729, 422, 1057, 526, 15931, 198, 198, 11748, 1822, 29572, 198, 6738, 3384, 4487, 1330, 3440, 62, 80, 2411, 82, 11, 3440, 62, 5143, 198, 11748, 299, 32152, 355, 45941, 198, 198, 361, 11593, 3672, 834, 6624, 36...
2.886792
53
import torch import torch.nn as nn import torch.nn.functional as F #Unicamente como esta ahorita funciona para un grafo de 5x5.
[ 11748, 28034, 198, 11748, 28034, 13, 20471, 355, 299, 77, 220, 198, 11748, 28034, 13, 20471, 13, 45124, 355, 376, 198, 198, 2, 3118, 291, 3263, 68, 401, 78, 1556, 64, 257, 17899, 5350, 25439, 32792, 31215, 555, 7933, 6513, 390, 642, ...
2.808511
47
''' Module containing the in-game mayhem instances such as the ship, planets, asteroid objects etc etc... Written by Naphat Amundsen ''' import numpy as np import pygame as pg import configparser import sys import os sys.path.insert(0,'..') from classes import spaceship from classes import planet from classes import maps from classes import interface import user_settings as user_cng from instances import instance_config as icng pg.font.init() w_shape = user_cng.w_shape w_norm = np.linalg.norm(w_shape) COLORS = pg.colordict.THECOLORS # The initial values of the objects # are mostly just educated guesses game_map = maps.game_map( map_shape=(icng.map_shape) ) minimap = maps.minimap( gmap=game_map, w_shape=w_shape, w_norm=w_norm) ship = spaceship.spaceship( pos=(200,200), init_dir=icng.RIGHT ) sun = planet.planet( pos=game_map.center, init_vel=None, init_dir=None, rforce=None ) earth = planet.rotating_planet( pos=(game_map.shape[0]/2, 800), init_vel=[-3,0], init_dir=[1,0], r_force=25000, omega=0.25 ) venus = planet.rotating_planet( pos=(game_map.shape[0]/2, 2000), init_vel=[-5,0], init_dir=[1,0], r_force=40000, omega=0.25 ) asteroids = [ planet.rotating_planet( pos=(3000, 1000), init_vel=[-8,2], init_dir=[1,0], r_force=150000, omega=0.25 ), planet.rotating_planet( pos=(1200, 1000), init_vel=[10,1], init_dir=[1,0], r_force=390000, omega=0.25 ), planet.rotating_planet( pos=(500, 2000), init_vel=[2,10], init_dir=[1,0], r_force=540000, omega=0.25 ), planet.rotating_planet( pos=(6500, 6000), init_vel=[5,-15], init_dir=[1,0], r_force=1500000, omega=0.5 ), planet.rotating_planet( pos=(6000, 6000), init_vel=[-15,1], init_dir=[1,0], r_force=1000000, omega=0.5 ), planet.rotating_planet( pos=(6000, 500), init_vel=[-8,-2], init_dir=[1,0], r_force=600000, omega=0.25 ), planet.rotating_planet( pos=(5000, 2000), init_vel=[-2,-8], init_dir=[1,0], r_force=200000, omega=0.25 ), planet.rotating_planet( pos=(game_map.shape[0]/2, 800), init_vel=[15,0], init_dir=[1,0], r_force=590000, omega=0.25 ), planet.rotating_planet( pos=(5000, game_map.shape[1]/2), init_vel=[0,10], init_dir=[1,0], r_force=150000, omega=0.25 ), ] # For convenience planets = [earth, venus] all_celestials = planets + asteroids minimap_colors = [ COLORS['white'], COLORS['orange'], COLORS['blue'], COLORS['green'] ] minimap_sizes = [ 1, int(500/5000*minimap.shape[0]), int(250/5000*minimap.shape[0]), 1 ] '''Minimap stuff for LAN-mayhem''' minimap_colors_online = [ COLORS['white'], COLORS['orange'], COLORS['blue'], COLORS['green'], COLORS['red'], ] minimap_sizes_online = [ 1, int(500/5000*minimap.shape[0]), int(250/5000*minimap.shape[0]), 1, 3 ]
[ 7061, 6, 201, 198, 26796, 7268, 262, 287, 12, 6057, 43744, 10245, 201, 198, 10508, 355, 262, 4074, 11, 14705, 11, 27460, 5563, 3503, 3503, 986, 201, 198, 201, 198, 25354, 416, 14332, 5183, 1703, 917, 6248, 201, 198, 7061, 6, 201, 19...
1.88895
1,819
import sys import os simp_path = 'TCGAIntegrator' abs_path = os.path.abspath(simp_path) sys.path.append(abs_path) from TCGAIntegrator import TCGAData as TCGAData if __name__ == '__main__': main()
[ 11748, 25064, 198, 11748, 28686, 198, 82, 11011, 62, 6978, 796, 705, 4825, 9273, 34500, 12392, 6, 198, 8937, 62, 6978, 796, 28686, 13, 6978, 13, 397, 2777, 776, 7, 82, 11011, 62, 6978, 8, 198, 17597, 13, 6978, 13, 33295, 7, 8937, ...
2.46988
83
from synergy.db.model.queue_context_entry import queue_context_entry from synergy.scheduler.scheduler_constants import PROCESS_GC, TOKEN_GC, PROCESS_MX, TOKEN_WERKZEUG, EXCHANGE_UTILS, \ PROCESS_SCHEDULER, TOKEN_SCHEDULER, QUEUE_UOW_STATUS, QUEUE_JOB_STATUS, PROCESS_LAUNCH_PY, TOKEN_LAUNCH_PY, \ ROUTING_IRRELEVANT from synergy.supervisor.supervisor_constants import PROCESS_SUPERVISOR, TOKEN_SUPERVISOR from synergy.db.model.daemon_process_entry import daemon_context_entry process_context = { PROCESS_LAUNCH_PY: daemon_context_entry( process_name=PROCESS_LAUNCH_PY, classname='', token=TOKEN_LAUNCH_PY, routing=ROUTING_IRRELEVANT, exchange=EXCHANGE_UTILS), PROCESS_MX: daemon_context_entry( process_name=PROCESS_MX, token=TOKEN_WERKZEUG, classname=''), PROCESS_GC: daemon_context_entry( process_name=PROCESS_GC, token=TOKEN_GC, classname=''), PROCESS_SCHEDULER: daemon_context_entry( process_name=PROCESS_SCHEDULER, classname='synergy.scheduler.synergy_scheduler.Scheduler.start', token=TOKEN_SCHEDULER, queue='', routing='', exchange=''), PROCESS_SUPERVISOR: daemon_context_entry( process_name=PROCESS_SUPERVISOR, classname='synergy.supervisor.synergy_supervisor.Supervisor.start', token=TOKEN_SUPERVISOR), } mq_queue_context = { QUEUE_UOW_STATUS: queue_context_entry(exchange=EXCHANGE_UTILS, queue_name=QUEUE_UOW_STATUS), QUEUE_JOB_STATUS: queue_context_entry(exchange=EXCHANGE_UTILS, queue_name=QUEUE_JOB_STATUS), } timetable_context = { }
[ 6738, 42193, 13, 9945, 13, 19849, 13, 36560, 62, 22866, 62, 13000, 1330, 16834, 62, 22866, 62, 13000, 198, 6738, 42193, 13, 1416, 704, 18173, 13, 1416, 704, 18173, 62, 9979, 1187, 1330, 41755, 7597, 62, 15916, 11, 5390, 43959, 62, 159...
2.195739
751
""" Fyle V3 APIs Base Class """ from .expenses import Expenses from .reports import Reports from .employees import Employees from .orgs import Orgs from .reimbursements import Reimbursements from .cost_centes import CostCenters from .categories import Categories from .projects import Projects from .refunds import Refunds from .balance_transfers import BalanceTransfers from .settlements import Settlements from .advance_requests import AdvanceRequests from .advances import Advances from .bank_transactions import BankTransactions from .trip_requests import TripRequests from .expense_custom_properties import ExpenseCustomProperties from .employee_custom_properties import EmployeeCustomProperties from .advance_request_custom_properties import AdvanceRequestCustomProperties from .trip_request_custom_properties import TripRequestCustomProperties
[ 37811, 198, 37, 2349, 569, 18, 23113, 7308, 5016, 198, 37811, 198, 6738, 764, 11201, 4541, 1330, 5518, 4541, 198, 6738, 764, 48922, 1330, 17905, 198, 6738, 764, 7033, 2841, 1330, 30260, 198, 6738, 764, 2398, 82, 1330, 1471, 14542, 198, ...
4.018868
212
from datetime import date as d #---------------------------HOTEL---------------------------# main()
[ 6738, 4818, 8079, 1330, 3128, 355, 288, 201, 198, 201, 198, 2, 22369, 6329, 39, 2394, 3698, 22369, 6329, 2, 201, 198, 201, 198, 201, 198, 201, 198, 201, 198, 201, 198, 201, 198, 201, 198, 201, 198, 201, 198, 201, 198, 201, 198, ...
2.645833
48
import sys import maya.standalone maya.standalone.initialize(name='python') from maya import cmds # try: run() maya.standalone.uninitialize() # except Exception as e: # sys.stdout.write(1)
[ 11748, 25064, 198, 11748, 743, 64, 13, 1481, 17749, 198, 11261, 64, 13, 1481, 17749, 13, 36733, 1096, 7, 3672, 11639, 29412, 11537, 198, 6738, 743, 64, 1330, 23991, 82, 198, 198, 2, 1949, 25, 198, 198, 5143, 3419, 198, 11261, 64, 13...
2.728571
70
from GreedyGRASP.Solver import Solver from GreedyGRASP.Solution import Solution from GreedyGRASP.LocalSearch import LocalSearch # Inherits from a parent abstract solver.
[ 198, 6738, 11955, 4716, 10761, 1921, 47, 13, 50, 14375, 1330, 4294, 332, 198, 6738, 11955, 4716, 10761, 1921, 47, 13, 46344, 1330, 28186, 198, 6738, 11955, 4716, 10761, 1921, 47, 13, 14565, 18243, 1330, 10714, 18243, 198, 198, 2, 47025,...
3.44
50
import inspect import math as _math from copy import deepcopy import matplotlib.pyplot as _plt import numpy as np import pandas as pd import statsmodels.api as _sm from statslib._lib.gcalib import CalibType
[ 11748, 10104, 198, 11748, 10688, 355, 4808, 11018, 198, 6738, 4866, 1330, 2769, 30073, 198, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 4808, 489, 83, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 19798, 292, 355, 279, 67, 19...
3.149254
67
List1 = [1, 2, 3, 4] List2 = ['I', 'tripped', 'over', 'and', 'hit', 'the', 'floor'] print(List1 + List2) List3 = List1 + List2 print(List3) fibs = (0, 1, 2, 3) print(fibs[3])
[ 8053, 16, 796, 685, 16, 11, 362, 11, 513, 11, 604, 60, 198, 8053, 17, 796, 37250, 40, 3256, 705, 28461, 1496, 3256, 705, 2502, 3256, 705, 392, 3256, 705, 17945, 3256, 705, 1169, 3256, 705, 28300, 20520, 198, 4798, 7, 8053, 16, 134...
2.047059
85
import os from flask import Flask, render_template, request, jsonify from display.predict import predict_file app = Flask(__name__, static_folder="./display/static", template_folder="./display/templates") if __name__ == '__main__': if not os.path.exists('./display/files'): os.mkdir('./display/files') app.run(debug=True)
[ 11748, 28686, 198, 6738, 42903, 1330, 46947, 11, 8543, 62, 28243, 11, 2581, 11, 33918, 1958, 198, 6738, 3359, 13, 79, 17407, 1330, 4331, 62, 7753, 198, 198, 1324, 796, 46947, 7, 834, 3672, 834, 11, 9037, 62, 43551, 28, 1911, 14, 138...
2.796748
123
import unittest from ortools.linear_solver import pywraplp
[ 11748, 555, 715, 395, 198, 198, 6738, 393, 31391, 13, 29127, 62, 82, 14375, 1330, 12972, 29988, 489, 79, 198 ]
3
20
# Uno PWM bipolar curve tracer app by simple-circuit 12-22-19 # rev 3 1-13-20 from tkinter import * from tkinter import ttk from tkinter import filedialog from tkinter import font import numpy as np import serial root = Tk() default_font = font.nametofont("TkDefaultFont") default_font.configure(size=9) canvas = Canvas(root) root.geometry("720x540") root.title('Uno Curve Tracer in Python') canvas.grid(column=0, row=0, sticky=(N,W,E,S)) root.grid_columnconfigure(0, weight=1) root.grid_rowconfigure(0, weight=1) xtvar = BooleanVar() xtvar.set(False) contvar = BooleanVar() contvar.set(False) crampvar = BooleanVar() crampvar.set(False) #ser = serial.Serial('/dev/ttyACM0', baudrate=115200, timeout = 1) ser = serial.Serial('COM10', baudrate=115200, timeout = 1) globalVar() stepn = IntVar() stepn.set(-1) canvas.create_rectangle((0,0,512,512),fill='green') for i in range(11): canvas.create_line((51.2*i, 0, 51.2*i, 512), fill='black', width=1) canvas.create_line((0,51.2*i, 512, 51.2*i), fill='black', width=1) for i in range(50): canvas.create_line((10.24*i, 254, 10.24*i, 258), fill='green', width=1) canvas.create_line((254,10.24*i, 258, 10.24*i), fill='green', width=1) canvas.create_line((612,10,612,480), fill='grey', width=3) canvas.create_line((520,10,605,10), fill='grey', width=3) canvas.create_line((520,115,605,115), fill='grey', width=3) canvas.create_line((520,220,605,220), fill='grey', width=3) canvas.create_line((520,247,605,247), fill='grey', width=3) canvas.create_line((520,335,605,335), fill='grey', width=3) canvas.create_line((520,430,605,430), fill='grey', width=3) canvas.create_line((620,10,705,10), fill='grey', width=3) canvas.create_line((620,75,705,75), fill='grey', width=3) canvas.create_line((620,170,705,170), fill='grey', width=3) canvas.create_line((620,275,705,275), fill='grey', width=3) canvas.create_line((620,370,705,370), fill='grey', width=3) canvas.create_line((520,515,705,515), fill='grey', width=3) trcvar = IntVar(value=0) # initial value trc = Spinbox(canvas, from_= 0, to = 4, increment = 1, width = 1, command = plotxy, textvariable=trcvar) trc.place(x = 620, y = 20) trcvar.set(0) labeltrc = Label(canvas) labeltrc.place(x = 655, y = 20) labeltrc.config(text = 'Trace') mtrcvar = IntVar(value=1) # initial value mtrc = Spinbox(canvas, from_= 1, to = 5, increment = 1, width = 1, command = plotxy, textvariable=mtrcvar) mtrc.place(x = 620, y = 45) mtrcvar.set(1) labelmtrc = Label(canvas) labelmtrc.place(x = 655, y = 45) labelmtrc.config(text = 'Multiple') trcsave = ttk.Button(canvas, text="Save", command = runSave) trcsave.place(x = 620, y = 90) trcload = ttk.Button(canvas, text="Load", command = runLoad) trcload.place(x = 620, y = 130) startvar = DoubleVar(value=0.6) # initial value startval = Spinbox(canvas, from_= 0.0, to = 5.0, increment = 0.02, width = 4, command = runStart, textvariable=startvar) startval.place(x = 620, y = 185) startvar.set(0.6) labelstart = Label(canvas) labelstart.place(x = 680, y = 185) labelstart.config(text = 'Start') stepvar = DoubleVar(value=0.88) # initial value stepval = Spinbox(canvas, from_= 0.0, to = 5.0, increment = 0.02, width = 4, textvariable=stepvar) stepval.place(x = 620, y = 205) stepvar.set(0.88) labelstep = Label(canvas) labelstep.place(x = 680, y = 205) labelstep.config(text = 'Step') trcload = ttk.Button(canvas, text="Run Steps", command = runSteps) trcload.place(x = 620, y = 235) adcvar = IntVar(value=0) # initial value adcval = Spinbox(canvas, from_= 0, to = 5, increment = 1, width = 2, textvariable=adcvar) adcval.place(x = 620, y = 325) adcvar.set(0) labeladc = Label(canvas) labeladc.place(x = 660, y = 325) labeladc.config(text = '0.000V') adcread = ttk.Button(canvas, text="Read ADC", command = runAdc) adcread.place(x = 620, y = 295) cts = ttk.Button(canvas, text="Sine") cts.place(x = 520, y = 20) cts.bind("<Button-1>", runSine) magvar = DoubleVar(value=11.5) # initial value sinmag = Spinbox(canvas, from_= 2.4, to = 11.5, increment = 0.1, width = 4, command = runMag, textvariable=magvar) sinmag.place(x = 520, y = 50) magvar.set(11.5) sinmag.bind("<Return>", runMag) labelmag = Label(canvas) labelmag.place(x = 575, y = 50) labelmag.config(text = 'Vp') freqvar = DoubleVar(value=16) # initial value freq = Spinbox(canvas, from_= 4, to =50, increment = 1.0, width = 2, command = runFreq, textvariable=freqvar) freq.place(x = 520, y = 75) freqvar.set(16) labelfreq = Label(canvas) labelfreq.place(x = 555, y = 75) labelfreq.config(text = '60.2 Hz') cnt = ttk.Checkbutton(canvas, text="Cont. Sine", variable=contvar, onvalue=True) cnt.place(x = 520, y = 95) ctr = ttk.Button(canvas, text="Ramp") ctr.place(x = 520, y = 125) ctr.bind("<Button-1>", runRamp) posvar = DoubleVar(value=11.5) # initial value posmag = Spinbox(canvas, from_= -11.5, to = 11.5, increment = 0.1, width = 4, command = runPos, textvariable=posvar) posmag.place(x = 520, y = 155) posvar.set(11.5) posmag.bind("<Return>", runPos) labelpos = Label(canvas) labelpos.place(x = 572, y = 155) labelpos.config(text = 'Vmax') negvar = DoubleVar(value=-11.5) # initial value negmag = Spinbox(canvas, from_= -11.5, to = 11.5, increment = 0.1, width = 4, command = runNeg, textvariable=negvar) negmag.place(x = 520, y = 180) negvar.set(-11.5) negmag.bind("<Return>", runNeg) labelneg = Label(canvas) labelneg.place(x = 572, y = 180) labelneg.config(text = 'Vmin') cramp = ttk.Checkbutton(canvas, text="Cont. Ramp", variable=crampvar, onvalue=True) cramp.place(x = 520, y = 200) xt = ttk.Checkbutton(canvas, text="X-t Plot", variable=xtvar, command=runXt, onvalue=True) xt.place(x = 520, y = 225) curvar = IntVar(value= 0) cursor = Spinbox(canvas, from_= 0, to = 255, width = 3, command = runPlot, textvariable = curvar) cursor.place(x = 520, y = 255) cursor.bind("<Return>", runPlot) labelcur = Label(canvas) labelcur.place(x = 565, y = 255) labelcur.config(text = 'Cursor') label1 = Label(canvas) label1.place(x = 520, y = 275) label1.config(text = 'V') label2 = Label(canvas) label2.place(x = 520, y = 295) label2.config(text = 'mA') label3 = Label(canvas) label3.place(x = 520, y = 315) label3.config(text = 'ms') mrk = ttk.Button(canvas, text="Mark") mrk.place(x = 520, y = 345, height = 22) mrk.bind("<Button-1>", runMark) labelm1 = Label(canvas) labelm1.place(x = 520, y = 370) labelm1.config(text = 'V') labelm2 = Label(canvas) labelm2.place(x = 520, y = 390) labelm2.config(text = 'mA') labelm3 = Label(canvas) labelm3.place(x = 520, y = 410) labelm3.config(text = 'ms') labeldt = Label(canvas) labeldt.place(x = 540, y = 433) labeldt.config(text = 'Delta') labeld1 = Label(canvas) labeld1.place(x = 520, y = 450) labeld1.config(text = 'V') labeld2 = Label(canvas) labeld2.place(x = 520, y = 470) labeld2.config(text = 'mA') labeld3 = Label(canvas) labeld3.place(x = 520, y = 490) labeld3.config(text = 'ms') labelr = Label(canvas) labelr.place(x = 520, y = 520) labelr.config(text = 'ohms') labelc = Label(canvas) labelc.place(x = 640, y = 520) labelc.config(text = 'C = uF') canvas.bind("<Button-1>", runMouse) plotxy() root.after(0, runCont) root.wm_protocol ("WM_DELETE_WINDOW", endserial) root.mainloop()
[ 2, 791, 78, 350, 22117, 31170, 12133, 491, 11736, 598, 416, 2829, 12, 21170, 5013, 1105, 12, 1828, 12, 1129, 198, 2, 2710, 513, 352, 12, 1485, 12, 1238, 198, 198, 6738, 256, 74, 3849, 1330, 1635, 198, 6738, 256, 74, 3849, 1330, 25...
2.39747
3,004
import time import smbus from Adafruit_I2C import Adafruit_I2C # =========================================================================== # TMP102 Class # ===========================================================================
[ 11748, 640, 198, 11748, 895, 10885, 198, 6738, 1215, 1878, 4872, 62, 40, 17, 34, 1330, 1215, 1878, 4872, 62, 40, 17, 34, 198, 198, 2, 38093, 2559, 855, 198, 2, 309, 7378, 15377, 5016, 198, 2, 38093, 2559, 855, 628 ]
5.756098
41
from flask import Flask app = Flask(__name__) if __name__ == '__main__': app.run(port=5000, debug=True)
[ 6738, 42903, 1330, 46947, 628, 198, 1324, 796, 46947, 7, 834, 3672, 834, 8, 628, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 198, 220, 220, 220, 598, 13, 5143, 7, 634, 28, 27641, 11, 14257, 28, 17821, 8 ]
2.642857
42
# -*- coding: utf-8 -*- # Copyright (c) 2015, Indictrans and contributors # For license information, please see license.txt from __future__ import unicode_literals import frappe import json import string from frappe.model.document import Document from frappe.utils import cstr, flt, getdate, comma_and, cint from frappe import _ from erpnext.controllers.item_variant import get_variant, copy_attributes_to_variant, ItemVariantExistsError
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 15069, 357, 66, 8, 1853, 11, 1423, 713, 26084, 290, 20420, 198, 2, 1114, 5964, 1321, 11, 3387, 766, 5964, 13, 14116, 198, 198, 6738, 11593, 37443, 834, 1330, 28000,...
3.318182
132
import logging from typing import Text, List from src.utils.io import read_json from src.utils.fuzzy import is_relevant_string from src.utils.common import is_float from src.utils.constants import ( MEDICAL_TEST_PATH, QUANTITATIVE_PATH, POSITIVE_TEXT, TestResult ) logger = logging.getLogger(__name__)
[ 11748, 18931, 198, 6738, 19720, 1330, 8255, 11, 7343, 198, 6738, 12351, 13, 26791, 13, 952, 1330, 1100, 62, 17752, 198, 6738, 12351, 13, 26791, 13, 69, 4715, 88, 1330, 318, 62, 49659, 62, 8841, 198, 6738, 12351, 13, 26791, 13, 11321, ...
2.682927
123
import requests import sys from time import sleep from tabulate import tabulate if __name__=='__main__': try: with open('.secret', 'r') as f: secret = f.read().strip() except IOException: secret = sys.argv[1] get_scams(secret)
[ 11748, 7007, 198, 11748, 25064, 198, 6738, 640, 1330, 3993, 198, 6738, 7400, 5039, 1330, 7400, 5039, 628, 198, 198, 361, 11593, 3672, 834, 855, 6, 834, 12417, 834, 10354, 198, 220, 220, 220, 1949, 25, 220, 198, 220, 220, 220, 220, 2...
2.377193
114
# Real-time Hair Segmentation and Recoloring on Mobile GPUs (https://arxiv.org/abs/1907.06740) # TODO
[ 2, 6416, 12, 2435, 23102, 1001, 5154, 341, 290, 3311, 349, 3255, 319, 12173, 32516, 357, 5450, 1378, 283, 87, 452, 13, 2398, 14, 8937, 14, 1129, 2998, 13, 15, 3134, 1821, 8, 198, 2, 16926, 46 ]
2.72973
37
import logging from .forms import PostSearchForm from .models import Blog
[ 11748, 18931, 198, 198, 6738, 764, 23914, 1330, 2947, 18243, 8479, 198, 6738, 764, 27530, 1330, 14001, 628, 198 ]
4.052632
19
from opencmiss.utils.maths.algorithms import calculate_line_plane_intersection
[ 6738, 1280, 66, 3927, 13, 26791, 13, 11018, 82, 13, 282, 7727, 907, 1330, 15284, 62, 1370, 62, 14382, 62, 3849, 5458, 628 ]
3.478261
23
# -*- coding: utf-8 -*- """ SHARED - DATA VALIDATION """ # %% FILE IMPORT
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 9693, 1503, 1961, 532, 42865, 26173, 2389, 6234, 198, 37811, 198, 198, 2, 43313, 45811, 30023, 9863, 628 ]
2.235294
34
# Copyright (c) 2018, Arm Limited and affiliates. # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import unittest from mbed_os_tools.test.host_tests_runner.host_test_default import DefaultTestSelector if __name__ == '__main__': unittest.main()
[ 2, 15069, 357, 66, 8, 2864, 11, 7057, 15302, 290, 29116, 13, 198, 2, 30628, 55, 12, 34156, 12, 33234, 7483, 25, 24843, 12, 17, 13, 15, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156,...
3.497778
225
# Copyright 2016 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Delete command for gcloud debug logpoints command group.""" from googlecloudsdk.api_lib.debug import debug from googlecloudsdk.calliope import base from googlecloudsdk.core import log from googlecloudsdk.core import properties
[ 2, 15069, 1584, 3012, 3457, 13, 1439, 6923, 33876, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845, 287, 11846, 351, 262, 13789, ...
3.869159
214
# directed graph problem or breadth first search variant from collections import defaultdict import re input_file = open("input.txt", "r") input_lines = input_file.readlines() letter_value = { 'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5, 'F': 6, 'G': 7, 'H': 8, 'I': 9, 'J': 10, 'K': 11, 'L': 12, 'M': 13, 'N': 14, 'O': 15, 'P': 16, 'Q': 17, 'R': 18, 'S': 19, 'T': 20, 'U': 21, 'V': 22, 'W': 23, 'X': 24, 'Y': 25, 'Z': 26 } # construct graph of nodes and edges # Read nodes and edges from input with regex # A set of possible nodes to work on (starts with C) # pick the first alphabetical node and remove it and its edges # Part 1 # print(work_nodes(construct_graph(input_lines))) # Part 2 nodes, edges = construct_graph(input_lines) total_time = work_nodes_in_parallel(nodes, edges, 5, 60) print(f"It took {total_time} seconds")
[ 2, 7924, 4823, 1917, 393, 32483, 717, 2989, 15304, 198, 6738, 17268, 1330, 4277, 11600, 198, 11748, 302, 198, 198, 15414, 62, 7753, 796, 1280, 7203, 15414, 13, 14116, 1600, 366, 81, 4943, 198, 15414, 62, 6615, 796, 5128, 62, 7753, 13,...
2.250597
419
from __future__ import print_function from .. import PyPI, DjangoPyPI, PackageNotFound from prettytable import PrettyTable from pkg_resources import parse_version, resource_filename import requests import re try: from urlparse import unquote except ImportError: # Python 3 from urllib.parse import unquote
[ 6738, 11593, 37443, 834, 1330, 3601, 62, 8818, 198, 198, 6738, 11485, 1330, 9485, 11901, 11, 37770, 20519, 11901, 11, 15717, 3673, 21077, 198, 6738, 2495, 11487, 1330, 20090, 10962, 198, 6738, 279, 10025, 62, 37540, 1330, 21136, 62, 9641,...
3.595506
89
import numpy as np from scipy.interpolate import InterpolatedUnivariateSpline from scipy.fftpack import fft from combined_functions import check_ft_grid from scipy.constants import pi, c, hbar from numpy.fft import fftshift from scipy.io import loadmat from time import time import sys import matplotlib.pyplot as plt from scipy.integrate import simps def fv_creator(fp, df, F, int_fwm): """ Cretes frequency grid such that the estimated MI-FWM bands will be on the grid and extends this such that to avoid fft boundary problems. Inputs:: lamp: wavelength of the pump (float) lamda_c: wavelength of the zero dispersion wavelength(ZDW) (float) int_fwm: class that holds nt (number of points in each band) betas: Taylor coeffiencts of beta around the ZDW (Array) M : The M coefficient (or 1/A_eff) (float) P_p: pump power Df_band: band frequency bandwidth in Thz, (float) Output:: fv: Frequency vector of bands (Array of shape [nt]) """ f_centrals = [fp + i * F for i in range(-1, 2)] fv1 = np.linspace(f_centrals[0], f_centrals[1], int_fwm.nt//4 - 1, endpoint=False) df = fv1[1] - fv1[0] fv2 = np.linspace(f_centrals[1], f_centrals[2], int_fwm.nt//4) try: assert df == fv2[1] - fv2[0] except AssertionError: print(df, fv2[1] - fv2[0]) fv0, fv3 = np.zeros(int_fwm.nt//4 + 1), np.zeros(int_fwm.nt//4) fv0[-1] = fv1[0] - df fv3[0] = fv2[-1] + df for i in range(1, len(fv3)): fv3[i] = fv3[i - 1] + df for i in range(len(fv0) - 2, -1, -1): fv0[i] = fv0[i + 1] - df assert not(np.any(fv0 == fv1)) assert not(np.any(fv1 == fv2)) assert not(np.any(fv2 == fv3)) fv = np.concatenate((fv0, fv1, fv2, fv3)) for i in range(3): assert f_centrals[i] in fv check_ft_grid(fv, df) p_pos = np.where(np.abs(fv - fp) == np.min(np.abs(fv - fp)))[0] return fv, p_pos, f_centrals
[ 11748, 299, 32152, 355, 45941, 198, 6738, 629, 541, 88, 13, 3849, 16104, 378, 1330, 4225, 16104, 515, 3118, 42524, 26568, 500, 198, 6738, 629, 541, 88, 13, 487, 83, 8002, 1330, 277, 701, 198, 6738, 5929, 62, 12543, 2733, 1330, 2198, ...
2.101159
949
# The test suite runs in <20 seconds so is worth running here to # make sure there are no issues with the C/Cython extensions import astropy_healpix astropy_healpix.test()
[ 2, 383, 1332, 18389, 4539, 287, 1279, 1238, 4201, 523, 318, 2861, 2491, 994, 284, 198, 2, 787, 1654, 612, 389, 645, 2428, 351, 262, 327, 14, 34, 7535, 18366, 198, 11748, 6468, 28338, 62, 258, 282, 79, 844, 198, 459, 28338, 62, 258...
3.372549
51
""" Way2sms """ from way2sms.app import Sms
[ 37811, 198, 25309, 17, 82, 907, 198, 37811, 198, 198, 6738, 835, 17, 82, 907, 13, 1324, 1330, 311, 907, 198 ]
2.142857
21
import time from graphql_client import GraphQLClient # some sample GraphQL server which supports websocket transport and subscription client = GraphQLClient('ws://localhost:9001') # Simple Query Example # query example with GraphQL variables query = """ query getUser($userId: Int!) { users (id: $userId) { id username } } """ # This is a blocking call, you receive response in the `res` variable print('Making a query first') res = client.query(query, variables={'userId': 2}) print('query result', res) # Subscription Example subscription_query = """ subscription getUser { users (id: 2) { id username } } """ # Our callback function, which will be called and passed data everytime new data is available print('Making a graphql subscription now...') sub_id = client.subscribe(subscription_query, callback=my_callback) print('Created subscription and waiting. Callback function is called whenever there is new data') # do some operation while the subscription is running... time.sleep(10) client.stop_subscribe(sub_id) client.close()
[ 11748, 640, 198, 6738, 4823, 13976, 62, 16366, 1330, 29681, 9711, 11792, 198, 198, 2, 617, 6291, 29681, 9711, 4382, 543, 6971, 2639, 5459, 4839, 290, 14569, 198, 16366, 796, 29681, 9711, 11792, 10786, 18504, 1378, 36750, 25, 24, 8298, 1...
3.488599
307
# coding:utf-8 import os import sys if __name__ == '__main__': Scopus2HistCite()
[ 2, 19617, 25, 40477, 12, 23, 201, 198, 11748, 28686, 201, 198, 11748, 25064, 201, 198, 201, 198, 201, 198, 201, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 201, 198, 220, 220, 220, 1446, 25790, 17, 13749, 34, 578,...
2.136364
44
""" Mel-scale definition. """ import torch from torch import Tensor from typing import Union import numpy as np from math import log import librosa from librosa.filters import mel as mel_fn def hz_to_mel( frequencies: Union[float, int, Tensor, np.ndarray], htk=False) -> Union[float, int, Tensor, np.ndarray]: """Convert Hz to Mels. Extending librosa.hz_to_mel to accepting Tensor. """ if not isinstance(frequencies, Tensor): return librosa.hz_to_mel(frequencies) if htk: return 2595.0 * torch.log10(1.0 + frequencies / 700.0) f_min = 0.0 f_sp = 200.0 / 3 mels = (frequencies - f_min) / f_sp min_log_hz = 1000.0 # beginning of log region (Hz) min_log_mel = (min_log_hz - f_min) / f_sp # same (Mels) logstep = log(6.4) / 27.0 # step size for log region log_t = frequencies >= min_log_hz mels[log_t] = min_log_mel + torch.log(frequencies[log_t] / min_log_hz) / \ logstep return mels def mel_to_hz( mels: Union[int, float, Tensor, np.ndarray], htk=False) -> Union[int, float, Tensor, np.ndarray]: """Convert mel bin numbers to frequencies.""" if not isinstance(mels, Tensor): return librosa.mel_to_hz(mels, htk=htk) if htk: return 700.0 * (10.0 ** (mels / 2595.0) - 1.0) f_min = 0.0 f_sp = 200.0 / 3 freqs = f_min + f_sp * mels min_log_hz = 1000.0 # beginning of log region (Hz) min_log_mel = (min_log_hz - f_min) / f_sp # same (Mels) logstep = log(6.4) / 27.0 # step size for log region log_t = mels >= min_log_mel freqs[log_t] = min_log_hz * \ torch.exp(logstep * (mels[log_t] - min_log_mel)) return freqs def linear_mel_matrix( sampling_rate: int, fft_size: int, mel_size: int, mel_min_f0: Union[int, float], mel_max_f0: Union[int, float], device: torch.device ) -> Tensor: """ Args: sampling_rate: Sampling rate in Hertz. fft_size: FFT size, must be an even number. mel_size: Number of mel-filter banks. mel_min_f0: Lowest frequency in the mel spectrogram. mel_max_f0: Highest frequency in the mel spectrogram. device: Target device of the transformation matrix. Returns: basis: [mel_size, fft_size // 2 + 1]. """ basis = torch.FloatTensor( mel_fn(sampling_rate, fft_size, mel_size, mel_min_f0, mel_max_f0) ).transpose(-1, -2) return basis.to(device)
[ 37811, 198, 21102, 12, 9888, 6770, 13, 198, 37811, 198, 11748, 28034, 198, 6738, 28034, 1330, 309, 22854, 198, 6738, 19720, 1330, 4479, 198, 11748, 299, 32152, 355, 45941, 198, 6738, 10688, 1330, 2604, 198, 11748, 9195, 4951, 64, 198, 6...
2.240622
1,093
from django.urls import path from order import views urlpatterns = [ # path('ticket/submit/', views.TicketOrderSubmitView.as_view(), name='ticket_submit'), # path('order/detail/<int:sn>/', views.OrderDetail.as_view(), name='order_detail'), # path('order/list/', views.OrderListView.as_view(), name='order_list') ]
[ 6738, 42625, 14208, 13, 6371, 82, 1330, 3108, 201, 198, 201, 198, 6738, 1502, 1330, 5009, 201, 198, 201, 198, 6371, 33279, 82, 796, 685, 201, 198, 220, 220, 220, 1303, 220, 201, 198, 220, 220, 220, 3108, 10786, 43350, 14, 46002, 14,...
2.482517
143
from django.db import models
[ 6738, 42625, 14208, 13, 9945, 1330, 4981, 628 ]
3.75
8
""" unminify ======== """ def unminify(soup, encoding='utf-8'): """ """ return soup.prettify().encode(encoding)
[ 37811, 198, 403, 1084, 1958, 198, 2559, 198, 198, 37811, 628, 198, 4299, 555, 1084, 1958, 7, 82, 10486, 11, 21004, 11639, 40477, 12, 23, 6, 2599, 198, 220, 220, 220, 37227, 198, 220, 220, 220, 37227, 198, 220, 220, 220, 1441, 17141,...
2.309091
55
import hashlib
[ 11748, 12234, 8019 ]
4.666667
3
from typing import Tuple from rdkit import Chem from rdkit.Chem import Draw import re import itertools import numpy as np import networkx as nx import logging import collections def FindBreakingBonds(cnids: list, bids: list, bts: list, atomic_nums: list) -> list: """Returns bond ids to be broken. Check for double/triple bonds; if exists, check if heteroatom; if heteroatom, bonds of that C atom are not broken.""" x1s = [] rmflag = None for (i, bt) in enumerate(bts): for (j, x) in enumerate(bt): if x == Chem.rdchem.BondType.DOUBLE or x == Chem.rdchem.BondType.TRIPLE: if atomic_nums[cnids[i][j]] != 6 and atomic_nums[cnids[i][j]] != 1: rmflag = True break if not rmflag: x1s.append(i) rmflag = None return [bids[x1] for x1 in x1s] def FragNeighborBreakingBondTypes( neighbor_ids: list, fnids: list, faids: list, bond_type_matrix: list ) -> list: """Determine broken bond types between fragments and fragment neighbors.""" # neighbor ids of fragment neighbors nids_of_fnids = [[neighbor_ids[x] for x in y] for y in fnids] # atom ids 'bonded' to fragment neighbor int_ = [ [Intersection(x, faids[i])[0] for x in y] for (i, y) in enumerate(nids_of_fnids) ] return [ [bond_type_matrix[x[i]][y[i]] for (i, z) in enumerate(x)] for (x, y) in zip(fnids, int_) ] def EditFragNeighborIds(fnids: list, bbtps: list) -> list: """Remove fragment neighbor ids that are doubly/triply bonded to fragment.""" # not double/triple bonds n23bonds = [ [ (x != Chem.rdchem.BondType.DOUBLE and x != Chem.rdchem.BondType.TRIPLE) for x in y ] for y in bbtps ] # return new fragment neighbor ids return [ [x for (j, x) in enumerate(y) if n23bonds[i][j]] for (i, y) in enumerate(fnids) ] def num_atom_rings_1bond(atom_rings: tuple, bond_rings: tuple, num_atoms: int) -> list: """Number of rings each atoms is in. Only rings sharing at most 1 bond with neighboring rings are considered.""" # atom ids of rings that share at most 1 bond with neighboring rings atom_rings_1bond = [ atom_rings[i] for (i, y) in enumerate(bond_rings) if not any( IntersectionBoolean(x, y, 2) for x in [z for (j, z) in enumerate(bond_rings) if i != j] ) ] return [sum(i in x for x in atom_rings_1bond) for i in range(num_atoms)] def UniqueElements(x: list) -> list: """Returns unique elements of a list (not order preserving).""" keys = {} for e in x: keys[e] = 1 return list(keys.keys()) def NeighborIDs(neighbor_ids: list, atomic_nums: list, y: list) -> list: """Find neighbor ids of a list of atoms (Hs not included).""" # neighbor ids z = [neighbor_ids[x] for x in y] # remove Hs return [[x for x in y if atomic_nums[x] != 1] for y in z] def GetFragments( smiles: str, mol: Chem.rdchem.Mol, neighbor_ids: list, atomic_nums: list, bond_id_matrix: list, bond_type_matrix: list, ) -> Tuple[list, list]: """Fragment the molecule with isolated carbons method, see Lian and Yalkowsky, JOURNAL OF PHARMACEUTICAL SCIENCES 103:2710-2723.""" # carbons cids = [i for (i, x) in enumerate(atomic_nums) if x == 6] # carbon neighbor ids cnids = NeighborIDs(neighbor_ids, atomic_nums, cids) # bond ids bids = [ [bond_id_matrix[cid][cnid] for cnid in cnids] for (cid, cnids) in zip(cids, cnids) ] # bond types bts = [ [bond_type_matrix[cid][cnid] for cnid in cnids] for (cid, cnids) in zip(cids, cnids) ] # broken bond ids bbids = FindBreakingBonds(cnids, bids, bts, atomic_nums) # break bonds, get fragments try: fmol = Chem.FragmentOnBonds( mol, UniqueElements(list(itertools.chain.from_iterable(bbids))) ) except: fmol = mol logging.info("fragmentation exception: %s" % (smiles)) # draw fragments, debugging only, expensive # Draw.MolToFile(fmol,'fmol.png') # fragment atom ids faids = [list(x) for x in Chem.rdmolops.GetMolFrags(fmol)] # fragment smiles fsmiles = [Chem.rdmolfiles.MolFragmentToSmiles(fmol, frag) for frag in faids] # fragment smarts fsmarts = [Chem.rdmolfiles.MolFragmentToSmarts(fmol, frag) for frag in faids] return faids, fsmiles, fsmarts def FragNeighborID(fsmile: str) -> list: """End atoms bonded to a fragment.""" fnid = re.compile(r"(%s|%s)" % ("\d+(?=\*)", "\*[^\]]")).findall(fsmile) fnid = fnid if fnid else ["-1"] return [int(x) if "*" not in x else 0 for x in fnid] def FragNeighborIDs(fsmiles: list) -> list: """End atoms bonded to fragments.""" fnids = list(map(FragNeighborID, fsmiles)) return [x if (-1 not in x) else [] for x in fnids] def BondedFragNeighborIDs(true_faids: list, fnids: list) -> list: """Neighbor fragment ids (not atom ids).""" return [[k for (k, x) in enumerate(true_faids) for j in i if j in x] for i in fnids] def NumHybridizationType(htype: Chem.rdchem.HybridizationType, fnhybrds: list) -> list: """Number of specified hybridization type for each fragment.""" return [sum(x == htype for x in fnhybrd) for fnhybrd in fnhybrds] def Intersection(x: list, y: list) -> list: """Elements that match between two lists.""" return list(set(x) & set(y)) def IntersectionBoolean(x: list, y: list, z: int) -> bool: """Returns whether or not two lists overlap with at least z common elements.""" return len(set(x) & set(y)) >= z def FindIdsWithHtype( fids: list, fnids: list, fnhybrds: list, htype: Chem.rdchem.HybridizationType ) -> list: """Find fragment neighbor ids with htype.""" fnhybrds_in_fids = [fnhybrds[x] for x in fids] fnids_in_fids = [fnids[x] for x in fids] hids = [] x1 = 0 for x in fnhybrds_in_fids: x2 = 0 for y in x: if y == htype: hids.append(fnids_in_fids[x1][x2]) x2 += 1 x1 += 1 return hids def AromaticRings(atom_ids_in_rings: list, bond_type_matrix: list) -> list: """Return if bonds in rings are aromatic.""" # atom ids in rings atom_ids_in_rings = [np.array(x) for x in atom_ids_in_rings] return [ [ (bond_type_matrix[int(x)][int(y)] == Chem.rdchem.BondType.AROMATIC) for (x, y) in zip(z, z.take(range(1, len(z) + 1), mode="wrap")) ] for z in atom_ids_in_rings ] def TrueFragAtomIDs(num_atoms: int, faids: list) -> list: """Remove dummy atom ids from fragments.""" return [[x for x in y if x < num_atoms] for y in faids] def FindCentralCarbonsOfBiphenyl( biphenyl_substructs: list, neighbor_ids: list, atomic_nums: list, bond_matrix: list, bond_type_matrix: list, ) -> list: """Find central carbons of biphenyl substructures.""" # find one of the central carbons in biphenyl substructures cc = [] for z in biphenyl_substructs: for (x, y) in zip(z, z.take(range(1, len(z) + 1), mode="wrap")): if not bond_matrix[int(x)][int(y)]: cc.append(int(y)) break # find carbon that is singly bonded - other central carbon ccs = [] for (i, y) in enumerate(NeighborIDs(neighbor_ids, atomic_nums, cc)): for x in y: if bond_type_matrix[cc[i]][x] == Chem.rdchem.BondType.SINGLE: ccs.append([cc[i], x]) break return ccs def Flatten(x: list) -> list: """Flatten a list.""" return list(itertools.chain.from_iterable(x)) def RemoveElements(x: list, y: list) -> list: """Remove elements (y) from a list (x).""" for e in y: x.remove(e) return x def Graph(x: tuple) -> nx.classes.graph.Graph: """Make graph structure from atom ids. Used to find independent ring systems.""" # initialize graph graph = nx.Graph() # add nodes and edges for part in x: graph.add_nodes_from(part) graph.add_edges_from(zip(part[:-1], part[1:])) return graph def NumIndRings(x: tuple) -> int: """Number of independent single, fused, or conjugated rings.""" return len(list(nx.connected_components(Graph(x)))) def ReduceFsmarts(fsmarts: list) -> list: """Rewrite fragment smarts.""" return [re.sub(r"\d+\#", "#", x) for x in fsmarts] def EndLabels(fnbbtps: list) -> list: """End label of group. - : bonded to one neighbor and btype = single = : one neighbor is bonded with btype = double tri- : one neighbor is bonded with btype = triple allenic : allenic atom, two neighbors are bonded with btype = double""" l = ["" for x in fnbbtps] for (i, x) in enumerate(fnbbtps): if len(x) == 1 and x.count(Chem.rdchem.BondType.SINGLE) == 1: l[i] = "-" continue if x.count(Chem.rdchem.BondType.DOUBLE) == 1: l[i] = "=" continue if x.count(Chem.rdchem.BondType.TRIPLE) == 1: l[i] = "tri-" continue if x.count(Chem.rdchem.BondType.DOUBLE) == 2: l[i] = "allenic-" return l def FragAtomBondTypeWithSp2( fnhybrds: list, fnids: list, neighbor_ids: list, atomic_nums: list, faids: list, bond_type_matrix: list, ) -> list: """Bond type between fragment atom and neighboring sp2 atom.""" # fragment ids bonded to one sp2 atom fids = [ i for i, x in enumerate( NumHybridizationType(Chem.rdchem.HybridizationType.SP2, fnhybrds) ) if x == 1 ] # atom id in fragments corresponding to the sp2 atom sp2ids = FindIdsWithHtype(fids, fnids, fnhybrds, Chem.rdchem.HybridizationType.SP2) # neighbor atom ids of sp2 atoms sp2nids = NeighborIDs(neighbor_ids, atomic_nums, sp2ids) # intersection between sp2nids and atom ids in fragments with one sp2 atom faid = list( itertools.chain.from_iterable( [Intersection(x, y) for (x, y) in zip([faids[x] for x in fids], sp2nids)] ) ) # bond type fragment atom and sp2 atom bts = [bond_type_matrix[x][y] for (x, y) in zip(sp2ids, faid)] # generate list with bond types for each fragment, zero for fragments without one sp2 atom afbts = [0] * len(fnhybrds) for (x, y) in zip(fids, bts): afbts[x] = y return afbts symm_rules: dict = { 2: { 1: { Chem.rdchem.HybridizationType.SP: 2, Chem.rdchem.HybridizationType.SP2: 2, Chem.rdchem.HybridizationType.SP3: 2, }, 2: { Chem.rdchem.HybridizationType.SP: 1, Chem.rdchem.HybridizationType.SP2: 1, Chem.rdchem.HybridizationType.SP3: 1, }, }, 3: { 1: {Chem.rdchem.HybridizationType.SP2: 6, Chem.rdchem.HybridizationType.SP3: 3}, 2: {Chem.rdchem.HybridizationType.SP2: 2, Chem.rdchem.HybridizationType.SP3: 1}, 3: {Chem.rdchem.HybridizationType.SP2: 1, Chem.rdchem.HybridizationType.SP3: 1}, }, 4: { 1: {Chem.rdchem.HybridizationType.SP3: 12}, 2: {Chem.rdchem.HybridizationType.SP3: 0}, 3: {Chem.rdchem.HybridizationType.SP3: 1}, 4: {Chem.rdchem.HybridizationType.SP3: 1}, }, } def Symm( smiles: str, num_attached_atoms: int, num_attached_types: int, center_hybrid: Chem.rdchem.HybridizationType, count_rankings: collections.Counter, ) -> int: """Molecular symmetry.""" try: symm = symm_rules[num_attached_atoms][num_attached_types][center_hybrid] except: logging.warning("symmetry exception: {}".format(smiles)) symm = np.nan # special case if symm == 0: vals = list(count_rankings.values()) symm = 3 if (vals == [1, 3] or vals == [3, 1]) else 2 return symm def DataReduction(y: dict, group_labels: list) -> None: """Remove superfluous data for single molecule.""" for l in group_labels: y[l] = list(itertools.compress(zip(y["fsmarts"], range(y["num_frags"])), y[l])) def NFragBadIndices(d: np.ndarray, group_labels: list, smiles: list) -> None: """Indices of compounds that do not have consistent number of fragments.""" def NFragCheck(y: dict) -> bool: """Check number of fragments and group contributions are consistent.""" num_frags = 0 for l in group_labels: num_frags += len(y[l]) return num_frags != y["num_frags"] x = list(map(NFragCheck, d)) indices = list(itertools.compress(range(len(x)), x)) logging.info( "indices of molecules with inconsistent number of fragments:\n{}".format( indices ) ) logging.info("and their smiles:\n{}".format([smiles[x] for x in indices])) def UniqueGroups(d: np.ndarray, num_mol: int, group_labels: list) -> list: """Unique fragments for each environmental group.""" # fragments for each group groups = [[d[i][j] for i in range(num_mol)] for j in group_labels] # eliminate fragment ids groups = [[x[0] for x in Flatten(y)] for y in groups] return [UniqueElements(x) for x in groups] def UniqueLabelIndices(flabels: list) -> list: """Indices of unique fingerprint labels.""" sort_ = [sorted(x) for x in flabels] tuple_ = [tuple(x) for x in sort_] unique_labels = [list(x) for x in sorted(set(tuple_), key=tuple_.index)] return [[i for (i, x) in enumerate(sort_) if x == y] for y in unique_labels] def UniqueLabels(flabels: list, indices: list) -> list: """Unique fingerprint labels.""" return [flabels[x[0]] for x in indices] def UniqueFingerprint(indices: list, fingerprint: np.ndarray) -> np.ndarray: """Reduce fingerprint according to unique labels.""" fp = np.zeros((fingerprint.shape[0], len(indices))) for (j, x) in enumerate(indices): fp[:, j] = np.sum(fingerprint[:, x], axis=1) return fp def UniqueLabelsAndFingerprint( flabels: list, fingerprint: np.ndarray ) -> Tuple[list, np.ndarray]: """Reduced labels and fingerprint.""" uli = UniqueLabelIndices(flabels) ul = UniqueLabels(flabels, uli) fp = UniqueFingerprint(uli, fingerprint) return ul, fp def CountGroups(fingerprint_groups: list, group_labels: list, d: dict) -> list: """Count groups for fingerprint.""" return [ [[x[0] for x in d[y]].count(z) for z in fingerprint_groups[i]] for (i, y) in enumerate(group_labels) ] def Concat(x: list, y: list) -> list: """Concatenate groups and singles in fingerprint.""" return x + y def MakeFingerprint( fingerprint_groups: list, labels: dict, d: np.ndarray, num_mol: int ) -> np.ndarray: """Make fingerprint.""" # count groups and make fingerprint fp_groups = [ Flatten(CountGroups(fingerprint_groups, labels["groups"], d[:, 0][i])) for i in range(num_mol) ] # reduce singles to requested fp_singles = [[d[:, 1][i][j] for j in labels["singles"]] for i in range(num_mol)] # concat groups and singles return np.array(list(map(Concat, fp_groups, fp_singles))) def ReduceMultiCount(d: dict) -> None: """Ensure each fragment belongs to one environmental group. Falsify Y, Z when YZ true Falsify YY, Z when YYZ true Falsify YYY, Z when YYYZ true Falsify RG when AR true ...""" def TrueIndices(group: str) -> list: """Return True indices.""" x = d[group] return list(itertools.compress(range(len(x)), x)) def ReplaceTrue(replace_group: list, actual_group: list) -> None: """Replace True elements with False to avoid overcounting fragment contribution.""" replace_indices = list(map(TrueIndices, replace_group)) actual_indices = list(map(TrueIndices, actual_group)) for actual_index in actual_indices: for (group, replace_index) in zip(replace_group, replace_indices): int_ = Intersection(replace_index, actual_index) for x in int_: d[group][x] = False replace_groups = [ ["Y", "Z"], ["YY", "Z"], ["YYY", "Z"], ["RG"], ["X", "Y", "YY", "YYY", "YYYY", "YYYYY", "Z", "ZZ", "YZ", "YYZ"], ["RG", "AR"], ["AR", "BR2", "BR3", "FU"], ["RG", "AR"], ] actual_groups = [ ["YZ"], ["YYZ"], ["YYYZ"], ["AR"], ["RG", "AR"], ["BR2", "BR3"], ["BIP"], ["FU"], ] list(map(ReplaceTrue, replace_groups, actual_groups)) def RewriteFsmarts(d: dict) -> None: """Rewrite fsmarts to 'fsmiles unique' fsmarts.""" def FsmartsDict(d: dict) -> dict: """Dict of original fsmarts to 'fsmiles unique' fsmarts.""" # unique smarts in dataset, mols fsmarts = UniqueElements(Flatten([x[0]["fsmarts"] for x in d])) fmols = [Chem.MolFromSmarts(x) for x in fsmarts] # smiles, not necessarily unique fsmiles = [Chem.MolToSmiles(x) for x in fmols] # dict: original fsmarts to 'fsmiles unique' fsmarts dict_ = collections.defaultdict(lambda: len(dict_)) fsmarts_dict = {} for (i, x) in enumerate(fsmarts): fsmarts_dict[x] = fsmarts[dict_[fsmiles[i]]] return fsmarts_dict fsmarts_dict = FsmartsDict(d) # rewrite fsmarts for (i, y) in enumerate(d): d[i][0]["fsmarts"] = [fsmarts_dict[x] for x in y[0]["fsmarts"]]
[ 6738, 19720, 1330, 309, 29291, 198, 6738, 374, 67, 15813, 1330, 12870, 198, 6738, 374, 67, 15813, 13, 41829, 1330, 15315, 198, 11748, 302, 198, 11748, 340, 861, 10141, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 3127, 87, 355, 299, ...
2.266897
7,812
# ============================================================================= # # -*- coding: utf-8 -*- # """ # Created on Sun Aug 5 08:07:19 2018 # # @author: lenovo # """ # 25. Reverse Nodes in k-Group # Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. # # k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is. # # Example: # # Given this linked list: 1->2->3->4->5 # # For k = 2, you should return: 2->1->4->3->5 # # For k = 3, you should return: 3->2->1->4->5 # # Note: # # Only constant extra memory is allowed. # You may not alter the values in the list's nodes, only nodes itself may be changed. # ============================================================================= # ============================================================================= # difficulty: hard # acceptance: 32.7% # contributor: LeetCode # ============================================================================= # reverseList(head, k) # ============================================================================= # def reverseList(head, k): # pre = None # cur = head # while cur and k: # temp = cur.next # cur.next = pre # pre = cur # cur = temp # k -= 1 # return (cur, pre) # ============================================================================= #------------------------------------------------------------------------------ # note: below is the test code a = ListNode(1) b = ListNode(2) c = ListNode(3) d = ListNode(4) a.next = b b.next = c c.next = d test = a S = Solution() result = S.reverseKGroup(test, 3) #result = a while result: print(result.val) result = result.next #------------------------------------------------------------------------------ # note: below is the submission detail # ============================================================================= # Submission Detail # 81 / 81 test cases passed. # Status: Accepted # Runtime: 56 ms # Submitted: 0 minutes ago # beats 93.99% python3 submissions # =============================================================================
[ 2, 38093, 25609, 198, 2, 1303, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 37227, 198, 2, 15622, 319, 3825, 2447, 220, 642, 8487, 25, 2998, 25, 1129, 2864, 198, 2, 220, 198, 2, 2488, 9800, 25, 18896, 18768, 19...
3.759076
606
from django.conf import settings from django.core import mail from django.core.urlresolvers import reverse from perma.urls import urlpatterns from .utils import PermaTestCase
[ 6738, 42625, 14208, 13, 10414, 1330, 6460, 198, 6738, 42625, 14208, 13, 7295, 1330, 6920, 198, 6738, 42625, 14208, 13, 7295, 13, 6371, 411, 349, 690, 1330, 9575, 198, 198, 6738, 583, 2611, 13, 6371, 82, 1330, 19016, 33279, 82, 198, 19...
3.52
50
import FWCore.ParameterSet.Config as cms #Note: distances in mm instead of in cm usually used in CMS generator = cms.EDFilter("Pythia8PtAndLxyGun", maxEventsToPrint = cms.untracked.int32(1), pythiaPylistVerbosity = cms.untracked.int32(1), pythiaHepMCVerbosity = cms.untracked.bool(True), PGunParameters = cms.PSet( ParticleID = cms.vint32(-15, -15), AddAntiParticle = cms.bool(True), # antiparticle has opposite momentum and production point symmetric wrt (0,0,0) compared to corresponding particle MinPt = cms.double(15.00), MaxPt = cms.double(300.00), MinEta = cms.double(-2.5), MaxEta = cms.double(2.5), MinPhi = cms.double(-3.14159265359), MaxPhi = cms.double(3.14159265359), LxyMin = cms.double(0.0), LxyMax = cms.double(550.0), # most tau generated within TOB (55cm) LzMax = cms.double(300.0), dxyMax = cms.double(30.0), dzMax = cms.double(120.0), ConeRadius = cms.double(1000.0), ConeH = cms.double(3000.0), DistanceToAPEX = cms.double(850.0), LxyBackFraction = cms.double(0.0), # fraction of particles going back towards to center at transverse plan; numbers outside the [0,1] range are set to 0 or 1 LzOppositeFraction = cms.double(0.0), # fraction of particles going in opposite direction wrt to center along beam-line than in transverse plane; numbers outside the [0,1] range are set to 0 or 1 ), Verbosity = cms.untracked.int32(0), ## set to 1 (or greater) for printouts psethack = cms.string('displaced taus'), firstRun = cms.untracked.uint32(1), PythiaParameters = cms.PSet(parameterSets = cms.vstring()) )
[ 11748, 48849, 14055, 13, 36301, 7248, 13, 16934, 355, 269, 907, 198, 198, 2, 6425, 25, 18868, 287, 8085, 2427, 286, 287, 12067, 3221, 973, 287, 40773, 198, 8612, 1352, 796, 269, 907, 13, 1961, 22417, 7203, 47, 5272, 544, 23, 47, 83,...
2.333333
732
import logging from typing import List, Optional from django.conf import settings from django.contrib.auth import get_user_model from django.core.exceptions import ObjectDoesNotExist from django.db import models VOTE_UP = 1 VOTE_DOWN = -1 VOTE_CHOICES = ((VOTE_UP, "Vote Up"), (VOTE_DOWN, "Vote Down")) User = get_user_model() logger = logging.getLogger(__name__)
[ 11748, 18931, 198, 198, 6738, 19720, 1330, 7343, 11, 32233, 198, 198, 6738, 42625, 14208, 13, 10414, 1330, 6460, 198, 6738, 42625, 14208, 13, 3642, 822, 13, 18439, 1330, 651, 62, 7220, 62, 19849, 198, 6738, 42625, 14208, 13, 7295, 13, ...
2.9375
128
from datetime import datetime from fastapi import APIRouter, Request from ..classes.jwt_authenticator import JWTAuthenticator from ..repositories import bookmark_repository from ..schemas.bookmark_schema import RequestSchema, ResponseSchema router = APIRouter( prefix='/bookmarks', tags=['bookmarks'], ) # Index # Store a new bookmark, or update if exists
[ 6738, 4818, 8079, 1330, 4818, 8079, 198, 6738, 3049, 15042, 1330, 3486, 4663, 39605, 11, 19390, 198, 6738, 11485, 37724, 13, 73, 46569, 62, 41299, 26407, 1330, 449, 54, 5603, 315, 6925, 26407, 198, 6738, 11485, 260, 1930, 270, 1749, 133...
3.181034
116
import os, urllib, datetime, time, sys import getpass from franz.openrdf.sail.allegrographserver import AllegroGraphServer from franz.openrdf.repository.repository import Repository from franz.miniclient import repository from franz.openrdf.query.query import QueryLanguage from franz.openrdf.model import URI from franz.openrdf.vocabulary.rdf import RDF from franz.openrdf.vocabulary.rdfs import RDFS from franz.openrdf.vocabulary.owl import OWL from franz.openrdf.vocabulary.xmlschema import XMLSchema from franz.openrdf.query.dataset import Dataset from franz.openrdf.rio.rdfformat import RDFFormat from franz.openrdf.rio.rdfwriter import NTriplesWriter from franz.openrdf.rio.rdfxmlwriter import RDFXMLWriter
[ 11748, 28686, 11, 2956, 297, 571, 11, 4818, 8079, 11, 640, 11, 25064, 198, 11748, 651, 6603, 198, 198, 6738, 1216, 35410, 13, 9654, 4372, 69, 13, 82, 603, 13, 282, 1455, 3828, 1470, 15388, 1330, 26326, 305, 37065, 10697, 198, 6738, ...
2.902439
246
import pandas as pd
[ 11748, 19798, 292, 355, 279, 67 ]
3.166667
6
import pprint import time import chess.pgn import IPython.display as display import ipywidgets as widgets
[ 11748, 279, 4798, 198, 11748, 640, 198, 198, 11748, 19780, 13, 79, 4593, 198, 11748, 6101, 7535, 13, 13812, 355, 3359, 198, 11748, 20966, 88, 28029, 11407, 355, 40803, 628, 628, 198 ]
3.46875
32
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! import grpc import version_pb2 as version__pb2 def add_serviceServicer_to_server(servicer, server): rpc_method_handlers = { 'version': grpc.unary_unary_rpc_method_handler( servicer.version, request_deserializer=version__pb2.request.FromString, response_serializer=version__pb2.response.SerializeToString, ), } generic_handler = grpc.method_handlers_generic_handler( 'falco.version.service', rpc_method_handlers) server.add_generic_rpc_handlers((generic_handler,))
[ 2, 2980, 515, 416, 262, 308, 49, 5662, 11361, 8435, 17050, 13877, 13, 8410, 5626, 48483, 0, 198, 11748, 1036, 14751, 198, 198, 11748, 2196, 62, 40842, 17, 355, 2196, 834, 40842, 17, 628, 628, 198, 4299, 751, 62, 15271, 11838, 16647, ...
2.632743
226
import sys import json import requests import subprocess from datetime import datetime #dict storing data collection={} def update_collection(): ''' Download bioarxiv and medarxiv collections ''' link='https://connect.biorxiv.org/relate/collection_json.php?grp=181' outfile='collection.json' print('Downloading ...') for output in execute_commandRealtime(['curl','-o',outfile,link]): print (output) def read_collection(): ''' open file ''' filename='collection.json' with open(filename) as f: data = json.load(f) i=0 for key,value in data.items() : #print (key,":",value) if key=='rels': val=data[key] print('{} records found'.format(len(val))) return value def filter_date(res,startdate): ''' keep results by date ''' filtered=[] for d in res: if datetime.strptime(d['rel_date'], '%Y-%m-%d')>=startdate: filtered.append(d) return filtered #step 1 update collection downloads around 15 MB .json data #update_collection() #read collection in memory collection=read_collection() #see available terms #get_terms() #perform search #res=search(' RNA-seq') tosearch=[' RNA-seq','transcriptom','express','sequencing'] res=searchall(tosearch) print(len(res)) print(len(get_title(res))) fdate=datetime.strptime('2020-06-25', '%Y-%m-%d') print('filtering results before',fdate) final_res=get_title(filter_date(res,fdate)) print(len(final_res)) print('\n'.join(final_res))
[ 11748, 25064, 198, 11748, 33918, 198, 11748, 7007, 198, 11748, 850, 14681, 198, 6738, 4818, 8079, 1330, 4818, 8079, 198, 198, 2, 11600, 23069, 1366, 198, 43681, 34758, 92, 628, 198, 4299, 4296, 62, 43681, 33529, 198, 220, 220, 220, 705,...
2.467949
624
import tornado.web from core.logger_helper import logger from core.server.wxauthorize import WxConfig from core.server.wxauthorize import WxAuthorServer from core.cache.tokencache import TokenCache
[ 11748, 33718, 13, 12384, 198, 6738, 4755, 13, 6404, 1362, 62, 2978, 525, 1330, 49706, 198, 6738, 4755, 13, 15388, 13, 49345, 9800, 1096, 1330, 370, 87, 16934, 198, 6738, 4755, 13, 15388, 13, 49345, 9800, 1096, 1330, 370, 87, 13838, 10...
3.685185
54
#!/usr/bin/python # # Write in Python3.6 # Filename: # # Mapping_JsonToCsvExtractor.py # # # Basic Usage: # # python Mapping_JsonToCsvExtractor.py /directory/containing/datastream/mapping/json/files # # Utilities import sys import os import json import argparse # write a line to the target file if __name__ == '__main__': sys.exit(main())
[ 2, 48443, 14629, 14, 8800, 14, 29412, 198, 2, 198, 2, 19430, 287, 11361, 18, 13, 21, 198, 2, 7066, 12453, 25, 198, 2, 198, 2, 220, 220, 220, 220, 337, 5912, 62, 41, 1559, 2514, 34, 21370, 11627, 40450, 13, 9078, 198, 2, 198, 2...
2.564286
140
import sys from flask import Flask, redirect, request, session, url_for from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.login import LoginManager, current_user from flask_script import Manager from flask_migrate import Migrate, MigrateCommand from flask_wtf.csrf import CsrfProtect from .sessions import ShuttlSessionInterface app = Flask(__name__) app.config.from_object("shuttl.settings.DevelopmentConfig") app.session_interface = ShuttlSessionInterface() csrf = CsrfProtect(app) db = SQLAlchemy(app) login_manager = LoginManager() login_manager.init_app(app) from shuttl.MiddleWare import OrganizationMiddleware from .Views import * from .Models import * from .misc import shuttl, shuttlOrgs migrate = Migrate(app, db) manager = Manager(app) manager.add_command('db', MigrateCommand) from .Commands.FillDB import FillDB from .Commands.TestSuite import TestSuite from .Commands.Add import Add from .Commands.DemoFiller import DemoFiller from .Commands.ResetPublishers import ResetPublishers from .Commands.UploadToS3 import UploadS3 from .Templates.Tags import load_tags # load_tags(app.jinja_env) manager.add_command('test', TestSuite()) manager.add_command('add', Add()) manager.add_command('filldb', FillDB()) manager.add_command('demofiller', DemoFiller()) manager.add_command("resetQueue", ResetPublishers()) manager.add_command('upload', UploadS3) app.register_blueprint(shuttl) app.register_blueprint(shuttlOrgs) from .Models.Reseller import Reseller, ResellerDoesNotExist from .Models.organization import Organization, OrganizationDoesNotExistException from .Models.FileTree.FileObjects.FileObject import FileObject FileObject.LoadMapper()
[ 11748, 25064, 198, 6738, 42903, 1330, 46947, 11, 18941, 11, 2581, 11, 6246, 11, 19016, 62, 1640, 198, 6738, 42903, 13, 2302, 13, 25410, 282, 26599, 1330, 16363, 2348, 26599, 198, 6738, 42903, 13, 2302, 13, 38235, 1330, 23093, 13511, 11,...
3.241313
518
from utils import initialize from pandas import DataFrame from genetic import GA import numpy as np import argparse import random import time import sys sys.setrecursionlimit(2000) random.seed(time.time()) parser = argparse.ArgumentParser() parser.add_argument('--mr', help='Mutation Rate') parser.add_argument('--cr', help='Crossover Rate') parser.add_argument('--size', help='Population Size') parser.add_argument('--ngen', help='Number of Generations') parser.add_argument('--base', help='Base de Teste [Easy, Middle, Hard, Newton, Einstein, Pythagorean]') args, unknown = parser.parse_known_args() #cls && python main.py --mr 0.05 --cr 0.8 --size 100 --ngen 5000 --base Easy #cr:[0.7, 0.75, 0.8] mr:[0.05, 0.1, 0.2] size:[10, 50, 100] mutation_rate = float(args.mr) crossover_rate = float(args.cr) size = int(args.size) ngen = int(args.ngen) test = args.base # f(x) = 2*x easy = {} easy['x'] = {'a':np.array(np.arange(100), dtype='float64')} easy['y'] = easy['x']['a']*2 easy['terminal_symb'] = ['a'] # f(x,y,z) = sqrt(x+y)+z medium = {} medium['x'] = {'x':np.array(np.arange(100), dtype='float64'), 'y':np.array(np.random.randint(100)),#, dtype='float64'), 'z':np.array(np.random.randint(100))}#, dtype='float64')} medium['y'] = (medium['x']['x']+medium['x']['y'])**0.5 + medium['x']['z'] medium['terminal_symb'] = ['x','y','z'] # f(x,y,z) = sin(x)+sqrt(y)-tan(z+x) hard = {} hard['x'] = {'x':np.array(np.arange(100), dtype='float64'), 'y':np.array(np.random.randint(100), dtype='float64'),#, dtype='float64'), 'z':np.array(np.random.randint(100), dtype='float64')}#, dtype='float64')} hard['y'] = np.sin(hard['x']['x']) + hard['x']['y']**0.5 - np.tan(hard['x']['z'] + hard['x']['x']) hard['terminal_symb'] = ['x','y','z'] #Pythagorean Theorem # c = a+b pythagorean_theorem = {} pythagorean_theorem['x'] = {'a': np.array(np.random.randint(100, size=100), dtype='float64'), 'b': np.array(np.arange(100), dtype='float64')} pythagorean_theorem['y'] = pythagorean_theorem['x']['a']**2 +pythagorean_theorem['x']['b']**2 pythagorean_theorem['terminal_symb'] = ['a','b'] #Einstein's Theory of Relativity # E = m*c # c = 299.792.458 m/s einstein_relativity = {} einstein_relativity['x'] = {'m': np.random.random(100)} einstein_relativity['y'] = einstein_relativity['x']['m']*(299792458**2) #c=89875517873681764 einstein_relativity['terminal_symb'] = ['m'] #Newton's Universal Law of Gravitation # F = G*m1*m2/d G = 6.674*10E-11 newton_law = {} newton_law['x'] = {'m1': 10*np.array(np.random.random(100), dtype='float64'), 'm2': np.array(np.random.randint(100, size=100), dtype='float64'), 'd': np.array(np.random.randint(100, size=100)+np.random.rand(100)+10E-11, dtype='float64')} newton_law['y'] = (newton_law['x']['m1']*newton_law['x']['m2']*G)/(newton_law['x']['d']**2) newton_law['terminal_symb'] = ['m1','m2','d'] base = {'Easy': easy, 'Pythagorean':pythagorean_theorem, 'Middle': medium, 'Hard': hard, 'Newton': newton_law, "Einstein": einstein_relativity} #cr:[0.7, 0.75, 0.8] mr:[0.05, 0.1, 0.2] size:[10, 50, 100] results = {} duration = {} ngen = 2000 for test in ['Hard']:#,'Hard','Hard']: for crossover_rate in [0.7, 0.8]: for mutation_rate in [0.05]:#, 0.1, 0.2]: for size in [10, 100]: ga = GA(terminal_symb=base[test]['terminal_symb'], x=base[test]['x'], y=base[test]['y'], size=size, num_generations=ngen, crossover_rate=crossover_rate, mutation_rate=mutation_rate, early_stop=0.1) ga.run() loss = ga.loss_history loss = np.concatenate((loss, [loss[len(loss)-1] for i in range(ngen - len(loss))] ) ) results[test+'_cr_'+str(crossover_rate)+'_mr_'+str(mutation_rate)+'_size_'+str(size)] = loss duration[test+'_cr_'+str(crossover_rate)+'_mr_'+str(mutation_rate)+'_size_'+str(size)] = [ga.duration] df = DataFrame(results) df.to_csv('Resultados Hard GA.csv', index=False, decimal=',', sep=';') df = DataFrame(duration) df.to_csv('Durao Hard GA.csv', index=False, decimal=',', sep=';')
[ 6738, 3384, 4487, 1330, 41216, 201, 198, 6738, 19798, 292, 1330, 6060, 19778, 201, 198, 6738, 8513, 1330, 14545, 201, 198, 11748, 299, 32152, 355, 45941, 201, 198, 11748, 1822, 29572, 201, 198, 11748, 4738, 201, 198, 11748, 640, 201, 19...
2.216187
1,841
#Creado por Jhon Edison Castro Snchez #Diccionario tomado de https://github.com/danielmiessler/SecLists/blob/bb915befb208fd900592bb5a25d0c5e4f869f8ea/Passwords/Leaked-Databases/rockyou.txt.tar.gz #Se usa para generar el mismo comportamiento de openssl de linux #https://docs.python.org/2/library/crypt.html import crypt #Funcion que me permite generar los hash de las palabras de 8 caracteres #Se usa el hash dado en la PEC #La salida es un archivo con un par de valores por linea #la primera es el hash y al frente el valor del password en texto plano #Funcion que recibe el archivo de entrada y el de salida y llama a otra funcion #que valida el tamao de los strings #Funcion que verifica cada linea y si es de 8 caracteres me genera un archivo nuevo #Con esto ya puedo generar los hash y comparar. #Llamado a las funciones if __name__ == "__main__": with open('rockyou.txt','r')as f: text = f.read() DESDictionary('rockyou.txt','pec1.txt') salt1='tl' salt2='as' generateHash('pec1.txt','hashed1.txt', salt1) generateHash('pec1.txt','hashed2.txt', salt2)
[ 2, 34, 961, 78, 16964, 449, 24130, 37448, 21193, 5489, 2395, 89, 198, 2, 35, 44240, 295, 4982, 16667, 4533, 390, 3740, 1378, 12567, 13, 785, 14, 67, 6321, 11632, 33730, 14, 6558, 43, 1023, 14, 2436, 672, 14, 11848, 40248, 65, 891, ...
2.580189
424
from nltk.book import * print letterFrequ(text1) print letterFrequ(text5)
[ 6738, 299, 2528, 74, 13, 2070, 1330, 1635, 628, 220, 220, 220, 220, 198, 4798, 3850, 37, 8897, 7, 5239, 16, 8, 198, 4798, 3850, 37, 8897, 7, 5239, 20, 8, 198 ]
2.5
32
import connectBD as connectDB from pprint import pprint
[ 11748, 2018, 14529, 355, 2018, 11012, 198, 6738, 279, 4798, 1330, 279, 4798 ]
4.230769
13
from utils import hrsize from time import time_ns
[ 6738, 3384, 4487, 1330, 36201, 1096, 198, 6738, 640, 1330, 640, 62, 5907, 198 ]
3.571429
14
''' PDF to Image Converter Author: Fraser Love, me@fraser.love Created: 2020-06-13 Latest Release: v1.0.1, 2020-06-21 Python: v3.6.9 Dependancies: pdf2image Converts multiple pdf's to images (JPEG format) and stores them in a logical folder structure under the desired image directory. Usage: Update the pdf_dir and img_dir paths to point to the directory that holds the pdf files and the directory that the generated images should be placed under. ''' from pdf2image import convert_from_path import os pdf_dir = 'pdfs/' # Include trailing forward slash img_dir = 'images/' first_page_only = True # Only convert the first page of the pdf to an image pdf_names = [pdf_name.split('.')[0] for pdf_name in os.listdir(pdf_dir) if pdf_name[-4:] == ".pdf"] for pdf_name in pdf_names: pages = convert_from_path('{}{}.pdf'.format(pdf_dir, pdf_name)) if first_page_only: pages[0].save('{}/{}.jpg'.format(img_dir, pdf_name), 'JPEG') else: directory = '{}{}'.format(img_dir, pdf_name) if not os.path.exists(directory): os.makedirs(directory) for i, page in enumerate(pages): page.save('{}{}/{}-{}.jpg'.format(img_dir, pdf_name, pdf_name, i), 'JPEG')
[ 7061, 6, 198, 20456, 284, 7412, 35602, 353, 198, 13838, 25, 28059, 5896, 11, 502, 31, 8310, 6005, 13, 23205, 198, 41972, 25, 12131, 12, 3312, 12, 1485, 198, 39478, 13868, 25, 410, 16, 13, 15, 13, 16, 11, 12131, 12, 3312, 12, 2481,...
2.669584
457
from fvttmv.exceptions import FvttmvException from fvttmv.reference_tools import ReferenceTools from fvttmv.search.__references_searcher_string import ReferencesSearcherString from test.common import TestCase
[ 6738, 277, 85, 926, 76, 85, 13, 1069, 11755, 1330, 376, 85, 926, 76, 85, 16922, 198, 6738, 277, 85, 926, 76, 85, 13, 35790, 62, 31391, 1330, 20984, 33637, 198, 6738, 277, 85, 926, 76, 85, 13, 12947, 13, 834, 5420, 4972, 62, 325,...
3.333333
63
# -*- coding: utf-8 -*- """ Created on Wed Aug 19 19:50:43 2020 @author: beck """ import cv2 import datetime import dateparser import os import sys import pandas as pd import pytz from hachoir.parser import createParser from hachoir.metadata import extractMetadata from PIL import Image import numpy as np import pytesseract import imutils import time from GPSPhoto import gpsphoto from threading import Thread
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 201, 198, 37811, 201, 198, 41972, 319, 3300, 2447, 678, 678, 25, 1120, 25, 3559, 12131, 201, 198, 201, 198, 31, 9800, 25, 47673, 201, 198, 37811, 201, 198, 11748, 269, 85, ...
2.850649
154
#! /home/seanchen/anaconda3/bin/python from __future__ import absolute_import from __future__ import division from __future__ import print_function #import sys import rospy from std_msgs.msg import String import torch import torch.nn.parallel import torch.nn.functional as F import numpy as np import cv2 from LPN import LPN from fall_net import Fall_Net from pose_utils import Cropmyimage from pose_utils import Drawkeypoints import plot_sen from time import * from sensor_msgs.msg import Image from cv_bridge import CvBridge, CvBridgeError #sys.path.remove('/opt/ros/kinetic/lib/python2.7/dist-packages') global cam_image if __name__ == '__main__': rospy.init_node('detector', anonymous=True) pub = rospy.Publisher('det_result', Image, queue_size=10) rospy.Subscriber('cam_image', Image, callback) rate = rospy.Rate(50) # 10hz # model pose_net = LPN(nJoints=17) pose_net.load_state_dict(torch.load('/home/seanchen/robot_fall_det/pose_net_pred100.pth.tar')) pose_net.cuda() fall_net = Fall_Net(64, 48, 17, device=torch.device('cuda')) fall_net.cuda().double() fall_net.load_state_dict(torch.load('/home/seanchen/robot_fall_det/fall_net_pred5.pth.tar')) pose_net.eval() fall_net.eval() print('Load successfully!') bridge = CvBridge() global cam_image cam_image = np.array([]) fall_count = [] while not rospy.is_shutdown(): rate.sleep() if not cam_image.any(): print('waiting!') continue start = time() # # image initialize #photo_file = '/home/seanchen/robot_fall_det/fall1.jpg' #input = cv2.imread(photo_file)# cv2 np.array(w,h,channel) input = cam_image bbox = [0, 0, input.shape[1], input.shape[0]] input_image, details = Cropmyimage(input, bbox) input_image = np.array([input_image.numpy()]) #print(input_image.shape) input_image = torch.from_numpy(input_image) #input_image.cuda() # get posedetails pose_out = pose_net(input_image.cuda()) fall_out, pose_cor = fall_net(pose_out) # # neck = (pose_cor[:, 5:6, :] + pose_cor[:, 6:7, :]) / 2 pose_cor = torch.cat((pose_cor, neck), dim=1) pose_cor = pose_cor * 4 + 2. scale = torch.Tensor([[256, 192]]).cuda() pose_cor = pose_cor / scale scale = torch.Tensor([[details[3]-details[1], details[2]-details[0]]]).cuda() pose_cor = pose_cor * scale scale = torch.Tensor([[details[1], details[0]]]).cuda() pose_cor = pose_cor + scale #pose_cor_1 = (4*pose_cor[:, :, 0]+2.)/64*(details[3]-details[1])/4+details[1] #pose_cor_2 = (4*pose_cor[:, :, 1]+2.)/48*(details[2]-details[0])/4+details[0] pose_cor = torch.flip(pose_cor, dims=[2]) ones = torch.ones(1, 18, 1).cuda() pose_cor = torch.cat((pose_cor, ones), dim=2).cpu().detach().numpy() #det_result = torch.zeros(64, 48, 3).numpy() det_result = plot_sen.plot_poses(input, pose_cor) #print(det_result.shape) # #if fall_out.indices == 1: # print('Down!') #if fall_out.indices == 0: # print('Not Down!') fall_out = torch.max(F.softmax(fall_out, dim=0), dim=0) fall_count.append(fall_out.indices) fall_dis = sum(fall_count[len(fall_count)-30 : len(fall_count)]) #print(len(fall_count)) end = time() run_time = end-start if fall_dis > 24: print('Normal!', 1. / run_time) else: print('Down!', 1. / run_time) det_result = bridge.cv2_to_imgmsg(det_result, encoding="passthrough") pub.publish(det_result) #print(1. / run_time) # spin() simply keeps python from exiting until this node is stopped #rospy.spin() #while True: #pass
[ 2, 0, 1220, 11195, 14, 325, 1192, 831, 14, 272, 330, 13533, 18, 14, 8800, 14, 29412, 198, 6738, 11593, 37443, 834, 1330, 4112, 62, 11748, 198, 6738, 11593, 37443, 834, 1330, 7297, 198, 6738, 11593, 37443, 834, 1330, 3601, 62, 8818, ...
2.150715
1,818
import tensorflow as tf from sound_lstm_test import data batch_size = 10 x = tf.placeholder(tf.float32, [batch_size, 512, 80]) y_ = tf.placeholder(tf.float32, [batch_size, 59]) w_conv1 = tf.Variable(tf.truncated_normal([16, 2, 1, 64], stddev=0.1), name='conv1_w') b_conv1 = tf.Variable(tf.constant(0.1, shape=[64]), name='conv1_b') x_image = tf.reshape(x, [-1, 512, 80, 1]) h_conv1 = tf.nn.relu(tf.nn.conv2d(x_image, w_conv1, strides=[1, 2, 1, 1], padding='VALID') + b_conv1) h_pool1 = tf.nn.max_pool(h_conv1, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='VALID') w_conv2 = tf.Variable(tf.truncated_normal([2, 16, 64, 128], stddev=0.1), name='conv2_w') b_conv2 = tf.Variable(tf.constant(0.1, shape=[128]), name='conv2_b') h_conv2 = tf.nn.relu(tf.nn.conv2d(h_pool1, w_conv2, strides=[1, 1, 1, 1], padding='VALID') + b_conv2) h_pool2 = tf.nn.max_pool(h_conv2, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='VALID') w_fc1 = tf.Variable(tf.truncated_normal([61 * 12 * 128, 1024], stddev=0.1), name='fc1_w') b_fc1 = tf.Variable(tf.constant(0.1, shape=[1024]), name='fc1_b') h_pool2_flat = tf.reshape(h_pool2, [-1, 61 * 12 * 128]) h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, w_fc1) + b_fc1) rate = tf.placeholder(tf.float32) h_fc1_drop = tf.nn.dropout(h_fc1, rate=rate) w_fc2 = tf.Variable(tf.truncated_normal([1024, 59], stddev=0.1), name='fc2_w') b_fc2 = tf.Variable(tf.constant(0.1, shape=[59]), name='fc2_b') y_conv = tf.matmul(h_fc1_drop, w_fc2) + b_fc2 variables = tf.trainable_variables() conv1_variable = [t for t in variables if t.name.startswith('conv1')] conv2_variable = [t for t in variables if t.name.startswith('conv2')] fc1_variable = [t for t in variables if t.name.startswith('fc1')] fc2_variable = [t for t in variables if t.name.startswith('fc2')] correct_prediction = tf.equal(tf.argmax(y_conv, 1), tf.arg_max(y_, 1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(labels=y_, logits=y_conv)) grads_conv1, _ = tf.clip_by_global_norm(tf.gradients(loss, conv1_variable), clip_norm=5) grads_conv2, _ = tf.clip_by_global_norm(tf.gradients(loss, conv2_variable), clip_norm=5) grads_fc1, _ = tf.clip_by_global_norm(tf.gradients(loss, fc1_variable), clip_norm=5) grads, _ = tf.clip_by_global_norm(tf.gradients(loss, variables), clip_norm=5) conv1_optimizer = tf.train.AdamOptimizer(0.001) conv2_optimizer = tf.train.AdamOptimizer(0.001) fc1_optimizer = tf.train.AdamOptimizer(0.001) fc2_optimizer = tf.train.AdamOptimizer(0.001) optimizer = tf.train.AdamOptimizer(0.001) conv1_op = conv1_optimizer.apply_gradients(zip(grads_conv1, conv1_variable)) conv2_op = conv2_optimizer.apply_gradients(zip(grads_conv2, conv2_variable)) fc1_op = fc1_optimizer.apply_gradients(zip(grads_fc1, fc1_variable)) fc2_op = fc2_optimizer.apply_gradients(zip(grads_fc2, fc2_variable)) op = optimizer.apply_gradients(zip(grads, variables)) init = tf.global_variables_initializer() with tf.Session() as sess: sess.run(init) train_data = data.np_load(batch_size=10, batch_type='train/') test_data = data.np_load(batch_size=10, batch_type='test/') for i in range(1000): for _ in range(100): input_, label = next(train_data) sess.run([conv1_op, conv2_op, fc1_op, fc2_op], feed_dict={x: input_, y_: label, rate: 0}) test_total_accuracy = 0 for i in range(10): test_input_, test_label = next(test_data) test_accuracy, _ = sess.run([accuracy, tf.no_op()], feed_dict={x: test_input_, y_: test_label, rate: 0}) test_total_accuracy += test_accuracy print('%.3f' % (test_total_accuracy / 10))
[ 11748, 11192, 273, 11125, 355, 48700, 198, 6738, 2128, 62, 75, 301, 76, 62, 9288, 1330, 1366, 198, 198, 43501, 62, 7857, 796, 838, 198, 198, 87, 796, 48700, 13, 5372, 13829, 7, 27110, 13, 22468, 2624, 11, 685, 43501, 62, 7857, 11, ...
2.223629
1,659
'''' You're given 2 huge integers represented by linked lists. Each linked list element is a number from 0 to 9999 that represents a number with exactly 4 digits. The represented number might have leading zeros. Your task is to add up these huge integers and return the result in the same format. Example For a = [9876, 5432, 1999] and b = [1, 8001], the output should be addTwoHugeNumbers(a, b) = [9876, 5434, 0]. Explanation: 987654321999 + 18001 = 987654340000. For a = [123, 4, 5] and b = [100, 100, 100], the output should be addTwoHugeNumbers(a, b) = [223, 104, 105]. Explanation: 12300040005 + 10001000100 = 22301040105. Input/Output [execution time limit] 4 seconds (py3) [input] linkedlist.integer a The first number, without its leading zeros. Guaranteed constraints: 0 a size 104, 0 element value 9999. [input] linkedlist.integer b The second number, without its leading zeros. Guaranteed constraints: 0 b size 104, 0 element value 9999. [output] linkedlist.integer The result of adding a and b together, returned without leading zeros in the same format. '''' # Definition for singly-linked list: class ListNode(object): def __init__(self, x): self.value = x self.next = None def addTwoHugeNumbers(a, b): a = reverseList(a) b = reverseList(b) helper = ListNode(None) r = helper carry = 0 while a != None or b != None or carry > 0: aValue = 0 if a == None else a.value bValue = 0 if b == None else b.value total = aValue + bValue + carry carry = total // 10000 total = total % 10000 r.next = ListNode(total) r = r.next if a != None: a = a.next if b != None: b = b.next return reverseList(helper.next) def reverseList(a): if a == None: return None stack = [] while a != None: stack.append(a.value) a = a.next r = ListNode(stack.pop()) head = r while len(stack) > 0: r.next = ListNode(stack.pop()) r = r.next return head def printList(a): while a != None: print (a.value) a = a.next
[ 39115, 198, 1639, 821, 1813, 362, 3236, 37014, 7997, 416, 6692, 8341, 13, 5501, 6692, 1351, 5002, 318, 257, 1271, 422, 657, 284, 860, 17032, 326, 6870, 257, 1271, 351, 3446, 604, 19561, 13, 383, 7997, 1271, 1244, 423, 3756, 1976, 2749...
2.444568
902
""" @file @brief Functions to handle data coming from :epkg:`Cancer Imaging Archive`. """ import os import pydicom import pandas import cv2 from pyquickhelper.filehelper.synchelper import explore_folder_iterfile # pylint: disable=C0411 def convert_dcm2png(folder, dest, fLOG=None): """ Converts all medical images in a folder from format :epkg:`dcm` to :epkg:`png`. @param folder source folder @param dest destination folder @param fLOG logging function @return :epkg:`pandas:DataFrame` with many data The function uses module :epkg:`pydicom`. """ if not os.path.exists(dest): raise FileNotFoundError("Unable to find folder '{}'.".format(dest)) if fLOG is not None: fLOG("[convert_dcm2png] convert dcm files from '{}'.".format(folder)) fLOG("[convert_dcm2png] into '{}'.".format(dest)) done = {} rows = [] for name in explore_folder_iterfile(folder, ".*[.]dcm$"): relname = os.path.relpath(name, folder) if fLOG is not None: fLOG("[convert_dcm2png] read {}: '{}'.".format( len(rows) + 1, relname)) f1 = relname.replace("\\", "/").split("/")[0] name_ = "img_%06d.png" % len(done) if "_" in f1: sub = f1.split('_')[0] fsub = os.path.join(dest, sub) if not os.path.exists(fsub): if fLOG is not None: fLOG("[convert_dcm2png] create folder '{}'.".format(sub)) os.mkdir(fsub) new_name = os.path.join(sub, name_) else: new_name = name_ # read ds = pydicom.dcmread(name) # data obs = dict(_src=relname, _dest=new_name, _size=len(ds.pixel_array)) _recurse_fill(obs, ds) rows.append(obs) # image full_name = os.path.join(dest, new_name) if os.path.exists(full_name): done[name] = full_name continue pixel_array_numpy = ds.pixel_array cv2.imwrite(full_name, pixel_array_numpy) # pylint: disable=E1101 done[name] = full_name final = os.path.join(dest, "_summary.csv") if fLOG is not None: fLOG("[convert_dcm2png] converted {} images.".format(len(rows))) fLOG("[convert_dcm2png] write '{}'.".format(final)) df = pandas.DataFrame(rows) df.to_csv(final, index=False, encoding="utf-8") return df
[ 37811, 198, 31, 7753, 198, 31, 65, 3796, 40480, 284, 5412, 1366, 2406, 422, 198, 25, 538, 10025, 25, 63, 34, 8250, 48656, 20816, 44646, 198, 37811, 198, 11748, 28686, 198, 11748, 279, 5173, 291, 296, 198, 11748, 19798, 292, 198, 11748...
2.051581
1,202
import re import collections import shutil from tensorflow.python.platform import gfile num_movie_scripts = 10 vocabulary_size = 10000 fraction_dev = 50 path_for_x_train = 'X_train.txt' path_for_y_train = 'y_train.txt' path_for_x_dev = 'X_dev.txt' path_for_y_dev = 'y_dev.txt' _PAD = b"_PAD" _GO = b"_GO" _EOS = b"_EOS" _UNK = b"_UNK" _START_VOCAB = [_PAD, _GO, _EOS, _UNK] PAD_ID = 0 GO_ID = 1 EOS_ID = 2 UNK_ID = 3 _WORD_SPLIT = re.compile(b"([.,!?\":;)(])") _DIGIT_RE = re.compile(br"\d") #FROM DATA UTILS # Build the dictionary with word-IDs from self-made dictionary and replace rare words with UNK token. def generate_encoded_files2(x_train_file, y_train_file, x_dev_file, y_dev_file, tokenized_sentences, dictionary): """Sentence A is in x_train, Sentence B in y_train""" encoded_holder = [] unk_id = dictionary['_UNK'] for sentence in tokenized_sentences: encoded_holder.append(encode_sentence(sentence, dictionary, unk_id)) f1 = open(x_train_file, 'w') f2 = open(y_train_file, 'w') fraction = int(len(encoded_holder) / fraction_dev) if (len(encoded_holder) % 2 == 0): end = len(encoded_holder) else: end = len(encoded_holder)-1 for i in xrange(0,fraction,2): f1.write(str(encoded_holder[i]) + '\n') f2.write(str(encoded_holder[i+1]) + '\n') f1.close() f2.close() d1 = open(x_dev_file, 'w') d2 = open(y_dev_file, 'w') for i in xrange(fraction, end, 2): d1.write(str(encoded_holder[i]) + '\n') d2.write(str(encoded_holder[i+1]) + '\n') d1.close() d2.close() def generate_encoded_files(x_train_file, y_train_file, x_dev_file, y_dev_file, tokenized_sentences, dictionary): """Sentence A is in x_train and y_train, Sentence B in X_train and y_train""" encoded_holder = [] f1 = open(x_train_file, 'w') last_line = tokenized_sentences.pop() first_line = tokenized_sentences.pop(0) dev_counter = int(len(tokenized_sentences) - len(tokenized_sentences)/fraction_dev) unk_id = dictionary['_UNK'] first_line_encoded = encode_sentence(first_line, dictionary, unk_id) f1.write(first_line_encoded + '\n') # Creates data for X_train for x in xrange(dev_counter): encoded_sentence = encode_sentence(tokenized_sentences[x], dictionary, unk_id) encoded_holder.append(encoded_sentence) f1.write(encoded_sentence + '\n') # Write sentence to file f1.close() d1 = open(x_dev_file, 'w') # Creates data for x_dev_file for x in xrange(dev_counter, len(tokenized_sentences)): encoded_sentence = encode_sentence(tokenized_sentences[x], dictionary, unk_id) encoded_holder.append(encoded_sentence) d1.write(encoded_sentence + '\n') # Write sentence to file d1.close() # Creates data for y_train f2 = open(y_train_file, 'w') for x in xrange(dev_counter + 1): f2.write(encoded_holder[x] + '\n') # Write sentence to file f2.close() # Creates data for y_dev d2 = open(y_dev_file, 'w') for x in xrange(dev_counter + 1, len(tokenized_sentences)): d2.write(encoded_holder[x] + '\n') # Write sentence to file last_line_encoded = encode_sentence(last_line, dictionary, unk_id) d2.write(last_line_encoded + '\n') d2.close() def basic_tokenizer(sentence): """Very basic tokenizer: split the sentence into a list of tokens""" words = [] for space_separated_fragment in sentence.strip().split(): words.extend(re.split(_WORD_SPLIT, space_separated_fragment)) return [w for w in words if w] def sentence_to_token_ids(sentence, vocabulary): """Convert a string to list of integers representing token-ids. For example, a sentence "I have a dog" may become tokenized into ["I", "have", "a", "dog"] and with vocabulary {"I": 1, "have": 2, "a": 4, "dog": 7"} this function will return [1, 2, 4, 7]. Returns: a list of integers, the token-ids for the sentence. """ words = basic_tokenizer(sentence) return [vocabulary.get(w, UNK_ID) for w in words] # Reads data and puts every sentence in a TWO DIMENSIONAL array as tokens # data_tokens[0] = ['This', 'is', 'a', 'sentence'] #-----------------------Printing methods----------------------------
[ 11748, 302, 198, 11748, 17268, 198, 11748, 4423, 346, 198, 6738, 11192, 273, 11125, 13, 29412, 13, 24254, 1330, 308, 7753, 198, 198, 22510, 62, 41364, 62, 46521, 796, 838, 198, 18893, 22528, 62, 7857, 796, 33028, 198, 69, 7861, 62, 79...
2.410039
1,773
from rest_framework import serializers from dfirtrack_main.models import System, Systemtype
[ 6738, 1334, 62, 30604, 1330, 11389, 11341, 198, 6738, 47764, 343, 11659, 62, 12417, 13, 27530, 1330, 4482, 11, 4482, 4906, 198 ]
4.181818
22
from exasol_advanced_analytics_framework.interface.create_event_handler_udf \ import CreateEventHandlerUDF udf = CreateEventHandlerUDF(exa)
[ 6738, 409, 292, 349, 62, 32225, 2903, 62, 38200, 14094, 62, 30604, 13, 39994, 13, 17953, 62, 15596, 62, 30281, 62, 463, 69, 3467, 198, 220, 220, 220, 1330, 13610, 9237, 25060, 52, 8068, 198, 198, 463, 69, 796, 13610, 9237, 25060, 52...
2.979592
49
# -*- coding: utf-8 -*- """ Created on Tue Mar 24 15:25:14 2020 @author: Nicola VIGAN, Computational Imaging group, CWI, The Netherlands, and ESRF - The European Synchrotron, Grenoble, France """ import numpy as np from . import operators from . import solvers def get_circular_mask(vol_shape, radius_offset=0, coords_ball=None, mask_drop_off="const", data_type=np.float32): """Computes a circular mask for the reconstruction volume. :param vol_shape: The size of the volume. :type vol_shape: numpy.array_like :param radius_offset: The offset with respect to the volume edge. :type radius_offset: float. Optional, default: 0 :param coords_ball: The coordinates to consider for the non-masked region. :type coords_ball: list of dimensions. Optional, default: None :param data_type: The mask data type. :type data_type: numpy.dtype. Optional, default: np.float32 :returns: The circular mask. :rtype: (numpy.array_like) """ vol_shape = np.array(vol_shape, dtype=np.intp) coords = [np.linspace(-(s - 1) / 2, (s - 1) / 2, s, dtype=data_type) for s in vol_shape] coords = np.meshgrid(*coords, indexing="ij") if coords_ball is None: coords_ball = np.arange(-np.fmin(2, len(vol_shape)), 0, dtype=np.intp) else: coords_ball = np.array(coords_ball, dtype=np.intp) radius = np.min(vol_shape[coords_ball]) / 2 + radius_offset coords = np.stack(coords, axis=0) if coords_ball.size == 1: dists = np.abs(coords[coords_ball, ...]) else: dists = np.sqrt(np.sum(coords[coords_ball, ...] ** 2, axis=0)) if mask_drop_off.lower() == "const": return dists <= radius elif mask_drop_off.lower() == "sinc": cut_off = np.min(vol_shape[coords_ball]) / np.sqrt(2) - radius outter_region = 1 - (dists <= radius) outter_vals = 1 - np.sinc((dists - radius) / cut_off) return np.fmax(1 - outter_region * outter_vals, 0) else: raise ValueError("Unknown drop-off function: %s" % mask_drop_off) def pad_sinogram(sinogram, width, pad_axis=-1, mode="edge", **kwds): """Pads the sinogram. :param sinogram: The sinogram to pad. :type sinogram: numpy.array_like :param width: The width of the padding. :type width: either an int or tuple(int, int) :param pad_axis: The axis to pad. :type pad_axis: int. Optional, default: -1 :param mode: The padding type (from numpy.pad). :type mode: string. Optional, default: 'edge'. :param kwds: The numpy.pad arguments. :returns: The padded sinogram. :rtype: (numpy.array_like) """ pad_size = [(0, 0)] * len(sinogram.shape) if len(width) == 1: width = (width, width) pad_size[pad_axis] = width return np.pad(sinogram, pad_size, mode=mode, **kwds) def apply_flat_field(projs, flats, darks=None, crop=None, data_type=np.float32): """Apply flat field. :param projs: Projections :type projs: numpy.array_like :param flats: Flat fields :type flats: numpy.array_like :param darks: Dark noise, defaults to None :type darks: numpy.array_like, optional :param crop: Crop region, defaults to None :type crop: numpy.array_like, optional :param data_type: numpy.dtype, defaults to np.float32 :type data_type: Data type of the processed data, optional :return: Falt-field corrected and linearized projections :rtype: numpy.array_like """ if crop is not None: projs = projs[..., crop[0] : crop[2], crop[1] : crop[3]] flats = flats[..., crop[0] : crop[2], crop[1] : crop[3]] if darks is not None: darks = darks[..., crop[0] : crop[2], crop[1] : crop[3]] if darks is not None: projs -= darks flats -= darks flats = np.mean(flats.astype(data_type), axis=0) return projs.astype(data_type) / flats def apply_minus_log(projs): """Apply -log. :param projs: Projections :type projs: numpy.array_like :return: Falt-field corrected and linearized projections :rtype: numpy.array_like """ return np.fmax(-np.log(projs), 0.0) def denoise_image( img, reg_weight=1e-2, stddev=None, error_norm="l2b", iterations=250, axes=(-2, -1), lower_limit=None, verbose=False ): """Image denoiser based on (simple, weighted or dead-zone) least-squares and wavelets. The weighted least-squares requires the local pixel-wise standard deviations. It can be used to denoise sinograms and projections. :param img: The image or sinogram to denoise. :type img: `numpy.array_like` :param reg_weight: Weight of the regularization term, defaults to 1e-2 :type reg_weight: float, optional :param stddev: The local standard deviations. If None, it performs a standard least-squares. :type stddev: `numpy.array_like`, optional :param error_norm: The error weighting mechanism. When using std_dev, options are: {'l2b'} | 'l1b' | 'hub' | 'wl2' \ (corresponding to: 'l2 dead-zone', 'l1 dead-zone', 'Huber', 'weighted least-squares'). :type error_norm: str, optional :param iterations: Number of iterations, defaults to 250 :type iterations: int, optional :param axes: Axes along which the regularization should be done, defaults to (-2, -1) :type iterations: int or tuple, optional :param lower_limit: Lower clipping limit of the image, defaults to None :type iterations: float, optional :param verbose: Turn verbosity on, defaults to False :type verbose: boolean, optional :return: Denoised image or sinogram. :rtype: `numpy.array_like` """ OpI = operators.TransformIdentity(img.shape) if stddev is not None: if error_norm.lower() == "l2b": img_weight = compute_lsb_weights(stddev) data_term = solvers.DataFidelity_l2b(img_weight) elif error_norm.lower() == "l1b": img_weight = compute_lsb_weights(stddev) data_term = solvers.DataFidelity_l1b(img_weight) elif error_norm.lower() == "hub": img_weight = compute_lsb_weights(stddev) data_term = solvers.DataFidelity_Huber(img_weight) elif error_norm.lower() == "wl2": (img_weight, reg_weight) = compute_wls_weights(stddev, OpI.T, reg_weight) data_term = solvers.DataFidelity_wl2(img_weight) else: raise ValueError('Unknown error method: "%s". Options are: {"l2b"} | "l1b" | "hub" | "wl2"' % error_norm) else: data_term = error_norm if isinstance(axes, int): axes = (axes,) reg_wl = solvers.Regularizer_l1swl(reg_weight, "bior4.4", 2, axes=axes, normalized=False) sol_wls_wl = solvers.CP(verbose=verbose, regularizer=reg_wl, data_term=data_term) (denoised_img, _) = sol_wls_wl(OpI, img, iterations, x0=img, lower_limit=lower_limit) return denoised_img
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 41972, 319, 30030, 1526, 1987, 1315, 25, 1495, 25, 1415, 12131, 198, 198, 31, 9800, 25, 40396, 569, 3528, 1565, 11, 22476, 864, 48656, 1448, 11, 24006, 40, ...
2.48302
2,768
from .b_cap_client import BCapClient from .b_cap_exception import BCapException
[ 6738, 764, 65, 62, 11128, 62, 16366, 1330, 11843, 499, 11792, 198, 6738, 764, 65, 62, 11128, 62, 1069, 4516, 1330, 11843, 499, 16922, 198 ]
3.2
25
''' @author: l4zyc0d3r People who are happy makes other happy. I am gonna finish it slowly but definitely.cdt '''
[ 7061, 6, 198, 31, 9800, 25, 300, 19, 7357, 66, 15, 67, 18, 81, 220, 198, 8061, 508, 389, 3772, 1838, 584, 3772, 13, 314, 716, 8066, 5461, 340, 6364, 475, 4753, 13, 10210, 83, 198, 7061, 6, 198 ]
2.948718
39
from cal_setup import get_calendar_service if __name__ == '__main__': main()
[ 6738, 2386, 62, 40406, 1330, 651, 62, 9948, 9239, 62, 15271, 198, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 198, 220, 220, 1388, 3419 ]
2.857143
28
# coding=utf-8 """Client blueprint"""
[ 2, 19617, 28, 40477, 12, 23, 198, 37811, 11792, 30881, 37811 ]
3.363636
11
from __future__ import annotations import json import asyncio import itertools import typing as t from collections import defaultdict from contextlib import asynccontextmanager from aiohttp import ClientSession from aiohttp.client import ClientWebSocketResponse from aiohttp.http_websocket import WSMsgType, WSCloseCode from aiohttp.client_exceptions import ( ClientResponseError, ClientConnectorError, ClientConnectionError, ServerDisconnectedError ) from pycdp.utils import ContextLoggerMixin, LoggerMixin, SingleTaskWorker, retry_on from pycdp import cdp T = t.TypeVar('T') _CLOSE_SENTINEL = object
[ 6738, 11593, 37443, 834, 1330, 37647, 198, 11748, 33918, 198, 11748, 30351, 952, 198, 11748, 340, 861, 10141, 198, 11748, 19720, 355, 256, 198, 6738, 17268, 1330, 4277, 11600, 198, 6738, 4732, 8019, 1330, 355, 2047, 535, 261, 5239, 37153,...
3.497175
177
# -*- coding:utf-8 -*- # Copyright (c) 2020 Huawei Technologies Co.,Ltd. # # openGauss is licensed under Mulan PSL v2. # You can use this software according to the terms # and conditions of the Mulan PSL v2. # You may obtain a copy of Mulan PSL v2 at: # # http://license.coscl.org.cn/MulanPSL2 # # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, # WITHOUT WARRANTIES OF ANY KIND, # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. # See the Mulan PSL v2 for more details. # ---------------------------------------------------------------------------- import os import subprocess from multiprocessing.dummy import Pool as ThreadPool from gspylib.common.Common import DefaultValue from gspylib.inspection.common.CheckItem import BaseItem from gspylib.inspection.common.CheckResult import ResultStatus from gspylib.os.gsfile import g_file
[ 2, 532, 9, 12, 19617, 25, 40477, 12, 23, 532, 9, 12, 198, 2, 15069, 357, 66, 8, 12131, 43208, 21852, 1766, 1539, 43, 8671, 13, 198, 2, 198, 2, 1280, 35389, 1046, 318, 11971, 739, 17996, 272, 6599, 43, 410, 17, 13, 198, 2, 921,...
3.22028
286
from . import toolFuncs def DefineTrend(data, K): ''' Filter all the trend whose range less than K% ''' pairs = list(zip(data['Date'], data['Close'])) is_extreme = toolFuncs.extreme_point(data['Close'], K, recognition_method='height') output = [pairs[i] for i in range(len(is_extreme)) if is_extreme[i]] return {'DefineTrend': {'name': 'Trend', 'data': output, 'position': 'main', 'type': 'line', 'lineStyle': {'normal': {'width': 3}, 'showSymbol':False} } }
[ 6738, 764, 1330, 2891, 24629, 6359, 198, 220, 220, 220, 220, 198, 220, 220, 220, 220, 198, 220, 220, 220, 220, 198, 220, 220, 220, 220, 198, 220, 220, 220, 220, 198, 4299, 2896, 500, 45461, 7, 7890, 11, 509, 2599, 198, 220, 220, ...
2.104317
278
# Author: # Charles # Function: # Triplet loss function. import torch from torch.autograd import Function import sys sys.path.append('../') from utils.utils import *
[ 2, 6434, 25, 198, 2, 220, 197, 28711, 198, 2, 15553, 25, 198, 2, 220, 197, 14824, 37069, 2994, 2163, 13, 198, 11748, 28034, 198, 6738, 28034, 13, 2306, 519, 6335, 1330, 15553, 198, 11748, 25064, 198, 17597, 13, 6978, 13, 33295, 1078...
3.111111
54