def train(self, text, w): assert 2 * w + 1 == len(self.skew) # starting frame: center can be accessed via frame[0] + w frame = (-w, w) tlen = len(text) for i in range(0, tlen): self.update_net(frame, text) frame = (frame[0] + 1, frame[1] + 1) progress = (i + 0.) / tlen progressbar.update_progress(progress)
def greedyinit(self, ): # pass np.random.shuffle(self.bd) # flags = np.zeros(self.N, dtype=np.bool) # all False # choices = np.arange(self.N) reached = False self.threshold = 100 print("greedy initialization") for i in range(self.N): if self.with_progressbar_when_initializing: update_progress(i / self.N) if not reached: if self.dp[self.N - self.bd[i] + i] == 0 and self.dn[self.bd[i] + i + 1] == 0: self.dp[self.N - self.bd[i] + i] += 1 self.dn[self.bd[i] + i + 1] += 1 else: foundit = False for j in range(self.threshold): # print("i = {}, self.N = {}".format(i,self.N)) tmp = np.random.randint(i, self.N) if self.dp[self.N - tmp + i] == 0 and self.dn[tmp + i + 1] == 0: self.bd[i], self.bd[tmp] = self.bd[tmp], self.bd[i] self.dp[self.N - self.bd[i] + i] += 1 self.dn[self.bd[i] + i + 1] += 1 foundit = True break if j == self.threshold - 1: # print("sldjflsjfas;djf;lsdfj;alskdjfsa;djfs;aokfsalkdjf;asldfja;sldkfjl;sdf") reached = True break # reached = True if j == threshold-1 if not foundit: self.dp[self.N - self.bd[i] + i] += 1 self.dn[self.bd[i] + i + 1] += 1 else: self.dp[self.N - self.bd[i] + i] += 1 self.dn[self.bd[i] + i + 1] += 1 # self.dp[self.N-self.bd[i]+i] += 1 # self.dn[self.bd[i]+i+1] += 1 total = 0 for i in self.dn: if i > 1: total += i - 1 for j in self.dp: if j > 1: total += j - 1 self.collisions = total self.compute_attack_matrix()
def repair(self, withprogressbar=False): self.iter_num = 0 while self.collisions > 0: self.iter_num += 1 # print("enter first loop") self.randinit() self.collisions = self.compute_collisions() # print(self.collisions) self.limit = self.collisions * self.C1 # self.compute_attacks() self.loopcount = 0 # print("iternum = {}".format(self.iter_num)) print("\niteration {}".format(self.iter_num)) while self.loopcount <= self.C2 * self.N: # print("loop count = {}, self.C2 * self.N = {}".format(self.loopcount,self.C2 * self.N)) # print(float(self.loopcount) / (self.C2 * self.N)) if withprogressbar: update_progress(float(self.loopcount) / (self.C2 * self.N)) # print("enter second loop") # for k in range(self.number_of_attacks): # print(self.attack) for i in self.attack: # print("third loop's {}".format(i)) j = np.random.randint(0, self.N) # choose j if self.swap_ok(i, j): # print("swap ok@@ ") # self.printall() self.perform_swap( i, j) # update collision matrix and board # self.collisions -= diff # update collision # print("see if collision is wrong",self.collisions) if self.collisions == 0: return if self.collisions < self.limit: self.limit = self.C1 * self.collisions self.compute_attack_matrix() self.loopcount += len(self.attack) # break return True
def find_utt_info(): # Finding prices accoruding to ultimateteamtrading.com # Only using these prices as a starting point as they are not updated # frequently enough print "Fetching information from ultimateteamtrading.com" i = 0 for p in params[1:]: update_progress(i/float(len(params[1:]))) i+=1 r = requests.get(p[0]+'?position='+p[1]) if len(p) == 2: #first run # Find nation and team data = r.text.split('<div id="playerFlags">')[1]\ .split('<div id="cardstats">')[0].split('<br>') p.append(data[1].strip()) # nation p.append(convert_name(data[2].strip())) #team # Find name p.append((r.text.split('<title>')[1][2:].split('FUT 14')[0].strip())) p.append(0) #dummies p.append(0) #dummies p.append(0) #dummies # Find last updated time updated_ago = int(r.text.split('Update:')[1].split('minutes')[0].strip()) # Find price data = r.text.split('<div class="number priceNumber">')[1]\ .split('<')[0].strip() if "," in data: data = data.split(',')[0] +data.split(',')[1] p[-3] = futfunctions.fut_round(int(data)) if updated_ago < 6: p[-2] = futfunctions.lower_price(int(data)) else: p[-2] = 0 if p[-3] == 0: print "Error in utt. Player missing price from site!" print p update_progress(1.0) print
# Mowed GRT1 = imread(args.class1) # Resizing GRT0 = GRT0[res_i[0]:res_i[1],res_j[0]:res_j[1]] GRT1 = GRT1[res_i[0]:res_i[1],res_j[0]:res_j[1]] # Labelling im_parcels = (GRT0 < 255).astype(np.uint8) N0, im_parcels0 = cv2.connectedComponents(im_parcels) im_parcels = (GRT1 < 255).astype(np.uint8) N1, im_parcels1 = cv2.connectedComponents(im_parcels) print('Overlay removal') update_progress(0) nbrem = 0 for n in range(1, N0): t_start = time() if np.min(GRT1[im_parcels0 == n]) == 1: GRT0[im_parcels0 == n] = 255 nbrem += 1 update_progress((n-1)/(N0-0.9), (time()-t_start)*(N0-n-1)) #################### ## Labelling #im_parcels = (GRT0 < 255).astype(np.uint8) #N0, im_parcels0 = cv2.connectedComponents(im_parcels)
parser.add_argument('-g', '--groundtruth', help='Groundtruth vector', required=True) parser.add_argument('-p', '--parcels', help='Parcel image', required=True) parser.add_argument('-d', '--datesgrid', help='Dates grid array', required=True) parser.add_argument('-t', '--tiledir', help='Directory to the modal dataset', required=True) args = parser.parse_args() update_progress(0) res_i = (0, 7000) res_j = (2500, 9500) df_dates = pd.read_csv(args.datesgrid, index_col='Unnamed: 0') df_dates = df_dates.drop('dates', axis=1) GRT = np.load(args.groundtruth) im_parcels = imread(args.parcels) N = np.max(im_parcels) # nb of parcels T = len(df_dates) # nb of dates nbS2_im = len( glob(args.tiledir + '/*/*/*%s*/*.tif' % (df_dates['dateS2str'][0]))) nbS1_pol = 3
def find_prices_ea(): time_between_checks = int(3600) if relist_mode: return None if int(time.time() - params[0]) < time_between_checks\ and len([p for p in params[1:] if p[-2]==0]) == 0\ and len([p for p in params[1:] if p[-1]==0]) == 0: return None # Starting with getting info from utt14.com # this is faster find_utt_info() # Finding prices from ultimate team webapp print time.ctime()+": Fetching prices from the web app. " count = 50 i = 0 for p in params[1:]: i+=1 update_progress(i/float(len(params[1:]))) sell_price = futfunctions.higher_price(p[-3]) if int(time.time() - params[0]) < time_between_checks and p[-2] > 0 and p[-1] > 0: continue while sell_price > 0: # check if prices from utt are old or missing # resource id # p[-2] is set to 0 in find_from_utt if updated time of prices is older than # 5 minutes. p[-1] is 0 if no if p[-2] != 0 and p[-1] != 0: break auctions = client.search_auctions( card_type='player',pos=p[1],lev='gold', nat=parameters.nation[p[2].replace(" ","")], team=parameters.team[p[3].replace(" ","")], max_bin=sell_price,count=count) tmp_count = 0 for card in auctions: # Find resource ID by checking name and rating if card.name.split(' ')[-1].lower() in p[0] and str(card.rating)\ in p[0] and card.resourceID not in p: p[-1] = card.resourceID # Count number of correct cards we found if card.resourceID == p[-1]: tmp_count +=1 if p[-2] != 0: # We have resourceid and price break if p[-1] == 0: # Sometimes we cant find any players and therefor not any resid # increasing price to make sure we find the player if sell_price > p[-3]*3: # i.e. something is bugged. to avoid endless loop sell_price = 0 break sell_price = futfunctions.fut_round(sell_price*1.2) tmp_count=count if tmp_count > int(count/2): sell_price= futfunctions.lower_price(sell_price) else: p[-2] = futfunctions.lower_price(sell_price) # make sure the price we have found is lower than the one given # on utt14.com p[-2] = min(p[-2],futfunctions.lower_price(p[-3])) break if int(time.time() - params[0]) > time_between_checks: params[0] = int(time.time()) update_progress(i/float(len(params[1:]))) pickle.dump(params, open( "players_to_buy.p", "wb" ))
def folder(images_directory, res_type='FRE', im_format='tif'): ''' Input: Images directory (location of SENTINEL-2 *FOLDER*) Resolution type (default FRE : Full REsolution) Image format (default TIF) Process: Writting of vegetation index images in specified format and in specified folder Output: Surprise (if it works well TT) ''' images_dir = glob(images_directory + '/*') I = len(images_dir) for i, im_dir in enumerate(images_dir): update_progress(max(0, (i - 4 / 5)) / (I - 0.9)) B3 = cv2.imread( glob(im_dir + '/*_' + res_type + '_' + 'B3.' + im_format)[0], -1).astype('float32') B5 = cv2.imread( glob(im_dir + '/*_' + res_type + '_' + 'B5.' + im_format)[0], -1).astype('float32') B5 = cv2.resize(B5, (10980, 10980), 2, 2, cv2.INTER_CUBIC) im = Image.fromarray(nari(B3, B5).astype('float32')) im.save(glob(im_dir + '/*_FRE_B2.tif')[0][:-6] + 'NARI.' + im_format) im = None # release memory B3 = None # release memory B5 = None # release memory update_progress(max(0, (i - 3 / 5)) / (I - 0.9)) B4 = cv2.imread( glob(im_dir + '/*_' + res_type + '_' + 'B4.' + im_format)[0], -1).astype('float32') B8 = cv2.imread( glob(im_dir + '/*_' + res_type + '_' + 'B8.' + im_format)[0], -1).astype('float32') im = Image.fromarray(ndvi(B4, B8).astype('float32')) im.save(glob(im_dir + '/*_FRE_B2.tif')[0][:-6] + 'NDVI.' + im_format) im = None # release memory update_progress(max(0, (i - 2 / 5)) / (I - 0.9)) im = Image.fromarray(savi(B4, B8).astype('float32')) im.save(glob(im_dir + '/*_FRE_B2.tif')[0][:-6] + 'SAVI.' + im_format) im = None # release memory update_progress(max(0, (i - 1 / 5)) / (I - 0.9)) B2 = cv2.imread( glob(im_dir + '/*_' + res_type + '_' + 'B2.' + im_format)[0], -1).astype('float32') im = Image.fromarray(evi(B2, B4, B8).astype('float32')) im.save(glob(im_dir + '/*_FRE_B2.tif')[0][:-6] + 'EVI.' + im_format) im = None # release memory B2 = None # release memory B4 = None # release memory B8 = None # release memory update_progress(i / (I - 0.9)) return True
im = Image.fromarray(savi(B4, B8).astype('float32')) im.save(glob(im_dir + '/*_FRE_B2.tif')[0][:-6] + 'SAVI.' + im_format) im = None # release memory update_progress(max(0, (i - 1 / 5)) / (I - 0.9)) B2 = cv2.imread( glob(im_dir + '/*_' + res_type + '_' + 'B2.' + im_format)[0], -1).astype('float32') im = Image.fromarray(evi(B2, B4, B8).astype('float32')) im.save(glob(im_dir + '/*_FRE_B2.tif')[0][:-6] + 'EVI.' + im_format) im = None # release memory B2 = None # release memory B4 = None # release memory B8 = None # release memory update_progress(i / (I - 0.9)) return True for images_directory in args.folders: print() print('Processing of ' '%s' '' % (images_directory)) update_progress(0) if folder(images_directory): update_progress(1) print('Everything' 's done !')