Example #1
0
 def setUp(self):
     self.x, self.y, self.word2Id, self.Id2word, self.dataId2word = read(
         'D:\Emphasis_Selection\Github\Taher_Github\emphasis\input/test_case_train.txt'
     )
     self.x_test = read(
         'D:\Emphasis_Selection\Github\Taher_Github\emphasis\input/test_case_train.txt',
         word2Id=self.word2Id)
     self.one_hot_x = get_one_hot_matrix(self.x, len(self.word2Id))
Example #2
0
 def get_data(self, spreadsheetId):
     q = read(spreadsheetId, 'pergunta')
     a = read(spreadsheetId, 'resposta')
     for row in a:
         self.answers[int(row[0]) + self.offset] = row[1]
     for row in q:
         t = (preprocess(row[0], self.sub_dict), int(row[1]) + self.offset)
         self.faq += [t]
     self.offset += 1000
 def setUp(self):
     self.X, self.y, self.word2Id, self.Id2word, self.dataId2word = read('D:\Emphasis_Selection\Github\Taher_Github\emphasis\input/test_case_models.txt')
     self.x_test = read('D:\Emphasis_Selection\Github\Taher_Github\emphasis\input/test_case_train.txt', word2Id= self.word2Id)
     self.one_hot_X = get_one_hot_matrix(self.X, len(self.word2Id))
     self.one_hot_y = get_one_hot_matrix(self.y, len(self.word2Id))
     model = WordConditionalModel()
     model.fit(np.array(self.one_hot_X), np.array(self.one_hot_y))
     self.model = model.get_model()
     print(self.Id2word)
     self.predictions = model.predict(self.one_hot_X)
Example #4
0
def main(argv):
    argc = len(argv)
    if argc < 2:
        print(get_help())
        exit(0)

    if argv[1] == 't':
        net = ANN(Functions.SIGMOID, Functions.MSE)
        nb = NaiveBayes()
        bn = Bernoulli()
        selected_tweets = reader.read(argv[2])
        rejected_tweets = reader.read(argv[3])
        t1 = threading.Thread(target=train_net,\
                              args=(net, selected_tweets, rejected_tweets))
        t2 = threading.Thread(target=train_nb,\
                              args=(nb, selected_tweets, rejected_tweets))
        t3 = threading.Thread(target=train_bn,\
                              args=(bn, selected_tweets, rejected_tweets))
        t1.start()
        t2.start()
        t3.start()
        t1.join()
        t2.join()
        t3.join()

    elif argv[1] == 'c':
        f_net = open(argv[2], 'rb')
        net = pickle.load(f_net)
        f_net.close()

        f_nb = open(argv[3], 'rb')
        nb = pickle.load(f_nb)
        f_nb.close()

        f_bn = open(argv[4], 'rb')
        bn = pickle.load(f_bn)
        f_bn.close()

        tweets = reader.read(argv[5])

        t1 = threading.Thread(target=classify_using_net,\
                              args=(net, tweets))
        t2 = threading.Thread(target=classify_using_nb,\
                              args=(nb, tweets))
        t3 = threading.Thread(target=classify_using_bn,\
                              args=(bn, tweets))
        t1.start()
        t2.start()
        t3.start()
        t1.join()
        t2.join()
        t3.join()
    else:
        print(get_help())
        exit(0)
Example #5
0
def date_registration(message):
    global commandlist
    global fromplace
    global toplace
    global dateregistration
    global loadsticerpack
    if message.text.lower() in commandlist:
        exec(commandlist[message.text.lower()])
    elif message.text.lower() in commandlist_ru:
        exec(commandlist_ru[message.text.lower()])
    elif '/' + message.text.lower() in commandlist:
        exec(commandlist['/' + message.text.lower()])
    else:
        dateregistration = message.text.lower()
        print(fromplace)
        print(toplace)
        print(dateregistration)
        Sendler(fromInput=fromplace, fromOutput=toplace,
                date=dateregistration).send()
        bot.send_message(message.chat.id,
                         'Ищу билеты по выбранному направлению')
        bot.send_sticker(message.chat.id, random.choice(loadstickerpack))
        bot.send_message(
            message.chat.id, 'Билеты по маршруту {0} - {1} на {2} '.format(
                fromplace, toplace, dateregistration) + "\n" + reader.read())
Example #6
0
def elaborate(name, ocr=False, lang="eng", debug=False):
    global phase
    nameDoc = name
    app_folder = os.getcwd()
    fi = os.path.join(app_folder, "raw_data")
    fo = os.path.join(app_folder, "images")
    phase = 1
    cropper.crop(fi, fo, debug)
    if ocr:
        fi, fo, focr, foPDF = fo, os.path.join(
            app_folder, "images"), os.path.join(app_folder,
                                                "hocr"), os.path.join(
                                                    app_folder, "pdf_complete")
        phase = 2
        reader.read(fi, fo, focr, foPDF, lang, debug, name)
    phase = 0
Example #7
0
 def GetRatio(self, request, context):
     print("send to client current status for:", request.baseCurCode)
     filter_fun = filter_factory(request.baseCurCode,
                                 request.wantedCurCodes)
     raw_ratio = filter(filter_fun, read(self.filename))
     ratio = map(map_raw_ratio, raw_ratio)
     return CurrenciesRatio(ratio=list(ratio))
Example #8
0
def run(method='read', expr=None, vars=None, time=None, fields=None, limit=1000, sort=None, fill=None):
    # Create an empty response object.
    response = geoweb.empty_response();

    # Check the requested method.
    if method not in ['find', 'read']:
        response['error'] = "Unsupported data operation '%s'" % (method)
        return bson.json_util.dumps(response)

    # Decode the strings into Python objects.
    try:
        if expr is not None: expr = decode(expr, 'expr', response)
        if vars is not None: vars = decode(vars, 'vars', response)
        if time is not None: time = decode(time, 'time', response)
        if fields is not None: fields = decode(fields, 'f', response)
        if sort is not None: sort = decode(sort, 'sort', response)
        if fill is not None:
            fill = decode(fill, 'fill', response)
        else:
            fill = True
    except ValueError:
        return bson.json_util.dumps(response)

    # Cast the limit value to an int
    try:
        limit = int(limit)
    except ValueError:
        response['error'] = "Argument 'limit' ('%s') could not be converted to int." % (limit)
        return bson.json_util.dumps(response)

    # Perform the requested action.
    if method == 'find':
        # @todo This method should find the matching data on the server
        pass
    elif method == 'read':
        # Load reader module
        import reader
        try:
            it = reader.read(expr, vars, time)

            # Create a list of the results.
            if fill:
                results = [it]
            else:
                results = []

            # Create an object to structure the results.
            retobj = {}
            retobj['count'] = 1
            retobj['data'] = results

            # Pack the results into the response object, and return it.
            response['result'] = retobj
        except IOError as io:
            response['error'] = io.message
    else:
        raise RuntimeError("illegal method '%s' in module 'mongo'")

    # Return the response object.
    return bson.json_util.dumps(response)
Example #9
0
 def test_step6_reader_read_string(self):
     read = reader.read('(read-string "(1 2   (3  4) nil)")')
     self.assertTrue(isinstance(read, MalList))
     arg = read.native()[1]
     self.assertTrue(isinstance(arg, MalString))
     native_str = arg.native()
     self.assertEqual("(1 2   (3  4) nil)", native_str)
Example #10
0
def move_abs_run_agg(direction, aggregate):
    """ Changes absorber position, 
    runs direction with output to dataframe (as Direction class attribute),
    calculates aggregate of dataframe columns (sum, mean, etc)
    returns new dataframe with coords and columns aggregate """
    cols = ["efficiency", *reader.columns.keys()]
    df = pd.DataFrame(columns=["abs_x", "abs_y", *cols])
    for x in tqdm(abs_positions(centered_x)):
        for y in abs_positions(centered_y):
            move_absorber(direction.geometry_path, x, y)
            direction.df = export.df(direction)
            tr_df = reader.read(direction)
            df = df.append(
                {
                    "abs_x": round(x, 3),
                    "abs_y": round(y, 3),
                    "efficiency": getattr(tr_df["efficiency"], aggregate)(),
                    "potential_flux": getattr(tr_df["potential_flux"],
                                              aggregate)(),
                    "absorbed_flux": getattr(tr_df["absorbed_flux"],
                                             aggregate)(),
                    "cos_factor": getattr(tr_df["cos_factor"], aggregate)(),
                    "shadow_losses": getattr(tr_df["shadow_losses"],
                                             aggregate)()
                },
                ignore_index=True)
    move_absorber(direction.geometry_path, 0, 0)
    csvpath = direction.raw_file.split(".")[0] + f"-{aggregate}.csv"
    df.to_csv(csvpath, index=False)
Example #11
0
    def read_n_map(self):
        """
        Read input.
        Lengths is the max distance for each document
        """
        if not self.params['window']:
            lengths, sents, self.documents, self.entities, self.pairs = \
                read(self.input, self.documents, self.entities, self.pairs)
        else:
            lengths, sents, self.documents, self.entities, self.pairs = \
                read_subdocs(self.input, self.params['window'], self.documents, self.entities, self.pairs)

        self.find_max_length(lengths)

        # map types and positions and relation types
        for did, d in self.documents.items():
            self.add_document(d)

        for did, e in self.entities.items():
            for k, v in e.items():
                self.add_type(v.type)

        for dist in np.arange(0, self.max_distance + 1):
            self.add_dist(dist)

        for did, p in self.pairs.items():
            for k, v in p.items():
                if v.type == 'not_include':
                    continue
                self.add_relation(v.type)
        assert len(self.entities) == len(self.documents) == len(self.pairs)
Example #12
0
def _parse_tweets(tweets_csv, f):
    '''
    format of each tweet: {
      text: string, original text of tweet msg,
      unigrams: string[], relevant bits of tweet msg,
      tagged_unigrams: string[], relevant bits of tweet msg, POS-tagged,
      datetime: float, created date of tweet in Unix time,
      users: string[], user ids of relevant users,
      rt_count: int, no. of times retweeted,
      fav_count: int, no. of times favorited
    }
    '''
    for json in reader.read(tweets_csv):
        tweet = {}
        
        # text
        tweet['text'] = json['text']
        tweet['unigrams'], tweet['tagged_unigrams'] = _parse_text(json['text'])
        
        # datetime
        tweet['datetime'] = _parse_datetime(json['created_at'])
        
        # user ids
        tweet['users'] = []
        _append_if_exists(json['user']['id_str'], tweet, 'users')
        _extend_if_exists(json['entities']['user_mentions'], 'id_str', tweet, 'users')
        _append_if_exists(json['in_reply_to_user_id_str'], tweet, 'users')
        
        # counts
        tweet['rt_count'] = json['retweet_count']
        tweet['fav_count'] = json['favorite_count']
        
        f(tweet)
Example #13
0
def start():
    for c in code:
        expr = read(c)
        if read_only:
            print(repr(expr))
        else:
            print(expr.eval(global_env))
Example #14
0
    def testName(self):

        # read data
        data = reader.read("../data/log_1_fixed.txt",
                           jstartline=15000,
                           maxlines=5000)

        # preprocess data
        preprocess.preproc(data)

        # initialize model
        layers = [13, 8, 1]
        activf = [
            activation.linear(),
            activation.tanh(),
            activation.sigmoid()
        ]  # activation.tanh(1.75, 3./2.),
        net = ffnet.FFNet(layers, activf)
        net.initw(0.1)

        # create training options
        opts = trainsg.options()

        # write function
        f = open("../output/trainsg_test.txt", "w+")
        writefcn = lambda s: f.write(s)

        # training
        trainsg.train(data, opts, net, writefcn)

        # close file
        f.close()
Example #15
0
 def test_reader(self):
     got = reader.read('data.in')
     self.assertIsNotNone(got)
     self.assertIsInstance(got['entries'], list)
     self.assertIsInstance(got['errors'], list)
     self.assertTrue(len(got['entries']) > 0)
     self.assertTrue(len(got['errors']) > 0)
Example #16
0
def main():
    """The main function of this program.
    """
    structure = None
    print("Welcome to {0}.".format(basename(__file__)))
    print("=" * 76)
    print_help()

    while True:
        in_str = input("your command>>>\n").lower().strip()

        if in_str.startswith("quit"):
            print("Bye, bye.")
            return

        elif in_str.startswith("help"):
            print_help()

        elif in_str.startswith("open"):
            filenm, nstrips = in_str.replace("open ", "").split(" into ")
            structure = read(filenm, int(nstrips))
            structure.print_strip_statistics()

        elif in_str.startswith("p") or in_str.startswith(
                "c") or in_str.startswith("r"):

            if structure is None:
                print("No points read yet, open a file first!")

            else:
                print_statistics(structure.query(parse(in_str)))
Example #17
0
def solve(problems):
    files = {'a': 'a_example.txt',
             'b': 'b_read_on.txt',
             'c': 'c_incunabula.txt',
             'd': 'd_tough_choices.txt',
             'e': 'e_so_many_books.txt',
             'f': 'f_libraries_of_the_world.txt'}

    pool = Pool()
    for f in problems:
        run_file = files[f]
        days_left, remaining_libs = reader.read('./inputs/' + run_file)
        outputs = []
        while days_left > 0 and len(remaining_libs) > 0:
            # Tuning:
            # For b, c, f: 50 is better than 0
            # For e: 0 is better than 50
            scores = pool.map(lambda x: x.get_score(days_left),
                              remaining_libs)
            next_lib = remaining_libs[np.argmax(scores)]
            _ = pool.map(lambda x: x.scan_copy(), next_lib.books.values())
            remaining_libs.remove(next_lib)
            next_lib.books = next_lib.avail_books(days_left)
            if not next_lib.books:
                continue
            _ = pool.map(lambda x: x.remove_dupes(next_lib.books.keys()),
                         remaining_libs)

            days_left = days_left - next_lib.signup
            outputs.append(next_lib)

        writer.write('./outputs/' + run_file, outputs)
        return scorer.score(run_file)
