internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: napari/napari

Issue:
Add basic colormaps
## 🚀 Feature
<!-- A clear and concise description of the feature proposal -->

As discussed in #89 it would be nice to add some standard colormaps that people might want to use (particularly in biology) like the following:

> Blues - black to blue
Reds - black to red
Greens - black to green
Magenta - black to magenta
Yellow - black to yellow
Cyan - black to cyan

It might also be nice to add some standard diverging ones too like red to blue through white or red to blue through black - though I don't think we want to try and make an exhaustive list

Similarly looking through the list of colormaps now it seems like there are some that could be removed as they are less popular


Discussion:

Resolving patch:
diff --git a/napari/layers/_image_layer/model.py b/napari/layers/_image_layer/model.py
--- a/napari/layers/_image_layer/model.py
+++ b/napari/layers/_image_layer/model.py
@@ -16,7 +16,7 @@
                                   interpolation_index_to_name as _index_to_name,  # noqa
                                   interpolation_name_to_index as _name_to_index)  # noqa
 from ...util.misc import guess_metadata
-from ...util.colormaps import matplotlib_colormaps
+from ...util.colormaps import matplotlib_colormaps, simple_colormaps
 from ...util.colormaps.vendored import cm
 from ...util.event import Event
 
@@ -66,10 +66,12 @@ def vispy_or_mpl_colormap(name):
     return cmap
 
 
-AVAILABLE_COLORMAPS = {k: vispy_or_mpl_colormap(k)
-                       for k in matplotlib_colormaps +
-                       list(vispy.color.get_colormaps())}
+# A dictionary mapping names to VisPy colormap objects
+ALL_COLORMAPS = {k: vispy_or_mpl_colormap(k) for k in matplotlib_colormaps}
+ALL_COLORMAPS.update(simple_colormaps)
 
+# ... sorted alphabetically by name
+AVAILABLE_COLORMAPS = {k: v for k, v in sorted(ALL_COLORMAPS.items())}
 
 @add_to_viewer
 class Image(Layer):
diff --git a/napari/util/colormaps/__init__.py b/napari/util/colormaps/__init__.py
--- a/napari/util/colormaps/__init__.py
+++ b/napari/util/colormaps/__init__.py
@@ -1 +1 @@
-from .colormaps import matplotlib_colormaps
+from .colormaps import matplotlib_colormaps, simple_colormaps
diff --git a/napari/util/colormaps/colormaps.py b/napari/util/colormaps/colormaps.py
--- a/napari/util/colormaps/colormaps.py
+++ b/napari/util/colormaps/colormaps.py
@@ -11,6 +11,23 @@
     matplotlib_colormaps = [line.rstrip() for line in fin]
 
 
+primary_color_names = ['red', 'green', 'blue',
+                       'cyan', 'magenta', 'yellow']
+primary_colors = np.array([
+        (1, 0, 0),
+        (0, 1, 0),
+        (0, 0, 1),
+        (0, 1, 1),
+        (1, 0, 1),
+        (1, 1, 0),
+    ], dtype=float)
+
+
+simple_colormaps = {name: vispy.color.Colormap([[0., 0., 0.], color])
+                    for name, color in
+                    zip(primary_color_names, primary_colors)}
+
+
 def _all_rgb():
     """Return all 256**3 valid rgb tuples."""
     base = np.arange(256, dtype=np.uint8)


Test patch:
Repository: napari/napari

Issue:
Labels colormap wrong
## 🐛 Bug

The labels colormap is now broken - I think from merging #330 - as it now renders with a different colormap and not the desired one. It's pretty unclear to be how this PR broke the functionality (or if it broke somewhere else), but it should be fixed!

Maybe @jni can look into it too


