def get_collection_image_metadata(collection=None, data_dir=None, limit=10): ''' Get image metadata associated with collection Args: collection: (int) collection id data_dir: (str) data directory limit: (int) number of images to increment Returns: metadata: (pd.DataFrame) Dataframe with full image metadata from collection ''' if os.path.isfile(os.path.join(data_dir, 'metadata.csv')): dat = pd.read_csv(os.path.join(data_dir, 'metadata.csv')) else: offset = 0 api = Client() i = api.get_collection_images(collection_id=collection, limit=limit, offset=offset) dat = pd.DataFrame(columns=i['results'][0].keys()) while int(offset) < int(i['count']): for x in i['results']: dat = dat.append(x, ignore_index=True) offset = offset + limit i = api.get_collection_images(collection_id=collection, limit=limit, offset=offset) dat.to_csv(os.path.join(data_dir, 'metadata.csv'), index=False) return dat
def get_collection_image_metadata(collection=None, data_dir=None, limit=10): """ Get image metadata associated with collection Args: collection (int, optional): collection id. Defaults to None. data_dir (str, optional): data directory. Defaults to None. limit (int, optional): number of images to increment. Defaults to 10. Returns: pd.DataFrame: Dataframe with full image metadata from collection """ if os.path.isfile(os.path.join(data_dir, "metadata.csv")): dat = pd.read_csv(os.path.join(data_dir, "metadata.csv")) else: offset = 0 api = Client() i = api.get_collection_images(collection_id=collection, limit=limit, offset=offset) dat = pd.DataFrame(columns=i["results"][0].keys()) while int(offset) < int(i["count"]): for x in i["results"]: dat = dat.append(x, ignore_index=True) offset = offset + limit i = api.get_collection_images(collection_id=collection, limit=limit, offset=offset) dat.to_csv(os.path.join(data_dir, "metadata.csv"), index=False) return dat