Skip to content

Commit

Permalink
Merge pull request #543 from jgrewe/warnings
Browse files Browse the repository at this point in the history
fix test warnings
  • Loading branch information
achilleas-k authored Nov 8, 2024
2 parents 444aae5 + caff10d commit beec115
Show file tree
Hide file tree
Showing 22 changed files with 167 additions and 76 deletions.
6 changes: 5 additions & 1 deletion docs/source/examples/categoryData.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import nixio
import matplotlib.pyplot as plt

import docutils

def create_data():
categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
Expand All @@ -23,7 +24,10 @@ def plot(data_array):
plt.bar(range(data_array.shape[0]), data_array[:], color="tab:blue")
plt.xticks(range(data_array.shape[0]), labels=data_array.dimensions[0].labels)
plt.ylabel("%s %s" % (data_array.label, "[%s]" % data_array.unit if data_array.unit else ""))
plt.show()
if docutils.is_running_under_pytest():
plt.close()
else:
plt.show()


def main():
Expand Down
4 changes: 4 additions & 0 deletions docs/source/examples/docutils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os

def is_running_under_pytest():
return "PYTEST_CURRENT_TEST" in os.environ
5 changes: 4 additions & 1 deletion docs/source/examples/imageData.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import numpy as np
from PIL import Image as img

import docutils


def load_image():
image = img.open('lenna.png')
Expand All @@ -42,7 +44,8 @@ def plot_data(data_array):
data_array.read_direct(img_data)
img_data = np.array(img_data, dtype='uint8')
new_img = img.fromarray(img_data)
new_img.show()
if not docutils.is_running_under_pytest():
new_img.show()


if __name__ == '__main__':
Expand Down
17 changes: 11 additions & 6 deletions docs/source/examples/imageWithMetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
http://en.wikipedia.org/wiki/File:Lenna.png#mediaviewer/File:Lenna.png
"""

import nixio as nix
import numpy as np
from PIL import Image as img
import nixio as nix
import matplotlib.pyplot as plt

import docutils

from PIL import Image as img


def print_metadata_table(section, ax):
columns = ['Name', 'Value']
Expand Down Expand Up @@ -73,10 +75,13 @@ def plot_data(data_array):
img_axis.imshow(new_img)

info_axis = fig.add_subplot(122)
print_metadata_table(data.metadata, info_axis)
print_metadata_table(data_array.metadata, info_axis)
fig.subplots_adjust(left=0.075, right=0.975, bottom=0.075, top=0.975)
fig.savefig('image_with_metadata.png')
fig.show()
if docutils.is_running_under_pytest():
plt.close()
else:
fig.savefig('image_with_metadata.png')
fig.show()


def add_image_information(nix_file):
Expand Down
7 changes: 6 additions & 1 deletion docs/source/examples/irregularlySampledData.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import numpy as np
import matplotlib.pyplot as plt

import docutils


def create_data(duration, interval):
times = np.around(np.cumsum(np.random.poisson(interval * 1000, int(1.5 * duration / interval))) / 1000., 3)
Expand All @@ -37,7 +39,10 @@ def plot_data(data_array):
plt.legend()
plt.xlim([0, x[-1]])
plt.ylim(np.min(y) * 1.1, np.max(y) * 1.1)
plt.show()
if docutils.is_running_under_pytest():
plt.close()
else:
plt.show()


def main():
Expand Down
17 changes: 13 additions & 4 deletions docs/source/examples/multipleROIs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from PIL import Image as img
import matplotlib.pyplot as plt

import docutils


def load_image():
image = img.open('lenna.png')
Expand Down Expand Up @@ -57,8 +59,12 @@ def plot_data(tag):
# new_img = img.fromarray(img_data)
plt.imshow(img_data)
plt.gcf().set_size_inches((5.5, 5.5))
# plt.savefig("../images/multiple_rois.png")
plt.show()
if docutils.is_running_under_pytest():
plt.close()
else:
# plt.savefig("../images/multiple_rois.png")
plt.show()


def plot_roi_data(tag):
position_count = tag.positions.shape[0]
Expand All @@ -71,8 +77,11 @@ def plot_roi_data(tag):
image = img.fromarray(roi_data)
ax.imshow(image)

# fig.savefig('../images/retrieved_rois.png')
plt.show()
if docutils.is_running_under_pytest():
plt.close()
else:
# fig.savefig('../images/retrieved_rois.png')
plt.show()


def main():
Expand Down
9 changes: 7 additions & 2 deletions docs/source/examples/multipleTimeSeries.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import numpy as np
import matplotlib.pylab as plt

import docutils


def create_data(duration=1, freq=10, stepsize=0.01):
x = np.arange(0, duration * 2 * np.pi, stepsize)
Expand All @@ -42,8 +44,11 @@ def plot_data(data_array):
plt.xlim(0, np.max(x))
plt.ylim((1.1 * np.min(y), 1.1 * np.max(y)))
plt.legend()
plt.savefig('multiple_time_series.png')
plt.show()
if docutils.is_running_under_pytest():
plt.close()
else:
plt.savefig('multiple_time_series.png')
plt.show()

def main():
# fake some data
Expand Down
8 changes: 6 additions & 2 deletions docs/source/examples/multiple_points.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import nixio
import docutils
import numpy as np
import matplotlib.pyplot as plt

Expand Down Expand Up @@ -36,8 +37,11 @@ def plot(multi_tag):
ax.spines["right"].set_visible(False)
fig.subplots_adjust(bottom=0.175, left=0.15, right=0.95, top=0.95)
ax.legend(loc=3, frameon=False, ncol=2)
# fig.savefig("../images/multiple_points.png")
plt.show()
if docutils.is_running_under_pytest():
plt.close()
else:
# fig.savefig("../images/multiple_points.png")
plt.show()


def main():
Expand Down
18 changes: 13 additions & 5 deletions docs/source/examples/multiple_regions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import numpy as np
import nixio
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches

import docutils


def create_example_data(nixfile):
sampling_interval = 0.001
Expand Down Expand Up @@ -79,8 +81,11 @@ def plot(nixfile):
ax.spines["top"].set_visible(False)
ax.spines["right"].set_visible(False)
fig.subplots_adjust(bottom=0.175, left=0.15, right=0.95, top=0.95)
# fig.savefig("../images/multiple_regions.png")
plt.show()
if docutils.is_running_under_pytest():
plt.close()
else:
# fig.savefig("../images/multiple_regions.png")
plt.show()


def plot_tagged_data(nixfile):
Expand All @@ -106,8 +111,11 @@ def plot_tagged_data(nixfile):
else:
ax.set_yticklabels([])
fig.subplots_adjust(left=0.15, bottom=0.2, wspace=0.5, right=0.975)
# fig.savefig("../images/reading_tagged_data.png")
plt.show()
if docutils.is_running_under_pytest():
plt.close()
else:
# fig.savefig("../images/reading_tagged_data.png")
plt.show()


def main():
Expand Down
7 changes: 6 additions & 1 deletion docs/source/examples/regularlySampledData.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import numpy as np
import matplotlib.pyplot as plt

import docutils


def create_sinewave(duration=1, freq=10, stepsize=0.01):
x = np.arange(0, duration * 2 * np.pi, stepsize)
Expand All @@ -36,7 +38,10 @@ def plot_data(data_array):
plt.xlim(0, np.max(x))
plt.ylim((1.1 * np.min(y), 1.1 * np.max(y)))
plt.legend()
plt.show()
if docutils.is_running_under_pytest():
plt.close()
else:
plt.show()


def main():
Expand Down
8 changes: 5 additions & 3 deletions docs/source/examples/singleROI.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import numpy as np
from PIL import Image as img

import docutils


def load_image():
image = img.open('lenna.png')
Expand All @@ -51,9 +53,9 @@ def plot_data(tag):
ext = tuple(map(int, tag.extent))
draw_rect(img_data, pos, ext)
new_img = img.fromarray(img_data)

# new_img.save("../images/single_roi.png")
new_img.show()
if not docutils.is_running_under_pytest():
# new_img.save("../images/single_roi.png")
new_img.show()


def main():
Expand Down
9 changes: 6 additions & 3 deletions docs/source/examples/spikeFeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
See https://github.com/G-node/nix/wiki for more information.
"""

