code: def _to_rgb(data, mesh_data_kind):
      """
      Helper function to convert array to RGB(A) where required
      """
      if mesh_data_kind in ("rgb", "rgba"):
          cmap = plt.get_cmap()
          norm = mcolors.Normalize()
          new_data = cmap(norm(data))
          if mesh_data_kind == "rgb":
              new_data = new_data[..., 0:3]
              if np.ma.is_masked(data):
                  # Use data's mask as an alpha channel
                  mask = np.ma.getmaskarray(data)
                  mask = np.broadcast_to(
                      mask[..., np.newaxis], new_data.shape
                  ).copy()
                  new_data = np.ma.array(new_data, mask=mask)
  
          return new_data
  
      return data
  
imports: import re
  import matplotlib.colors
  import matplotlib.pyplot
  import numpy
  import pytest
  import cartopy.crs
  from cartopy.mpl import _MPL_38
  from cartopy.tests.conftest import requires_scipy
label_desc: Use image node_id 14 for calling a global function with example usage: _to_rgb(data, mesh_data_kind) and returns: data, new_data