parameters: (metadata, **kwargs)
docstring: Write list `metadata` of objects to disk
docstring_summary: Write list `metadata` of objects to disk
docstring_tokens: Write list metadata of objects to disk
function: def write_metadata(metadata, **kwargs):
    '''Write list `metadata` of objects to disk'''
    if not metadata: return
    out_dir = join(kwargs['out_dir'], 'metadata')
    for i in ['filters', 'options', 'file']:
      out_path = join(out_dir, i)
      if not exists(out_path): os.makedirs(out_path)
    # create the lists of images with each tag
    d = defaultdict(list)
    for i in metadata:
      filename = clean_filename(i['filename'])
      i['tags'] = [j.strip() for j in i.get('tags', '').split('|')]
      for j in i['tags']: d[ '__'.join(j.split()) ].append(filename)
      write_json(os.path.join(out_dir, 'file', filename + '.json'), i, **kwargs)
    write_json(os.path.join(out_dir, 'filters', 'filters.json'), [{
      'filter_name': 'select',
      'filter_values': list(d.keys()),
    }], **kwargs)
    # create the options for the category dropdown
    for i in d:
      write_json(os.path.join(out_dir, 'options', i + '.json'), d[i], **kwargs)
    # create the map from date to images with that date (if dates present)
    date_d = defaultdict(list)
    for i in metadata:
      date = i.get('year', '')
      if date:
        date_d[date].append(clean_filename(i['filename']))
    # find the min and max dates to show on the date slider
    dates = np.array([int(i.strip()) for i in date_d if is_number(i)])
    domain = {'min': float('inf'), 'max': -float('inf')}
    mean = np.mean(dates)
    std = np.std(dates)
    for i in dates:
      # update the date domain with all non-outlier dates
      if abs(mean-i) < (std*4):
        domain['min'] = int(min(i, domain['min']))
        domain['max'] = int(max(i, domain['max']))
    # write the dates json
    if len(date_d) > 1:
      write_json(os.path.join(out_dir, 'dates.json'), {
        'domain': domain,
        'dates': date_d,
      }, **kwargs)
function_tokens: def write_metadata ( metadata , * * kwargs ) : if not metadata : return out_dir = join ( kwargs [ 'out_dir' ] , 'metadata' ) for i in [ 'filters' , 'options' , 'file' ] : out_path = join ( out_dir , i ) if not exists ( out_path ) : os . makedirs ( out_path ) # create the lists of images with each tag d = defaultdict ( list ) for i in metadata : filename = clean_filename ( i [ 'filename' ] ) i [ 'tags' ] = [ j . strip ( ) for j in i . get ( 'tags' , '' ) . split ( '|' ) ] for j in i [ 'tags' ] : d [ '__' . join ( j . split ( ) ) ] . append ( filename ) write_json ( os . path . join ( out_dir , 'file' , filename + '.json' ) , i , * * kwargs ) write_json ( os . path . join ( out_dir , 'filters' , 'filters.json' ) , [ { 'filter_name' : 'select' , 'filter_values' : list ( d . keys ( ) ) , } ] , * * kwargs ) # create the options for the category dropdown for i in d : write_json ( os . path . join ( out_dir , 'options' , i + '.json' ) , d [ i ] , * * kwargs ) # create the map from date to images with that date (if dates present) date_d = defaultdict ( list ) for i in metadata : date = i . get ( 'year' , '' ) if date : date_d [ date ] . append ( clean_filename ( i [ 'filename' ] ) ) # find the min and max dates to show on the date slider dates = np . array ( [ int ( i . strip ( ) ) for i in date_d if is_number ( i ) ] ) domain = { 'min' : float ( 'inf' ) , 'max' : - float ( 'inf' ) } mean = np . mean ( dates ) std = np . std ( dates ) for i in dates : # update the date domain with all non-outlier dates if abs ( mean - i ) < ( std * 4 ) : domain [ 'min' ] = int ( min ( i , domain [ 'min' ] ) ) domain [ 'max' ] = int ( max ( i , domain [ 'max' ] ) ) # write the dates json if len ( date_d ) > 1 : write_json ( os . path . join ( out_dir , 'dates.json' ) , { 'domain' : domain , 'dates' : date_d , } , * * kwargs )