Transform the field-to-obs mapping into a printable dictionary.

  Args:
    field_to_obs: Dict that maps string field to `Observation` list.

  Returns:
    A dict with the keys and values to print to console.
969953
def get_dict_to_print(field_to_obs):
  

  def compressed_steps(steps):
    return {'num_steps': len(set(steps)),
            'min_step': min(steps),
            'max_step': max(steps),
            'last_step': steps[-1],
            'first_step': steps[0],
            'outoforder_steps': get_out_of_order(steps)}

  def full_steps(steps):
    return {'steps': steps, 'outoforder_steps': get_out_of_order(steps)}

  output = {}
  for field, observations in field_to_obs.items():
    if not observations:
      output[field] = None
      continue

    steps = [x['step'] for x in observations]
    if field in SHORT_FIELDS:
      output[field] = compressed_steps(steps)
    if field in LONG_FIELDS:
      output[field] = full_steps(steps)

  return output
1242156
def from_stream(cls, stream, marker_code, offset):
        
        # field                 off  type   notes
        # ------------------  ---  -----  ----------------------------
        # segment length       0   short
        # Data precision       2   byte
        # Vertical lines       3   short  px_height
        # Horizontal lines     5   short  px_width
        # ------------------  ---  -----  ----------------------------
        segment_length = stream.read_short(offset)
        px_height = stream.read_short(offset, 3)
        px_width = stream.read_short(offset, 5)
        return cls(marker_code, offset, segment_length, px_width, px_height)
363738
def _convert_observ(self, observ):
    
    if not np.isfinite(observ).all():
      raise ValueError('Infinite observation encountered.')
    if observ.dtype == np.float64:
      return observ.astype(np.float32)
    if observ.dtype == np.int64:
      return observ.astype(np.int32)
    return observ
356528
def retrieve_outputs(self):
        

        metrics = {}
        for obs in self._observers['cv_metrics']:
            metrics[obs.name] = obs.retrieve_metrics()
        self.metrics = metrics
382562
def model_to_dict(instance, fields=None, exclude=None):
    

    return {
        field.name: field_to_dict(field, instance)
        for field in chain(instance._meta.concrete_fields, instance._meta.many_to_many)  # pylint: disable=W0212
        if not should_exclude_field(field, fields, exclude)
    }
762674
def to_dict(self):
        
        return {field_name: getattr(self, field_name, None)
                for field_name in self.meta_.declared_fields}
1354832
def _build_obs(self, **kwargs):
        
        logging.debug('Building ObservationTree...')
        tree = ObservationTree()
        for k,v in kwargs.items():
            if k in self.ic.bands:
                if np.size(v) != 2:
                    logging.warning('{}={} ignored.'.format(k,v))
                    # continue
                    v = [v, np.nan]
                o = Observation('', k, 99) #bogus resolution=99
                s = Source(v[0], v[1])
                o.add_source(s)
                logging.debug('Adding {} ({})'.format(s,o))
                tree.add_observation(o)

        self.obs = tree
522539
def _encode_observations(self, observations):
    """"""
    return [
        Observation(
            self._session.obj.run(
                self._encoded_image_t.obj,
                feed_dict={self._decoded_image_p.obj: observation}
            ),
            self._decode_png
        )
        for observation in observations
    ]
1240373
def add_obs_function(self):
        
        obs_function = self.model['obs_function']
        for condition in obs_function:
            condprob = etree.SubElement(self.observation_function, 'CondProb')
            self.add_conditions(condition, condprob)
        return self.__str__(self.observation_function)[:-1]
1096641
def get_observations(self):
    '''  '''
    return [rpt for rpt in self._reports if rpt.report_type in self.OBS_TYPES]
823629
def p_obj_fields(self, p):
        
        p[0] = dict([p[1]] if len(p) == 2 else p[1] + [p[3]])
758020
def dict_fields(obj, parent=[]):
    
    rtn_obj = {}
    for key, value in obj.items():
        new_key = parent + [key]
        new_key = ".".join(new_key)
        if isinstance(value, list):
            if value:
                value = value[0]
        if isinstance(value, dict):
            rtn_obj.update(dict_fields(value, [new_key]))
        else:
            rtn_obj.update({new_key: value})
    return rtn_obj
822419
def to_representation(self, field, instance):
        
        self.parent_field = field
        return super(FacetFieldSerializer, self).to_representation(instance)
14170
def render_obs(self, obs):
    """"""
    start_time = time.time()
    self._obs = obs
    self.check_valid_queued_action()
    self._update_camera(point.Point.build(
        self._obs.observation.raw_data.player.camera))

    for surf in self._surfaces:
      # Render that surface.
      surf.draw(surf)

    mouse_pos = self.get_mouse_pos()
    if mouse_pos:
      # Draw a small mouse cursor
      self.all_surfs(_Surface.draw_circle, colors.green, mouse_pos.world_pos,
                     0.1)

    self.draw_actions()

    with sw("flip"):
      pygame.display.flip()

    self._render_times.append(time.time() - start_time)
593463
def to_serializable_value(self):
        
        return_dict = {}
        for name, field in self.__dict__.items():
            if isinstance(field, fields.Field):
                return_dict[name] = field.to_serializable_value()
        return return_dict
1252000
def create_ogr_field_from_definition(field_definition):
    
    if isinstance(field_definition['type'], list):
        # Use the first element in the list of type
        field_type = field_definition['type'][0]
    else:
        field_type = field_definition['type']

    # Conversion to OGR field
    field_type = field_type_converter.get(field_type, ogr.OFTString)

    return ogr.FieldDefn(field_definition['field_name'], field_type)
1192650
def _fields_list_to_dict(fields):
    
    for key in fields:
        assert isinstance(key, (str,unicode))
    return dict([[key, 1] for key in fields])