# Getting Started with CDSim

The CDSim package provides an easy workflow for simulating climate data such as temperature and rainfall across multiple synthetic weather stations. It is useful for testing models, teaching climate analysis, generating demo data, and creating datasets with controlled variability.

This vignette demonstrates:

- how to create synthetic weather stations

- how to generate multi-year climate time series

- how to export results to CSV and NetCDF

- how to perform a quick visualization

## Creating Weather Stations

The stations can be created either by:

- loading from a CSV file,

- accepting an existing data frame,

- or auto-generating synthetic stations in a bounding box.

    library(CDSim)

We begin by generating a set of synthetic weather stations. The seed ensures reproducibility.

    stations <- create_stations(n = 3, seed = 123)
    #> Generating synthetic station network...
    #> Generated 3 synthetic stations within bounding box.
    stations
    #>     Station        LON       LAT
    #> 1 Station_1 -2.0621124 10.681122
    #> 2 Station_2  0.4415257 11.083271
    #> 3 Station_3 -1.4551154  4.818895

Each station typically contains:

1. station name

2. longitude

3. latitude

## Simulating Climate Data

Once the stations are created, we can generate daily or monthly climate time series using built-in stochastic models.

    sim <- simulate_climate_series(stations, start_year = 2019, end_year = 2024)
    head(sim)
    #>     Station       LON      LAT Year Month       Date Avg.Tn Avg.Tx Sum.Rf
    #> 1 Station_1 -2.062112 10.68112 2019     1 2019-01-15   19.5   33.2    7.7
    #> 2 Station_1 -2.062112 10.68112 2019     2 2019-02-15   22.7   36.5    5.3
    #> 3 Station_1 -2.062112 10.68112 2019     3 2019-03-15   25.1   34.6   26.6
    #> 4 Station_1 -2.062112 10.68112 2019     4 2019-04-15   22.4   35.4   55.6
    #> 5 Station_1 -2.062112 10.68112 2019     5 2019-05-15   20.0   32.6   55.7
    #> 6 Station_1 -2.062112 10.68112 2019     6 2019-06-15   17.6   29.9   38.4
    #>   Avg.Rf
    #> 1   0.25
    #> 2   0.19
    #> 3   0.86
    #> 4   1.85
    #> 5   1.80
    #> 6   1.28

A typical simulated record includes:

- date

- min and max temperature

- rainfall

- station metadata

## Exporting Data to CSV and NetCDF

CDSim includes convenient exporters such as CSV and NetCDF for storing climate data. This makes it easier for packages such as ncdf4, terra, or stars to read the outputs.

    write_station_csv(sim, file = "climate_data.csv")

    write_station_netcdf(sim, out_nc = "climate_data.nc")

## Quick Visualization

To demonstrate a quick plot, here’s the maximum temperature series of the first station.

    plot_station_timeseries(sim,'Station_1', var = "Avg.Tx")
    #> `geom_smooth()` using formula = 'y ~ x'