data
index
/mnt/f/University of Exeter/environmental_insights/data.py

 
Modules
       
geopandas
itertools
numpy
os
overpy
pandas

 
Functions
       
air_pollution_concentration_complete_set_real_time_global(time)
Retrieve the complete calculated dataset for a given timestamp in the global dataset.
 
Parameters:
time (string): A string denoting the timestamp desired, of the form DD-MM-YYYY HHmmss
 
Returns:
geodataframe: A geodataframe of the dataset for the UK for a given timestamp.
air_pollution_concentration_complete_set_real_time_united_kingdom(time)
Retrieve the complete predicted dataset for a given timestamp in the UK dataset.
 
Parameters:
time (string): A string denoting the timestamp desired, of the form YYYY-MM-DD HHmmss
 
Returns:
geodataframe: A geodataframe of the dataset for the UK for a given timestamp.
air_pollution_concentration_nearest_point_real_time_global(latitude, longitude, time, global_grids)
Retrieve a single air pollution concentration data point predicted based on the global data, based on the cloest point given by the latitude and longitude.
 
Parameters:
latitude (float): A float denoting the desired latitude.
longitude (float): A float denoting the desired longitude.
time (string): A string denoting the timestamp desired, of the form DD-MM-YYYY HHmmss
global_grids (geodataframe): A Geodataframe that describes the estimation points for the uk model
 
Returns:
geodataframe: A geodataframe of the nearest point in the data at the given timestamp.
air_pollution_concentration_nearest_point_real_time_united_kingdom(latitude, longitude, time, uk_grids)
Retrieve a single air pollution concentration data point predicted based on the UK data, based on the cloest point given by the latitude and longitude.
 
Parameters:
latitude (float): A float denoting the desired latitude.
longitude (float): A float denoting the desired longitude.
time (string): A string denoting the timestamp desired, of the form YYYY-MM-DD HHmmss.
uk_grids (geodataframe): A Geodataframe that describes the estimation points for the uk model.
 
Returns:
geodataframe: A geodataframe of the nearest point in the data at the given timestamp.
air_pollution_concentration_nearest_point_typical_day_united_kingdom(month, day_of_Week, hour, latitude, longitude, uk_grids)
Retrieve a single air pollution concentration data point predicted based on the UK data, based on the cloest point given by the latitude and longitude.
 
Parameters:
Parameters:
month (int): An int to represent the month of interest, 1 being january, and 12 being December.
day_of_Week (string): A string to represent the day of week of interest in the form of "Friday".
hour (int):  An int to represent the hour of interest, 0 being midnight, and 23 being the final possible hour of the day
latitude (float): A float denoting the desired latitude.
longitude (float): A float denoting the desired longitude.
 
Returns:
geodataframe: A geodataframe of the nearest point in the data at the given timestamp.
air_pollution_concentration_typical_day_real_time_united_kingdom(month, day_of_Week, hour)
Retrieve the typical day complete dataset for the UK for a given time
 
Parameters:
month (int): An int to represent the month of interest, 1 being january, and 12 being December.
day_of_Week (string): A string to represent the day of week of interest in the form of "Friday".
hour (int):  An int to represent the hour of interest, 0 being midnight, and 23 being the final possible hour of the day
 
Returns:
geodataframe: A geodataframe of the typical dataset for the UK for a given tiem of interest
calculate_new_metrics_distance_total(current_infrastructure, highway_type, start_point, end_point, land_grids_centroids, land_grids)
Simulate the addition of a proposed highway to current infrastructure and calculate new metrics.
 
This function creates a new proposed highway segment based on given start and end points.
The proposed highway is then added to the current infrastructure dataset. After adding the
new highway, the function calculates distance metrics and total length of the specific highway type.
 
Parameters:
current_infrastructure (GeoDataFrame): The current infrastructure dataset with existing highways.
highway_type (str): Type of the highway for which metrics are calculated (e.g., "motorway").
start_point (tuple of float): Coordinates (x, y) for the starting point of the proposed highway.
end_point (tuple of float): Coordinates (x, y) for the ending point of the proposed highway.
land_grids_centroids (dataframe) : Dataframe of the grids for predicition to be made on, with the geometry being a set of points representing the centroid of such grids. 
land_grids (dataframe) : Dataframe of the grids for predicition to be made on, with the geometry being a set of polygons representing the grids themselves. 
 
Returns:
tuple:
  - GeoDataFrame: Contains metrics such as road infrastructure distance and total road length for each grid.
  - GeoDataFrame: A merged dataset of current infrastructure and the proposed highway.
 
