Package: uc-sgsim
Sonar Cloud QualityMetricPythonCQuality GateReliability RatingSecurity RatingMaintainability RatingWarningThis project is still in the pre-dev stage, the API usuage may be subject to changeUnConditional Sequential Gaussian SIMulation (UCSGSIM)An unconditional random field generation tools that are easy to use.Introduction to UCSGSIMUnConditional Sequential Gaussian Simulation (UCSGSIM) is a method for generating random fields that is based on the kriging interpolation technique.Unconditional simulation does not adhere to the patterns observed in the data but instead follows the user's settings, such as mean and variance.The core ideas of UCSGSIM are:Create the grid (no data values exist at this stage).$$ \Omega\to R $$Select a random point within the model (draw one random value from the x_grid).$$ X = RandomValue(\Omega),  X:\Omega\to R $$Choose thetheoretical covariance modelto use and set thesillandrangeproperly.$$ Gaussian = (C_{0} - s)(1 - e^{-h^{2}/r^{2}a})$$$$ Spherical = (C_{0} - s)(3h/2r - h^3/2r^3)$$$$ Exponential = (C_{0} - s)(1 - e^{-h/ra})$$If there are more than one data value close to the visited point (based on therangeof the covariance model), proceed to the next step. Otherwise, draw a random value from a normal distribution as the simulation result for this iteration.$$ Z_{k}({X_{simulation}}) = RandomNormal(m = 0 ,\sigma^2 = Sill)$$Calculateweightsfrom thedata covarainceanddistance coavariance$$ \sum_{j=1}^{n}\omega_{j} = C(X_{data}^{i},X_{data}^{i})C^{-1}(X_i,X_i), i=1...N $$Calculate thekriging estimatefrom theweightsanddata value$$ Z_{k}(X_{estimate}) = \sum_{i=1}^{n} \omega_{i} Z(X_{data}) + (1- \sum_{i=1}^{n} \omega_{i} m_{g}) $$Calculate thekriging error (kriging variance)fromweightsanddata covariance$$ \sigma_{krige}^{2} = \sum_{i=1}^{n}\omega_{i}C(X_{data}^{i},X_{data}^{i}) $$Draw a random value from the normal distribution and add to thekriging estimate.$$ Z(X_{simulation}) = Z(X_{estimate}) + RandomNormal(m = 0, \sigma^2 = \sigma_{krige}^{2}) $$Repeat 2 ~ 8 until the entire model is simulated.Repeat 1 ~ 9 with differentrandomseed numberto produce mutiple realizations.Installationpipinstalluc-sgsimFeaturesOne dimensional unconditional randomfield generation with sequential gaussian simulation algorithmMuti-cores simulation (mutiprocessing)Ability to generate random fields in Python using either a C interface via ctype or directly in Python using the NumPy and SciPy libraries.Examplesimportmatplotlib.pyplotaspltimportuc_sgsimasucfromuc_sgsim.cov_modelimportGaussianif__name__=='__main__':x=151# Model grid, only 1D case is support nowbw_s=1# lag stepbw_l=35# lag rangerandomseed=151# randomseed for simulationk_range=17.32# effective range of covariance modelsill=1# sill of covariance modelnR=10# numbers of realizations in each CPU cores,# if nR = 1 n_process = 8# than you will compute total 8 realizations# Create Covariance model firstcov_model=Gaussian(bw_l,bw_s,k_range,sill)# Create simulation and input the Cov model# You could also set z_min, z_max and max_neighbor for sgsim by key words# sgsim = uc.UCSgsimDLL(x, nR, cov_model, z_min=-6, z_max=6, max_neigh=10)# set z_min, z_max and max_neighbor by directly assign# sgsim.z_min = -6# sgsim.z_max = 6# sgsim.max_neigh = 10# Create simulation with default z_min, z_max and max_neigh paramssgsim_py=uc.UCSgsim(x,nR,cov_model)# run sgsim with pythonsgsim_c=uc.UCSgsimDLL(x,nR,cov_model)# run sgsim with c# Start compute with n CPUssgsim_c.compute(n_process=2,randomseed=randomseed)sgsim_py.compute(n_process=2,randomseed=987654)sgsim_c.mean_plot('ALL')# Plot meansgsim_c.variance_plot()# Plot variancesgsim_c.cdf_plot(x_location=10)# CDFsgsim_c.hist_plot(x_location=10)# Histsgsim_c.variogram_compute(n_process=2)# Compute variogram before plotting# Plot variogram and mean variogram for validationsgsim.variogram_plot()# Save random_field and variogramsgsim_c.save_random_field('randomfields.csv',save_single=True)sgsim_c.save_variogram('variograms.csv',save_single=True)# show figureplt.show()If you prefer to utilize pure C to execute this code, you can make modifications to the c_example.c file located in the root directory. Once you've made the necessary changes to c_example.c, you can compile and execute the code using the following commands:On Linuxshcmake_build.shOn Windowscmake_build.batC example file// c_example.c#include<stdio.h>#include<stdlib.h>#include"./uc_sgsim/c_core/include/sgsim.h"#include"./uc_sgsim/c_core/include/cov_model.h"# if defined(__linux__) || defined(__unix__)# define PAUSE printf("Press Enter key to continue..."); fgetc(stdin);//NOLINT# elif _WIN32# define PAUSE system("PAUSE");# endifintmain(){// you can also set z_min and z_max at sgsim_t. Default value will depend on// sill value in cov_model_tsgsim_tsgsim_example={.x_len=150,.realization_numbers=5,.randomseed=12345,.kriging_method=1,.if_alloc_memory=1,// This should be equal to 1 if you want to run by c.};// you can also set max_negibor at cov_model_t. Defualt value is 4.cov_model_tcov_example={.bw_l=35,.bw_s=1,.k_range=17.32,.use_cov_cache=0,.sill=1,.nugget=0,};sgsim_run(&sgsim_example,&cov_example,0);sgsim_t_free(&sgsim_example);PAUSEreturn0;}Future plans2D unconditional randomfield generationGUI (pyhton)More covariance modelsMore kriging methods (etc. Oridinary Kriging)Performance enhancementProviding more comprehensive documentation and user-friendly design improvements.PerformanceParameters:

model len = 150

number of realizations = 1000

Range scale = 17.32

Variogram model = Gaussian model

---------------------------------------------------------------------------------------

Testing platform:

CPU: AMD Ryzen 9 4900 hs

RAM: DDR4 - 3200 40GB (Dual channel 16GB)

Disk: WD SN530