hong2p.xarray module

Utility functions for working with xarray objects, primarily DataArrays

hong2p.xarray.assign_scalar_coords_to_dim(arr, dim)[source]

Returns DataArray with all scalar coordinates moved to dimension dim.

Assumes scalar coordinates are non-dimension coordinates.

May also depend on dim being of size >1 (at least for some intended uses)

Return type

DataArray

hong2p.xarray.drop_scalar_coords(arr)[source]

Returns DataArray with all scalar coordinates dropped.

Return type

DataArray

hong2p.xarray.is_scalar_coord(arr)[source]

Whether item from <DataArray>.coords.values() corresponds to a scalar coordinate.

Return type

bool

hong2p.xarray.move_all_coords_to_index(arr)[source]

Returns array with all coord variables associated with a dim to index on that dim

Return type

DataArray

hong2p.xarray.odor_corr_frame_to_dataarray(df, metadata=None)[source]

Converts (odor X odor) correlation DataFrame to DataArray.

Return type

DataArray

hong2p.xarray.scalar_coords(arr)[source]

Returns all scalar coordinates as a dict

Converts any datatime64[ns] to pandas Timestamp

Return type

dict

hong2p.xarray.unique_coord_value(arr, coord=None)[source]

Returns unique value for a DataArray coordinate, if there is one.

If arr[coord] has multiple values, raises ValueError.

Can also call like unique_coord_value(arr.<coord_name>).

Return type

Any