Chile’s Atacama desert is becoming the world’s biggest battery farm
Back to Tutorials
techTutorialbeginner

Chile’s Atacama desert is becoming the world’s biggest battery farm

May 27, 202615 views5 min read

Learn to simulate a solar battery storage system like the one in Chile's Atacama desert using Python. This beginner-friendly tutorial teaches you how to model solar generation, battery charging, and power delivery.

Introduction

In this tutorial, you'll learn how to simulate and model a solar battery storage system using Python. This is inspired by the groundbreaking solar-plus-storage facility in Chile's Atacama desert, which combines 231 megawatts of solar capacity with 1.3 gigawatt-hours of battery storage. Understanding these systems is crucial for renewable energy planning and optimization. We'll build a simple simulation that shows how solar energy is collected during the day and stored in batteries for use at night.

Prerequisites

Before starting this tutorial, you'll need:

  • A computer with Python installed (version 3.6 or higher)
  • Basic understanding of Python programming concepts
  • Some knowledge of solar energy and battery storage concepts

Don't worry if you're new to Python or renewable energy - we'll explain everything step by step!

Step-by-step Instructions

1. Install Required Python Libraries

First, we need to install the libraries we'll use for our simulation. Open your terminal or command prompt and run:

pip install numpy matplotlib pandas

Why we do this: These libraries provide the mathematical calculations (numpy), data handling (pandas), and visualization (matplotlib) we need to model our solar battery system.

2. Create Your Python Project Structure

Create a new folder for your project and open it in your code editor. Create a file called solar_battery_simulation.py. This will be our main simulation file.

Why we do this: Organizing our code into a proper project structure makes it easier to manage and extend in the future.

3. Import Required Libraries

Add the following code to your solar_battery_simulation.py file:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

print("Solar Battery Simulation Initialized")

Why we do this: These imports give us access to mathematical functions, data manipulation tools, and visualization capabilities needed for our simulation.

4. Define System Parameters

Next, define the key parameters for our solar battery system:

# Solar system parameters
solar_capacity_mw = 231  # Megawatts peak
battery_capacity_gwh = 1.3  # Gigawatt-hours
max_discharge_mw = 200  # Maximum discharge rate

# Time parameters
hours_in_day = 24
solar_peak_hour = 12  # When solar power is at maximum

print(f"System initialized with {solar_capacity_mw} MW solar capacity")
print(f"Battery storage: {battery_capacity_gwh} GWh")

Why we do this: These parameters represent the real-world values from the Chilean facility. The solar capacity is 231 MW peak, and the battery storage is 1.3 GWh.

5. Create Solar Power Generation Profile

Now, we'll simulate how solar power varies throughout the day:

def generate_solar_profile(hours):
    # Create a realistic solar profile
    solar_profile = []
    for hour in range(hours):
        # Solar power follows a bell curve with peak at noon
        power = solar_capacity_mw * np.exp(-0.5 * ((hour - solar_peak_hour) / 3) ** 2)
        solar_profile.append(max(0, power))  # Ensure no negative power
    return solar_profile

solar_generation = generate_solar_profile(hours_in_day)
print("Solar generation profile created")

Why we do this: This creates a realistic solar generation curve that peaks at noon and drops to zero at night, mimicking real solar behavior.

6. Create Battery Storage Simulation

Next, we'll simulate how the battery stores and discharges energy:

def simulate_battery_storage(solar_profile, battery_capacity_gwh, max_discharge_mw):
    battery_charge = 0  # Starting with empty battery
    battery_history = [0]  # Track battery charge over time
    discharge_history = []  # Track how much power was discharged
    
    for hour, solar_power in enumerate(solar_profile):
        # Calculate how much energy is produced
        energy_produced = solar_power * 1  # 1 hour of generation
        
        # Add to battery if not full
        if battery_charge + energy_produced <= battery_capacity_gwh:
            battery_charge += energy_produced
        else:
            # If battery is full, excess solar is lost
            battery_charge = battery_capacity_gwh
            
        # Calculate how much power to discharge (if needed)
        if battery_charge > 0:
            # Discharge at maximum rate or what's available
            discharge_rate = min(max_discharge_mw, battery_charge)
            battery_charge -= discharge_rate
        else:
            discharge_rate = 0
            
        discharge_history.append(discharge_rate)
        battery_history.append(battery_charge)
        
    return battery_history, discharge_history

battery_history, discharge_history = simulate_battery_storage(solar_generation, battery_capacity_gwh, max_discharge_mw)
print("Battery storage simulation completed")

Why we do this: This simulates how the battery charges during the day when solar is available and discharges during the night when solar is not available.

7. Visualize the Results

Now let's create a visualization to see how our system performs:

# Create the visualization
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 8))

# Plot solar generation
hours = list(range(hours_in_day))
ax1.plot(hours, solar_generation, 'b-', linewidth=2, label='Solar Generation')
ax1.set_title('Solar Power Generation Over 24 Hours')
ax1.set_ylabel('Power (MW)')
ax1.grid(True)
ax1.legend()

# Plot battery charge and discharge
ax2.plot(hours, battery_history[:-1], 'g-', linewidth=2, label='Battery Charge')
ax2.plot(hours, discharge_history, 'r--', linewidth=2, label='Power Discharge')
ax2.set_title('Battery Storage and Discharge')
ax2.set_xlabel('Hour of Day')
ax2.set_ylabel('Power (MW)')
ax2.grid(True)
ax2.legend()

plt.tight_layout()
plt.savefig('solar_battery_simulation.png')
plt.show()

print("Simulation visualization saved as solar_battery_simulation.png")

Why we do this: Visualizing the data helps us understand how the solar system and battery storage work together to provide consistent power throughout the day and night.

8. Analyze the Results

Finally, let's add some analysis to our simulation:

# Calculate some key metrics
max_battery_charge = max(battery_history)
max_discharge = max(discharge_history)
total_solar_generated = sum(solar_generation)

print(f"Maximum battery charge: {max_battery_charge:.2f} GWh")
print(f"Maximum discharge rate: {max_discharge:.2f} MW")
print(f"Total solar energy generated: {total_solar_generated:.2f} MWh")

# Calculate how much energy was stored vs. lost
energy_stored = max_battery_charge
energy_lost = total_solar_generated - (energy_stored * 1000)  # Convert GWh to MWh

print(f"Energy stored in battery: {energy_stored:.2f} GWh")
print(f"Energy lost due to battery limits: {energy_lost:.2f} MWh")

Why we do this: This analysis helps us understand the efficiency of our simulated system and how much energy is actually usable versus what gets lost.

Summary

In this tutorial, you've learned how to simulate a solar battery storage system like the one in Chile's Atacama desert. You've created a model that shows how solar energy is collected during the day and stored in batteries for use at night. The simulation includes:

  • Solar power generation profile that peaks at noon
  • Battery charging and discharging behavior
  • Visualization of the entire system performance
  • Key performance metrics analysis

This simple model demonstrates the core concepts behind large-scale renewable energy storage systems. While this is a simplified simulation, it shows how solar and battery technologies work together to provide consistent power even when the sun isn't shining. As renewable energy continues to grow globally, understanding these systems becomes increasingly important for energy planning and optimization.

Source: TNW Neural

Related Articles