Note:
- The function assumes the use of EPSG:4326 and EPSG:3395 for coordinate reference systems.
- It also assumes the existence of helper functions like `getEvenSpacedPoints` and a global variable `land_grids_centroids`.
ckd_nearest_LineString(gdf_A, gdf_B, gdf_B_cols)
Calculate the nearest points between two GeoDataFrames containing LineString geometries.
 
This function uses cKDTree to efficiently find the nearest points between two sets
of LineStrings. For each point in `gdf_A`, the function finds the closest point
in `gdf_B` and returns the distances along with selected columns from `gdf_B`.
 
Parameters:
gdf_A (GeoDataFrame): A GeoDataFrame containing LineString geometries.
gdf_B (GeoDataFrame): A GeoDataFrame containing LineString geometries which will be
                     used to find the closest points to `gdf_A`.
gdf_B_cols (list or tuple): A list or tuple containing column names from `gdf_B`
                           which will be included in the resulting DataFrame.
 
Returns:
GeoDataFrame: A GeoDataFrame with each row containing a geometry from `gdf_A`,
              corresponding closest geometry details from `gdf_B` (as specified by `gdf_B_cols`),
              and the distance to the closest point in `gdf_B`.
 
Note:
The resulting GeoDataFrame maintains the order of `gdf_A` and attaches the nearest
details from `gdf_B`.
This code was adapted from the code avaliable here: https://gis.stackexchange.com/questions/222315/finding-nearest-point-in-other-geodataframe-using-geopandas
download_file_data(filename)
Checks if a file that has been requested has been downloaded and if it has then it will download the file
 
Parameters:
filename (string): The dataset filename to be downloaded from the remote server
fetch_amenities_as_geodataframe(amenity_type, min_lat, min_lon, max_lat, max_lon)
Fetch amenities of a given type within a bounding box and return as a GeoDataFrame.
 
 
Parameters:
amenity_type (string): Type of amenity, e.g., "hospital"
min_lat (float): Minimum latitude
min_lon (float): Minimum longitude
max_lat (float): Maximum latitude
max_lon (float): Maximum longitude
 
Returns:
geodataframe: GeoDataFrame containing the amenities with their names and coordinates
get_even_spaced_points(points, number_of_points)
Generate a list of evenly spaced points between two given points.
 
This function calculates the distance (or difference) between two input points
and divides this distance into `number_of_points` equal segments. The resulting
points, including the start and end points, are returned in a list.
 
Parameters:
points (list or tuple of float): A list or tuple containing two points
                                (start and end) between which the evenly spaced points
                                are to be calculated.
number_of_points (int): The total number of points to generate,
                      including the start and end points.
 
Returns:
list: A list of evenly spaced points between the provided start and end points.
 
Example:
>>> getEvenSpacedPoints([1, 10], 5)
[1.0, 3.25, 5.5, 7.75, 10.0]
 
Note:
The function assumes that the points list is sorted in ascending order.
get_global_grids()
Get the spatial grids that represent the locations at air pollution estimations are made on for the Global Model.
 
Returns:
geodataframe : A Geodataframe of the polygons for each of the grids in the Global Model and unique ID.
get_highways_as_geodataframe(highway_type, min_lat, min_lon, max_lat, max_lon)
Fetch highways of a specified type within a bounding box from OSM and return as a GeoDataFrame.
 
Parameters:
highway_type (string): Type of highway, e.g., "motorway", "residential"
min_lat (float): Minimum latitude
min_lon (float): Minimum longitude
max_lat (float): Maximum latitude
max_lon (float): Maximum longitude
 
Returns:
geodataframe: GeoDataFrame containing the highways with their names and coordinates
get_uk_grids()
Get the spatial grids that represent the locations at air pollution estimations are made on for the UK Model.
 
Returns:
geodataframe : A Geodataframe of the polygons for each of the grids in the UK Model alongside their centroid and unique ID.
replace_feature_vector_column(feature_vector, new_feature_vector, feature_vector_name)
Replace the feature vector column name with the new feature vector column name, replacing the data within the dataframe with new environmental conditions. 
Parameters:
feature_vector (dataframe) : dataframe of the original data.
new_feature_vector (dataframe) : dataframe containing the new feature vector that is to be used to replace the data in feature_vector. 
feature_vector_name (string) : Name of the feature vector to be changed.
 
Returns:
dataframe : A dataframe of the original data that was added with the feature vector now replace by the new data.