Thank you very much Matthew!

Your idea did work, however I had to change it a bit. I’m leaving the code here so that anyone can use it:

ad = ds.all_data() # or whatever data object you want
mi_base = ad["index", "morton_index"].view('u8')
a_gas = wherever_you_got_it_from()

def match_gas(field, data):
    mi = data["index", "morton_index"].view('u8')
    mi = np.reshape(mi, mi.size)
    if np.count_nonzero(mi_base == mi[0]) != 0:
        starting_point = np.nonzero(mi_base == mi[0])[0][0]
        return a_gas[starting_point:starting_point + mi.size, 0]
    else:
        return data['relative_x']

The problem was that in the derived field the data are given in a different format:
mi_base.shape gives (35026307,)
mi.shape gives (16, 16, 16)

So I had to reshape it to turn into a 1d array. I guess, the data are given in some chunks here.

Then, even though mi_base included all data in the dataset, some marton indexes wouldn’t match in starting_point = np.nonzero(mi_base == mi[0])[0][0] and I would be given an empty array (array([], dtype=int64),). I took that into account by checking np.count_nonzero, and fill cells with zeros if the indexes don’t match.

Again, many thanks
Nina