Discussion:
Here is an image of the colormap not working:
![image](https://user-images.githubusercontent.com/6531703/59473076-9e121580-8df5-11e9-880d-2d807695200f.png)

The problem is the `self.events.colormap()` call is now happening before the `self._qt_properties = QtLabelsLayer(self)` which we need to fix. I'll look into it


Resolving patch:
diff --git a/napari/layers/_labels_layer/model.py b/napari/layers/_labels_layer/model.py
--- a/napari/layers/_labels_layer/model.py
+++ b/napari/layers/_labels_layer/model.py
@@ -88,10 +88,10 @@ def __init__(
         self._need_display_update = False
         self._need_visual_update = False
 
-        self.events.opacity.connect(lambda e: self._update_thumbnail())
-
         self._node.clim = [0.0, 1.0]
-        self.events.colormap()
+        self._node.cmap = self.colormap
+
+        self.events.opacity.connect(lambda e: self._update_thumbnail())
 
     def raw_to_displayed(self, raw):
         """Determines displayed image from a saved raw image and a saved seed.


Test patch:
Repository: napari/napari

Issue:
styling on layer widgets on new layer
## 🐛 Bug

When a new layer gets added the styling of the new layer does not reflect that it is selected, but the control panels display and functionality indicates that it is


Discussion:
see the [3rd](https://github.com/napari/napari/pull/330#discussion_r293176542) and [4th](https://github.com/napari/napari/pull/330#discussion_r293176737) review comment on https://github.com/napari/napari/pull/330#pullrequestreview-249089637

Resolving patch:
diff --git a/napari/layers/_base_layer/view/properties.py b/napari/layers/_base_layer/view/properties.py
--- a/napari/layers/_base_layer/view/properties.py
+++ b/napari/layers/_base_layer/view/properties.py
@@ -21,8 +21,8 @@ def __init__(self, layer):
         super().__init__()
 
         self.layer = layer
-        layer.events.select.connect(self._on_select)
-        layer.events.deselect.connect(self._on_deselect)
+        layer.events.select.connect(lambda v: self.setSelected(True))
+        layer.events.deselect.connect(lambda v: self.setSelected(False))
         layer.events.name.connect(self._on_layer_name_change)
         layer.events.blending.connect(self._on_blending_change)
         layer.events.opacity.connect(self._on_opacity_change)
@@ -120,15 +120,11 @@ def __init__(self, layer):
         self.grid_layout.setColumnMinimumWidth(0, 100)
         self.grid_layout.setColumnMinimumWidth(1, 100)
 
-    def _on_select(self, event):
-        self.setProperty('selected', True)
-        self.nameTextBox.setEnabled(True)
-        self.style().unpolish(self)
-        self.style().polish(self)
+        self.setSelected(True)
 
-    def _on_deselect(self, event):
-        self.setProperty('selected', False)
-        self.nameTextBox.setEnabled(False)
+    def setSelected(self, state):
+        self.setProperty('selected', state)
+        self.nameTextBox.setEnabled(state)
         self.style().unpolish(self)
         self.style().polish(self)
 


Test patch:
Repository: napari/napari

Issue:
Canvas splitter no longer expanding when widening the viewer
## 🐛 Bug

Introduced by #443 or #453 I presume.

![napari-resize](https://user-images.githubusercontent.com/492549/62437699-ebca4080-b709-11e9-8683-6f58908bec3e.png)


Discussion:
oops - was caused by #443 - will fix :-(

Resolving patch:
diff --git a/napari/_qt/qt_viewer.py b/napari/_qt/qt_viewer.py
--- a/napari/_qt/qt_viewer.py
+++ b/napari/_qt/qt_viewer.py
@@ -13,7 +13,7 @@
     QFileDialog,
     QSplitter,
 )
-from qtpy.QtWidgets import QStackedWidget
+from qtpy.QtWidgets import QStackedWidget, QSizePolicy
 from qtpy.QtGui import QCursor, QPixmap
 from qtpy import API_NAME
 from vispy.scene import SceneCanvas, PanZoomCamera, ArcballCamera
@@ -89,6 +89,7 @@ def __init__(self, viewer):
         right_layout.addWidget(self.layers)
         right_layout.addWidget(self.buttons)
         right.setLayout(right_layout)
+        right.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
 
         left = self.controls
 


Test patch:
Repository: napari/napari

Issue:
label layer can have its label id reduced below 0
## 🐛 Bug

not via the UI but via the property/keybindings

side-effect: the color preview thingy on the left disappears when this happens


Discussion:

Resolving patch:
diff --git a/napari/layers/labels/labels.py b/napari/layers/labels/labels.py
--- a/napari/layers/labels/labels.py
+++ b/napari/layers/labels/labels.py
@@ -252,6 +252,11 @@ def selected_label(self):
 
     @selected_label.setter
     def selected_label(self, selected_label):
+        if selected_label < 0:
+            raise ValueError('cannot reduce selected label below 0')
+        if selected_label == self.selected_label:
+            return
+
         self._selected_label = selected_label
         self._selected_color = self.get_color(selected_label)
         self.events.selected_label()


Test patch:
Repository: napari/napari

Issue:
Menu bar focus on Mac
## 🐛 Bug
We've now added a menubar, but you need to toggle focus in and out of napari before it becomes active on the mac. This bug has been encountered in other Qt apps, but we still need to look into fixing.

See here - https://github.com/robotology/yarp/issues/457


Discussion:

Resolving patch:
diff --git a/napari/_qt/qt_main_window.py b/napari/_qt/qt_main_window.py
--- a/napari/_qt/qt_main_window.py
+++ b/napari/_qt/qt_main_window.py
@@ -146,7 +146,6 @@ def show(self):
         """
         self._qt_window.resize(self._qt_window.layout().sizeHint())
         self._qt_window.show()
-        self._qt_window.raise_()
 
     def _update_palette(self, palette):
         # set window styles which don't use the primary stylesheet


Test patch:
Repository: napari/napari

Issue:
Repo cleanup on github and pypi
## 🐛 Not a bug but a cleanup request

We have some stall repos and packages on github and pypi.
pypi: napari-gui
github: image-types, plugin-cookiecutter,  ...

I think it would be great to clean that up and for example delete
napari-gui so as to avoid confusion and in general clutter... 
 
We can discuss here what can be deleted or somehow archived.
Perhaps we could have an archive repo on github  to keep old
unused code, i.e. some of Kira's  original plugin machinery for 
reference and future use. This is better than having repos that
appear legit to newcomers but are in fact completely stale. An 
archive repo would be a very explicit place to retire such old
stuff while keeping them for future reference.




Discussion:
related to this, we should be cleaning branches on napari repo as well
`image-types` is experimental but not deprecated...

We could move some of these to people's personal accounts, including `image-types`...
I don't have access rights to our old https://pypi.org/project/napari-gui/ - @jni is there a way to archive that?
Can we also maybe clean-up / organize the number of files we have at the top level directory - for example can we maybe put all our `CAPS_LOCK.md` files apart from `README.md` into a folder in `docs`? Maybe our `LICENSE` can go in there too? Maybe `generate_release_notes.py` can also find another home? Maybe our `.github` folder with our templates we can also put inside `docs` and drop the `.` from?

I just feel when people arrive now they have to scroll quite a lot to get to our the actual readme, and the number of files at the top level might be intimidating
I partially agree @sofroniewn . I think `README.md` and `LICENSE` should stay at root but for rest we can find new homes.

About `.github` folder i think github has a hook specifically with that name. I am not sure if we can drop the `.`.
I achieved repos that i found unused. Please do check, if there are no complaints, i can delete those. 
I'm ok with deleting those, but imho we should wait for @kne42 to be back to get her go ahead. She did a lot of that early work and might like to have a copy of it. If you want to do the cleanup urgently, you could create a new org, eg `napari-archive`, and transfer ownership of those repos to that.
yeah, let's wait. I think no need for the new org right now, might only lead to more confusion. I don't see it as that urgent.

The one repo I might make an exception for is `napari-app` because the only thing on there is a PR from @jni. Do you agree @jni?
Oh yeah, nuke that sucker! =P
i just deleted `napari-app`. @jni has deleted `napari-gui` from PyPi.

let's leave this open till I rearrange our docs files as discussed with @AhmetCanSolak 

Resolving patch:
diff --git a/generate_release_notes.py b/docs/release/generate_release_notes.py
similarity index 100%
rename from generate_release_notes.py
rename to docs/release/generate_release_notes.py


Test patch:
Repository: napari/napari

Issue:
io.magic_read not updated in __main__.py
## 🐛 Bug

Call to `io.magic_read()` on line 56 of `__main__.py` not updated to `io.magic_imread()` after #601 

<!-- A clear and concise description of what the bug is. -->

## To Reproduce

Steps to reproduce the behavior:

1. Running `napari some_file.png` from command line

I'm happy to open this one line change Pull Request, or it can be done by one of the maintainers




Discussion:
If you can make a PR to fix that would be great! my fault!

Resolving patch:
diff --git a/napari/__main__.py b/napari/__main__.py
--- a/napari/__main__.py
+++ b/napari/__main__.py
@@ -53,7 +53,7 @@ def main():
     with gui_qt():
         v = Viewer()
         if len(args.images) > 0:
-            images = io.magic_read(
+            images = io.magic_imread(
                 args.images, use_dask=args.use_dask, stack=not args.layers
             )
             if args.layers:


Test patch:
Repository: napari/napari

Issue:
channel_axis argument fails with dask.array
## 🐛 Bug
Just wanted to post this here so I don't forget.
Dask arrays do not have a `take` method, so if you try to call `add/view_image` on a dask array with the `channel_axis` argument, you get: `AttributeError: 'Array' object has no attribute 'take'` at line 552 below:

https://github.com/napari/napari/blob/15deef08f1aea5e6a6951f7a83d4713f16070ed4/napari/components/viewer_model.py#L545-L552

```python
import napari
import numpy as np
import dask.array as da 

napari.view_image(np.random.random((2,10,10,10)), channel_axis=0)  # works
napari.view_image(da.random.random((2,10,10,10)), channel_axis=0)  # Attribute Error
```
Can't immediately think of an elegant fix, other than checking if `isinstance(data, da.Array)` and then calling `da.take`


Discussion:
That's no good! I thought I had tried this with a dask array, but evidently not. Here is the dock string for [`da.take`](https://docs.dask.org/en/latest/array-api.html#dask.array.take). It looks like this can actually just be replaced by `np.take` and that will still return as dask array. i will make a short PR

Resolving patch:
diff --git a/napari/components/viewer_model.py b/napari/components/viewer_model.py
--- a/napari/components/viewer_model.py
+++ b/napari/components/viewer_model.py
@@ -545,11 +545,11 @@ def add_image(
             for i, cmap, clims, _gamma, name in zipped_args:
                 if is_pyramid:
                     image = [
-                        data[j].take(i, axis=channel_axis)
+                        np.take(data[j], i, axis=channel_axis)
                         for j in range(len(data))
                     ]
                 else:
-                    image = data.take(i, axis=channel_axis)
+                    image = np.take(data, i, axis=channel_axis)
                 layer = layers.Image(
                     image,
                     rgb=rgb,


Test patch:
diff --git a/napari/components/tests/test_multichannel.py b/napari/components/tests/test_multichannel.py
--- a/napari/components/tests/test_multichannel.py
+++ b/napari/components/tests/test_multichannel.py
@@ -1,4 +1,5 @@
 import numpy as np
+import dask.array as da
 from napari.components import ViewerModel
 from napari.util import colormaps
 
@@ -174,3 +175,15 @@ def test_rgb_images():
     for i in range(data.shape[-1]):
         assert viewer.layers[i].rgb is True
         assert viewer.layers[i]._data_view.ndim == 3
+
+
+def test_dask_array():
+    """Test adding multichannel dask array."""
+    viewer = ViewerModel()
+    np.random.seed(0)
+    data = da.random.random((2, 10, 10, 5))
+    viewer.add_image(data, channel_axis=0)
+    assert len(viewer.layers) == data.shape[0]
+    for i in range(data.shape[0]):
+        assert viewer.layers[i].data.shape == data.shape[1:]
+        assert isinstance(viewer.layers[i].data, da.Array)
Repository: napari/napari

Issue:
Tests failing on numpy 1.18
## 🐛 Bug
we've got some new problems with our tests and numpy 1.18.
these two are failing:
`napari/layers/labels/tests/test_label_utils.py::test_interpolate_coordinates`
`napari/layers/labels/tests/test_labels.py::test_mouse_move`

see for example: https://cirrus-ci.com/task/4992774893469696

Tests failing on numpy 1.18
## 🐛 Bug
we've got some new problems with our tests and numpy 1.18.
these two are failing:
`napari/layers/labels/tests/test_label_utils.py::test_interpolate_coordinates`
`napari/layers/labels/tests/test_labels.py::test_mouse_move`

see for example: https://cirrus-ci.com/task/4992774893469696



Discussion:

Resolving patch:
diff --git a/napari/layers/labels/labels_utils.py b/napari/layers/labels/labels_utils.py
--- a/napari/layers/labels/labels_utils.py
+++ b/napari/layers/labels/labels_utils.py
@@ -24,7 +24,7 @@ def interpolate_coordinates(old_coord, new_coord, brush_size):
         max(abs(np.array(new_coord) - np.array(old_coord))) / brush_size * 4
     )
     coords = [
-        np.linspace(old_coord[i], new_coord[i], num=num_step + 1)
+        np.linspace(old_coord[i], new_coord[i], num=int(num_step + 1))
         for i in range(len(new_coord))
     ]
     coords = np.stack(coords).T


Test patch:
Repository: napari/napari

Issue:
Crash when trying the right click contrast limits slider popup 
Hi every one!
I was really excited with the new features of the last release. Unfortunately, I quickly run into an issue:  when trying the new right click feature on contrast limits, napari throws an error and ignores the click if launched from spyder (using `with napari.gui_qt():`), or throws the error and exits when launched as standalone from the conda prompt.

This is the error that it throws:
```
WARNING: Traceback (most recent call last):
  File "c:\users\nico\anaconda3\lib\site-packages\napari\_qt\layers\qt_image_base_layer.py", line 78, in _clim_mousepress
    self.clim_pop.show_at('top')
  File "c:\users\nico\anaconda3\lib\site-packages\napari\_qt\qt_modal.py", line 72, in show_at
    self.setGeometry(*xy.toTuple(), max(width, 20), max(height, 20))
AttributeError: 'QPoint' object has no attribute 'toTuple'
WARNING:vispy:Traceback (most recent call last):
  File "c:\users\nico\anaconda3\lib\site-packages\napari\_qt\layers\qt_image_base_layer.py", line 78, in _clim_mousepress
    self.clim_pop.show_at('top')
  File "c:\users\nico\anaconda3\lib\site-packages\napari\_qt\qt_modal.py", line 72, in show_at
    self.setGeometry(*xy.toTuple(), max(width, 20), max(height, 20))
AttributeError: 'QPoint' object has no attribute 'toTuple'
```
I am running python 3.7.4 on a conda install in Windows 10, with the latest qt version. Let me know if a can provide any other piece of information useful to debug this.

Thanks, and congatulations for this awesome piece of software!

Nico



Discussion:
Thanks for the report!  Will take a look ASAP 
Thanks for the report @ndefrancesco! I can replicate this. It appears that we wrote some code that was incompatible with both PyQt5 and PySide2.

Resolving patch:
diff --git a/napari/_qt/qt_modal.py b/napari/_qt/qt_modal.py
--- a/napari/_qt/qt_modal.py
+++ b/napari/_qt/qt_modal.py
@@ -69,7 +69,7 @@ def show_at(self, position='top', *, width_ratio=0.9):
 
         # necessary for transparent round corners
         self.resize(self.sizeHint())
-        self.setGeometry(*xy.toTuple(), max(width, 20), max(height, 20))
+        self.setGeometry(xy.x(), xy.y(), max(width, 20), max(height, 20))
         self.show()
 
     def keyPressEvent(self, event):


Test patch:
Repository: napari/napari

Issue:
picking label outside 
## 🐛 Bug
Tiny little bug that I can't fix now but don't want to forget.  When using "pick mode" in a label layer, if you click outside the image, you get:
```
Traceback (most recent call last):
  File "~/miniconda3/envs/napdev/lib/python3.7/site-packages/vispy/app/backends/_qt.py", line 447, in mousePressEvent
    modifiers=self._modifiers(ev),
  File "~/miniconda3/envs/napdev/lib/python3.7/site-packages/vispy/app/base.py", line 181, in _vispy_mouse_press
    ev = self._vispy_canvas.events.mouse_press(**kwargs)
  File "~/miniconda3/envs/napdev/lib/python3.7/site-packages/vispy/util/event.py", line 455, in __call__
    self._invoke_callback(cb, event)
  File "~/miniconda3/envs/napdev/lib/python3.7/site-packages/vispy/util/event.py", line 475, in _invoke_callback
    self, cb_event=(cb, event))
  File "~/miniconda3/envs/napdev/lib/python3.7/site-packages/vispy/util/event.py", line 471, in _invoke_callback
    cb(event)
  File "~/napari/napari/_qt/qt_viewer.py", line 338, in on_mouse_press
    self.layer_to_visual[layer].on_mouse_press(event)
  File "~/napari/napari/_vispy/vispy_base_layer.py", line 194, in on_mouse_press
    self.layer.on_mouse_press(event)
  File "~/napari/napari/layers/labels/labels.py", line 542, in on_mouse_press
    self.selected_label = self._value
  File "~/napari/napari/layers/labels/labels.py", line 270, in selected_label
    if selected_label < 0:
TypeError: '<' not supported between instances of 'NoneType' and 'int'
```


Discussion:
ah good catch - should be fixed

Resolving patch:
diff --git a/napari/layers/labels/labels.py b/napari/layers/labels/labels.py
--- a/napari/layers/labels/labels.py
+++ b/napari/layers/labels/labels.py
@@ -539,7 +539,7 @@ def on_mouse_press(self, event):
             # If in pan/zoom mode do nothing
             pass
         elif self._mode == Mode.PICKER:
-            self.selected_label = self._value
+            self.selected_label = self._value or 0
         elif self._mode == Mode.PAINT:
             # Start painting with new label
             self._save_history()


Test patch:
Repository: napari/napari

Issue:
Setup.py displays invalid command
Not sure why, but setup.py says `pip install python==3.6` installs Python 3.6, which is not at all true?  pip is a dependency manager for Python, not a version manager like [RVM](https://rvm.io), I think you may be looking for Pyenv?


Discussion:
You're completely right, thanks for reporting this! If you'd like to remove these incorrect instructions, it'd be a pretty simple PR. Otherwise I can do this for you :)

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -4,6 +4,12 @@
 GUI component of Napari.
 """
 
+import os.path as osp
+import sys
+from setuptools import setup, find_packages
+
+import versioneer
+
 MIN_PY_VER = '3.6'
 DISTNAME = 'napari'
 DESCRIPTION = 'n-dimensional array viewer in Python.'
@@ -33,22 +39,12 @@
     'Operating System :: MacOS',
 ]
 
-
-import os
-import os.path as osp
-import sys
-from setuptools import setup, find_packages
-
-import versioneer
-
-
 if sys.version_info < (3, 6):
     sys.stderr.write(
         f'You are using Python '
         + "{'.'.join(str(v) for v in sys.version_info[:3])}.\n\n"
         + 'napari only supports Python 3.6 and above.\n\n'
-        + 'Please install Python 3.6 using:\n'
-        + '  $ pip install python==3.6\n\n'
+        + 'Please install Python 3.6 or later.\n'
     )
     sys.exit(1)
 


Test patch: