nodes: 0, module; 1, function_definition; 2, function_name:get_best_dataset_key; 3, parameters; 4, block; 5, identifier:key; 6, identifier:choices; 7, expression_statement; 8, comment:# Choose the wavelength closest to the choice; 9, if_statement; 10, if_statement; 11, if_statement; 12, if_statement; 13, if_statement; 14, return_statement; 15, comment:"""Choose the "best" `DatasetID` from `choices` based on `key`.
  
      The best key is chosen based on the follow criteria:
  
          1. Central wavelength is nearest to the `key` wavelength if
             specified.
          2. Least modified dataset if `modifiers` is `None` in `key`.
             Otherwise, the modifiers are ignored.
          3. Highest calibration if `calibration` is `None` in `key`.
             Calibration priority is chosen by `satpy.CALIBRATION_ORDER`.
          4. Best resolution (smallest number) if `resolution` is `None`
             in `key`. Otherwise, the resolution is ignored.
  
      This function assumes `choices` has already been filtered to only
      include datasets that match the provided `key`.
  
      Args:
          key (DatasetID): Query parameters to sort `choices` by.
          choices (iterable): `DatasetID` objects to sort through to determine
                              the best dataset.
  
      Returns: List of best `DatasetID`s from `choices`. If there is more
               than one element this function could not choose between the
               available datasets.
  
      """; 16, boolean_operator; 17, comment:# find the dataset with a central wavelength nearest to the; 18, comment:# requested wavelength; 19, block; 20, boolean_operator; 21, block; 22, boolean_operator; 23, block; 24, boolean_operator; 25, block; 26, boolean_operator; 27, block; 28, identifier:choices; 29, comparison_operator:key.wavelength is not None; 30, identifier:choices; 31, expression_statement; 32, expression_statement; 33, comparison_operator:key.modifiers is None; 34, identifier:choices; 35, expression_statement; 36, expression_statement; 37, comparison_operator:key.calibration is None; 38, identifier:choices; 39, expression_statement; 40, if_statement; 41, comparison_operator:key.resolution is None; 42, identifier:choices; 43, expression_statement; 44, if_statement; 45, comparison_operator:key.level is None; 46, identifier:choices; 47, expression_statement; 48, if_statement; 49, attribute; 50, None; 51, assignment; 52, assignment; 53, attribute; 54, None; 55, assignment; 56, assignment; 57, attribute; 58, None; 59, assignment; 60, identifier:best_cal; 61, block; 62, attribute; 63, None; 64, assignment; 65, identifier:low_res; 66, block; 67, attribute; 68, None; 69, assignment; 70, identifier:low_level; 71, block; 72, identifier:key; 73, identifier:wavelength; 74, identifier:nearest_wl; 75, call; 76, identifier:choices; 77, list_comprehension; 78, identifier:key; 79, identifier:modifiers; 80, identifier:num_modifiers; 81, call; 82, identifier:choices; 83, list_comprehension; 84, identifier:key; 85, identifier:calibration; 86, identifier:best_cal; 87, list_comprehension; 88, expression_statement; 89, expression_statement; 90, identifier:key; 91, identifier:resolution; 92, identifier:low_res; 93, list_comprehension; 94, expression_statement; 95, expression_statement; 96, identifier:key; 97, identifier:level; 98, identifier:low_level; 99, list_comprehension; 100, expression_statement; 101, expression_statement; 102, identifier:min; 103, argument_list; 104, identifier:c; 105, for_in_clause; 106, if_clause; 107, identifier:min; 108, generator_expression; 109, identifier:c; 110, for_in_clause; 111, if_clause; 112, attribute; 113, for_in_clause; 114, if_clause; 115, assignment; 116, assignment; 117, attribute; 118, for_in_clause; 119, if_clause; 120, assignment; 121, assignment; 122, attribute; 123, for_in_clause; 124, if_clause; 125, assignment; 126, assignment; 127, list_comprehension; 128, identifier:c; 129, identifier:choices; 130, comparison_operator:_wl_dist(key.wavelength, c.wavelength) == nearest_wl; 131, call; 132, for_in_clause; 133, identifier:c; 134, identifier:choices; 135, comparison_operator:len(
              c.modifiers or tuple()) == num_modifiers; 136, identifier:x; 137, identifier:calibration; 138, identifier:x; 139, identifier:choices; 140, attribute; 141, identifier:best_cal; 142, call; 143, identifier:choices; 144, list_comprehension; 145, identifier:x; 146, identifier:resolution; 147, identifier:x; 148, identifier:choices; 149, attribute; 150, identifier:low_res; 151, call; 152, identifier:choices; 153, list_comprehension; 154, identifier:x; 155, identifier:level; 156, identifier:x; 157, identifier:choices; 158, attribute; 159, identifier:low_level; 160, call; 161, identifier:choices; 162, list_comprehension; 163, call; 164, for_in_clause; 165, if_clause; 166, call; 167, identifier:nearest_wl; 168, identifier:len; 169, argument_list; 170, identifier:x; 171, identifier:choices; 172, call; 173, identifier:num_modifiers; 174, identifier:x; 175, identifier:calibration; 176, identifier:min; 177, argument_list; 178, identifier:c; 179, for_in_clause; 180, if_clause; 181, identifier:x; 182, identifier:resolution; 183, identifier:min; 184, argument_list; 185, identifier:c; 186, for_in_clause; 187, if_clause; 188, identifier:x; 189, identifier:level; 190, identifier:max; 191, argument_list; 192, identifier:c; 193, for_in_clause; 194, if_clause; 195, identifier:_wl_dist; 196, argument_list; 197, identifier:x; 198, identifier:choices; 199, comparison_operator:x.wavelength is not None; 200, identifier:_wl_dist; 201, argument_list; 202, boolean_operator; 203, identifier:len; 204, argument_list; 205, identifier:best_cal; 206, keyword_argument; 207, identifier:c; 208, identifier:choices; 209, comparison_operator:c.calibration == best_cal; 210, identifier:low_res; 211, identifier:c; 212, identifier:choices; 213, comparison_operator:c.resolution == low_res; 214, identifier:low_level; 215, identifier:c; 216, identifier:choices; 217, comparison_operator:c.level == low_level; 218, attribute; 219, attribute; 220, attribute; 221, None; 222, attribute; 223, attribute; 224, attribute; 225, call; 226, boolean_operator; 227, identifier:key; 228, lambda; 229, attribute; 230, identifier:best_cal; 231, attribute; 232, identifier:low_res; 233, attribute; 234, identifier:low_level; 235, identifier:key; 236, identifier:wavelength; 237, identifier:x; 238, identifier:wavelength; 239, identifier:x; 240, identifier:wavelength; 241, identifier:key; 242, identifier:wavelength; 243, identifier:c; 244, identifier:wavelength; 245, identifier:x; 246, identifier:modifiers; 247, identifier:tuple; 248, argument_list; 249, attribute; 250, call; 251, lambda_parameters; 252, subscript; 253, identifier:c; 254, identifier:calibration; 255, identifier:c; 256, identifier:resolution; 257, identifier:c; 258, identifier:level; 259, identifier:c; 260, identifier:modifiers; 261, identifier:tuple; 262, argument_list; 263, identifier:x; 264, identifier:CALIBRATION_ORDER; 265, identifier:x
code: def get_best_dataset_key(key, choices):
      """Choose the "best" `DatasetID` from `choices` based on `key`.
  
      The best key is chosen based on the follow criteria:
  
          1. Central wavelength is nearest to the `key` wavelength if
             specified.
          2. Least modified dataset if `modifiers` is `None` in `key`.
             Otherwise, the modifiers are ignored.
          3. Highest calibration if `calibration` is `None` in `key`.
             Calibration priority is chosen by `satpy.CALIBRATION_ORDER`.
          4. Best resolution (smallest number) if `resolution` is `None`
             in `key`. Otherwise, the resolution is ignored.
  
      This function assumes `choices` has already been filtered to only
      include datasets that match the provided `key`.
  
      Args:
          key (DatasetID): Query parameters to sort `choices` by.
          choices (iterable): `DatasetID` objects to sort through to determine
                              the best dataset.
  
      Returns: List of best `DatasetID`s from `choices`. If there is more
               than one element this function could not choose between the
               available datasets.
  
      """
      # Choose the wavelength closest to the choice
      if key.wavelength is not None and choices:
          # find the dataset with a central wavelength nearest to the
          # requested wavelength
          nearest_wl = min([_wl_dist(key.wavelength, x.wavelength)
                            for x in choices if x.wavelength is not None])
          choices = [c for c in choices
                     if _wl_dist(key.wavelength, c.wavelength) == nearest_wl]
      if key.modifiers is None and choices:
          num_modifiers = min(len(x.modifiers or tuple()) for x in choices)
          choices = [c for c in choices if len(
              c.modifiers or tuple()) == num_modifiers]
      if key.calibration is None and choices:
          best_cal = [x.calibration for x in choices if x.calibration]
          if best_cal:
              best_cal = min(best_cal, key=lambda x: CALIBRATION_ORDER[x])
              choices = [c for c in choices if c.calibration == best_cal]
      if key.resolution is None and choices:
          low_res = [x.resolution for x in choices if x.resolution]
          if low_res:
              low_res = min(low_res)
              choices = [c for c in choices if c.resolution == low_res]
      if key.level is None and choices:
          low_level = [x.level for x in choices if x.level]
          if low_level:
              low_level = max(low_level)
              choices = [c for c in choices if c.level == low_level]
  
      return choices