Beispiel #1
0
def delete(update, context):
    chat_id = update.message.chat_id
    number_of_accounts = DataHandler.number_of_accounts(chat_id)

    if number_of_accounts == 0:
        reply(context, chat_id,
              'You don\'t have any registered account(s) to delete')
    elif number_of_accounts == 1:
        DataHandler.delete_user(chat_id)
        lookup_dict.pop(chat_id)
    else:
        try:
            acc_num = int(context.args[0])
            if acc_num > number_of_accounts:
                reply(
                    context, chat_id,
                    "You need to specify right account number as given in /listall"
                )
                return
            current_default = DataHandler.get_default_acc(chat_id)
            id_to_delete = DataHandler.account_id(chat_id, acc_num)
            DataHandler.delete_account(id_to_delete)
            if id_to_delete == current_default:
                DataHandler.upsert_user(chat_id, 1)
                load_account(chat_id, force_reload=True)
                account_info_tuple = DataHandler.account_info(chat_id)
                reply(
                    context, chat_id,
                    'Your current default account is now set to {username} @ {instance}'
                    .format(username=account_info_tuple[0],
                            instance=account_info_tuple[1]))
        except:
            reply(context, chat_id, '`usage:`\n`/delete <number>`')
Beispiel #2
0
class StreamPredict(StreamHandler):
    ''' Predicts on stream '''
    def __init__(self, data_stem, model_name):
        self.model = self.load_model(model_name)
        self.d = DataHandler(data_stem)
        self.d.bandpass(0.1, 2.0)
        self.d.scale()
        super().__init__()

    def load_model(self, model_name):
        # get full filename
        full_name = './models/' + model_name + str(
            len([f for f in os.listdir('./models/') if model_name in f]) -
            1) + '.pickle'
        print("Loading model: ", full_name)
        model = pickle.load(open(full_name, 'rb'))
        print("Model loaded!")
        return model

    def sample(self):
        ''' Pulls a single sample from inlet '''
        # assert(hasattr(self, inlet))
        # logging.debug("SAMPLE: pulling now")
        sample, timestamp = self.inlet.pull_sample()
        self.latest_timestamp = timestamp
        full_sample = [sample, timestamp]
        self.samples.append(full_sample)
        # PREDICT
        self.d.append_sample(full_sample)
        #self.d.y = np.append(self.d.y, None)
        self.d.bandpass(0.1, 2.0)
        self.d.scale()
        pred = self.model.pred(self.d.X[-1])
        print("PREDICTION: ", pred)
        return full_sample
Beispiel #3
0
def format_data(filename, class_ids):
    data = dh.pickDataClass(filename, class_ids)
    number_per_class = data[0].count(class_ids[0])
    test_instances = [31, 41]
    trainX, trainY, testX, testY = dh.splitData2TestTrain(data, number_per_class, test_instances)

    dh.write_2_file(trainX, trainY, testX, testY)
Beispiel #4
0
 def _interpret_slices_(self, item, data=None):
     '''overrides member class function to allow for nRange items'''
     if type(item) in (list, tuple, str):  # i.e. standard
         return DataHandler._interpret_slices_(self, item, data)
     else:
         return DataHandler._interpret_slices_(
             self, self._get_slices_from_nRange_(item), data)
Beispiel #5
0
def setdefault(update, context):
    chat_id = update.message.chat_id
    number_of_accounts = DataHandler.number_of_accounts(chat_id)
    if number_of_accounts == 0:
        reply(context, chat_id,
              'You have not registered any mastodon account yet')
        return
    if number_of_accounts == 1:
        acc = DataHandler.account_info(chat_id)
        reply(
            context, chat_id,
            "Your only registered account is `{}` at `{}`".format(
                acc[0], acc[1]))
        return
    try:
        newDefault = int(context.args[0])
        if newDefault <= number_of_accounts:
            DataHandler.upsert_user(chat_id, newDefault)
            accountObj = load_account(chat_id, force_reload=True)
            reply(
                context, chat_id,
                "Now you can toot to your account `{}` at `{}`".format(
                    accountObj.user, accountObj.instance))
        else:
            reply(
                context, chat_id,
                "You need to specify right account number as given in /listall"
            )
    except:
        reply(context, chat_id, "`/setdefault` <number>")
Beispiel #6
0
 def tick(self):
     self.tick_count += 1
     try:
         tickdata = PriceFetcher.ReportMulti()
         DataHandler.appendData(tickdata, self.worksheet)
     except Exception as e:
         self.stop(exception=e)
Beispiel #7
0
 def __init__(
     self,
     mode,
 ):
     self.workbook = DataHandler.initialize()
     self.worksheet = DataHandler.initializeWS(self.workbook)
     self.tick_count = 0
     self.gave_order = False
Beispiel #8
0
def TrainServer(number):
    import time
    DataHandler.send_email(Email, Password, Recipient, "Training model ",
                           "Dear user your model has started trianing")
    time.sleep(number)
    print("Training done")
    DataHandler.send_email(Email, Password, Recipient, "Training model ",
                           "Dear user your model has finished trianing")
Beispiel #9
0
def get_articles_by_category(category):
  try:
      cur = DataHandler.build_cursor(f"SELECT * FROM Articles WHERE category = %s", (category))  
      return DataHandler.mysql_cursor_to_json(cur)
  except Exception as e:
    print(e)
  finally:
    cur.close() 
