Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: write_asc_grid function does not run as expected #197

Closed
Amos-Zhao opened this issue Jun 7, 2021 · 4 comments · Fixed by #199
Closed

BUG: write_asc_grid function does not run as expected #197

Amos-Zhao opened this issue Jun 7, 2021 · 4 comments · Fixed by #199
Assignees
Labels
Milestone

Comments

@Amos-Zhao
Copy link

Amos-Zhao commented Jun 7, 2021

kriging_tools.py line 73

I got abs((x[-1] - x[0]) / (x.shape[0] - 1)) calculated as 0.999999999999998 , while dx calculated as 1, so the function didn't work.
Is there any way to overcome this problem

@MuellerSeb
Copy link
Member

Hey there,

I see the problem:

abs((x[-1] - x[0]) / (x.shape[0] - 1)) != dx

This should be implemented with a safer comparison of floats.

Could you give a minimal example to reproduce this behavior? maybe you could also correct the values for x and y, to make the routine work.

Cheers, Sebastian

@MuellerSeb MuellerSeb added the bug label Jun 7, 2021
@MuellerSeb MuellerSeb self-assigned this Jun 7, 2021
@Amos-Zhao
Copy link
Author

Amos-Zhao commented Jun 7, 2021

from pykrige import kriging_tools as kt
from pykrige.ok import OrdinaryKriging


import numpy as np
from hdhm.grid import RasterGrid

data = np.array(
    [
        [253387, 3496927, 2],
        [300000, 3529426, 10],
        [256087, 3536927, 6],
    ]
)

file_path = "huaihe/dem.txt"

grid, x, y, cell, no_data = kt.read_asc_grid(file_path)

OK = OrdinaryKriging(
    data[:, 0],
    data[:, 1],
    data[:, 2],
    variogram_model="linear",
    verbose=False,
    enable_plotting=False,
)
dem = RasterGrid(file_path)
z, ss = OK.execute("grid", x, y)
kt.write_asc_grid(x, y, z, filename="amos.asc", style=2)

dem.txt

@Amos-Zhao
Copy link
Author

Amos-Zhao commented Jun 7, 2021

I'm trying to convert result[z] to asc file by using numpy.savetxt("filename.txt",a) and following code

z = np.squeeze(np.array(z))
z = np.flip(z, axis=0)
np.savetxt("result.asc",z)

Thanks for your response.

@MuellerSeb
Copy link
Member

But remember that just because of the *.asc ending, this is not a valid ESRI-Grid file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants