<jupyter_start><jupyter_text>This notebook demonstrates the abiliyt to create a SpaceNET CSV from GeoJSON's as ground truth<jupyter_code>from spacenetutilities.labeltools import coreLabelTools as lT
import os
import glob
import argparse
## Src Directory for a Group of Tiff Files
srcDirectory = '/raid/nfs/data/Datasets/CosmiQ_General_Study/AOI_6_Atlanta/processedDatav3/SpaceNet-Off-Nadir_Train/Atlanta_nadir10_catid_1030010003993E00/'

## GeoJSON Directory
geojsonDirectory = "/raid/nfs/data/Datasets/CosmiQ_General_Study/AOI_6_Atlanta/processedDatav3/SpaceNet-Off-Nadir_Train/geojson/spacenet-buildings/"
## Get List of all Pan-Sharpen Tiffs in rasterList (Ensure Tiff is at resolutions required)
rasterList = glob.glob(os.path.join(srcDirectory, '**', 'Pan-Sharpen*.tif'), recursive=True)
geoJsonList = glob.glob(os.path.join(geojsonDirectory, '**', '*.geojson'), recursive=True)

# Use this flag to have the CSV be a prediction CSV with a Confidence Value Inserted for Creating Ground Truth Set to False
createProposalFile=False

chipSummaryList = []

# Set Pixel Precision (Round(pixelPrecision))  This says that each pixel coordinate should only have 3 decimals
pixelPrecision = 3

# Specify Competition type 
compType = "buildings"

## Specify Output File
outputCSVFileName = "/raid/nfs/workingDir/cw-tiler/AOI_6_Atlanta_Train_v6.csv"

## Specify whether to understand occluded_flag,  SpaceNet 4 added the occluded flag for Building footprints
occluded_flag=True


## Create Chip List, This look matches a GeoTiff, with a GeoJSON and then specifies the imageId for the CSV
for rasterName in rasterList:
    rasterBase = os.path.basename(rasterName)
    baseSplit = rasterBase.rsplit('_', 3)
    imageId = rasterBase.split('_',1)[1]
    geoVectorName = os.path.join(geojsonDirectory,
                                 "spacenet-buildings_{}_{}".format(baseSplit[2], baseSplit[3]).replace(".tif", ".geojson")
                                )
    
    
    chipSummary = {'chipName': rasterName,
                   'geoVectorName': geoVectorName,
                   'imageId': imageId.replace(".tif", "")}

    chipSummaryList.append(chipSummary)
    

## Call Final Command for 
lT.createCSVSummaryFile(chipSummaryList, outputCSVFileName,
                            replaceImageID="",
                            createProposalsFile=createProposalFile,
                            pixPrecision=pixelPrecision,
                            competitionType=compType,
                       occluded_flag=occluded_flag)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08855799373040753, 'fraction_numerical': 0.012147335423197491, 'mean_word_length': 3.5427046263345194, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '490446', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 832, 'n_tokens_neox': 764, 'n_words': 183, 'path': 'Build_Ground_TruthCSV.ipynb', 'repo_name': 'CosmiQ/cw-tiler', 'size': '2552'}