-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery Starbot ⭐ refactored knasti/PopNet #28
base: master
Are you sure you want to change the base?
Conversation
for cur_epoch in range(self.model.cur_epoch_tensor.eval(self.sess), 1, 1): | ||
for _ in range(self.model.cur_epoch_tensor.eval(self.sess), 1, 1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function BaseTrain.test
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
if self.i_test == self.list_num_test_batches[self.pair_no]: | ||
if self.i_test == self.list_num_test_batches[pair_no]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function DataGenerator.next_test_batch
refactored with the following changes:
- Use previously assigned local variable (
use-assigned-variable
)
for i in range(len(self.x_data)): | ||
for x_datum in self.x_data: | ||
cur_row = 0 | ||
cur_col = 0 | ||
x_datum | ||
for j in range(self.no_chunks): | ||
if self.chunk_cols == cur_col: # Change to new row and reset column if it reaches the end | ||
cur_row += 1 | ||
cur_col = 0 | ||
self.x_data[i] | ||
raster[cur_row * self.chunk_height: (cur_row + 1) * self.chunk_height, cur_col * self.chunk_width: (cur_col + 1) * self.chunk_width, :] = self.x_data[i][j] | ||
raster[ | ||
cur_row | ||
* self.chunk_height : (cur_row + 1) | ||
* self.chunk_height, | ||
cur_col * self.chunk_width : (cur_col + 1) * self.chunk_width, | ||
:, | ||
] = x_datum[j] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function PrepData.input_to_tif
refactored with the following changes:
- Hoist statements out of for/while loops (
hoist-statement-from-loop
) - Replace index in for loop with direct reference (
for-index-replacement
)
output_nr = 2020 | ||
for file in os.listdir(self.config.output_pred_dir): | ||
if file.endswith(".tif"): | ||
output_nr += 10 | ||
output_nr = 2020 + sum( | ||
10 | ||
for file in os.listdir(self.config.output_pred_dir) | ||
if file.endswith(".tif") | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function DataWriter.write_outputs
refactored with the following changes:
- Convert for loop into call to sum() (
sum-comprehension
)
for i in range(len(data_loader.data_label_pairs)): | ||
x_data = data_loader.data_label_pairs[i][0][:, :, :] | ||
y_true = data_loader.data_label_pairs[i][1][:, :, 0] | ||
for data_label_pair in data_loader.data_label_pairs: | ||
x_data = data_label_pair[0][data_loader] | ||
y_true = data_label_pair[1][data_loader.data_label_pairs[i][1][:, :, 0]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function main
refactored with the following changes:
- Replace index in for loop with direct reference (
for-index-replacement
)
summaries_dict = {} | ||
summaries_dict['loss'] = loss | ||
summaries_dict['acc'] = acc | ||
summaries_dict = {'loss': loss, 'acc': acc} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ExampleTrainer.train_epoch
refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign
)
summaries_dict = {} | ||
summaries_dict['pop_loss'] = pop_loss | ||
summaries_dict['abs_loss'] = abs_loss | ||
summaries_dict['loss'] = loss | ||
|
||
summaries_dict = {'pop_loss': pop_loss, 'abs_loss': abs_loss, 'loss': loss} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function PopTrainer.train_epoch
refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign
)
summaries_dict = {} | ||
summaries_dict['pop_loss'] = pop_loss | ||
summaries_dict['abs_loss'] = abs_loss | ||
summaries_dict['loss'] = loss | ||
|
||
summaries_dict = {'pop_loss': pop_loss, 'abs_loss': abs_loss, 'loss': loss} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function PopTrainer.test_epoch
refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign
)
utils/utils.py
Outdated
args = argparser.parse_args() | ||
return args No newline at end of file | ||
return argparser.parse_args() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_args
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
pred_2020 = pred_2020 + pop_array | ||
pred_2020 += pop_array | ||
else: | ||
pred_2020 = pop_array | ||
print(np.max(pop_array)) | ||
|
||
elif file == 'pred_2030.tif': | ||
if type(pred_2030) is np.ndarray: | ||
pred_2030 = pred_2030 + pop_array | ||
pred_2030 += pop_array | ||
else: | ||
pred_2030 = pop_array | ||
|
||
elif file == 'pred_2040.tif': | ||
if type(pred_2040) is np.ndarray: | ||
pred_2040 = pred_2040 + pop_array | ||
pred_2040 += pop_array | ||
else: | ||
pred_2040 = pop_array | ||
|
||
elif file == 'pred_2050.tif': | ||
if type(pred_2050) is np.ndarray: | ||
pred_2050 = pred_2050 + pop_array | ||
pred_2050 += pop_array | ||
else: | ||
pred_2050 = pop_array | ||
|
||
elif file == 'pred_2060.tif': | ||
if type(pred_2060) is np.ndarray: | ||
pred_2060 = pred_2060 + pop_array | ||
pred_2060 += pop_array | ||
else: | ||
pred_2060 = pop_array | ||
|
||
elif file == 'pred_2070.tif': | ||
if type(pred_2070) is np.ndarray: | ||
pred_2070 = pred_2070 + pop_array | ||
pred_2070 += pop_array | ||
else: | ||
pred_2070 = pop_array | ||
|
||
elif file == 'pred_2080.tif': | ||
if type(pred_2080) is np.ndarray: | ||
pred_2080 = pred_2080 + pop_array | ||
pred_2080 += pop_array | ||
else: | ||
pred_2080 = pop_array | ||
|
||
elif file == 'pred_2090.tif': | ||
if type(pred_2090) is np.ndarray: | ||
pred_2090 = pred_2090 + pop_array | ||
pred_2090 += pop_array | ||
else: | ||
pred_2090 = pop_array | ||
|
||
else: | ||
if type(pred_2100) is np.ndarray: | ||
pred_2100 = pred_2100 + pop_array | ||
pred_2100 += pop_array | ||
else: | ||
pred_2100 = pop_array | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 58-110
refactored with the following changes:
- Replace assignment with augmented assignment (
aug-assign
)
Sourcery Code Quality Report (beta)✅ Merging this PR will increase code quality in the affected files by 0.03 out of 10.
Here are some functions in these files that still need a tune-up:
Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! |
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run: