def radolan_to_xarray(data, attrs): """Converts RADOLAN data to xarray Dataset Parameters ---------- data : :func:`numpy:numpy.array` array of shape (number of rows, number of columns) attrs : dict dictionary of metadata information from the file header Returns ------- dset : xarray.Dataset RADOLAN data and coordinates """ product = attrs["producttype"] pattrs = _get_radolan_product_attributes(attrs) radolan_grid_xy = rect.get_radolan_grid(attrs["nrow"], attrs["ncol"]) x0 = radolan_grid_xy[0, :, 0] y0 = radolan_grid_xy[:, 0, 1] if pattrs: if "nodatamask" in attrs: data.flat[attrs["nodatamask"]] = pattrs["_FillValue"] if "cluttermask" in attrs: data.flat[attrs["cluttermask"]] = pattrs["_FillValue"] darr = xr.DataArray( data, attrs=pattrs, dims=["y", "x"], coords={"time": attrs["datetime"], "x": x0, "y": y0}, ) dset = xr.Dataset({product: darr}) dset = dset.pipe(xr.decode_cf) return dset
def radolan_to_xarray(data, attrs): """Converts RADOLAN data to xarray Dataset Parameters ---------- data : :func:`numpy:numpy.array` array of shape (number of rows, number of columns) attrs : dict dictionary of metadata information from the file header Returns ------- dset : xarray.Dataset RADOLAN data and coordinates """ product = attrs['producttype'] pattrs = _get_radolan_product_attributes(attrs) radolan_grid_xy = rect.get_radolan_grid(attrs['nrow'], attrs['ncol']) x0 = radolan_grid_xy[0, :, 0] y0 = radolan_grid_xy[:, 0, 1] if pattrs: if 'nodatamask' in attrs: data.flat[attrs['nodatamask']] = pattrs['_FillValue'] if 'cluttermask' in attrs: data.flat[attrs['cluttermask']] = pattrs['_FillValue'] darr = xr.DataArray( data, attrs=pattrs, dims=['y', 'x'], coords={ 'time': attrs['datetime'], 'x': x0, 'y': y0, }, ) dset = xr.Dataset({product: darr}) dset = dset.pipe(xr.decode_cf) return dset