Example #18
0
 def testName(self):
     
     # read data
     data = reader.read("../data/log_1_fixed.txt", jstartline=15000, maxlines=5000)
             
     # preprocess data
     preprocess.preproc(data)
     
     # initialize model
     layers = [13, 8, 1]
     activf = [activation.linear(), activation.tanh(), activation.sigmoid()] #  ,  activation.tanh(1.75, 3./2.),
     net = ffnet.FFNet(layers, activf)
     net.initw(0.1) 
     
     # create training options
     opts = trainb.options()
     
     # write function
     f = open("../output/trainb_test.txt", "w+")
     writefcn = lambda s: f.write(s)
             
     # training
     trainb.train(data, opts, net, writefcn)
     
     # close file
     f.close()
Example #19
0
def loader(parent_dir, override_db_name=False):

    parent = pathlib.Path(parent_dir)
    db_name = override_db_name or DB_FILENAME

    if parent.exists() is False:
        raise RuntimeError(
            f"Provided {parent=!r} but this dir couldn't be found")

    if parent.is_dir() is False:
        raise RuntimeError(f"Provided {parent=!r} is not a directory")

    print(f"Creating DB")
    create_schema(db_name)

    print("Connecting to DB")

    conn = sqlite3.connect(db_name)
    cursor = conn.cursor()

    print("Storing parent path")

    cursor.execute("INSERT INTO ParentDir(path) VALUES(?)", [str(parent)])
    conn.commit()

    cursor.execute("SELECT id FROM ParentDir WHERE path=?", [str(parent)])
    parent_id = cursor.fetchone()[0]

    print(f"Processing {parent=!r}")

    for index, song in enumerate(walker(parent)):
        if song.name.endswith((
                ".mp3",
                ".ogg",
        )):
            # print(f"Found {index}: {song.name=}")
            tags = read(song)
            columns = "title,track,artist_id,album_id,filesize,duration,filename,rel_path,parent_dir"
            rel_path = str(song).replace(str(parent), "")

            data = [
                tags.title, tags.track,
                Artist.Get(conn, tags.albumartist),
                Album.Get(conn, Artist.Get(conn, tags.albumartist),
                          tags.album), tags.filesize, tags.duration,
                tags.filename, rel_path, parent_id
            ]

            try:
                cursor.execute(
                    f"INSERT INTO Song({columns}) VALUES(?,?,?,?,?,?,?,?,?)",
                    data)
            except sqlite3.IntegrityError:
                print(f"Sus duplicate: {song=}, {tags.title=}, {parent_id=}")
        else:
            print(f"WARNING - {song.name}")

    conn.commit()
    conn.close()
Example #20
0
    def addDatasets(self, platTrack, fileList, nameList, bands):
        # appends a list of 2D or 3D datsets to the geometry group. Can be lat.rdr, lon.rdr, z.rdr, los.rdr, a mask file, etc
        import reader
        if fileList is not None:
            self.h5file = h5py.File(self.output, 'a')

            numDataSets = len(fileList)
            for i in range(numDataSets):
                print('adding ', fileList[i])
                if bands is None:
                    data = reader.read(fileList[i])
                else:
                    data = reader.read(fileList[i], bands=[bands[i]])

                self.h5file['/' + platTrack + '/geometry'].create_dataset(
                    nameList[i], data=data, shape=data.shape, dtype=data.dtype)
            self.h5file.close()
Example #21
0
def readImage(reader):
    imageList = []
    for i in range(28):
        imageRowList = []
        for j in range(28):
            imageRowList.append(reader.read())
        imageList.append(imageRowList)
    return imageList
Example #22
0
def readImageLinear(reader):
    imageList = []
    for i in range(28):
        imageRowList = []
        for j in range(28):
            imageRowList.append(transGrayToBinary(reader.read()))
        imageList.append(imageRowList)
    return imageList
def load():
    global __user_list
    # Read the stored data from the file.
    data = reader.read(DATA_FILE)
    # Deserialize the data from string.
    __user_list = json.loads(data)

    return __user_list
Example #24
0
    def addDatasets(self, platTrack, fileList, nameList, bands):
        # appends a list of 2D or 3D datsets to the geometry group. Can be lat.rdr, lon.rdr, z.rdr, los.rdr, a mask file, etc
        import reader
        if fileList is not None:
            self.h5file = h5py.File(self.output, 'a')

            numDataSets = len(fileList)
            for i in range(numDataSets):
                print('adding ', fileList[i])
                if bands is None:
                    data = reader.read(fileList[i])
                else:
                    data = reader.read(fileList[i], bands=[bands[i]])

                dsg = self.h5file['/'+platTrack+'/geometry'].create_dataset(
                    nameList[i], data=data, shape=data.shape, dtype=data.dtype)
            self.h5file.close()
Example #25
0
    def read(self, family):

        self.get_metadata(family)
        bands_key = self.processor + '-' + family
        if bands_key in bandsDict.keys():
            bands = bandsDict[bands_key]
        else:
            bands = None
        data = reader.read(self.file, self.processor, bands=bands)
        return data, self.metadata
