code: def main(raster_file, vector_file, driver, mask_value):
      with rasterio.Env():
          with rasterio.open(raster_file) as src:
              image = src.read(1)
  
          if mask_value is not None:
              mask = image == mask_value
          else:
              mask = None
  
          results = (
              {"properties": {"raster_val": v}, "geometry": s}
              for i, (s, v) in enumerate(
                  shapes(image, mask=mask, transform=src.transform)
              )
          )
  
          with fiona.open(
              vector_file,
              "w",
              driver=driver,
              crs=src.crs,
              schema={
                  "properties": [("raster_val", "int")],
                  "geometry": "Polygon",
              },
          ) as dst:
              dst.writerecords(results)
  
      return dst.name
  
file_path: rasterio/examples/rasterio_polygonize.py
imports: import argparse
  import logging
  import subprocess
  import sys
  import fiona
  import rasterio
  from rasterio.features import shapes
label_desc: Use image node_id 1 for calling a global function with example usage: main(raster_file, vector_file, driver, mask_value) and returns: dst