Skip to content

Access to axis label's values conditionaly filtered on data values #248

Open
@tim-evain

Description

@tim-evain

Hi,

I'm trying to retrieve axis label values of data that fit a certain condition. With xarray (python) I would go with something like:

import numpy as np
import xarray as xr

data = xr.DataArray(np.random.random([5,2,2]),dims=('time','slice','biomarker'),coords={'time':[0,5,10,15,20],'slice':['-0.15','0.15'],'biomarker':['A','B']})
filt_data = data.where(data>0.5,drop=True)
retrieved_labels = []
for time_i in filt_data.time:
    for slice_i in filt_data.slice:
        for bio_i in filt_data.biomarker:
            if not filt_data.sel(time=time_i,slice=slice_i,biomarker=bio_i).isnull():
                retrieved_labels.append((time_i.values[()],slice_i.values[()],bio_i.values[()]))

but I'm failing to replicate that through xframe on multiple aspects:

xf::xaxis<int>
     time_axis = xf::axis({ 0,5,10,15,20 });
xf::xaxis<xf::fstring>
     slice_axis = xf::axis({ "-0.15", "0.15" }),
     biomarker_axis = xf::axis({ "A", "B" });
xf::xcoordinate<xf::fstring> coord_descriptor({ {"Time", time_axis}, {"Location", slice_axis},  {"Biomarker", biomarker_axis } });
xf::xdimension<xf::fstring> dim_organizer({ "Time", "SliceLocation", "Biomarker" }); 
xf::xvariable<double, xf::xcoordinate<xf::fstring>>::data_type data = xt::eval(xt::random::rand({ 5, 2, 2 }, 0., 1.));
xf::xvariable<double, xf::xcoordinate<xf::fstring>> data_array(data,coord_descriptor, dim_organizer);

//Axis values can later be fetched through:
auto t_axis = data_array.coordinates()["Time"];
std::vector<xf::fstring> all_labels = xf::get_labels<xf::fstring>(t_axis);
// or
xf::fstring label_X = xtl::xget<xf::fstring>(t_axis.label(X));

My bet was to go with masking with something like xf::where(data_array, data_array > 0.5), but that's not working since xf::where seems a filter on label and not data.

What would be the best way to achieve that?

Also, when looking for comparison operator, I wasn't able to find xf::greater and like functions in the code (from the "From xarray to xframe" documentation). I guess they are still under development?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions