waymo_processed / extract.sh
Brainkite's picture
Add files using upload-large-folder tool
29c8e15 verified
#!/bin/bash
# Exit script immediately if any command fails
set -e
# Ensure pipeline commands fail if any part fails (important for cat | zstd | tar)
set -o pipefail
# --- Configuration ---
DEFAULT_TARGET_DIR="/workspace/Pointcept/data/waymo"
# Define the pattern for the split training archive parts.
# Assumes parts are in the current directory where the script is run.
# Adjust the path if the parts are elsewhere, e.g., /path/to/parts/processed_waymo...
TRAINING_ARCHIVE_PATTERN="./processed_waymo_training.tar.zst.part.*"
# Define the single validation archive file.
# Assumes the file is in the current directory where the script is run.
# Adjust the path if the file is elsewhere, e.g., /path/to/file/processed_waymo...
VALIDATION_ARCHIVE="./processed_waymo_validation.tar.zst"
# --- Determine Target Directory ---
# Use the first command-line argument ($1) if provided, otherwise use the default.
if [[ -n "$1" ]]; then
TARGET_DIR="$1"
echo "Using custom target directory provided: $TARGET_DIR"
else
TARGET_DIR="$DEFAULT_TARGET_DIR"
echo "No custom target directory provided. Using default: $TARGET_DIR"
fi
echo # Blank line for spacing
# --- Script Start ---
echo "--- Waymo Data Extraction Script ---"
START_TIME=$SECONDS
# --- Check and Create Target Directory ---
echo "Ensuring target directory exists: $TARGET_DIR"
if [ ! -d "$TARGET_DIR" ]; then
echo "Target directory does not exist. Creating..."
# Create the directory, including any necessary parent directories (-p)
mkdir -p "$TARGET_DIR"
echo "Created directory: $TARGET_DIR"
else
echo "Target directory already exists."
fi
echo # Blank line for spacing
# --- Extract Training Archive (Split) ---
echo "Starting extraction of TRAINING archive..."
echo "Source pattern: $TRAINING_ARCHIVE_PATTERN"
echo "This may take a while..."
# Check if any training parts exist before attempting cat
if ! ls $TRAINING_ARCHIVE_PATTERN > /dev/null 2>&1; then
echo "ERROR: No files found matching training archive pattern: $TRAINING_ARCHIVE_PATTERN"
exit 1
fi
# 1. Concatenate the parts using cat
# 2. Pipe the combined stream to zstd for decompression (-d = decompress, -c = to stdout)
# 3. Pipe the decompressed tar stream to tar for extraction
# -x = extract
# -v = verbose (shows files being extracted)
# -f - = read archive from stdin (the pipe)
# -C "$TARGET_DIR" = change directory to TARGET_DIR before extracting
cat $TRAINING_ARCHIVE_PATTERN | zstd -dc - | tar -xvf - -C "$TARGET_DIR"
echo "Training archive extraction complete."
echo # Blank line for spacing
# --- Extract Validation Archive (Single File) ---
echo "Starting extraction of VALIDATION archive..."
echo "Source file: $VALIDATION_ARCHIVE"
echo "This may take a while..."
# Check if validation archive exists
if [ ! -f "$VALIDATION_ARCHIVE" ]; then
echo "ERROR: Validation archive file not found: $VALIDATION_ARCHIVE"
exit 1
fi
# 1. Decompress the file with zstd (-d = decompress, -c = to stdout)
# 2. Pipe the decompressed tar stream to tar for extraction (same flags as above)
zstd -dc "$VALIDATION_ARCHIVE" | tar -xvf - -C "$TARGET_DIR"
echo "Validation archive extraction complete."
echo # Blank line for spacing
# --- Stats and Summary ---
END_TIME=$SECONDS
DURATION=$((END_TIME - START_TIME))
echo "--- Extraction Summary ---"
echo "Extraction process finished successfully."
echo "Total time taken: $DURATION seconds."
echo "Data extracted to: $TARGET_DIR"
# Show the top-level directories created inside the target directory
echo "Contents of target directory ($TARGET_DIR):"
ls -l "$TARGET_DIR"
echo "--------------------------"
exit 0