コード例 #1
0
ファイル: xarray.py プロジェクト: CagtayFabry/weldx
def xr_3d_matrix(data: wxt.ArrayLike, time: Time = None) -> xr.DataArray:
    """Create an xarray 3d matrix with correctly named dimensions and coordinates.

    Parameters
    ----------
    data :
        Data
    time :
        Optional time data (Default value = None)

    Returns
    -------
    xarray.DataArray

    """
    if time is not None and np.array(data).ndim == 3:
        if isinstance(time, Time):
            time = time.as_pandas_index()
        da = xr.DataArray(
            data=data,
            dims=["time", "c", "v"],
            coords={
                "time": time,
                "c": ["x", "y", "z"],
                "v": [0, 1, 2]
            },
        )
    else:
        da = xr.DataArray(
            data=data,
            dims=["c", "v"],
            coords={
                "c": ["x", "y", "z"],
                "v": [0, 1, 2]
            },
        )
    return da.astype(float).weldx.time_ref_restore()
コード例 #2
0
ファイル: test_time.py プロジェクト: CagtayFabry/weldx
 def test_pandas_index(arg, expected):
     """Test conversion to appropriate pd.TimedeltaIndex or pd.DatetimeIndex."""
     t = Time(arg)
     assert np.all(t.as_pandas_index() == expected)
     assert np.all(t.as_pandas_index() == t.index)
     assert np.all(t.as_timedelta_index() == t.timedelta)