Skip to content

Commit

Permalink
Naming convention (binsize -> bin_size, etc.) (NeuralEnsemble#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
dizcza committed Aug 7, 2020
1 parent 9007517 commit 9e67193
Show file tree
Hide file tree
Showing 51 changed files with 3,619 additions and 3,117 deletions.
9 changes: 6 additions & 3 deletions doc/style_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ throughout Elephant.

.. code-block:: python
def pair_of_signals_example(spiketrain_i, spiketrain_j):
# Add '_i' and '_j' suffixes to a pair of signals, spiketrains or any
# other variables that come in pairs.
def perfect_naming_of_parameters(spiketrains, spiketrain, reference_spiketrain,
target_spiketrain, signal, signals, max_iterations,
min_threshold, n_bins, n_surrogates, bin_size, max_size,
Expand Down Expand Up @@ -119,9 +123,8 @@ throughout Elephant.
Therefore, do not use terms as `n` or `n_surr`, that are not
immediately understood.
bin_size : pq.Quantity or int
Separate the words by underscore. Do not use `binsize`. Old functions
which use `binsize` will be gradually refactored to conform to the new
convention.
Separate the words by underscore. Do not use `bin_size`. Old functions
which use `binsize` are deprecated.
max_size : float
Another example showing that words should be separated by underscores.
This intersects with the naming convention for a maximum value.
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/asset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
],
"source": [
"# 2.1.1) create ASSET analysis object\n",
"# hint: try different binsizes, e.g. binsize=2.5, 3.5, 4.0 ms\n",
"# hint: try different bin sizes, e.g. bin_size=2.5, 3.5, 4.0 ms\n",
"asset_obj = asset.ASSET(spiketrains, bin_size=3*pq.ms)\n",
"\n",
"# 2.1.2) compute the intersection matrix\n",
Expand Down
18 changes: 9 additions & 9 deletions doc/tutorials/parallel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
"source": [
"### Example 2. Custom functions and positional argument\n",
"\n",
"Sometimes you might want to iterate over the second (or third, etc.) argument of a function. To do this, you need to create a custom function that passes its first input argument into the right position of the original function. Below is an example of how to compute time histograms of spiketrains with different `binsize` values (the second argument)."
"Sometimes you might want to iterate over the second (or third, etc.) argument of a function. To do this, you need to create a custom function that passes its first input argument into the right position of the original function. Below is an example of how to compute time histograms of spiketrains with different `bin_size` values (the second argument)."
]
},
{
Expand All @@ -269,9 +269,9 @@
"spiketrains = [homogeneous_poisson_process(rate, t_stop=10*pq.s) for _ in range(8)]\n",
"\n",
"# step 2: define your custom function\n",
"def my_custom_function(binsize):\n",
"def my_custom_function(bin_size):\n",
" # specify all custom key-word options here\n",
" return time_histogram(spiketrains, binsize, output='counts')"
" return time_histogram(spiketrains, bin_size, output='counts')"
]
},
{
Expand All @@ -282,9 +282,9 @@
},
"outputs": [],
"source": [
"binsize_list = np.linspace(0.1, 1, num=8) * pq.s\n",
"bin_size_list = np.linspace(0.1, 1, num=8) * pq.s\n",
"\n",
"time_hist = ProcessPoolExecutor().execute(my_custom_function, binsize_list)"
"time_hist = ProcessPoolExecutor().execute(my_custom_function, bin_size_list)"
]
},
{
Expand Down Expand Up @@ -334,7 +334,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"`time_hist` contains 8 AnalogSignals - one AnalogSignal per `binsize` from `binsize_list`.\n",
"`time_hist` contains 8 AnalogSignals - one AnalogSignal per `bin_size` from `bin_size_list`.\n",
"\n",
"### Benchmark\n",
"\n",
Expand All @@ -351,7 +351,7 @@
"warnings.filterwarnings(\"ignore\")\n",
"\n",
"# initialize the iteration list\n",
"binsize_list = np.linspace(0.1, 1, 100) * pq.s"
"bin_size_list = np.linspace(0.1, 1, 100) * pq.s"
]
},
{
Expand All @@ -369,7 +369,7 @@
],
"source": [
"# sequential processing\n",
"%timeit [time_histogram(spiketrains, binsize) for binsize in binsize_list]"
"%timeit [time_histogram(spiketrains, bin_size) for bin_size in bin_size_list]"
]
},
{
Expand All @@ -387,7 +387,7 @@
],
"source": [
"# with parallelization\n",
"%timeit ProcessPoolExecutor(max_workers=4).execute(my_custom_function, binsize_list)"
"%timeit ProcessPoolExecutor(max_workers=4).execute(my_custom_function, bin_size_list)"
]
}
],
Expand Down
12 changes: 6 additions & 6 deletions doc/tutorials/unitary_event_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
},
"outputs": [],
"source": [
"def plot_UE(data,Js_dict,Js_sig,binsize,winsize,winstep, pat,N,t_winpos,**kwargs):\n",
"def plot_UE(data,Js_dict,Js_sig,bin_size,winsize,winstep, pat,N,t_winpos,**kwargs):\n",
" \"\"\"\n",
" Examples:\n",
" ---------\n",
Expand Down Expand Up @@ -150,9 +150,9 @@
" if len(x)>0:\n",
" xx = []\n",
" for j in sig_idx_win:\n",
" xx =np.append(xx,x[np.where((x*binsize>=t_winpos[j]) &(x*binsize<t_winpos[j] + winsize))])\n",
" xx =np.append(xx,x[np.where((x*bin_size>=t_winpos[j]) &(x*bin_size<t_winpos[j] + winsize))])\n",
" plt.plot(\n",
" np.unique(xx)*binsize, np.ones_like(np.unique(xx))*tr + n*(num_tr + 1) + 1,\n",
" np.unique(xx)*bin_size, np.ones_like(np.unique(xx))*tr + n*(num_tr + 1) + 1,\n",
" ms=arg_dict['marker_size'], marker = 's', ls = '',mfc='none', mec='r')\n",
" plt.axhline((tr + 2)*(n+1) ,lw = 2, color = 'k')\n",
" y_ticks_pos = np.arange(num_tr/2 + 1,N*(num_tr+1), num_tr+1)\n",
Expand Down Expand Up @@ -181,7 +181,7 @@
" np.ones_like(data_tr[n].magnitude)*tr + n*(num_tr + 1) + 1,\n",
" '.', markersize=0.5, color = 'k')\n",
" plt.plot(\n",
" np.unique(Js_dict['indices']['trial'+str(tr)])*binsize,\n",
" np.unique(Js_dict['indices']['trial'+str(tr)])*bin_size,\n",
" np.ones_like(np.unique(Js_dict['indices']['trial'+str(tr)]))*tr + n*(num_tr + 1) + 1,\n",
" ls = '',ms=arg_dict['marker_size'], marker = 's', markerfacecolor='none', markeredgecolor='c')\n",
" plt.axhline((tr + 2)*(n+1) ,lw = 2, color = 'k')\n",
Expand Down Expand Up @@ -300,10 +300,10 @@
"outputs": [],
"source": [
"UE = ue.jointJ_window_analysis(\n",
" spiketrains, binsize=5*pq.ms, winsize=100*pq.ms, winstep=10*pq.ms, pattern_hash=[3])\n",
" spiketrains, bin_size=5*pq.ms, winsize=100*pq.ms, winstep=10*pq.ms, pattern_hash=[3])\n",
"\n",
"plot_UE(\n",
" spiketrains, UE, ue.jointJ(0.05),binsize=5*pq.ms,winsize=100*pq.ms,winstep=10*pq.ms,\n",
" spiketrains, UE, ue.jointJ(0.05),bin_size=5*pq.ms,winsize=100*pq.ms,winstep=10*pq.ms,\n",
" pat=ue.inverse_hash_from_pattern([3], N=2), N=2,\n",
" t_winpos=ue._winpos(0*pq.ms,spiketrains[0][0].t_stop,winsize=100*pq.ms,winstep=10*pq.ms))\n",
"plt.show()"
Expand Down

0 comments on commit 9e67193

Please sign in to comment.