NOAA-OWP / hydrovis

Other
12 stars 9 forks source link

Use shapely objects to store geometries. #941

Closed groutr closed 3 weeks ago

groutr commented 1 month ago

process_schism_fim uses a lot of memory. I tested with the pacific domain and discovered that loading the shapefile into memory takes almost 3GB of RAM.

Fiona represents geometries as dictionaries of objects. When storing large geometries such as those in the pacific domain, it becomes very inefficient. Fortunately, we can store geometries as shapely objects, which only use a fraction of the memory.

Before/after memory usage of get_mask_geoms_by_group

atlgulf:
increment: 2849.89 MiB   # old
increment: 604.03 MiB   # new

pacific:
increment: 2882.93 MiB   # old
increment: 515.28 MiB    # new

hi:
increment: 0.00 MiB
increment: 0.00 MiB

prvi:
increment: 0.00 MiB
increment: 0.01 MiB

Other misc fixes are removing two ineffective gc calls and an unnecessary enumeration.