surveyweathertool.src.weather_x_survey.weather_survey

Module Contents

Functions

get_nearest_points(hh_df, weather_df[, n_neighbors])

For each household, find the n nearest points in the weather grid.

calculate_weights(nearest_df)

Calculate the weights for the inverse distance weighting interpolation.

interpolate_values(weighted_nearest_df, weather_df, ...)

Interpolate the values for the households based on the weights of the nearest points.

get_weather_for_household_survey(household_df, ...[, ...])

Get the interpolated weather data for each household on the day of the survey.

get_monthly_weather_for_household_survey(household_df, ...)

Get the interpolated weather data for each household for the month of the survey.

get_seasonal_weather_for_household_survey(...[, ...])

Get the interpolated weather data for each household for the season of the survey.

get_yearly_weather_for_household_survey(household_df, ...)

Get the interpolated weather data for each household for the year of the survey.

merge_weather_household(hh_df, weather_df, column_name)

Merge weather data from different time periods (monthly, seasonal, yearly) for different metrics (precipitation, temperature, etc. )

merge_survey_weather_hh_level(→ pandas.DataFrame)

combine_with_poverty_index(map_df, household_df, ...)

Function to combine two GeoDataFrames based on a spatial join operation and computes the

surveyweathertool.src.weather_x_survey.weather_survey.get_nearest_points(hh_df, weather_df, n_neighbors=4)

For each household, find the n nearest points in the weather grid.

Parameters: hh_df: DataFrame

Household data, including ‘lat’, ‘lon’ columns.

weather_df: DataFrame

Weather grid data, including ‘lat’, ‘lon’ columns.

n_neighbors: int

The number of nearest weather grid points to find for each household.

Returns: DataFrame

A new DataFrame with the same index as hh_df, and with two additional columns: ‘nearest_points’ - list of indices of the nearest points in weather_df, ‘distances’ - list of distances to the nearest points.

surveyweathertool.src.weather_x_survey.weather_survey.calculate_weights(nearest_df)

Calculate the weights for the inverse distance weighting interpolation.

Parameters: nearest_df: DataFrame

DataFrame with ‘nearest_points’ and ‘distances’ columns, as returned by get_nearest_points().

Returns: DataFrame

A new DataFrame with the same index as nearest_df, and with an additional column ‘weights’.

surveyweathertool.src.weather_x_survey.weather_survey.interpolate_values(weighted_nearest_df, weather_df, value_cols)

Interpolate the values for the households based on the weights of the nearest points.

Parameters: weighted_nearest_df: DataFrame

DataFrame with ‘nearest_points’ and ‘weights’ columns, as returned by calculate_weights().

weather_df: DataFrame

The weather DataFrame with the values to interpolate.

value_cols: list of str

The names of the columns in weather_df that contains the values to interpolate.

Returns: DataFrame

A new DataFrame with the interpolated values for each household.

surveyweathertool.src.weather_x_survey.weather_survey.get_weather_for_household_survey(household_df, weather_df, value_col, n_neighbors=4)

Get the interpolated weather data for each household on the day of the survey.

Parameters: household_df: DataFrame

Household survey data, including ‘date’, ‘lat’, ‘lon’ columns.

weather_df: DataFrame

Daily weather data, including ‘date’, ‘lat’, ‘lon’ and ‘precipitation’ columns.

value_col: str

The name of the column in weather_df that contains the values to interpolate.

n_neighbors: int

The number of nearest weather points to use for interpolation.

Returns: DataFrame

A new DataFrame with the interpolated weather data for each household.

surveyweathertool.src.weather_x_survey.weather_survey.get_monthly_weather_for_household_survey(household_df, weather_df, value_col, n_neighbors=4)

Get the interpolated weather data for each household for the month of the survey.

Parameters: household_df: DataFrame

Household survey data, including ‘date’, ‘lat’, ‘lon’ columns.

weather_df: DataFrame

Monthly weather data, including ‘year’, ‘month’, ‘lat’, ‘lon’ and ‘precipitation’ columns.

value_col: str

The name of the column in weather_df that contains the values to interpolate.

n_neighbors: int

The number of nearest weather points to use for interpolation.

Returns: DataFrame

A new DataFrame with the interpolated weather data for each household.

surveyweathertool.src.weather_x_survey.weather_survey.get_seasonal_weather_for_household_survey(household_df, weather_df, value_col, n_neighbors=4)

Get the interpolated weather data for each household for the season of the survey.

Parameters: household_df: DataFrame

Household survey data, including ‘date’, ‘lat’, ‘lon’ columns.

weather_df: DataFrame

Seasonal weather data, including ‘year’, ‘season’, ‘lat’, ‘lon’ and ‘precipitation’ columns.

value_col: str

The name of the column(s) in weather_df that contains the values to interpolate.

n_neighbors: int

The number of nearest weather points to use for interpolation.

Returns: DataFrame

A new DataFrame with the interpolated weather data for each household.

surveyweathertool.src.weather_x_survey.weather_survey.get_yearly_weather_for_household_survey(household_df, weather_df, value_col, n_neighbors=4)

Get the interpolated weather data for each household for the year of the survey.

Parameters: household_df: DataFrame

Household survey data, including ‘date’, ‘lat’, ‘lon’ columns.

weather_df: DataFrame

Yearly weather data, including ‘year’, ‘lat’, ‘lon’ and ‘precipitation’ columns.

value_col: str

The name of the column(s) in weather_df that contains the values to interpolate.

n_neighbors: int

The number of nearest weather points to use for interpolation.

Returns: DataFrame

A new DataFrame with the interpolated weather data for each household.

surveyweathertool.src.weather_x_survey.weather_survey.merge_weather_household(hh_df, weather_df, column_name)

Merge weather data from different time periods (monthly, seasonal, yearly) for different metrics (precipitation, temperature, etc. ) into a single DataFrame. The merged DataFrame will contain weather data for each household, with separate columns for each time period and metric.

Parameters: hh_df: DataFrame

Household survey data, including ‘date’, ‘lat’, ‘lon’ columns.

weather_df: DataFrame

Particular weather dataframe with geographic and weather information to aggregate

Returns: DataFrame

A merged DataFrame containing weather data for each household for different time periods and metrics.

surveyweathertool.src.weather_x_survey.weather_survey.merge_survey_weather_hh_level(survey_filepath: str, weather_filepath: str, export_flag: True, export_format: str, export_path: str) pandas.DataFrame
surveyweathertool.src.weather_x_survey.weather_survey.combine_with_poverty_index(map_df: geopandas.GeoDataFrame, household_df: geopandas.GeoDataFrame, col_dissolve: str, wave: int = 1, poverty_index_col_name: str = 'unicef_poverty_index', method: str = 'intersects', epsg: int = 4326)

Function to combine two GeoDataFrames based on a spatial join operation and computes the aggregate mean of the poverty index for households in each region.

Parameters

map_dfgeopandas.GeoDataFrame

The GeoDataFrame with the geometry column to be used for the spatial join.

household_dfgeopandas.GeoDataFrame

The GeoDataFrame with household data, including poverty index.

col_dissolvestr

The column name in map_df used to dissolve the geometry into unique polygons.

wave: int

The wave in the survey to consider

poverty_index_col_name: str

The column name in household_df that has poverty index

methodstr, optional

The method to be used for the spatial join operation. It could be “intersects”, “within”, “contains”, etc. Default is “intersects”.

epsg

EPSG code to set the Coordinate Reference System (CRS) for the data

Returns

admin_dbgeopandas.GeoDataFrame

The GeoDataFrame resulting from the spatial join with aggregate mean poverty index.