add dimension to an xarray DataArray
<p>I need to add a dimension to a <code>DataArray</code>, filling the values across the new dimension. Here's the original array.</p>

<pre><code>a_size = 10
a_coords = np.linspace(0, 1, a_size)

b_size = 5
b_coords = np.linspace(0, 1, b_size)

# original 1-dimensional array
x = xr.DataArray(
    np.random.random(a_size),
    coords=[('a', a coords)])
</code></pre>

<p>I guess I could create an empty DataArray with the new dimension and copy the existing data in.</p>

<pre><code>y = xr.DataArray(
    np.empty((b_size, a_size),
    coords=([('b', b_coords), ('a', a_coords)])
y[:] = x
</code></pre>

<p>A better idea might be to be to use <code>concat</code>. It took me a while to figure out how to specify both the dims and the coords for the concat dimension, and none of these options seem great. Is there something I'm missing that can makes this version cleaner?</p>

<pre><code># specify the dimension name, then set the coordinates
y = xr.concat([x for _ in b_coords], 'b')
y['b'] = b_coords

# specify the coordinates, then rename the dimension
y = xr.concat([x for _ in b_coords], b_coords)
y.rename({'concat_dim': 'b'})

# use a DataArray as the concat dimension
y = xr.concat(
    [x for _ in b_coords],
    xr.DataArray(b_coords, name='b', dims=['b']))
</code></pre>

<p>Still, is there a better way to do this than either of the two above options?</p>