Example #26
0
def main():
    option = input("What do you want to do?"
                   "\t1 for the Hazanot-O-mat"
                   "\t2 for a CSV of all data\n")
    write = {'1': hazanotomat.write, '2': csvfy.write}.get(option) or exit(0)

    write(reader.read())

    report_uuid_errors()
    print("Done")
Example #27
0
def set_layout():
    global df
    df = read()
    return html.Div([
        dcc.Location(id='url', refresh=False, href='/bedas'),
        navbar(),
        dbc.Container(id="content",
                      style={"padding": "20px"},
                      children=[home(df)])
    ])
Example #28
0
def load(dataset="training", data_size=10000):

    # Lamda functins for preprocessing
    imgs = lambda dset : \
        np.array([data[1] for data in dset], dtype='f')
    labels = lambda dset: np.array([data[0] for data in dset])

    dset = list(reader.read(dataset=dataset, data_size=data_size))

    return (imgs(dset), labels(dset))
Example #29
0
def load_variables():
    variables = dict()
    tabs = ['colegiado', 'formacao_complementar', 'bot']
    for tab in tabs:
        data = read(VARIABLES_SHEET, tab)
        for row in data:
            k = row[0]
            value = row[1]
            variables['var_' + k] = value
    return variables
Example #30
0
def main():
    """The main function of this program.
    """
    structure = None
    shape = None
    points = []

    print("Welcome to {0}.".format(basename(__file__)))
    print("=" * 76)
    print_help()

    while True:
        try:
            in_str = input("your command>>>\n").lower().strip()

            if in_str.startswith("quit"):
                print("Bye, bye.")
                return

            elif in_str.startswith("help"):
                print_help()

            elif in_str.startswith("open"):

                filenm, nstrips = in_str.replace("open ", "").split(" into ")
                structure = read(filenm, int(nstrips))
                structure.print_strip_statistics()

            elif in_str.startswith("p") or in_str.startswith(
                    "c") or in_str.startswith("r"):
                if structure is None:
                    print("No points read yet, open a file first!")
                else:
                    shape = parse(in_str)
                    points = structure.query(shape)
                    print_statistics(points)

            # custom dump for testing
            elif in_str.startswith("dump") and shape and structure:
                with open('strips.wkt', "w") as fh:
                    fh.write(structure.dumps_strips())
                with open('points.wkt', "w") as fh:
                    fh.write(structure.dumps_points())
                with open('shape.wkt', "w") as fh:
                    fh.write('shape;\n%s;' % shape)
                with open('result.wkt', "w") as fh:
                    fh.write('points;\n')
                    for p in points:
                        fh.write('%s;\n' % p)
            else:
                print("Input not understood (use 'help')")

        except AssertionError:
            print('Invalid input value!')
Example #31
0
 def test_read(self):
     records = []
     for record in reader.read("test/resources/test_file.json"):
         records.append(record)
     self.assertEqual(len(records), 1)
     record = records[0]
     fields = [key for key in record.keys()]
     fields.sort()
     expected = ["latitude", "longitude", "user_id", "name"]
     expected.sort()
     self.assertListEqual(fields, expected)
Example #32
0
def main():
    #situation
    sit = reader.read(dirname(abspath(__file__))+'/../tools/data/bb.csv') #load data file for historical situation
    #requirement
    dam = BhumibolDam() #simple bhumibol dam requirement
    sim = Simulation(dam,sit,simple_alg) #make simulation with dam requirement, situation, and your chosen algorithm
    result = sim.run(True) #use sim.run() or sim.run(False) to abort when there is an error
    #it also returns the array or struct of bookkeeping result
    #try printing the result[0] to see what each element contain
    fig,ax = sim.plot(sit)
    ax.set_xlim(xmin=datetime.date(2009,01,01))
    plt.show()
def check_locale(path=""):
    global INVALIDS
    path = os.path.normpath(path)
    if ((not path == ".") and path.startswith(".")) or path.startswith("_"):
        return
    print(" " * (len(os.path.split(path)) - 1), "Folder:", path, sep="")
    folders = []
    for item in os.listdir(path):
        npath = os.path.normpath(os.path.join(path, item))
        if item.endswith(".locale"):
            beautiful_path = " " * len(os.path.split(npath)) + npath
            try:
                reader.read(npath)
            except Exception as e:
                print(beautiful_path, "FAIL(%s)" % e)
                INVALIDS += 1
            else:
                print(beautiful_path, "is valid")
        elif os.path.isdir(npath):
            folders.append(npath)
    for folder in folders:
        check_locale(folder)
Example #34
0
def read_and_display():
    csv_data = hreader.read('list.csv')
    header_count = csv_data[0]
    content = csv_data[1]

    elements_printed = 0
    dclr.foreground_paint('Yellow', '')
    for element in content:
        dclr.foreground_paint('Yellow', element)
        elements_printed += 1

        if elements_printed % header_count == 0:
            dclr.foreground_paint('Blue', '----')
Example #35
0
def main():
    corpus = reader.read('hamlet.txt')

    unigrams = generate_ngrams(corpus, 1)
    bigrams = generate_ngrams(corpus, 2)
    trigrams = generate_ngrams(corpus, 3)

    unigram_frequencies = get_corpus_frequencies(unigrams)
    bigram_frequencies = get_corpus_frequencies(bigrams)
    trigram_frequencies = get_corpus_frequencies(trigrams)

    print_most_frequent("unigram", unigram_frequencies, 10)  # 10 most frequent
    print_most_frequent("bigram", bigram_frequencies, 10)
    print_most_frequent("trigram", trigram_frequencies, 10)
Example #36
0
def main():

    # load training data
    data = reader.read("../data/log_1_fixed.txt")
    
    # preprocess 
    preprocess.preproc(data)
    
    # shuffle data
    perm = range(len(data))
    random.shuffle(perm)
    
    # train a network
    ntrain = 100000
    dtrain = la.idxview(data, perm[:ntrain])
    
    net = train(0, dtrain)
    
    # evaluate on training data
    evaluate(dtrain, net)
        
    # evaluate on test data
    devaluate = la.idxview(data, perm[ntrain:2*ntrain])
    evaluate(devaluate, net)
Example #37
0
except ImportError:
    pass  # but not everyone has it
import sys

from reader import read
from expr import global_env

# program start
if __name__ == '__main__':
    """Run a read-eval-print loop.
    `python3 repl.py` to start an interactive REPL.
    `python3 repl.py --read` to interactively read expressions and
      print their Python representations.
    """
    read_only = len(sys.argv) == 2 and sys.argv[1] == '--read'

    while True:
        try:
            # `input` prints the prompt, waits, and returns the user's input.
            user_input = input('> ')
            expr = read(user_input)
            if expr is not None:
                if read_only:
                    print(repr(expr))
                else:
                    print(expr.eval(global_env))
        except (SyntaxError, NameError, TypeError) as err:
            print(type(err).__name__ + ':', err)
        except (KeyboardInterrupt, EOFError):  # Ctrl-C, Ctrl-D
            print()  # blank line
            break  # exit while loop (and end program)
Example #38
0
	features.append(f3)
	f = border_definition(image, outline_mask)
	features.append(f)
	f = radial_gradient_index(image, outline_mask)	
	features.append(f)
	f = tangential_gradient_index(image, outline_mask)
	features.append(f)
#	f = line_enhancement_index(image, outline_mask)
#	features.append(f)

	return features

	
if __name__=='__main__':# A test main function, never used
	import sys
 
	outline_mask = get_outline_mask('(252, 399),(252, 399),(250, 399),(249, 399),(248, 399),(247, 399),(246, 399),(244, 399),(243, 399),(241, 399),(234, 402),(233, 403),(231, 406),(228, 408),(226, 413),(224, 414),(224, 415),(222, 417),(222, 418),(222, 421),(222, 424),(222, 425),(222, 427),(222, 429),(222, 432),(222, 435),(224, 437),(225, 438),(227, 440),(228, 441),(229, 443),(230, 443),(230, 444),(231, 445),(232, 445),(233, 445),(234, 445),(236, 446),(238, 446),(239, 446),(240, 446),(241, 445),(243, 444),(245, 443),(246, 442),(247, 441),(249, 441),(252, 439),(256, 435),(257, 435),(257, 434),(258, 432),(262, 428),(263, 428),(264, 427),(266, 426),(266, 425),(266, 423),(268, 418),(268, 417),(268, 415),(268, 413),(268, 412),(269, 411),(269, 409),(269, 408),(270, 407),(271, 403),(271, 402),(271, 401),(271, 400),(271, 399),(271, 398),(271, 397),(270, 396),(269, 395),(269, 394),(268, 393),(267, 393),(266, 393),(264, 393),(263, 393),(262, 393),(261, 393),(260, 393),(259, 394),(258, 394),(257, 394),(256, 394),(255, 394),(254, 394),(253, 394)', 560, 560)
	#print np.array_equal(img.astype(np.uint8), rasterize(img))
	#val = degree_of_circularity(rasterize(img))
	#val = degree_of_ellipticity(img) 
	#print val
	#fm, rmsv, doi = marginal_irregularity(img)
	#print border_definition(img, img)
	dcm = reader.read("000001.dcm")
	print dcm.shape	
	f = tangential_gradient_index(dcm, outline_mask)
	print f
	
	f = line_enhancement_index(dcm, outline_mask)
	print f
