Creates a GeoRaster from a Pandas DataFrame. Useful to plot or export data to rasters.
    Usage:
        raster = from_pandas(df, value='value', x='x', y='y', cellx= cellx, celly=celly,
                             xmin=xmin, ymax=ymax, geot=geot, nodata_value=ndv,
                             projection=projection, datatype=datatype)

    Although it does not require all the inputs, it is highly recommended to include
    the geographical information, so that the GeoRaster is properly constructed. As usual,
    the information can be added afterwards directly to the GeoRaster.

def from_pandas(df, value='value', x='x', y='y', cellx=None, celly=None, xmin=None, ymax=None,
                geot=None, nodata_value=None, projection=None, datatype=None):
    """
    Creates a GeoRaster from a Pandas DataFrame. Useful to plot or export data to rasters.
    Usage:
        raster = from_pandas(df, value='value', x='x', y='y', cellx= cellx, celly=celly,
                             xmin=xmin, ymax=ymax, geot=geot, nodata_value=ndv,
                             projection=projection, datatype=datatype)

    Although it does not require all the inputs, it is highly recommended to include
    the geographical information, so that the GeoRaster is properly constructed. As usual,
    the information can be added afterwards directly to the GeoRaster.
    """
    if not cellx:
        cellx = (df.sort_values(x)[x]-df.sort_values(x).shift(1)[x]).max()
    if not celly:
        celly = (df.sort_values(y, ascending=False)[y]-df.sort_values(y, ascending=False).shift(1)[y]).drop_duplicates().replace(0).max()
    if not xmin:
        xmin = df[x].min()
    if not ymax:
        ymax = df[y].max()
    row, col = map_pixel(df[x], df[y], cellx, celly, xmin, ymax)
    dfout = pd.DataFrame(np.array([row, col, df[value]]).T, columns=['row', 'col', 'value'])
    dfout = dfout = dfout.set_index(["row","col"]).unstack().value.reindex(index=np.arange(0,np.max(row)+1)).T.reindex(index=np.arange(0,np.max(col)+1)).T
    if nodata_value:
        dfout[np.isnan(dfout)] = nodata_value
    if not nodata_value:
        nodata_value = np.nan
    if not geot:
        geot = (xmin, cellx, 0, ymax, 0, celly)
    return GeoRaster(dfout, geot, nodata_value=nodata_value, projection=projection, datatype=datatype)