# -*- coding: utf-8 -*- """Rows (or pixels) and sizes of the released files of Table 3 and Table B1. Rows come from the Parquet metadata, pixels from the GeoTIFF header; sizes are in decimal units (1 MB = 10^6 bytes, 1 GB = 10^9 bytes), as in the tables. Input: paths.GLOBAL, paths.COARSER, paths.GRDC_XW and paths.SWORD_XW. Output: ../Data/Data24_release_files_rows_and_sizes.csv Usage: python Data24_release_files_rows_and_sizes.py """ import os, sys import pandas as pd, pyarrow.parquet as pq, rasterio sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import paths as PTH DATD = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'Data') G, C = 'flownest_merit90m_', 'flownest_merit90m_crosswalk_' FILES = [('Table 3', PTH.GLOBAL, G + f) for f in ( 'basin.parquet', 'basin.geo.parquet', 'basin_id.tif', 'pixel_1km2.parquet', 'pixel_seq_id_1km2.tif', 'reach_1km2.parquet', 'reach_location_1km2.parquet', 'reach_line_1km2.geo.parquet', 'unit_catchment_1km2.geo.parquet', 'reach_seq_id_1km2.tif')] FILES += [('Table B1', PTH.GRDC_XW, C + 'grdc_burek2023' + f) for f in ( '.parquet', '_location.parquet', '_point.geo.parquet', '_unit_catchment.geo.parquet', '_station_seq_id.tif', '_sword_v17c_node_pair.parquet')] FILES += [('Table B1', PTH.SWORD_XW, C + 'sword_v17c_' + f) for f in ( 'reach.parquet', 'reach_location.parquet', 'reach_line.geo.parquet', 'reach_unit_catchment.geo.parquet', 'reach_seq_id.tif', 'node.parquet', 'node_location.parquet', 'node_point.geo.parquet', 'node_seq_id.tif', 'subnetwork.parquet')] FILES += [('Table B1', PTH.COARSER, G + f) for f in ( 'reach_5km2.parquet', 'reach_25km2.parquet', 'reach_location_5km2.parquet', 'reach_location_25km2.parquet', 'reach_line_5km2.geo.parquet', 'reach_line_25km2.geo.parquet', 'crosswalk_reach_1km2_to_coarser.parquet')] def size_text(b): if b >= 1e9: return '%.2f GB' % (b / 1e9) return ('%.1f MB' if b < 1e8 else '%.0f MB') % (b / 1e6) rows = [] for table, folder, name in FILES: p = os.path.join(folder, name) if name.endswith('.tif'): with rasterio.open(p) as r: n = '%s × %s' % (format(r.height, ','), format(r.width, ',')) else: n = format(pq.ParquetFile(p).metadata.num_rows, ',') b = os.path.getsize(p) rows.append(dict(table=table, file=name, rows_or_pixels=n, bytes=b, size=size_text(b))) print('%-9s %-62s %26s %10s' % (table, name, n, size_text(b))) pd.DataFrame(rows).to_csv(os.path.join(DATD, 'Data24_release_files_rows_and_sizes.csv'), index=False)