Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hi all,

I'm computing a spatial random field using gstools on a 121-point grid (11x11) over a 100x100 area. However, in the resulting plot, I'm seeing sharp transitions and weird triangles instead of a smooth field. Is there something wrong with how I'm defining the grid? Also, I'm using matplotlib for contour plotting but have to transpose the field to match the output of SRF.plot(). Is this normal behavior, or am I missing something?
SRF
TransposedField

Additionally, I want to use the generated field values at 121 points as input to a kriging model. Is there an easy way to convert the field into a CSV file with columns x, y, and variable? The input to the kriging model looks like this:
cond_pos = [[data['x']], [data['y']]]
cond_val = [data['T']]
Below is the field generated which I want to convert to a format with 3 columns x,y, variable
generatedField

You must be logged in to vote

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:

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

Replies: 3 comments

Comment options

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:

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:

x,y,field
0.0,0.0,41.14544414217422
0.0,10.0,43.3021316578523
0.0,20.0,51.14123392299849
0.0,30.0,42.62513828267687
0.0,40.0,51.716181978469066
0.0,50.0,50.13614957997373
0.0,60.0,51.43807806694252
0.0,70.0,46.832772901760976
0.0,80.0,48.71947319354813
0.0,90.0,51.95330079175974
0.0,100.0,54.75345603557814
10.0,0.0,51.41566920646541
10.0,10.0,45.116424371503285
...

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()

Figure_1
Figure_2

Hope this helps.

Cheers, Sebastian

You must be logged in to vote
0 replies
Answer selected by MuellerSeb
Comment options

But a CSV exporter could be a handy idea. Created an issue for this: #367

You must be logged in to vote
0 replies
Comment options

Thank you for your response. It works as intended now.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.