Beispiel #10
0
def get_canidate_info(canidate):
  try:
      cur = DataHandler.Build_Cursor(f"SELECT * FROM Canidates WHERE Canidate=%s", (canidate))
      return DataHandler.mysql_cursor_to_json(cur)
  except Exception as eL
    print(e)
  finally:
  cur.close()
Beispiel #11
0
def get_article_by_id(article_id):
  try:
    cur = DataHandler.Build_Cursor(f"SELECT * FROM Articles WHERE ID = %s", (article_id))     
    return DataHandler.mysql_cursor_to_json(cur)
  except Exception as e:
    print(e)
  finally:
    cur.close() 
Beispiel #12
0
 def change_cellref(self, item0, item1=None):
     '''input a range in the form of two ints, two tuples, or a range of cells'''
     if item1 is not None:
         DataHandler.change_cellref(self, item0, item1)
     else:
         start, end = self._interpret_nRange_(item0)
         (self.start_row, self.start_col) = start
         (self.end_row, self.end_col) = end
Beispiel #13
0
 def dataExportSlot(self):
     print 'Exporting . . . '
     filename = QtGui.QFileDialog.getSaveFileName(self,
                                                  'Dialog Title',
                                                  root,
                                                  selectedFilter='*.mat')
     if filename.endsWith('.mat'):
         name = str(self.tableWidgetData.currentItem().text())
         DataHandler.exportAsMat(filename=filename, hdf5name=name)
Beispiel #14
0
    def onOkClickedSlot(self):
	if(self.comboBox.currentText().__str__()=='MAT'):
	    print 'Calling Mat Saver'
	    DataHandler.exportAsMat(self.lineEdit.text().__str__(),self.dataName)
	elif(self.comboBox.currentText().__str__()=='HDF5'):
	    print 'Calling HDF5 Saver'
	    shutil.copyfile(root+'/data/'+self.dataName+'.hdf5',self.lineEdit.text().__str__())
	self.signalRefreshTrigger.emit('\''+self.dataName+'\' has been exported with '+self.comboBox.currentText().__str__()+' format to location \''+self.lineEdit.text().__str__()+'\'')


	self.closedSlot()
Beispiel #15
0
def main(args):
        if len(args) > 1:
                print "Output for %s"%args[1]
                OperationsTable = DH.make_operations(args[1])
                DBMan(OperationsTable).execute()
        else:
                inputFiles = os.listdir("inputs/")
                inputFiles.remove("__init__.py")
                for file in inputFiles:
                        print "Output for %s"%file
                        OperationsTable = DH.make_operations("inputs/%s"%file)
                        DBMan(OperationsTable).execute()
                        print "===========================================\n"
Beispiel #16
0
    def create_item_dictionary(self, click_list):

        self.items = {}

        # if there is only a single click in a session
        if self.number_of_clicks == 1:

            actual_item = click_list[0]['id_item']

            self.items[actual_item] = ItemData(
                click_list[0]['id_item'],
                click_list[0]['category'],
                1,
                SessionData.default_clicktime
            )
            return

        for index in range(0, self.number_of_clicks - 1):
            actual_item = click_list[index]['id_item']

            actual_timestamp = click_list[index]['timestamp']
            next_timestamp = click_list[index + 1]['timestamp']

            actual_time = DataHandler.timestamp_diff(next_timestamp, actual_timestamp)

            # If item does not exist in session, add new item
            if actual_item not in self.items.keys():
                self.items[actual_item] = ItemData(
                    click_list[index]['id_item'],
                    click_list[index]['category'],
                    1,
                    actual_time
                )
            # If item already exists, update its values
            else:
                self.items[actual_item].update_item(1, actual_time)

        # manually one more time for the last indexed item without clicktime
        actual_item = click_list[-1]['id_item']
        actual_time = (DataHandler.timestamp_diff(click_list[0]['timestamp'], click_list[-1]['timestamp'])/(len(click_list)-1))

        if actual_item not in self.items.keys():
            self.items[actual_item] = ItemData(
                actual_item,
                click_list[-1]['category'],
                1,
                actual_time
            )

        else:
            self.items[actual_item].update_item(1, actual_time)
Beispiel #17
0
def deleteall(update, context):
    chat_id = update.message.chat_id
    try:
        assert (context.args[0] == 'yes')
    except:
        reply(
            context, chat_id,
            '`NOTE: delete all registered accounts \nusage:\n/deleteall yes`')
    else:
        DataHandler.delete_user(chat_id)
        try:
            lookup_dict.pop(chat_id)
        except KeyError:
            pass
Beispiel #18
0
def main():
    with requests.Session() as s:
        response = s.post(settings["base_url"] + settings["default_ext"],
                          qt_user)
        error_check(response)
        for count, link in enumerate(settings["links"]):
            file_name = settings["files"][count]
            response = s.get(settings["base_url"] + link)
            error_check(response)
            data = DataHandler.DataHandler().convert(response, link)
            if DataHandler.DataHandler().compare(data, file_name):
                DataHandler.DataHandler().updater(data, file_name)
                DataHandler.DataHandler().data_sender(data, settings["email"],
                                                      settings["key"],
                                                      file_name)
Beispiel #19
0
def main():
    root = tk.Tk()
    root.title("Smog simulation")

    DataHandler.getSmogLevel()

    app = App(root)
    app.pack()

    def onClosing():
        if messagebox.askokcancel("Quit", "Do you want to quit?"):
            exit()

    root.protocol("WM_DELETE_WINDOW", onClosing)
    root.mainloop()
Beispiel #20
0
def main(username, algos):

    userClasses = dict([(name, cls)
                        for name, cls in Algorithms.__dict__.items()
                        if name in Algorithms.usernames])

    countriesData = DataHandler.GetData()

    if username == NO_ARGUMENT:
        createAlgoSelect()
        for username in userClasses:
            usermod = userClasses[username]
            algomod = dict([(name, cls)
                            for name, cls in usermod.__dict__.items()
                            if name in usermod.classNames])
            for algo in algomod:
                runAlgo(username, algo, algomod[algo], countriesData)
    elif username in userClasses:
        usermod = userClasses[username]
        algomod = dict([(name, cls) for name, cls in usermod.__dict__.items()
                        if name in usermod.classNames])
        if algos[0] == NO_ARGUMENT:
            for algo in algomod:
                runAlgo(username, algo, algomod[algo], countriesData)
        else:
            for algo in algos:
                if algo in algomod:
                    runAlgo(username, algo, algomod[algo], countriesData)
                else:
                    print(algo + " algorithm not found!")
    else:
        print(username + " module not found!")
Beispiel #21
0
def load_and_preprocess_data(baseName,dimension, lowerLimit, upperLimit):
    
    data = File.ler('../data/'+baseName+'.txt')
    dh:DataHandler = DataHandler(data, dimension, 60, 20,20)
    X_train, y_train, val_set, val_target, X_test, y_test, arima_train, arima_val, arima_test= dh.redimensiondata(data, dimension, 60, 20,20)

    y = [[]]
    x = np.concatenate( (X_train,X_test) )   

    y = np.matrix( np.concatenate( (np.array(y_train),np.array(y_test)) ))   
    data = np.concatenate((x, y.T), axis=1)
    x, y = Padronizar.dividir(data, dimension, 1)


    # data = Arquivo.ler('../data/projeto base completa.csv')
    # x, y = Padronizar.dividir(data, 4, 1)
    # print("y")
    # print(y[y.columns[0]])
    # minmaxscaler = MinMaxScaler(feature_range=(0,1))
    # dataNX, listMin,  listMax  = Padronizar.normalizarLinear(x, lowerLimit, upperLimit)
    # dataNY, listMinY, listMaxY = Padronizar.normalizarLinear(y, lowerLimit, upperLimit)
    # scalerX,scalerY, dataNormalizadoX, dataNormalizadoY = Padronizar.normalizar(x,y)
    X_train, X_test, y_train, y_test = train_test_split(x, y, train_size = 0.6, test_size  = 0.4)
    X_test, X_val, y_test, y_val = train_test_split(X_test, y_test, train_size = 0.5, test_size  = 0.5)
    
    X_train = addBias(X_train.values)    
    X_val  = addBias(X_val.values)
    X_test  = addBias(X_test.values)
    
    # WE WILL USE ONLY THE FIRST COLUMN 														
    y_train = y_train[y_train.columns[0]].values
    y_test = y_test[y_test.columns[0]].values
    y_val = y_val[y_val.columns[0]].values
    
    return   X_train, y_train, X_val, y_val, X_test, y_test
Beispiel #22
0
def GetBestModel(clamp, lr, ss, n, steps, dx, v0x, vf, obs_t, obs_offset):
    data_handler = dh.DataHandler(10, "optimal_nn.csv", "eval_nn.csv", True, 2)
    T_opt, _, _, x = data_handler.getOptimalSolution(dx, v0x, vf, obs_t,
                                                     obs_offset)
    obs_x = x[13]
    obs_y = x[14]
    best_cost = float('inf')
    best_mu = float('inf') * np.ones(4)
    best_sig = float('inf') * np.ones(4)
    for i in range(n):
        net = wdnn.WaypointDistributionNN(len(x), lr, clamp)
        count = 0

        while count < steps:
            count += 1
            mu, S = net(x)
            mu = mu[0, :]
            S = S[0, :, :]
            sig = np.diag(S)
            wpts = mltnrm(mu, S, ss)
            Cs = []
            C_tot = 0
            for i in range(ss):
                T, T_col = data_handler.Evaluate(dx, v0x, vf, wpts[i, :],
                                                 obs_x, obs_y)
                C = data_handler.GetCost(T_opt, T_col, T)
                Cs += [C / ss]
                C_tot += C
            C_avg = C_tot / ss
            if C_avg < best_cost:
                best_cost = C_avg
                best_mu[:] = mu
                best_sig[:] = sig
            net.update(-np.array(Cs), wpts, np.vstack([x] * ss))
    return best_cost, best_mu, best_sig
Beispiel #23
0
def testGame(envName, verbose=True):
    env = Definitions.makeSeededEnvironment(envName)
    net = Net.Net(env.observation_space, env.action_space)
    net = net.to(Definitions.device)
    policy = PolicyLearner.PolicyLearner(net)
    dataHandler = DataHandler.DataHandler(policy, env)

    sumReward = 0.
    maxReward = -1e9
    nIters = 20
    for i in range(nIters):
        dataHandler.render(episodes=3)

        confidenceMul = i
        policy.setConfidenceMul(confidenceMul)
        for j in range(10):
            reward = dataHandler.generate(episodes=10)
            dataHandler.reset(keepSize=40000)
            dataHandler.train(batchSize=8, useFraction=0.1)
        if verbose:
            print(envName, "   iteration:",
                  str(i + 1) + "/" + str(nIters),
                  "   reward:", reward, "   trained on:",
                  len(dataHandler.inputs), "    confidence multipiler:",
                  confidenceMul)
        sumReward += reward
        maxReward = max(maxReward, reward)
        Definitions.saveModel(net, envName, i + 1, reward)

    avgReward = sumReward / nIters
    if verbose:
        print("%s   Avg: %.2f   Max: %.2f" % (envName, avgReward, maxReward))
        print()
    env.close()
    return avgReward, maxReward
Beispiel #24
0
    def test_generate_inspections_summary(self):
        expect_json = '''
[{
  "日付": "2020-03-20",
  "小計": 67
},
{
  "日付": "2020-03-21",
  "小計": 111
},
{
  "日付": "2020-03-22",
  "小計": 182
},
{
  "日付": "2020-03-23",
  "小計": 205
}]
'''.strip()
        null_data = self.__generate_null_data(datetime.datetime(2020, 3, 24))
        expect = json.loads(expect_json)
        expect.extend(null_data)

        dh = handler.DataHandler(
            patients_csvfile=self.patients_csvfile,
            data_summary_csvfile=self.data_summary_csvfile,
            total_sickbeds=TOTAL_SICKBEDS)
        result = dh.generate_inspections_summary()

        self.assertListEqual(result, expect)
Beispiel #25
0
    def test_generate_main_summary(self):
        expect_json = '''
{
  "attr": "累計",
  "value": 19,
  "children": [
      {
        "attr": "入院中",
        "value": 18
      },
      {
        "attr": "死亡",
        "value": 0
      },
      {
        "attr": "退院",
        "value": 1
      }
  ]
}
'''.strip()

        dh = handler.DataHandler(
            patients_csvfile=self.patients_csvfile,
            data_summary_csvfile=self.data_summary_csvfile)
        result = dh.generate_main_summary()
        expect = json.loads(expect_json)
        expect["date"] = self.datetime_now_str

        self.assertDictEqual(result, expect)
Beispiel #26
0
     def __init__(self, **kwargs):
         super().__init__(**kwargs)
         self.cols = 2
         self.add_widget(Label(text="Company Name:", font_size=30))
         self.Ticker = TextInput(multiline=False, font_size=30)
         self.add_widget(self.Ticker)
 
         self.add_widget(Label(text="Start Refrence (yyyy-mm-dd):", font_size=30))
         self.Start = TextInput(multiline=False, font_size=30)
         self.add_widget(self.Start)
         
         self.add_widget(Label(text="Stop Refrence(yyyy-mm-dd):", font_size=30))
         self.Stop = TextInput(multiline=False, font_size=30)
         self.add_widget(self.Stop)
         
         self.Predict = Button(text="Predict", font_size=30)
         self.Predict.bind(on_release=self.PredictButton)
         self.add_widget(self.Predict)
         
         self.Updates = Button(text="Version Information", font_size=30)
         self.Updates.bind(on_press=self.InfoPopup)
         self.add_widget(self.Updates)
         
         self.OutputPrediction = Label(text="Decision", font_size=30)
         self.add_widget(self.OutputPrediction)
         
         self.Probability = Label(text="Probability", font_size=30)
         self.add_widget(self.Probability)
         try:
             self.DH = DataHandler.BuySellHandler()
             self.Predictor = Model.StockPredictingModel((window_size,7))
             self.Predictor.Load()
         except:
             raise AssertionError("Load Failed")
Beispiel #27
0
    def test_generate_querents(self):
        expect_json = '''
[
  {
    "日付": "2020-03-20",
    "小計": 100
  },
  {
    "日付": "2020-03-21",
    "小計": 117
  },
  {
    "日付": "2020-03-22",
    "小計": 99
  },
  {
    "日付": "2020-03-23",
    "小計": 311
  }
]
'''.strip()

        expect = json.loads(expect_json)

        dh = handler.DataHandler(
            patients_csvfile=self.patients_csvfile,
            data_summary_csvfile=self.data_summary_csvfile)
        result = dh.generate_querents()

        self.assertListEqual(result, expect)
Beispiel #28
0
    def test_generate_patients_summary_by_date(self):

        expect_json = '''
[{
  "日付": "2020-03-17",
  "小計": 1
},
{
  "日付": "2020-03-18",
  "小計": 0
},
{
  "日付": "2020-03-19",
  "小計": 2
},
{
  "日付": "2020-03-20",
  "小計": 3
}]
'''.strip()
        # テストデータのため2020-03-21から本日までの日付のデータを作成する
        null_data = self.__generate_null_data(datetime.datetime(2020, 3, 21))
        expect = json.loads(expect_json)
        expect.extend(null_data)

        dh = handler.DataHandler(
            patients_csvfile=self.patients_csvfile,
            data_summary_csvfile=self.data_summary_csvfile)
        result = dh.generate_patients_summary_by_date()

        self.assertListEqual(result, expect)
Beispiel #29
0
    def __init__(self,
                 size_v,
                 size_h,
                 filters_no,
                 conv_kernel,
                 typeB='scalar',
                 typeC='matrix'):
        """
        :param size_v: vertical size of input image
        :param size_h: horizontal size of input image
        :param filters_no: how many feature maps
        :param conv_kernel: size of convolutional kernel (tuple)
        :param typeB: scalar or matrix version of feature map biases?
        :param typeC: scalar or matrix version of visible layer bias?
        """
        # RBM parameters
        self.insize_v = size_v
        self.insize_h = size_h
        self.filters_no = filters_no
        self.conv_kernel = conv_kernel
        # neurons, weigths and biases
        self.v = np.ndarray((size_v, size_h), dtype=np.float32)  # int32?
        self.h = [
            np.ndarray(
                (size_v - conv_kernel[0] + 1, size_h - conv_kernel[1] + 1),
                dtype=np.int8) for i in range(filters_no)
        ]
        self.W = [
            np.random.normal(0, 0.01, conv_kernel) for i in range(filters_no)
        ]

        if typeB not in ('scalar', 'matrix') or typeC not in ('scalar',
                                                              'matrix'):
            raise ValueError(
                'Wrong input arguments. typeB and typeC must be either \'scalar\' or \'matrix\''
            )
        self.typeB = typeB
        self.typeC = typeC

        if self.typeB == 'scalar':
            self.b = [np.random.normal(0, 0.01) for i in range(filters_no)]
        else:
            self.b = [
                np.random.normal(
                    0, 0.01,
                    (size_v - conv_kernel[0] + 1, size_h - conv_kernel[1] + 1))
                for i in range(filters_no)
            ]

        if self.typeC == 'scalar':
            self.c = np.random.normal(0, 0.01)
        else:
            self.c = np.random.normal(0, 0.01, (size_v, size_h))

        self.dh = DataHandler.DataHandler()
        self.imgInfo = None

        self.iterations = 0
        self.mse = []
        logger.info('Created CCRBM. {}'.format(self))
Beispiel #30
0
def init(inFile, outFile):
    global MPIFX3, MPIHandler, MPIProcessor
    global dev, handler, processor
    MPIFX3 = mp.Queue()
    MPIHandler = mp.Queue()
    MPIProcessor = mp.Queue()

    dev = FX3.Emulator(MPIFX3, inFile)
    pipe = dev.getPipe()
    buffSize = dev.getBufferSize()

    handler = DataHandler.DataHandler(MPIHandler,
                                      pipe,
                                      buffSize,
                                      filename=outFile)
    realtime = handler.getRealtimeQueue()
    handler.enableRealtime()

    processor = DataProcessor.DataProcessor(MPIProcessor,
                                            realtime, [[0, 2], [3, 3]],
                                            legacy=False,
                                            fs=2.5E6,
                                            bufferSize=buffSize,
                                            calcFlow=True,
                                            numProcessors=2)
Beispiel #31
0
    def pushButtonOkClicked(self):
        if self.lineEditData.text()=='' or self.lineEditFolderData.text()=='':
            QtGui.QMessageBox.about(self,'Incomplete Conversion','Data Left Out\nCheck Form again')
        #For TEXT option
        if(self.comboBox.currentIndex()==0 and str(self.lineEditData.text())!='' and self.lineEditFolderData.text()!=''):

            if(os.path.exists(self.lineEditFolderData.text()+'/test.txt')==0):
                QtGui.QMessageBox.about(self,'File Not Found',self.lineEditFolderData.text()+'/test.txt\n Does not Exist')
                return
            DataHandler.text2HDF5(str(self.lineEditData.text()), self.lineEditFolderData.text()+'/test.txt',self.root+'/Data',hasLabel=self.checkbox.isChecked())
            return
        #Jaley End

        if(self.comboBox.currentIndex()==2 and str(self.lineEditData.text())!='' and self.lineEditFolderData.text()!=''):
            if(os.path.exists(self.lineEditFolderData.text()+'/test.mat')==0):
                QtGui.QMessageBox.about(self,'File Not Found',self.lineEditFolderData.text()+'/test.mat\n Does not Exist')
                return
            DataHandler.mat2HDF5(str(self.lineEditData.text()), self.lineEditFolderData.text()+'/test.mat',self.root+'/Data',hasLabel=self.checkbox.isChecked())
            return

        if(self.comboBox.currentIndex()==1 and str(self.lineEditData.text())!='' and self.lineEditFolderData.text()!=''):
            if(os.path.exists(self.lineEditFolderData.text()+'/test_leveldb')==0):
                QtGui.QMessageBox.about(self,'File Not Found',self.lineEditFolderData.text()+'/test_leveldb\n Does not Exist')
                return
            DataHandler.leveldb2HDF5(str(self.lineEditData.text()), self.lineEditFolderData.text()+'/test_leveldb',self.root+'/Data',hasLabel=self.checkbox.isChecked())
            return
