Issue with Spatial Random Field Grid and Contour Plotting + CSV Output for Kriging Input #366
-
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hey there, for me the plot looks as expected. Remember, that you only defined 11 points along each axis, so one every 10 meters (or whatever unit). For your second point: In order to export the field to CSV, you need to generate the points of the grid from the given axis and then flatten the field to export it. Using pandas, this could look like this: import gstools as gs
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
x = y = np.linspace(0, 100, 11)
model = gs.Exponential(dim=2, var=20, len_scale=25, nugget=5)
srf = gs.SRF(model, mean=50, seed=19841201)
field = srf.structured((x, y))
# Generate grid values from axes
pos = gs.tools.generate_grid((x, y))
# Create a DataFrame
data = pd.DataFrame({'x': pos[0], 'y': pos[1], 'field': field.flatten()})
# Export to CSV
data.to_csv('output.csv', index=False) This gives you:
This could now be used for kriging like this: import gstools as gs
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('output.csv')
cond_pos = (data["x"].to_numpy(), data["y"].to_numpy())
cond_val = data["field"].to_numpy()
xx = yy = np.linspace(0, 100, 101)
model = gs.Exponential(dim=2, var=20, len_scale=25, nugget=5)
krig = gs.krige.Ordinary(model, cond_pos, cond_val)
krige_field, krige_var = krig.structured((xx, yy))
krig.plot(field="field")
krig.plot(field="krige_var")
plt.show() Hope this helps. Cheers, Sebastian |
Beta Was this translation helpful? Give feedback.
-
But a CSV exporter could be a handy idea. Created an issue for this: #367 |
Beta Was this translation helpful? Give feedback.
-
Thank you for your response. It works as intended now. |
Beta Was this translation helpful? Give feedback.
Hey there,
for me the plot looks as expected. Remember, that you only defined 11 points along each axis, so one every 10 meters (or whatever unit).
If you want the plot to look smoother, you should increase the points along each axis.
For your second point: In order to export the field to CSV, you need to generate the points of the grid from the given axis and then flatten the field to export it. Using pandas, this could look like this: