code: def from_cesium_dataset(X):
      """Transform a cesium-compatible dataset into a tslearn dataset.
  
      Parameters
      ----------
      X: list of cesium TimeSeries
          cesium-formatted dataset (cf.
          `link <http://cesium-ml.org/docs/api/cesium.time_series.html#cesium.time_series.TimeSeries>`_)
  
      Returns
      -------
      array, shape=(n_ts, sz, d)
          tslearn-formatted dataset.
  
      Examples
      --------
      >>> from cesium.time_series import TimeSeries
      >>> cesium_ds = [TimeSeries(m=numpy.array([1, 2, 3, 4]))]
      >>> tslearn_arr = from_cesium_dataset(cesium_ds)
      >>> tslearn_arr.shape
      (1, 4, 1)
      >>> cesium_ds = [
      ...     TimeSeries(m=numpy.array([[1, 2, 3, 4],
      ...                               [5, 6, 7, 8]]))
      ... ]
      >>> tslearn_arr = from_cesium_dataset(cesium_ds)
      >>> tslearn_arr.shape
      (1, 4, 2)
  
      Notes
      -----
      Conversion from/to cesium format requires cesium to be installed.
      """  # noqa: E501
      try:
          from cesium.time_series import TimeSeries
      except ImportError:
          raise ImportError(
              "Conversion from/to cesium cannot be performed "
              "if cesium is not installed."
          )
  
      def format_to_tslearn(ts):
          try:
              ts.sort()
          except ValueError:
              warnings.warn(
                  "Cesium dataset could not be sorted, assuming "
                  "it is already sorted before casting to "
                  "tslearn format."
              )
          if ts.measurement.ndim == 1:
              data = ts.measurement.reshape((1, -1))
          else:
              data = ts.measurement
          d = len(data)
          max_sz = max([len(ts_di) for ts_di in data])
          tslearn_ts = numpy.empty((max_sz, d))
          tslearn_ts[:] = numpy.nan
          for di in range(d):
              sz = data[di].shape[0]
              tslearn_ts[:sz, di] = data[di]
          return tslearn_ts
  
      if not isinstance(X, list) or [type(ts) for ts in X] != [
          TimeSeries
      ] * len(X):
          raise ValueError(
              "X is not a valid input cesium array. "
              "A list of cesium TimeSeries is expected."
          )
      dataset = [format_to_tslearn(ts) for ts in X]
      return to_time_series_dataset(dataset=dataset)
  
file_path: tslearn/tslearn/utils/cast.py
imports: import warnings
  import numpy
  from sklearn.utils import check_array
  from .utils import check_dataset, ts_size, to_time_series_dataset
label_desc: Use image node_id 15 for calling a global function with example usage: from_cesium_dataset(X) and returns: to_time_series_dataset, tslearn_ts