Example #39
0
def ToneBurst():
    global points,lastcanvas,lastcanvas2,values
    data=[]
    for i in range(4):
        t1=Record()
        t2=Play()
        t2.start()
        t1.start()
        while t1.isAlive() or t2.isAlive():
            continue
        data.append(reader.read(RECORDING_FILENAME,AMBIENT_FILENAME))

    t = arange(len(data[2]))*1.0/RATE
    f=Figure(figsize=(6,4),dpi=100)
    a=f.add_subplot(111)

    a.plot(t,data[2])
    a.set_title('Amplitude Waveform')
    a.set_xlabel('Time')
    a.set_ylabel('Amplitude')

    canvas=FigureCanvasTkAgg(f,master=root)
    canvas.show()
    
    if lastcanvas!=None:
        lastcanvas.pack_forget()
    lastcanvas=canvas.get_tk_widget()
    lastcanvas.pack(side=Tk.LEFT, fill=Tk.BOTH, expand=1)

    canvas._tkcanvas.pack(side=Tk.LEFT, fill=Tk.BOTH, expand=1)

    c80=reader.c80(data[2],RATE,TIME)
    c80_string="Clarity(C80) value is "+str(c80)+" dB"
    c80_label.config(text=c80_string)
    
    snd_energy=reader.soundEnergy(data[2],RATE,TIME)
    SS_string="Strength of sound received is "+str(snd_energy)
    SS_label.config(text=SS_string)
    data2=[]
    m=10000000
    for dat in data:
        data2.append(reader.dB(dat,RATE))
        if(len(data2[-1])<m):
            m=len(data2[-1])
    print m, "lalal"
    for i in range(4):
        data2[i]=data2[i][:m]
    mdat=[]
    for j in range(m):
        mdat.append(median([data2[0][j],data2[1][j],data2[2][j],data2[3][j]]))
    t2=arange(m)*1.0/RATE
    f2=Figure(figsize=(6,4),dpi=100)
    a2=f2.add_subplot(111)

    a2.plot(t2,mdat,color='r')
    a2.plot(t2, data2[0],color='g')
    a2.plot(t2, data2[1],color='b')
    a2.plot(t2, data2[2],color='y')
    a2.plot(t2, data2[3],color='k')
    a2.set_title('Sound Pressue Levels')
    a2.set_xlabel('Time')
    a2.set_ylabel('dBu(RMS)')
    
    #try:
    r_time,t_beg,t_end=reader.RT(mdat,RATE,TIME,False)
    RT_string="Reverberation Time (RT20) is "+str(r_time*1000)+" milliseconds. \n(Note:The red interval shows 20dB decay, which is extrapolated over 60dB to get RT)"
    RT_label.config(text=RT_string)
    a2.axvline(TIME/1000., color='k')
    a2.axvline(t_beg, color='r')
    a2.axvline(t_end, color='r')
##    except:
##        RT_string="Reverberation Time could not be measured. Try increasing the volume, or try a Frequency between 250 Hz and 2000 Hz"
##        RT_label.config(text=RT_string)
  
    canvas2=FigureCanvasTkAgg(f2,master=root)
    canvas2.show()
    
    if lastcanvas2!=None:
        lastcanvas2.pack_forget()
    lastcanvas2=canvas2.get_tk_widget()
    lastcanvas2.pack(side=Tk.RIGHT, fill=Tk.BOTH, expand=1)
    canvas2._tkcanvas.pack(side=Tk.RIGHT, fill=Tk.BOTH, expand=1)
    
    values=(r_time,c80,snd_energy)
    
    label.config(text="Please check if all values have been recorded. Measure again?")
    y_button.config(text="Yes")
    n_button.config(command=Prepare,state=Tk.NORMAL)
Example #40
0
import csv
from os.path import dirname
from matplotlib import pyplot as plt
from math import sin,pi
import sys
sys.path.append(dirname(__file__)+'../../natee/')
import reader
import util
fname = 'bb.csv'
data = reader.read(dirname(__file__)+'../data/'+fname)

data = [(x.date,x.water_lvl,x.water_in*50) for x in data]
date,lvl,influx = zip(*data)
period = 365
ur = [sin(2*pi*x/365)*262+13379 for x in range(len(lvl))]#luckily the shift is 0 for bb dam
lr = [(sin(2*pi*x/365)*2.5+237.5)*13462./260. for x in range(len(lvl))]
fig = plt.figure()
ax = fig.add_subplot(111)

ax.plot(range(len(influx)),influx,label = 'incoming water per day scaled up by 50',alpha=0.7,color ='green')
ax.plot(range(len(lvl)),lvl,label = 'water level',lw=2,alpha=0.7,color='red')
ax.plot(range(len(ur)),ur,color='blue',label="upper/lower rule")
ax.plot(range(len(lr)),lr,color='blue')
xticks = range(0,7500,365)
ax.set_xticks(xticks)

xticklabels = [ util.date2td(date[i]) if i < len(date) else '' for i in xticks ]
ax.set_xticklabels(xticklabels,rotation = 45)
locs = ax.get_xticks()
ax.set_title('Water Level in Bhumibol Dam')
ax.set_ylabel('million m^3')
Example #41
0
import sys
sys.path.insert(0, '/home/zack/Desktop')
import reader

path = "/home/zack/Desktop/data/pm15.csv"
data = reader.read(path)
for i in range(len(data)):
    print data[i]
Example #42
0
import random
import proceduralRandom
from reader import read_file as read
import os.path


#The text directory
TEXT_DIR = 'data/'

if not os.path.isfile(TEXT_DIR+'senSubjects'):
    TEXT_DIR = '../'+TEXT_DIR



subjects = read(TEXT_DIR + 'senSubjects').split(',')
verbs = read(TEXT_DIR + 'senVerbs').split(',')
verbsH = read(TEXT_DIR + 'senVerbsH').split(',')
nouns = read(TEXT_DIR + 'senNouns').split(',')
adjectives = read(TEXT_DIR + 'senAdjectives').split(',')
adverbs = read(TEXT_DIR + 'senAdverbs').split(',')

articles = ['the','a']
vowels = ['a','e','i','o','u','y']


def oneOf(theList,minRange = 1):
    return theList[random.randint(minRange - 1,len(theList)-1)]


def adjs():
    repTimes = proceduralRandom.proceduralRandom()
Example #43
0
    with open(path, 'r') as f:
        for line in f:
            yield line.split('\t')

HIERARCHY = dict([(a[1], [a[0]]) for a in db('hierarchy.txt')])


def ancestors(child):
    if child not in HIERARCHY:
        return []
    parents = HIERARCHY[child]
    grand_parents = ancestors(parents[-1])
    if grand_parents == []:
        return parents
    parents = parents + grand_parents
    return parents


def reverse_ancestor(child):
    a = ancestors(child)
    a.reverse()
    return a

if __name__ == '__main__':
    from reader import read

    for doc in read('allCountries.txt'):
        a = ancestors(doc['geonameid'])
        if a != []:
            print doc['name'], a
Example #44
0
from reader import read
from preprocessor import preprocess
from naivebayes import NaiveBayesClassifier
from knn import KNNClassifier
from metrics import calculate_metrics
import sys

if __name__ == '__main__':

  if len(sys.argv) != 2:
    print("Wrong number of arguments. Please specify a classifier. Choose from [naivebayes, knn]")

  else:
    if sys.argv[1] == 'naivebayes' or sys.argv[1] == 'knn':
      annotated_texts = read('blog-gender-dataset.xlsx')

      training_set_len = 0.7 * len(annotated_texts)

      training_set = []
      test_set = []

      for (text,gender) in annotated_texts:
        if 'M' in gender:
          gender = 'M'
        else:
          gender = 'F'
        if len(training_set) < training_set_len:
          training_set.append((preprocess(text), gender))
        else:
          test_set.append((preprocess(text), gender))
Example #45
0
def read(args):
    import reader
    output = reader.read(args[0])
    outfile = os.path.splitext(args[0])[0] + '.json'
    reader.write(output, outfile)
    print 'Completed rolodex file: %s' % outfile
Example #46
0
        nodes = sys.argv[2:]
    else:
        nodes = '127.0.0.1'

    print("nodes", nodes)
    es = Elasticsearch(nodes)

    if es.indices.exists('geoname'):
        es.indices.delete('geoname')

    print es.indices.create(index='geoname', body={
        'mappings': mappings,
        'settings': settings}
    )

    bulk(es, indexer(read(src)))

    es.indices.refresh('geoname')
    # 36m31.860s for 8600414 documents

    print es.indices.stats('geoname')
    #res = es.search(index="geoname", body={"query": {"match_all": {}}})
    #es.search('geoname', {
        #'query': {
            #'filtered': {
                #'filter': {
                    #'term': {'cc': 'FR'}
                #},
                #'query': {
                    #'query_string': {'query': 'Gre%'}
                #}
Example #47
0
            parser.error('invalid --wrap-output value: must be an integer or "no"')

    
    config.defines = {}
    if options.defines != None:
        for define in options.defines:
            d = define.split('=')
            if len(d) == 1:
                config.defines[d[0]] = ''
            else:
                config.defines[d[0]] = '='.join(d[1:])

    import reader, writer
    
    try:
        read_ok = reader.read(args[0])
    finally:
        if xmlparser.cache != None:
            xmlparser.cache.close()
            xmlparser.cache = None

    if not read_ok:
        sys.exit(1)

    if options.dump:
        import mk_dump
        mk_dump.dumpMakefile()
    else: 
        if not writer.write():
            sys.exit(1)