Return QMED estimate using best available methodology depending on what catchment attributes are available.

        The preferred/best order of methods is defined by :attr:`qmed_methods`. Alternatively, a method can be supplied
        e.g. `method='descriptors_1999'` to force the use of a particular method.

        ================= ======================= ======================================================================
        `method`          `method_options`        notes
        ================= ======================= ======================================================================
        `amax_records`    n/a                     Simple median of annual maximum flow records using
                                                  `Catchment.amax_records`.
        `pot_records`     n/a                     Uses peaks-over-threshold (POT) flow records. Suitable for flow
                                                  records shorter than 14 years.
        `descriptors`                             Synonym for `method=descriptors2008`.
        `descriptors2008` `as_rural=False`        FEH 2008 regression methodology using `Catchment.descriptors`. Setting
                          `donor_catchments=None` `as_rural=True` returns rural estimate and setting `donor_catchments`
                                                  to a specific list of :class:`Catchment` object **overrides**
                                                  automatic selection of the most suitable donor catchment. An empty
                                                  list forces no donors to be used at all.
        `descriptors1999` as_rural=False          FEH 1999 regression methodology.
        `area`            n/a                     Simplified FEH 1999 regression methodology using
                                                  `Cachment.descriptors.dtm_area` only.
        `channel_width`   n/a                     Emperical regression method using the river channel width only.
        ================= ======================= ======================================================================

        :param method: methodology to use to estimate QMED. Default: automatically choose best method.
        :type method: str
        :param method_options: any optional parameters for the QMED method function, e.g. `as_rural=True`
        :type method_options: kwargs

        :return: QMED in m³/s
        :rtype: float

def qmed(self, method='best', **method_options):
        """
        Return QMED estimate using best available methodology depending on what catchment attributes are available.

        The preferred/best order of methods is defined by :attr:`qmed_methods`. Alternatively, a method can be supplied
        e.g. `method='descriptors_1999'` to force the use of a particular method.

        ================= ======================= ======================================================================
        `method`          `method_options`        notes
        ================= ======================= ======================================================================
        `amax_records`    n/a                     Simple median of annual maximum flow records using
                                                  `Catchment.amax_records`.
        `pot_records`     n/a                     Uses peaks-over-threshold (POT) flow records. Suitable for flow
                                                  records shorter than 14 years.
        `descriptors`                             Synonym for `method=descriptors2008`.
        `descriptors2008` `as_rural=False`        FEH 2008 regression methodology using `Catchment.descriptors`. Setting
                          `donor_catchments=None` `as_rural=True` returns rural estimate and setting `donor_catchments`
                                                  to a specific list of :class:`Catchment` object **overrides**
                                                  automatic selection of the most suitable donor catchment. An empty
                                                  list forces no donors to be used at all.
        `descriptors1999` as_rural=False          FEH 1999 regression methodology.
        `area`            n/a                     Simplified FEH 1999 regression methodology using
                                                  `Cachment.descriptors.dtm_area` only.
        `channel_width`   n/a                     Emperical regression method using the river channel width only.
        ================= ======================= ======================================================================

        :param method: methodology to use to estimate QMED. Default: automatically choose best method.
        :type method: str
        :param method_options: any optional parameters for the QMED method function, e.g. `as_rural=True`
        :type method_options: kwargs

        :return: QMED in m³/s
        :rtype: float
        """
        if method == 'best':
            # Rules for gauged catchments
            if self.catchment.pot_dataset:
                if self.catchment.amax_records:
                    if self.catchment.record_length <= self.catchment.pot_dataset.record_length < 14:
                        use_method = 'pot_records'
                    elif self.catchment.record_length >= 2:
                        use_method = 'amax_records'
                    else:
                        use_method = None
                elif self.catchment.pot_dataset.record_length >= 1:
                    use_method = 'pot_records'
                else:
                    use_method = None
            elif self.catchment.record_length >= 2:
                use_method = 'amax_records'
            else:
                use_method = None  # None of the gauged methods will work
            if use_method:
                self.results_log['method'] = use_method
                return getattr(self, '_qmed_from_' + use_method)()

            # Ungauged methods
            for method in self.methods[1:]:
                try:
                    # Return the first method that works
                    self.results_log['method'] = method
                    return getattr(self, '_qmed_from_' + method)(**method_options)
                except (TypeError, InsufficientDataError):
                    pass
            # In case none of them worked
            return None

        else:
            # A specific method has been requested
            try:
                self.results_log['method'] = method
                return getattr(self, '_qmed_from_' + method)(**method_options)
            except AttributeError:
                raise AttributeError("Method `{}` to estimate QMED does not exist.".format(method))