CDSimX-introduction

library(CDSimX)

Introduction

The CDSimX package provides an advanced framework for climate simulation, forecasting, visualization, validation, and climate data export in R.

The package supports:

CDSimX is useful for:

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. We begin by generating synthetic climate stations.

stations <- create_stations(
  n = 3,
  seed = 123
)
#> Generating synthetic station network...
#> Generated 3 synthetic stations within bounding box.
#> Deriving climate-aware station attributes...
stations
#>     Station        LON       LAT  ELEV CLIMATE_ZONE COASTAL_INDEX TEMP_BASE
#> 1 Station_1 -2.0621124 10.681122 422.5     Savannah         0.932     27.17
#> 2 Station_2  0.4415257 11.083271 713.9     Savannah         1.000     26.27
#> 3 Station_3 -1.4551154  4.818895 441.1      Coastal         0.000     27.04
#>   RAIN_REGIME
#> 1   Monomodal
#> 2   Monomodal
#> 3     Bimodal

Each station contains:

Generating Time Indices

CDSimX supports daily, monthly, and yearly temporal resolutions.

time_index <- generate_time_index(
  start_date = "2019-01-01",
  end_date = "2024-12-31",
  frequency = "day"
)
#> Generated 2192 time steps at daily resolution.
head(time_index)
#>   START_DATE   END_DATE       DATE Year Month Day DOY Week Quarter Season
#> 1 2019-01-01 2019-01-01 2019-01-01 2019     1   1   1    1       1    Dry
#> 2 2019-01-02 2019-01-02 2019-01-02 2019     1   2   2    1       1    Dry
#> 3 2019-01-03 2019-01-03 2019-01-03 2019     1   3   3    1       1    Dry
#> 4 2019-01-04 2019-01-04 2019-01-04 2019     1   4   4    1       1    Dry
#> 5 2019-01-05 2019-01-05 2019-01-05 2019     1   5   5    1       1    Dry
#> 6 2019-01-06 2019-01-06 2019-01-06 2019     1   6   6    1       1    Dry
#>   Frequency
#> 1     daily
#> 2     daily
#> 3     daily
#> 4     daily
#> 5     daily
#> 6     daily

Simulating Climate Data

Climate variables can now be simulated using the generated stations and time index.

climate <- simulate_climate(
  stations = stations,
  time_index = time_index,
  seed = 123
)
#> Temperature simulation complete for 3 stations.
#> Rainfall simulation complete for 3 stations.
#> Relative humidity simulation complete for 3 stations.
#> Dew point simulation complete for 3 stations.
#> Wind speed simulation complete for 3 stations.
#> Wind direction simulation complete for 3 stations.
#> Solar radiation simulation complete for 3 stations.
#> Evapotranspiration simulation complete for 3 stations.
#> Integrated climate simulation complete for 3 stations.

head(climate)
#>     Station       DATE       LON      LAT  ELEV Year Month Season  Tmin  Tmax
#> 1 Station_1 2019-01-01 -2.062112 10.68112 422.5 2019     1    Dry 20.31 28.03
#> 2 Station_1 2019-01-02 -2.062112 10.68112 422.5 2019     1    Dry 20.21 28.64
#> 3 Station_1 2019-01-03 -2.062112 10.68112 422.5 2019     1    Dry 21.91 29.66
#> 4 Station_1 2019-01-04 -2.062112 10.68112 422.5 2019     1    Dry 21.96 30.36
#> 5 Station_1 2019-01-05 -2.062112 10.68112 422.5 2019     1    Dry 22.07 30.95
#> 6 Station_1 2019-01-06 -2.062112 10.68112 422.5 2019     1    Dry 23.76 32.02
#>   Avg.Temp  DTR CLIMATE_ZONE COASTAL_INDEX Rain_Days Rainfall Wet_Day
#> 1    24.17 7.72     Savannah         0.932         0     0.00       0
#> 2    24.42 8.43     Savannah         0.932         0     0.00       0
#> 3    25.78 7.75     Savannah         0.932         0     0.00       0
#> 4    26.16 8.41     Savannah         0.932         1     0.84       1
#> 5    26.51 8.88     Savannah         0.932         0     0.00       0
#> 6    27.89 8.26     Savannah         0.932         0     0.00       0
#>   Extreme_Event Rain_Anomaly    RH Humidity_Anomaly DewPoint
#> 1             0        -1.08 53.05            -5.07    13.35
#> 2             0        -1.08 52.75            -5.37    14.20
#> 3             0        -1.08 57.88            -0.23    16.23
#> 4             0        -0.24 58.04            -0.07    17.29
#> 5             0        -1.08 57.92            -0.19    18.05
#> 6             0        -1.08 62.81             4.70    20.03
#>   Dewpoint_Depression WindSpeed Extreme_Wind Wind_Anomaly WindDirection
#> 1               10.82      3.45            0        -3.87        148.59
#> 2               10.22      5.44            0        -1.87        140.34
#> 3                9.55      5.98            0        -1.34        240.74
#> 4                8.87      7.78            0         0.46        234.74
#> 5                8.46      9.15            0         1.84        231.49
#> 6                7.86      9.67            0         2.35        276.37
#>   WindSector Prevailing_Direction Direction_Variability Extreme_Shift Wind_u
#> 1         SE                  180                    60             0  -1.80
#> 2         SE                  180                    60             0  -3.47
#> 3         SW                  180                    60             0   5.22
#> 4         SW                  180                    30             0   6.35
#> 5         SW                  180                    30             0   7.16
#> 6          W                  180                    30             0   9.61
#>   Wind_v Solar_Radiation Clear_Sky_Radiation Cloud_Factor Sunshine_Fraction
#> 1   2.94           16.31               21.04         0.85         0.8739915
#> 2   4.19           21.47               21.07         0.93         0.9212083
#> 3   2.92           18.10               21.09         0.87         0.8337447
#> 4   4.49           17.12               21.12         0.93         0.8956804
#> 5   5.70           22.41               21.15         0.94         0.9298279
#> 6  -1.07           16.35               21.18         0.81         0.8450011
#>   Radiation_Anomaly Atmospheric_Pressure  VPD  ET0 Dryness_Index Dryness_Class
#> 1             -3.08                 96.4 1.42 5.88          0.82      Very Dry
#> 2              2.08                 96.4 1.45 6.78          0.64      Very Dry
#> 3             -1.29                 96.4 1.40 7.05          0.73      Very Dry
#> 4             -2.27                 96.4 1.42 6.77          0.79      Very Dry
#> 5              3.02                 96.4 1.46 7.58          0.62      Very Dry
#> 6             -3.04                 96.4 1.40 7.48          0.81      Very Dry
#>   ET_Anomaly
#> 1      -1.20
#> 2      -0.30
#> 3      -0.03
#> 4      -0.31
#> 5       0.50
#> 6       0.40

The simulated dataset may include:

Climate Visualization

CDSimX includes customizable visualization functions.

plot_station_timeseries(
  climate,
  station = "Station_1",
  var = "Tmax"
)
#> `geom_smooth()` using formula = 'y ~ x'

Users may customize:

Machine Learning Forecasting

CDSimX supports several machine learning forecasting approaches.

Available methods include:

forecast_result <- forecasting_ml(
  climate_data = climate,
  target = "Rainfall",
  forecast_horizon = 12,
  method = "rf"
)
#> Machine learning forecasting complete using rf method.
forecast_result$model_performance
#>   Method   Target  RMSE   MAE Correlation
#> 1     rf Rainfall 44.99 35.08        0.39

Forecasted values:

head(forecast_result$forecast_data)
#>         DATE Forecast
#> 1 2025-01-31    34.17
#> 2 2025-03-03    27.68
#> 3 2025-03-31    42.91
#> 4 2025-05-01    16.10
#> 5 2025-05-31    38.05
#> 6 2025-07-01    47.99

Climate Validation

CDSimX includes climate validation tools for checking realism and statistical consistency.

validation <- validate_climate(climate)
#> Climate dataset validation complete.
validation
#> $summary_statistics
#>                 Variable    Mean     SD     Min     Max Skewness
#> 1                    LON   -1.03   1.07   -2.06    0.44     0.54
#> 2                    LAT    8.86   2.86    4.82   11.08    -0.70
#> 3                   ELEV  525.83 133.21  422.50  713.90     0.70
#> 4                   Year 2021.50   1.71 2019.00 2024.00     0.00
#> 5                  Month    6.52   3.45    1.00   12.00    -0.01
#> 6                   Tmin   20.36   3.55   10.03   30.19    -0.23
#> 7                   Tmax   26.90   3.75   15.74   38.67     0.35
#> 8               Avg.Temp   23.63   3.46   13.60   34.36     0.10
#> 9                    DTR    6.54   2.33    1.79   10.29    -0.64
#> 10         COASTAL_INDEX    0.64   0.46    0.00    1.00    -0.70
#> 11             Rain_Days    0.42   0.49    0.00    1.00     0.31
#> 12              Rainfall   21.69  37.45    0.00  429.86     2.36
#> 13               Wet_Day    0.42   0.49    0.00    1.00     0.31
#> 14         Extreme_Event    0.01   0.08    0.00    1.00    11.83
#> 15          Rain_Anomaly    0.00  32.88  -69.56  381.95     1.84
#> 16                    RH   64.34  17.59   29.97  100.00     0.47
#> 17      Humidity_Anomaly    0.00   5.42  -19.15   19.99    -0.07
#> 18              DewPoint   16.03   6.36   -3.36   30.10    -0.33
#> 19   Dewpoint_Depression    7.60   4.14    0.00   17.23    -0.29
#> 20             WindSpeed    7.85   3.70    0.00   34.17     0.25
#> 21          Extreme_Wind    0.01   0.10    0.00    1.00    10.24
#> 22          Wind_Anomaly    0.00   2.89   -9.40   25.04     0.38
#> 23         WindDirection  187.24  78.26    0.21  359.89    -0.28
#> 24  Prevailing_Direction  195.00  21.21  180.00  225.00     0.71
#> 25 Direction_Variability   37.49  16.01   15.00   60.00     0.46
#> 26         Extreme_Shift    0.01   0.09    0.00    1.00    10.41
#> 27                Wind_u    2.46   6.14  -12.78   33.11     0.37
#> 28                Wind_v    3.10   4.68  -17.96   19.85    -0.62
#> 29       Solar_Radiation   20.99   2.48   12.61   29.50     0.04
#> 30   Clear_Sky_Radiation   24.55   1.59   20.90   26.83    -0.68
#> 31          Cloud_Factor    0.86   0.05    0.71    0.97    -0.08
#> 32     Sunshine_Fraction    0.85   0.06    0.64    1.00    -0.08
#> 33     Radiation_Anomaly    0.00   1.95   -6.91    6.27     0.01
#> 34  Atmospheric_Pressure   95.24   1.49   93.14   96.40    -0.70
#> 35                   VPD    1.02   0.49    0.00    1.65    -0.75
#> 36                   ET0    6.82   0.89    3.94    9.89     0.02
#> 37         Dryness_Index    0.47   0.22    0.00    0.98    -0.56
#> 38            ET_Anomaly    0.00   0.69   -2.66    2.64     0.01
#> 
#> $missing_values
#>                                    Variable Missing_Count Missing_Percent
#> Station                             Station             0               0
#> DATE                                   DATE             0               0
#> LON                                     LON             0               0
#> LAT                                     LAT             0               0
#> ELEV                                   ELEV             0               0
#> Year                                   Year             0               0
#> Month                                 Month             0               0
#> Season                               Season             0               0
#> Tmin                                   Tmin             0               0
#> Tmax                                   Tmax             0               0
#> Avg.Temp                           Avg.Temp             0               0
#> DTR                                     DTR             0               0
#> CLIMATE_ZONE                   CLIMATE_ZONE             0               0
#> COASTAL_INDEX                 COASTAL_INDEX             0               0
#> Rain_Days                         Rain_Days             0               0
#> Rainfall                           Rainfall             0               0
#> Wet_Day                             Wet_Day             0               0
#> Extreme_Event                 Extreme_Event             0               0
#> Rain_Anomaly                   Rain_Anomaly             0               0
#> RH                                       RH             0               0
#> Humidity_Anomaly           Humidity_Anomaly             0               0
#> DewPoint                           DewPoint             0               0
#> Dewpoint_Depression     Dewpoint_Depression             0               0
#> WindSpeed                         WindSpeed             0               0
#> Extreme_Wind                   Extreme_Wind             0               0
#> Wind_Anomaly                   Wind_Anomaly             0               0
#> WindDirection                 WindDirection             0               0
#> WindSector                       WindSector             0               0
#> Prevailing_Direction   Prevailing_Direction             0               0
#> Direction_Variability Direction_Variability             0               0
#> Extreme_Shift                 Extreme_Shift             0               0
#> Wind_u                               Wind_u             0               0
#> Wind_v                               Wind_v             0               0
#> Solar_Radiation             Solar_Radiation             0               0
#> Clear_Sky_Radiation     Clear_Sky_Radiation             0               0
#> Cloud_Factor                   Cloud_Factor             0               0
#> Sunshine_Fraction         Sunshine_Fraction             0               0
#> Radiation_Anomaly         Radiation_Anomaly             0               0
#> Atmospheric_Pressure   Atmospheric_Pressure             0               0
#> VPD                                     VPD             0               0
#> ET0                                     ET0             0               0
#> Dryness_Index                 Dryness_Index             0               0
#> Dryness_Class                 Dryness_Class             0               0
#> ET_Anomaly                       ET_Anomaly             0               0
#> 
#> $physical_checks
#> $physical_checks$Temperature_Inconsistency
#> [1] 0
#> 
#> $physical_checks$RH_Out_Of_Bounds
#> [1] 0
#> 
#> $physical_checks$Negative_Rainfall
#> [1] 0
#> 
#> $physical_checks$Negative_WindSpeed
#> [1] 0
#> 
#> $physical_checks$Invalid_WindDirection
#> [1] 0
#> 
#> $physical_checks$Invalid_DewPoint
#> [1] 0
#> 
#> $physical_checks$Invalid_SunshineFraction
#> [1] 0
#> 
#> $physical_checks$Negative_ET0
#> [1] 0
#> 
#> 
#> $correlation_matrix
#>                  Tmin  Tmax Avg.Temp Rainfall    RH DewPoint WindSpeed
#> Tmin             1.00  0.80     0.95    -0.04  0.65     0.94      0.73
#> Tmax             0.80  1.00     0.95    -0.25  0.08     0.59      0.45
#> Avg.Temp         0.95  0.95     1.00    -0.15  0.38     0.80      0.61
#> Rainfall        -0.04 -0.25    -0.15     1.00  0.28     0.10      0.11
#> RH               0.65  0.08     0.38     0.28  1.00     0.85      0.74
#> DewPoint         0.94  0.59     0.80     0.10  0.85     1.00      0.85
#> WindSpeed        0.73  0.45     0.61     0.11  0.74     0.85      1.00
#> Solar_Radiation  0.04  0.15     0.10    -0.19 -0.13    -0.03     -0.05
#> ET0              0.84  0.82     0.87    -0.13  0.40     0.75      0.73
#>                 Solar_Radiation   ET0
#> Tmin                       0.04  0.84
#> Tmax                       0.15  0.82
#> Avg.Temp                   0.10  0.87
#> Rainfall                  -0.19 -0.13
#> RH                        -0.13  0.40
#> DewPoint                  -0.03  0.75
#> WindSpeed                 -0.05  0.73
#> Solar_Radiation            1.00  0.37
#> ET0                        0.37  1.00
#> 
#> $seasonal_summary
#>     Season  Tmin  Tmax Avg.Temp Rainfall    RH DewPoint WindSpeed
#> 1      Dry 21.12 27.65    24.39     9.05 65.96    17.17      8.28
#> 2 Post-Wet 18.30 24.86    21.58    22.13 58.99    12.79      6.74
#> 3  Pre-Wet 22.83 29.37    26.10    15.98 70.55    19.91      9.36
#> 4      Wet 18.97 25.50    22.24    35.14 61.14    13.89      6.94
#>   Solar_Radiation  ET0
#> 1           19.83 6.82
#> 2           19.45 6.27
#> 3           22.48 7.46
#> 4           21.51 6.61
#> 
#> $station_summary
#>     Station  Tmin  Tmax Avg.Temp Rainfall    RH DewPoint WindSpeed
#> 1 Station_1 21.00 29.37    25.19    11.60 55.31    15.49      6.42
#> 2 Station_2 18.36 26.28    22.32    13.59 51.17    11.64      6.72
#> 3 Station_3 21.72 25.05    23.38    39.89 86.55    20.96     10.40
#>   Solar_Radiation  ET0
#> 1           21.00 6.97
#> 2           21.67 6.66
#> 3           20.31 6.83
#> 
#> $extreme_summary
#>                    Metric Value
#> 1 Extreme_Rainfall_Events    46
#> 2     Extreme_Wind_Events    61
#> 
#> $validation_summary
#>                Metric Value
#> 1           Mean_Tmin 20.36
#> 2           Mean_Tmax 26.90
#> 3    Mean_Temperature 23.63
#> 4       Mean_Rainfall 21.69
#> 5             Mean_RH 64.34
#> 6      Mean_WindSpeed  7.85
#> 7 Mean_SolarRadiation 20.99
#> 8            Mean_ET0  6.82

Validation diagnostics may include:

Exporting Climate Data

Export to CSV

export_csv(
  climate,
  file = "simulated_climate.csv"
)
#> CSV export completed successfully.

Export to NetCDF

export_netcdf(
  climate,
  file = "simulated_climate.nc"
)
#> NetCDF export completed successfully.

These formats support interoperability with:

Conclusion

CDSimX provides a modern climate simulation ecosystem for generating, forecasting, validating, visualizing, and exporting synthetic climate data.

The package is designed to support reproducible climate science, machine learning applications, and environmental modelling workflows.