docs: def convert_dataset(dataset_id, target_unit_abbreviation,**kwargs):
      """
          Convert a whole dataset (specified by 'dataset_id') to new unit ('target_unit_abbreviation').
          Conversion ALWAYS creates a NEW dataset, so function returns the dataset ID of new dataset.
      """
  
      ds_i = db.DBSession.query(Dataset).filter(Dataset.id==dataset_id).one()
  
      dataset_type = ds_i.type
  
      dsval = ds_i.get_val()
      source_unit_abbreviation = get_unit(ds_i.unit_id).abbreviation
  
      if source_unit_abbreviation is not None:
          if dataset_type == 'scalar':
              new_val = convert(float(dsval), source_unit_abbreviation, target_unit_abbreviation)
          elif dataset_type == 'array':
              dim = array_dim(dsval)
              vecdata = arr_to_vector(dsval)
              newvec = convert(vecdata, source_unit_abbreviation, target_unit_abbreviation)
              new_val = vector_to_arr(newvec, dim)
          elif dataset_type == 'timeseries':
              new_val = []
              for ts_time, ts_val in dsval.items():
                  dim = array_dim(ts_val)
                  vecdata = arr_to_vector(ts_val)
                  newvec = convert(vecdata, source_unit_abbreviation, target_unit_abbreviation)
                  newarr = vector_to_arr(newvec, dim)
                  new_val.append(ts_time, newarr)
          elif dataset_type == 'descriptor':
              raise HydraError('Cannot convert descriptor.')
  
          new_dataset = Dataset()
          new_dataset.type   = ds_i.type
          new_dataset.value  = str(new_val) # The data type is TEXT!!!
          new_dataset.name   = ds_i.name
  
          new_dataset.unit_id   = get_unit_by_abbreviation(target_unit_abbreviation).id
          new_dataset.hidden = 'N'
          new_dataset.set_metadata(ds_i.get_metadata_as_dict())
          new_dataset.set_hash()
  
          existing_ds = db.DBSession.query(Dataset).filter(Dataset.hash==new_dataset.hash).first()
  
          if existing_ds is not None:
              db.DBSession.expunge_all()
              return existing_ds.id
  
          db.DBSession.add(new_dataset)
          db.DBSession.flush()
  
          return new_dataset.id
  
      else:
          raise HydraError('Dataset has no units.')