def clustersgte10():
    # clusters with 10 or more measurements
    clusters_gte10 = set([i for i in clusters if clusters.count(i) >= 10])
    mvir_out,mvir_p_out,mvir_m_out,cvir_out,cvir_p_out,cvir_m_out = ([],[],[],[],[],[])
    z_out,methods_out = ([],[])
    for i in clusters_gte10:
        tmp_mvir,tmp_mvir_p,tmp_mvir_m,tmp_cvir,tmp_cvir_p,tmp_cvir_m = ([],[],[],[],[],[])
        tmp_z,tmp_methods = ([],[])
        for j in range(len(clusters)):
            if clusters[j] == i:
                if math.isnan(float(mvir[j])) or math.isnan(float(cvir[j])):
                    continue
                else:
                    tmp_mvir.append(mvir[j])
                    tmp_mvir_p.append(mvir_plus[j])
                    tmp_mvir_m.append(mvir_minus[j])
                    tmp_cvir.append(cvir[j])
                    tmp_cvir_p.append(cvir_plus[j])
                    tmp_cvir_m.append(cvir_minus[j])
                    tmp_z.append(redshift[j])
                    tmp_methods.append(methods[j])
        mvir_out.append(tmp_mvir)
        mvir_p_out.append(tmp_mvir_p)
        mvir_m_out.append(tmp_mvir_m)
        cvir_out.append(tmp_cvir)
        cvir_p_out.append(tmp_cvir_p)
        cvir_m_out.append(tmp_cvir_m)
        z_out.append(tmp_z)
        methods_out.append(tmp_methods)
    
    nplots = len(clusters_gte10) # subplots do not auto-update; need to do manually
    f, axes = plt.subplots(nrows=2, ncols=2, sharex=True, sharey=True)
    f.set_size_inches(7,7,forward=True)
    # loop structure only works for 3 clusters in a 2x2 grid format
    for i,j in enumerate(clusters_gte10):
        if i <= 1:
            axes[0][i].set_xlim(1e14,2e16)
            axes[0][i].set_ylim(1,30)
            axes[0][i].text(3e14,1.5,'{}'.format(j))
            axes[0][i].text(3e14,1.25,'z={}'.format(z_out[i][0]))
            axes[0][i].set_xscale('log')
            axes[0][i].set_yscale('log')
        else:
            axes[1][0].set_xlim(1e14,2e16)
            axes[1][0].set_ylim(1,30)
            axes[1][0].text(3e14,1.5,'{}'.format(j))
            axes[1][0].text(3e14,1.25,'z={}'.format(z_out[i][0]))
            axes[1][0].set_xscale('log')
            axes[1][0].set_yscale('log')
        print j
        for k in range(len(mvir_out[i])):
            print "Measurement number {}".format(k+1)
            flag = DH.scatter_flag(k,mvir_out[i],mvir_p_out[i],mvir_m_out[i],
                                   cvir_out[i],cvir_p_out[i],cvir_m_out[i])
            col = DH.colorselect(methods_out[i][k])
            if i <= 1:
                DH.plotwithflag(axes[0][i],flag,col,mvir_out[i][k]*1e14,mvir_p_out[i][k]*1e14,mvir_m_out[i][k]*1e14,
                                cvir_out[i][k],cvir_p_out[i][k],cvir_m_out[i][k],z_out[i][k],witherrors=True)
            else:
                DH.plotwithflag(axes[1][0],flag,col,mvir_out[i][k]*1e14,mvir_p_out[i][k]*1e14,mvir_m_out[i][k]*1e14,
                                cvir_out[i][k],cvir_p_out[i][k],cvir_m_out[i][k],z_out[i][k],witherrors=True)

    axes[1][1].scatter(1e6,1e6,color=DH.colorselect('X-ray'),label='X-ray')
    axes[1][1].scatter(1e6,1e6,color=DH.colorselect('WL'),label='WL')
    axes[1][1].scatter(1e6,1e6,color=DH.colorselect('SL'),label='SL')
    axes[1][1].scatter(1e6,1e6,color=DH.colorselect('WL+SL'),label='WL+SL')
    axes[1][1].scatter(1e6,1e6,color=DH.colorselect('CM'),label='CM')
    axes[1][1].scatter(1e6,1e6,color=DH.colorselect('LOSVD'),label='LOSVD')
    axes[1][1].set_xlim(1e14,2e16)
    axes[1][1].set_ylim(1,30)

    # over-plot cm relations
    # CO07_1
    mlistCO07_1_1689,clistCO07_1_1689,zCO07_1_1689 = DH.cmrelation_co07_1(1e14,2e16,z_out[0][0])
    mlistCO07_1_p_1689,clistCO07_1_p_1689,zCO07_1_1689 = DH.cmrelation_co07_1(1e14,2e16,z_out[0][0],c0=20.9,alpha=-0.02)
    mlistCO07_1_m_1689,clistCO07_1_m_1689,zCO07_1_1689 = DH.cmrelation_co07_1(1e14,2e16,z_out[0][0],c0=8.7,alpha=-0.26)
    mlistCO07_1_2137,clistCO07_1_2137,zCO07_1_2137 = DH.cmrelation_co07_1(1e14,2e16,z_out[1][0])
    mlistCO07_1_p_2137,clistCO07_1_p_2137,zCO07_1_2137 = DH.cmrelation_co07_1(1e14,2e16,z_out[1][0],c0=20.9,alpha=-0.02)
    mlistCO07_1_m_2137,clistCO07_1_m_2137,zCO07_1_2137 = DH.cmrelation_co07_1(1e14,2e16,z_out[1][0],c0=8.7,alpha=-0.26)
    mlistCO07_1_1835,clistCO07_1_1835,zCO07_1_1835 = DH.cmrelation_co07_1(1e14,2e16,z_out[2][0])
    mlistCO07_1_p_1835,clistCO07_1_p_1835,zCO07_1_1835 = DH.cmrelation_co07_1(1e14,2e16,z_out[2][0],c0=20.9,alpha=-0.02)
    mlistCO07_1_m_1835,clistCO07_1_m_1835,zCO07_1_1835 = DH.cmrelation_co07_1(1e14,2e16,z_out[2][0],c0=8.7,alpha=-0.26)
    # GR14_1
    mlistGR14_1_1689,clistGR14_1_1689,zGR14_1_1689 = DH.cmrelation_gr14_1(1e14,2e16,z_out[0][0])
    mlistGR14_1_p_1689,clistGR14_1_p_1689,zGR14_1_1689 = DH.cmrelation_gr14_1(1e14,2e16,z_out[0][0],c0=4.797,alpha=-0.049)
    mlistGR14_1_m_1689,clistGR14_1_m_1689,zGR14_1_1689 = DH.cmrelation_gr14_1(1e14,2e16,z_out[0][0],c0=4.753,alpha=-0.063)
    mlistGR14_1_2137,clistGR14_1_2137,zGR14_1_2137 = DH.cmrelation_gr14_1(1e14,2e16,z_out[1][0])
    mlistGR14_1_p_2137,clistGR14_1_p_2137,zGR14_1_2137 = DH.cmrelation_gr14_1(1e14,2e16,z_out[1][0],c0=4.797,alpha=-0.049)
    mlistGR14_1_m_2137,clistGR14_1_m_2137,zGR14_1_2137 = DH.cmrelation_gr14_1(1e14,2e16,z_out[1][0],c0=4.753,alpha=-0.063)
    mlistGR14_1_1835,clistGR14_1_1835,zGR14_1_1835 = DH.cmrelation_gr14_1(1e14,2e16,z_out[2][0])
    mlistGR14_1_p_1835,clistGR14_1_p_1835,zGR14_1_1835 = DH.cmrelation_gr14_1(1e14,2e16,z_out[2][0],c0=4.797,alpha=-0.049)
    mlistGR14_1_m_1835,clistGR14_1_m_1835,zGR14_1_1835 = DH.cmrelation_gr14_1(1e14,2e16,z_out[2][0],c0=4.753,alpha=-0.063)
    # BU01_1
    mlistBU01_1_1689,clistBU01_1_1689,zBU01_1_1689 = DH.cmrelation_bu01_1(1e14,2e16,z_out[0][0])
    mlistBU01_1_2137,clistBU01_1_2137,zBU01_1_2137 = DH.cmrelation_bu01_1(1e14,2e16,z_out[1][0])
    mlistBU01_1_1835,clistBU01_1_1835,zBU01_1_1835 = DH.cmrelation_bu01_1(1e14,2e16,z_out[2][0])
    # HE07_1
    mlistHE07_1_1689,clistHE07_1_1689,zHE07_1_1689 = DH.cmrelation_he07_1(1e14,2e16,z_out[0][0])
    mlistHE07_1_2137,clistHE07_1_2137,zHE07_1_2137 = DH.cmrelation_he07_1(1e14,2e16,z_out[1][0])
    mlistHE07_1_1835,clistHE07_1_1835,zHE07_1_1835 = DH.cmrelation_he07_1(1e14,2e16,z_out[2][0])
    # PR11_1
    #mlistPR11_1_1689,clistPR11_1_1689,zPR11_1_1689 = DH.cmrelation_pr11_1(1e14,2e16,z_out[0][0])
    #mlistPR11_1_2137,clistPR11_1_2137,zPR11_1_2137 = DH.cmrelation_pr11_1(1e14,2e16,z_out[1][0])
    #mlistPR11_1_1835,clistPR11_1_1835,zPR11_1_1835 = DH.cmrelation_pr11_1(1e14,2e16,z_out[2][0])

    # Abell 1689
    axes[0][0].plot(mlistCO07_1_1689,clistCO07_1_1689,color='b',linewidth=2,linestyle='--')
    #axes[0][0].plot(mlistBU01_1_1689,clistBU01_1_1689,color='y',linewidth=2,linestyle='--')
    #axes[0][0].plot(mlistHE07_1_1689,clistHE07_1_1689,color='orange',linewidth=2,linestyle='--')
    axes[0][0].plot(mlistGR14_1_1689,clistGR14_1_1689,color='green',linewidth=2,linestyle='--')
    #axes[0][0].plot(mlistPR11_1_1689,clistPR11_1_1689,color='green',linewidth=2,linestyle='--')
    axes[0][0].fill_between(mlistCO07_1_1689,clistCO07_1_p_1689,clistCO07_1_m_1689,alpha=0.25,color='blue')
    axes[0][0].fill_between(mlistGR14_1_1689,clistGR14_1_p_1689,clistGR14_1_m_1689,alpha=0.25,color='green')
    # MS 2137
    axes[0][1].plot(mlistCO07_1_2137,clistCO07_1_2137,color='b',linewidth=2,linestyle='--')
    #axes[0][1].plot(mlistBU01_1_2137,clistBU01_1_2137,color='y',linewidth=2,linestyle='--')
    #axes[0][1].plot(mlistHE07_1_2137,clistHE07_1_2137,color='orange',linewidth=2,linestyle='--')
    axes[0][1].plot(mlistGR14_1_2137,clistGR14_1_2137,color='green',linewidth=2,linestyle='--')
    #axes[0][1].plot(mlistPR11_1_2137,clistPR11_1_2137,color='green',linewidth=2,linestyle='--')
    axes[0][1].fill_between(mlistCO07_1_2137,clistCO07_1_p_2137,clistCO07_1_m_2137,alpha=0.25,color='blue')
    axes[0][1].fill_between(mlistGR14_1_2137,clistGR14_1_p_2137,clistGR14_1_m_2137,alpha=0.25,color='green')
    # Abell 1835
    axes[1][0].plot(mlistCO07_1_1835,clistCO07_1_1835,color='b',linewidth=2,linestyle='--')
    #axes[1][0].plot(mlistBU01_1_1835,clistBU01_1_1835,color='y',linewidth=2,linestyle='--')
    #axes[1][0].plot(mlistHE07_1_1835,clistHE07_1_1835,color='orange',linewidth=2,linestyle='--')
    axes[1][0].plot(mlistGR14_1_1835,clistGR14_1_1835,color='green',linewidth=2,linestyle='--')
    #axes[1][0].plot(mlistPR11_1_1835,clistPR11_1_1835,color='green',linewidth=2,linestyle='--')
    axes[1][0].fill_between(mlistCO07_1_1835,clistCO07_1_p_1835,clistCO07_1_m_1835,alpha=0.25,color='blue')
    axes[1][0].fill_between(mlistGR14_1_1835,clistGR14_1_p_1835,clistGR14_1_m_1835,alpha=0.25,color='green')

    axes[1][1].plot(1e6,1e6,color='b',linewidth=2,linestyle='--',label='CO07')
    #axes[1][1].plot(1e6,1e6,color='y',linewidth=2,linestyle='--',label='BU01')
    #axes[1][1].plot(1e6,1e6,color='orange',linewidth=2,linestyle='--',label='HE07')
    axes[1][1].plot(1e6,1e6,color='green',linewidth=2,linestyle='--',label='GR14')
    #axes[1][1].plot(1e6,1e6,color='green',linewidth=2,linestyle='--',label='PR11')
    axes[1][1].set_xscale('log')
    axes[1][1].set_yscale('log')

    f.subplots_adjust(hspace=0)
    f.subplots_adjust(wspace=0)
    f.text(0.5, 0.04, r'$\mathrm{M_{vir} (M_{\odot})}$', ha='center', va='center', fontsize=18)
    f.text(0.06, 0.5, r'$\mathrm{c_{vir} (1+z)}$', ha='center', va='center', rotation='vertical', fontsize=18)

    plt.legend(loc=0,scatterpoints=1,frameon=False)
    plt.show()
Beispiel #33
0
    def dataExportSlot(self):
	print 'Exporting . . . '
	filename = QtGui.QFileDialog.getSaveFileName(self, 'Dialog Title',root, selectedFilter='*.mat')
	if filename.endsWith('.mat'):
	    name=str(self.tableWidgetData.currentItem().text())
	    DataHandler.exportAsMat(filename=filename,hdf5name=name)
Beispiel #34
0
start_test_list = [330, 45, 45, 75, 60, 80, 50, 45, 45, 45, 45]

#indices = ['^NSEI', '^DJI', '^FTSE', '^AXJO', '^HSI', '^N225', '^IXIC']#, '000001.SS']
#market_name = ['nse', 'dji', 'ftse', 'aus', 'hsi', 'nikkei', 'nasdaq']#, 'sanghai']

indices = ['^NSEI', '^BSESN', '^AXJO', '^HSI', '^N225']#, '000001.SS']
market_name = ['nse', 'bse', 'aus', 'hsi', 'nikkei']#, 'sanghai']



if __name__ == '__main__':
    final_result=''
    for start_date,e,s in zip(start_date_list, end_date_list, start_test_list):
        end_date, start_test = get_date(start_date, e,s)

        d = DataHandler()
        data_frames = d.fetch_and_save_data(indices, market_name, start_date, end_date)

        # plot([data_frames[0]], 'Adj Close', market_name[0])

        for data_frame in data_frames:
            d.daily_return(data_frame)

        # for index, data_frame in zip(range(len(data_frames)), data_frames):
        #     plot([d.daily_return(data_frame)], 'Daily Return', market_name[index].upper()+' Index')

        # print(data_frames[0].head(5))

        #d.plot_data([data_frames[0],data_frames[7]], ['Daily Return'], market_names=market_name)
        #plt.show()