| Conditions | 1 |
| Total Lines | 82 |
| Code Lines | 64 |
| Lines | 82 |
| Ratio | 100 % |
| 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 boto3 |
||
| 50 | View Code Duplication | def sensitivity_it(counter): |
|
| 51 | |||
| 52 | import matplotlib as mpl |
||
| 53 | mpl.use('Agg') |
||
| 54 | import matplotlib.pyplot as plt |
||
| 55 | import diff_classifier.aws as aws |
||
| 56 | import diff_classifier.utils as ut |
||
| 57 | import diff_classifier.msd as msd |
||
| 58 | import diff_classifier.features as ft |
||
| 59 | import diff_classifier.imagej as ij |
||
| 60 | import diff_classifier.heatmaps as hm |
||
| 61 | |||
| 62 | from scipy.spatial import Voronoi |
||
| 63 | import scipy.stats as stats |
||
| 64 | from shapely.geometry import Point |
||
| 65 | from shapely.geometry.polygon import Polygon |
||
| 66 | import matplotlib.cm as cm |
||
| 67 | import os |
||
| 68 | import os.path as op |
||
| 69 | import numpy as np |
||
| 70 | import numpy.ma as ma |
||
| 71 | import pandas as pd |
||
| 72 | import boto3 |
||
| 73 | import itertools |
||
| 74 | |||
| 75 | #Sweep parameters |
||
| 76 | #---------------------------------- |
||
| 77 | radius = [4.5, 6.0, 7.0] |
||
| 78 | do_median_filtering = [True, False] |
||
| 79 | quality = [1.5, 4.5, 8.5] |
||
| 80 | linking_max_distance = [6.0, 10.0, 15.0] |
||
| 81 | gap_closing_max_distance = [6.0, 10.0, 15.0] |
||
| 82 | max_frame_gap = [1, 2, 5] |
||
| 83 | track_displacement = [0.0, 10.0, 20.0] |
||
| 84 | |||
| 85 | sweep = [radius, do_median_filtering, quality, linking_max_distance, gap_closing_max_distance, max_frame_gap, |
||
| 86 | track_displacement] |
||
| 87 | all_params = list(itertools.product(*sweep)) |
||
| 88 | |||
| 89 | #Variable prep |
||
| 90 | #---------------------------------- |
||
| 91 | s3 = boto3.client('s3') |
||
| 92 | |||
| 93 | folder = '01_18_Experiment' |
||
| 94 | s_folder = '{}/sensitivity'.format(folder) |
||
| 95 | local_folder = '.' |
||
| 96 | prefix = "P1_S1_R_0001_2_2" |
||
| 97 | name = "{}.tif".format(prefix) |
||
| 98 | local_im = op.join(local_folder, name) |
||
| 99 | aws.download_s3('{}/{}/{}.tif'.format(folder, prefix.split('_')[0], prefix), '{}.tif'.format(prefix)) |
||
| 100 | |||
| 101 | outputs = np.zeros((len(all_params), len(all_params[0])+2)) |
||
| 102 | |||
| 103 | #Tracking and calculations |
||
| 104 | #------------------------------------ |
||
| 105 | params = all_params[counter] |
||
| 106 | outfile = 'Traj_{}_{}.csv'.format(name.split('.')[0], counter) |
||
| 107 | msd_file = 'msd_{}_{}.csv'.format(name.split('.')[0], counter) |
||
| 108 | geo_file = 'geomean_{}_{}.csv'.format(name.split('.')[0], counter) |
||
| 109 | geoS_file = 'geoSEM_{}_{}.csv'.format(name.split('.')[0], counter) |
||
| 110 | msd_image = 'msds_{}_{}.png'.format(name.split('.')[0], counter) |
||
| 111 | iter_name = "{}_{}".format(prefix, counter) |
||
| 112 | |||
| 113 | ij.track(local_im, outfile, template=None, fiji_bin=None, radius=params[0], threshold=0., |
||
| 114 | do_median_filtering=params[1], quality=params[2], x=511, y=511, ylo=1, median_intensity=300.0, snr=0.0, |
||
| 115 | linking_max_distance=params[3], gap_closing_max_distance=params[4], max_frame_gap=params[5], |
||
| 116 | track_displacement=params[6]) |
||
| 117 | |||
| 118 | traj = ut.csv_to_pd(outfile) |
||
| 119 | msds = msd.all_msds2(traj, frames=651) |
||
| 120 | msds.to_csv(msd_file) |
||
| 121 | gmean1, gSEM1 = hm.plot_individual_msds(iter_name, alpha=0.05) |
||
| 122 | np.savetxt(geo_file, gmean1, delimiter=",") |
||
| 123 | np.savetxt(geoS_file, gSEM1, delimiter=",") |
||
| 124 | |||
| 125 | aws.upload_s3(outfile, '{}/{}'.format(s_folder, outfile)) |
||
| 126 | aws.upload_s3(msd_file, '{}/{}'.format(s_folder, msd_file)) |
||
| 127 | aws.upload_s3(geo_file, '{}/{}'.format(s_folder, geo_file)) |
||
| 128 | aws.upload_s3(geoS_file, '{}/{}'.format(s_folder, geoS_file)) |
||
| 129 | aws.upload_s3(msd_image, '{}/{}'.format(s_folder, msd_image)) |
||
| 130 | |||
| 131 | print('Successful parameter calculations for {}'.format(iter_name)) |
||
| 132 | |||
| 191 |