Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tim-evain opened this issue Apr 29, 2020 · 0 comments
Open

Comments

@tim-evain
Copy link

tim-evain commented Apr 29, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant