code: def scale_timeseries_unit(tsunit, scaling='density'):
      
      # set units
      if scaling == 'density':
          baseunit = units.Hertz
      elif scaling == 'spectrum':
          baseunit = units.dimensionless_unscaled
      else:
          raise ValueError("Unknown scaling: %r" % scaling)
      if tsunit:
          specunit = tsunit ** 2 / baseunit
      else:
          specunit = baseunit ** -1
      return specunit
docs: Scale the unit of a `TimeSeries` to match that of a `FrequencySeries`
  
      Parameters
      ----------
      tsunit : `~astropy.units.UnitBase`
          input unit from `TimeSeries`
      scaling : `str`
          type of frequency series, either 'density' for a PSD, or
          'spectrum' for a power spectrum.
  
      Returns
      -------
      unit : `~astropy.units.Unit`
          unit to be applied to the resulting `FrequencySeries`.