[Python] How to efficiently generate gridded data from 82k points time series data?

Discussão em 'Python' iniciado por Stack, Janeiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    I have a time series data with 82k point observations at 260 time steps. The points do not follow a regular gridded pattern. What is the most effective way in Python to convert all time series data to a regular grid?

    The code below is my solution. However, I'm unsure if this is the most optimal method. The compute time for a 8000 X 8000 grid for a time step is 10s. Is there any way I can run the code faster (than executing code for each time step separately)?

    from scipy.interpolate import griddata
    import matplotlib.pyplot as plt

    def interpolate_grid(x, y, values, target_size=(800, 800)):
    """Grid interpolation"""
    points = (x , y)
    xi = np.linspace(x.min(), x.max(), target_size[0])
    yi = np.linspace(y.min(), y.max(), target_size[1])
    xi, yi = np.meshgrid(xi, yi)
    zi = griddata(points, values , (xi, yi), method='linear')
    return xi, yi, zi

    x, y, z = interpolate_grid(x=gdf.geometry.x,
    y=gdf.geometry.y,
    values=gdf[gdf.columns[1]],
    target_size=(10000, 10000))

    Continue reading...

Compartilhe esta Página