API

Agrometeo.

class agrometeo.core.AgrometeoDataset(*, region=None, stations_id_name=None, time_name=None, crs=None, geocode_to_gdf_kws=None, sjoin_kws=None)

Agrometeo dataset.

property CRS

CRS of the data source.

get_ts_df(variable, start_date, end_date, *, scale=None, measurement=None, stations_id_col=None)

Get time series data frame.

Parameters:
  • variable (str or int) – Target variable, which can be either an agrometeo variable code (integer or string), an essential climate variable (ECV) following the meteostations-geopy nomenclature (string), or an agrometeo variable name (string).

  • start_date (str or datetime) – String in the “YYYY-MM-DD” format or datetime instance, respectively representing the start and end of the requested data period.

  • end_date (str or datetime) – String in the “YYYY-MM-DD” format or datetime instance, respectively representing the start and end of the requested data period.

  • scale (None or {"hour", "day", "month", "year"}, default None) – Temporal scale of the measurements. The default value of None returns the finest scale, i.e., 10 minutes.

  • measurement ({"min", "avg", "max"}, default "avg") – Whether the measurement values correspond to the minimum, average or maximum value for the required temporal scale. Ignored if scale is None.

  • stations_id_col (str, optional) – Column of stations_gdf that will be used in the returned data frame to identify the stations. If None, the value from settings.DEFAULT_STATIONS_ID_COL will be used.

Returns:

ts_df – Data frame with a time series of meaurements (rows) at each station (columns).

Return type:

pd.DataFrame

get_ts_gdf(variable, start_date, end_date, *, scale=None, measurement=None, stations_id_col=None)

Get time series geo-data frame.

Parameters:
  • variable (str or int) – Target variable, which can be either an agrometeo variable code (integer or string), an essential climate variable (ECV) following the meteostations-geopy nomenclature (string), or an agrometeo variable name (string).

  • start_date (str or datetime) – String in the “YYYY-MM-DD” format or datetime instance, respectively representing the start and end of the requested data period.

  • end_date (str or datetime) – String in the “YYYY-MM-DD” format or datetime instance, respectively representing the start and end of the requested data period.

  • scale (None or {"hour", "day", "month", "year"}, default None) – Temporal scale of the measurements. The default value of None returns the finest scale, i.e., 10 minutes.

  • measurement ({"min", "avg", "max"}, default "avg") – Whether the measurement values correspond to the minimum, average or maximum value for the required temporal scale. Ignored if scale is None.

  • stations_id_col (str, optional) – Column of stations_gdf that will be used in the returned data frame to identify the stations. If None, the value from settings.DEFAULT_STATIONS_ID_COL is used.

Returns:

ts_gdf – Geo-data frame with a time series of meaurements (columns) at each station (rows), with an additional geometry column with the stations’ locations.

Return type:

gpd.GeoDataFrame

property stations_gdf

Station geo-data frame.

property variables_df

Variables data frame.

Plotting.

agrometeo.plotting.plot_temperature_map(ts_gdf, *, dt=None, ax=None, cmap=None, legend=None, legend_position=None, legend_size=None, legend_pad=None, title=None, add_basemap=None, attribution=None, subplot_kws=None, plot_kws=None, set_title_kws=None, add_basemap_kws=None, append_axes_kws=None)

Plot a map of station measurements.

Parameters:
  • ts_gdf (geopandas.GeoDataFrame) – Geo-data frame with a time series of temperature measurements.

  • dt (str or datetime, optional) – String or datetime instance representing the instant to be plotted. The value must match a column of ts_gdf. If None, the first column (other than geometry) is used.

  • ax (matplotlib.axes.Axes instancd, optional) – Plot in given axis. If None creates a new figure.

  • cmap (str or matplotlib.colors.Colormap instance, optional) – Colormap of the plot. If None, the value from settings.PLOT_CMAP is used.

  • legend (bool, optional) – Whether a legend should be added to the plot. If None, the value from settings.PLOT_LEGEND is used.

  • legend_position (str {"left", "right", "bottom", "top"}, optional) – Position of the legend axes, passed to mpl_toolkits.axes_grid1.axes_divider.AxesDivider.append_axes. If None, the value from settings.PLOT_LEGEND_POSITION is used.

  • legend_size (numeric or str, optional) – Size of the legend axes, passed to mpl_toolkits.axes_grid1.axes_divider.AxesDivider.append_axes. If None, the value from settings.PLOT_LEGEND_SIZE is used.

  • legend_pad (numeric or str, optional) – Padding between the plot and legend axes, passed to mpl_toolkits.axes_grid1.axes_divider.AxesDivider.append_axes. If None, the value from settings.PLOT_LEGEND_PAD is used.

  • title (bool or str, optional) – Whether a title should be added to the plot. If True, the timestamp of the snapshot (geo-data frame column) is used. It is also possible to pass a string so that it is used as title label (instead of the timestamp). If None, the value from settings.PLOT_TITLE is used.

  • add_basemap (bool, optional) – Whether a basemap should be added to the plot using contextily.add_basemap. If None, the value from settings.PLOT_ADD_BASEMAP is used.

  • attribution (str or bool, optional) – Attribution text for the basemap source, added to the bottom of the plot, passed to contextily.add_basemap. If False, no attribution is added. If None, the value from settings.PLOT_ATTRIBUTION is used.

  • subplot_kws (dict, optional) – Keyword arguments passed to matplotlib.pyplot.subplots, geopandas.GeoDataFrame.plot, matplotlib.axes.Axes.set_title, contextily.add_basemap and mpl_toolkits.axes_grid1.axes_divider.AxesDivider.append_axes respectively.

  • plot_kws (dict, optional) – Keyword arguments passed to matplotlib.pyplot.subplots, geopandas.GeoDataFrame.plot, matplotlib.axes.Axes.set_title, contextily.add_basemap and mpl_toolkits.axes_grid1.axes_divider.AxesDivider.append_axes respectively.

  • set_title_kws (dict, optional) – Keyword arguments passed to matplotlib.pyplot.subplots, geopandas.GeoDataFrame.plot, matplotlib.axes.Axes.set_title, contextily.add_basemap and mpl_toolkits.axes_grid1.axes_divider.AxesDivider.append_axes respectively.

  • add_basemap_kws (dict, optional) – Keyword arguments passed to matplotlib.pyplot.subplots, geopandas.GeoDataFrame.plot, matplotlib.axes.Axes.set_title, contextily.add_basemap and mpl_toolkits.axes_grid1.axes_divider.AxesDivider.append_axes respectively.

  • append_axes_kws (dict, optional) – Keyword arguments passed to matplotlib.pyplot.subplots, geopandas.GeoDataFrame.plot, matplotlib.axes.Axes.set_title, contextily.add_basemap and mpl_toolkits.axes_grid1.axes_divider.AxesDivider.append_axes respectively.

Returns:

ax – Axes with the plot drawn onto it.

Return type:

matplotlib.axes.Axes