import lif
import nixio
import numpy as np
import scipy.signal as signal
import matplotlib.pylab as plt

import lif
import docutils

def fake_neuron(stepsize=0.001, offset=.8, sta_offset=1000):
stimulus = np.random.randn(102000) * 3.5
Expand Down Expand Up @@ -97,7 +97,10 @@ def plot_data(tag):
plt.subplots_adjust(left=0.15, top=0.875, bottom=0.1, right=0.98, hspace=0.35, wspace=0.25)
plt.gcf().set_size_inches((5.5, 4.5))
# plt.savefig("../images/spike_features.png")
plt.show()
if docutils.is_running_under_pytest():
plt.close()
else:
plt.show()


def main():
Expand Down
9 changes: 7 additions & 2 deletions docs/source/examples/spikeTagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import numpy as np
import matplotlib.pylab as plt

import docutils


def fake_neuron():
lif_model = lif.LIF(offset=1.0)
Expand Down Expand Up @@ -48,8 +50,11 @@ def plot_data(tag):
ax.set_ylim((1.5 * np.min(voltage), 1.5 * np.max(voltage)))
ax.legend()
fig.subplots_adjust(bottom=0.175, top=0.975, right=0.975)
# fig.savefig("../images/spike_tagging.png")
plt.show()
if docutils.is_running_under_pytest():
plt.close()
else:
# fig.savefig("../images/spike_tagging.png")
plt.show()


if __name__ == '__main__':
Expand Down
9 changes: 7 additions & 2 deletions docs/source/examples/taggedFeature.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
"""
import nixio
import lif
import numpy as np
import scipy.signal as signal
import matplotlib.pyplot as plt

import lif
import docutils


def fake_neuron(stepsize=0.001, offset=.8):
stimulus = np.random.randn(102000) * 2.5
Expand Down Expand Up @@ -119,7 +121,10 @@ def plot_data(tag):
plt.subplots_adjust(left=0.125, top=0.975, bottom=0.1, right=0.98, hspace=0.25, wspace=0.35)
plt.gcf().set_size_inches((5.5, 4.5))
# plt.savefig('../images/tagged_feature.png')
plt.show()
if docutils.is_running_under_pytest():
plt.close()
else:
plt.show()


if __name__ == '__main__':
Expand Down
13 changes: 9 additions & 4 deletions docs/source/examples/tagging_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import matplotlib.pyplot as plt
import scipy.signal as signal
import numpy as np
import nixio
import numpy as np
import scipy.signal as signal
import matplotlib.pyplot as plt

import docutils

interval = 0.001
duration = 3.5
Expand Down Expand Up @@ -56,7 +58,10 @@ def plot(time, response):
arrowprops=dict(facecolor='silver', connectionstyle="arc3", arrowstyle="->"),
)
# fig.savefig('../images/tag2.png')
plt.show()
if docutils.is_running_under_pytest():
plt.close()
else:
plt.show()


def create_data():
Expand Down
Loading

0 comments on commit beec115

Please sign in to comment.