def get_user_data(forwarded_message): user = forwarded_message.forward_from.id a = bot.get_chat_member(python_uz, user) if a.status == 'left': return False data = tools.get_info(user) try: ban_info = json.loads( f.open('./restricted/user_{}.json'.format(user), 'r').read())['times'] except: ban_info = 0 result = get_string('user_info') rest = is_restricted(python_uz, user) rest_date = get_string('user_info_date').format( get_restrict_time(python_uz, user)) if rest else '' rest = '{} {}'.format(get_string('yes'), rest_date) if rest else get_string('no') certified = get_string('yes') if data.cert else get_string('no') limit = data.limit if data.limit else '0' score = data.score if data.score else '0' result = result.format( rest, ban_info, certified, get_string('user_info_scores').format(score, limit) if data.cert else '') return result
def _process_tif_images(dir_path): tif_warning = QtGui.QMessageBox.warning( self, 'Warning!', '".tif" file chosen. The image sequence must first be loaded and ' + 'converted. This may take a few minutes. Do you wish to proceed?', QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) if tif_warning == QtGui.QMessageBox.Yes: self.info.setText('Processing .tif files.<br>Please wait.') self.mraw_path, self.cih_path = tools._tiff_to_temporary_file( self.dir_path) self.info_dict = tools.get_info(self.cih_path)
def course_query(self, name): name = urllib.parse.quote(name) data1['c0-e10'] = f'string:%25{name}%25' data1['c0-e1'] = f'string:{self.username}' r = self.session.post(self.query_url, data=data1).text info = get_info(r) for key, _ in data2.items(): if key in info: data2[key] = info[key] if key in ['c0-e1', 'c0-e11']: data2[key] = f'string:{self.username}' return info
def open_file(self): ''' Opens the selected folder and checks for image data. If found, displays a preview. ''' #self.load_settings(configfile=(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'settings.ini'))) self.update_settings( ) # Use user-defined settings instead of default ones self.naprejButton.setEnabled(False) self.imw.setImage(np.zeros((100, 100))) selected_path = QtGui.QFileDialog.getOpenFileName( self, 'Select path to .cih or .tif file.', self.dir_path, filter=("cih (*.cih);; tiff (*.tif)"))[0] self.dir_path = os.path.dirname(selected_path) self.save_path = self.dir_path + '/DIC_results/' self.savepathLineEdit.setText(self.save_path) #self.update_save_path() file_extension = selected_path.split('.')[-1].lower() def _process_tif_images(dir_path): tif_warning = QtGui.QMessageBox.warning( self, 'Warning!', '".tif" file chosen. The image sequence must first be loaded and ' + 'converted. This may take a few minutes. Do you wish to proceed?', QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) if tif_warning == QtGui.QMessageBox.Yes: self.info.setText('Processing .tif files.<br>Please wait.') self.mraw_path, self.cih_path = tools._tiff_to_temporary_file( self.dir_path) self.info_dict = tools.get_info(self.cih_path) def _incorrect_filetype_warning(): type_warning = QtGui.QMessageBox.warning( self, 'Warning!', 'Invalid file type selected. pyDIC currently only supports .mraw and .tif. ' + 'Please select a valid file') error = 0 # Initialize possible file type error variable. if not selected_path: error = 1 if file_extension == 'cih': self.cih_path = selected_path self.info_dict = tools.get_info(self.cih_path) self.image_type = self.info_dict['File Format'].lower() if self.image_type == 'mraw': self.mraw_path = self.cih_path[:-4] + '.mraw' elif self.image_type in ['tif', 'tiff']: _process_tif_images(self.dir_path) else: _incorrect_filetype_warning() error = 1 elif file_extension in ['tif', 'tiff']: self.image_type = 'tif' _process_tif_images(self.dir_path) if not error: self.show_sequence(self.mraw_path, nmax=100)
def test_callback(call): user = call.from_user.id cid = call.message.chat.id if call.data.startswith('done_'): dat = call.data.replace('done_', '', 1).split('|') uid = int(dat[0]) http = dat[1] if user == uid: bot.answer_callback_query( call.id, text=get_string('new_member_rules_prepare'), url="https://t.me/{}?start=rules_{}".format(botlink, http), show_alert=True) bot.delete_message(call.message.chat.id, call.message.message_id) else: bot.answer_callback_query( call.id, text=get_string('new_member_rules_taken_by_wrong_user'), show_alert=True) if call.data.startswith('info_'): path = call.data.replace('info_', '', 1) data = json.loads( f.open('./codes/{}_code.json'.format(path), 'r').read()) info = splitter(data['stats']) bot.answer_callback_query(callback_query_id=call.id, text=info, show_alert=True) if call.data.startswith('test_'): data = call.data.replace('test_', '', 1).split('_') ind = int(data[0]) + 1 answer = data[1] score = int(data[2]) scores = { '6': [3, 'E'], '7': [4, 'D'], '8': [5, 'C'], '9': [6, 'B'], '10': [7, 'A'] } if answer == 'True': score += 1 if ind == 11: if score >= 6: user_data = tools.get_info(user) data = json.loads( f.open('./user/{}/status.json'.format(user), 'r').read()) data['score'] = score if user_data.cert: data['limit'] = user_data.limit else: data['limit'] = scores[str(score)][0] data['date'] = datetime.now().strftime('%Y-%m-%d') number = "#{}{}".format(scores[str(score)][1], str(user)[-5:]) data['cert'] = number f.open('./user/{}/status.json'.format(user), 'w').write(json.dumps(data)) bot.edit_message_text( chat_id=cid, message_id=call.message.message_id, text=get_string('get_cert_completed_success').format( scores[str(score)][1], scores[str(score)][0])) try: data = json.loads( f.open('./certificates/users.json', 'r').read()) except: f.open('./certificates/users.json', 'w').write('{"all": []}') data = json.loads( f.open('./certificates/users.json', 'r').read()) data['all'].append(user) f.open('./certificates/users.json', 'w').write(json.dumps(data)) else: bot.edit_message_text( chat_id=cid, message_id=call.message.message_id, text=get_string('get_cert_completed_fail').format(score)) else: k = tools.btn_maker(ind, score) bot.edit_message_text(chat_id=cid, message_id=call.message.message_id, text="<b>{}-savol</b>\n{}".format( ind, tools.questions[str(ind)]['question']), parse_mode='html', reply_markup=k) if call.data.startswith('cert_'): uid = int(call.data.replace('cert_', '', 1)) if user == uid: bot.delete_message(cid, call.message.message_id) bot.answer_callback_query( call.id, url='https://t.me/{}?start=start_test'.format(botlink)) else: bot.answer_callback_query( call.id, text=get_string("get_cert_button_taken_by_wrong_user"), show_alert=True) if call.data.startswith('booknextpage_'): page_number = int(call.data.split('_')[1]) books = book.start() mark = book.books_in_keyboards(all_books=books, go=True, page_number=page_number) bot.edit_message_text(chat_id=cid, message_id=call.message.message_id, text=get_string('book_choose'), reply_markup=mark) if call.data.startswith('bookbackpage_'): page_number = int(call.data.split('_')[1]) books = book.start() mark = book.books_in_keyboards(all_books=books, back=True, page_number=page_number) bot.edit_message_text(chat_id=cid, message_id=call.message.message_id, text=get_string('book_choose'), reply_markup=mark)
import tools import spectral import matplotlib.pyplot as plt import numpy as np HICO_original, HICO_noisy, hico_wl, seawater_Rs = tools.get_info('data/HICO.mat') # kmeans(image, nclusters=10, max_iterations=20, **kwargs) # m = class_map, MxN array, values are indices of the cluster for the corresponding element in image # c = an n_clusters x B array of cluster centers (m, c) = spectral.kmeans(HICO_original, 10, 30) fig, (im, spectral_mes) = plt.subplots(ncols=2) im.set_title('k-means clustering results') im.imshow(m) xs = np.linspace(0.400, 1.000, 100) plt.title('k-means cluster centers') for k in range(c.shape[0]): spectral_mes.plot(xs, c[k]) plt.xlim(0.400, 1.000) fig1 = plt.gcf() plt.show() plt.draw() fig1.savefig('task_2a_k10_i30.png') plt.clf() # close the figure window