| Conditions | 1 |
| Total Lines | 54 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import sys |
||
| 79 | def BF_cell_features(prefix, folder, bucket='ccurtis.data'): |
||
| 80 | |||
| 81 | ffilename = 'features_{}.csv'.format(prefix) |
||
| 82 | mfilename = 'msd_{}.csv'.format(prefix) |
||
| 83 | bffilename = 'BF_cells_{}.tif'.format(prefix) |
||
| 84 | biim = 'bi_BF_cells_{}.tif'.format(prefix) |
||
| 85 | bimages = 'biproc_BF_cells_{}.png'.format(prefix) |
||
| 86 | |||
| 87 | aws.download_s3('{}/{}'.format(folder, ffilename), ffilename, bucket_name=bucket) |
||
| 88 | aws.download_s3('{}/{}'.format(folder, mfilename), mfilename, bucket_name=bucket) |
||
| 89 | aws.download_s3('{}/{}'.format(folder, bffilename), bffilename, bucket_name=bucket) |
||
| 90 | print('Successfully downloaded files') |
||
| 91 | |||
| 92 | fstats = pd.read_csv(ffilename, encoding = "ISO-8859-1") |
||
| 93 | msds = pd.read_csv(mfilename, encoding = "ISO-8859-1") |
||
| 94 | bfimage = plt.imread(bffilename) |
||
| 95 | tophimage = binary_BF(bfimage, opense=disk(12), bi_thresh=1.2, tophatse=disk(20)) |
||
| 96 | plt.savefig(bimages) |
||
| 97 | euimage = EuclideanTransform(tophimage)+EuclideanTransform(~tophimage) |
||
| 98 | print('Successfully performed image processing') |
||
| 99 | |||
| 100 | xa = -np.reshape(np.clip((fstats.Y.values-1).astype(int), a_min=0, a_max=2043), newshape=(fstats.Y.shape[0], 1)) |
||
| 101 | ya = np.reshape(np.clip((fstats.X.values-1).astype(int), a_min=0, a_max=2043), newshape=(fstats.X.shape[0], 1)) |
||
| 102 | xya = [tuple(l) for l in np.concatenate((xa, ya), axis=1).tolist()] |
||
| 103 | fstats['Cell Status'] = itemgetter(*xya)(tophimage) |
||
| 104 | fstats['Cell Distance'] = itemgetter(*xya)(euimage) |
||
| 105 | |||
| 106 | print('Successfully calculated Cell Status Params') |
||
| 107 | |||
| 108 | frames = 651 |
||
| 109 | xb = -np.reshape(np.clip((msds.Y.values-1).astype(int), a_min=0, a_max=2043), newshape=(int(msds.Y.shape[0]), 1)) |
||
| 110 | yb = np.reshape(np.clip((msds.X.values-1).astype(int), a_min=0, a_max=2043), newshape=(int(msds.X.shape[0]), 1)) |
||
| 111 | xyb = [tuple(l) for l in np.concatenate((xb, yb), axis=1).tolist()] |
||
| 112 | msds['Cell Status'] = itemgetter(*xyb)(tophimage) |
||
| 113 | msds['Cell Distance'] = itemgetter(*xyb)(euimage) |
||
| 114 | |||
| 115 | msds_cell_status = np.reshape(msds['Cell Status'].values, newshape=(int(msds.X.shape[0]/frames), frames)) |
||
| 116 | msds_cell_distance = np.reshape(msds['Cell Distance'].values, newshape=(int(msds.X.shape[0]/frames), frames)) |
||
| 117 | fstats['Membrane Xing'] = np.sum(np.diff(msds_cell_status, axis=1) == True, axis=1) |
||
| 118 | fstats['Distance Towards Cell'] = np.sum(np.diff(msds_cell_distance, axis=1), axis=1) |
||
| 119 | fstats['Percent Towards Cell'] = np.mean(np.diff(msds_cell_distance, axis=1) > 0, axis=1) |
||
| 120 | print('Successfully calculated Membrane Xing Params') |
||
| 121 | |||
| 122 | fstats.to_csv(ffilename, sep=',', encoding = "ISO-8859-1") |
||
| 123 | msds.to_csv(mfilename, sep=',', encoding = "ISO-8859-1") |
||
| 124 | plt.imsave(biim, tophimage, cmap='gray') |
||
| 125 | |||
| 126 | aws.upload_s3(ffilename, '{}/{}'.format(folder, ffilename), bucket_name=bucket) |
||
| 127 | aws.upload_s3(mfilename, '{}/{}'.format(folder, mfilename), bucket_name=bucket) |
||
| 128 | aws.upload_s3(biim, '{}/{}'.format(folder, biim), bucket_name=bucket) |
||
| 129 | aws.upload_s3(bimages, '{}/{}'.format(folder, bimages, bucket_name=bucket)) |
||
| 130 | print('Successfully uploaded files') |
||
| 131 | |||
| 132 | return fstats |
||
| 133 | |||
| 139 |