# Issues with New Module for Numpy Files

**URL:** <https://discourse.slicer.org/t/issues-with-new-module-for-numpy-files/21840>\
**Category:** Development\
**Tags:** file-import\
**Created:** [February 7, 2022, 4:06pm UTC](https://discourse.slicer.org/t/issues-with-new-module-for-numpy-files/21840 "2022-02-07T16:06:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [February 7, 2022, 4:06pm UTC](https://discourse.slicer.org/t/issues-with-new-module-for-numpy-files/21840/1 "2022-02-07T16:06:52Z")

</div>

Hi, I am trying to work out a new extension that is capable of going into a directory and pulling out all npy or npz files and importing them into 3D slicer as a volume. I am positive that the radio button logic on my code needs work, but I am not sure how to continue. I have looked through multiple instances of other codes using these radiobuttons and have tried their syntax only for it to break my script (obviously this is a problem caused by a lack of knowledge about UI code and connecting the logic up right). Attached is my gist if there is anyone willing to take a look.  
[https://gist.github.com/stevenagl12/2f933f8fb5e3a823ce506d55582583d4](https://gist.github.com/stevenagl12/2f933f8fb5e3a823ce506d55582583d4)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 8, 2022, 8:44pm UTC](https://discourse.slicer.org/t/issues-with-new-module-for-numpy-files/21840/2 "2022-02-08T20:44:45Z")

</div>

If you don’t want to immediately act on your radiobutton clicks then there is no need to connect any signals to them. In the `onApply` method you can get the state of the radiobutton like this:

```
isFormatNpy = self.FileTypeNPY.checked
```

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [February 10, 2022, 2:59am UTC](https://discourse.slicer.org/t/issues-with-new-module-for-numpy-files/21840/3 "2022-02-10T02:59:30Z")

</div>

Thanks for working on adding support for importing `npy` or `npz` files.

For convenience and to have it one-click away, the format is documented here: [numpy.lib.format — NumPy v1.22 Manual](https://numpy.org/doc/stable/reference/generated/numpy.lib.format.html#module-numpy.lib.format)

---

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [February 10, 2022, 9:56am UTC](https://discourse.slicer.org/t/issues-with-new-module-for-numpy-files/21840/4 "2022-02-10T09:56:07Z")

</div>

Thank you for your help. I have updated the script and it is working with numpy files as well as npz files. The last thing I wanted to do was to make it where the script was capable of creating a listing of all of the files that met a certain search parameter. In my code I used a list comprehension for this with a parameter called FileConstraints, but for some reason, when I run the script with a constraint, it is not capable of creating the desired list of filenames. Here is my gist again if there is anyone who can take a look. [https://gist.github.com/stevenagl12/2f933f8fb5e3a823ce506d55582583d4](https://gist.github.com/stevenagl12/2f933f8fb5e3a823ce506d55582583d4)

---

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [February 10, 2022, 9:57am UTC](https://discourse.slicer.org/t/issues-with-new-module-for-numpy-files/21840/5 "2022-02-10T09:57:44Z")

</div>

So, by the looks of the information you provided to me, do you think I should expand my script to be capable of using pickled array information in npy file format as well? My script is currently able to import npy file formats, but I don’t know how regularly people pickle npy files, as the only instance I have of this was with the npz files that do it natively as arr\_0.
