Skip to content

Commit

Permalink
Merge pull request #810 from cal-itp/more-metadata
Browse files Browse the repository at this point in the history
More metadata
  • Loading branch information
tiffanychu90 authored Jul 19, 2023
2 parents ad1a287 + d0f5129 commit 9b9e998
Show file tree
Hide file tree
Showing 16 changed files with 176 additions and 117 deletions.
4 changes: 4 additions & 0 deletions open_data/arcgis_pro_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ def rename_columns_with_dict(feature_class_list, rename_dict):

## (7) Move from file gdb to enterprise gdb
# License Select must be set to Advanced for this to work
# Exit and restart ArcPro to clear locks on layers in overwriting
# If we don't exit, the layer will be locked because it shows we're already using it
# staging to open_data), and it will prevent writing from open_data to the enterprise gdb.

ENTERPRISE_DATABASE = "Database Connections/HQrail(edit)@sv03tmcsqlprd1.sde"

for f in in_features:
Expand Down
1 change: 1 addition & 0 deletions open_data/check_exported_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"def print_stats(gdf):\n",
" print(f\"CRS: {gdf.crs.to_epsg()}\")\n",
" print(f\"{gdf.columns}\")\n",
" print(gdf.dtypes)\n",
" print(f\"# rows: {len(gdf)}\")"
]
},
Expand Down
4 changes: 2 additions & 2 deletions open_data/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def delete_old_xml_check_in_new_xml(open_data_dict: dict):
for key, value in open_data_dict.items():
file_path = value["path"]
file_name = os.path.basename(file_path)
os.replace(f"./metadata_xml/run_in_esri/{file_name}",
f"./metadata_xml/{file_name}")
os.replace(f"./xml/run_in_esri/{file_name}",
f"./xml/{file_name}")



Expand Down
21 changes: 10 additions & 11 deletions open_data/metadata_hqta.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""
HQTA transit areas and stops metadata elements
"""
from gcs_to_esri import open_data_dates
from update_vars import ESRI_BASE_URL

# HQTA transit areas and transit stops data dictionary
KEYWORDS = [
'Transportation',
'Land Use',
Expand All @@ -9,29 +12,25 @@
'High Quality Transit'
]

PURPOSE_AREAS = ('''
Estimated High Quality Transit Areas as described in Public Resources Code 21155, 21064.3, 21060.2.
'''
)
PURPOSE_AREAS = "Estimated High Quality Transit Areas as described in Public Resources Code 21155, 21064.3, 21060.2."

PURPOSE_STOPS = ('''
Estimated stops along High Quality Transit Corridors, plus major transit stops for bus rapid transit, ferry, rail modes as described in Public Resources Code 21155, 21064.3, 21060.2
'''
)

PURPOSE_STOPS = "Estimated stops along High Quality Transit Corridors, plus major transit stops for bus rapid transit, ferry, rail modes as described in Public Resources Code 21155, 21064.3, 21060.2."

ABSTRACT = "Use GTFS schedule trips, stop_times, shapes, and stops to estimate whether corridor segments have scheduled frequencies of 15 minutes or less."

METHODOLOGY = "This data was estimated using a spatial process derived from General Transit Feed Specification (GTFS) schedule data. To find high-quality bus corridors, we split each corridor into 1,500 meter segments and counted frequencies at the stop within that segment with the highest number of transit trips. If that stop saw at least 4 trips per hour for at least one hour in the morning, and again for at least one hour in the afternoon, we consider that segment a high-quality bus corridor. Segments without a stop are not considered high-quality corridors. Major transit stops were identified as either the intersection of two high-quality corridors from the previous step, a rail or bus rapid transit station, or a ferry terminal with bus service. Note that the definition of `bus rapid transit` in Public Resources Code 21060.2 includes features not captured by available data sources, these features were captured manually using information from transit agency sources and imagery. We believe this data to be broadly accurate, and fit for purposes including overall dashboards, locating facilities in relation to high quality transit areas, and assessing community transit coverage. However, the spatial determination of high-quality transit areas from GTFS data necessarily involves some assumptions as described above. Any critical determinations of whether a specific parcel is located within a high-quality transit area should be made in conjunction with local sources, such as transit agency timetables. Notes: Null values may be present. The `hqta_details` columns defines which part of the Public Resources Code definition the HQTA classification was based on. If `hqta_details` references a single operator, then `agency_secondary` and `base64_url_secondary` are null. If `hqta_details` references the same operator, then `agency_secondary` and `base64_url_secondary` are the same as `agency_primary` and `base64_url_primary`. Refer to https://github.com/cal-itp/data-analyses/blob/main/high_quality_transit_areas/README.md for more details."


ESRI_BASE_URL = "https://gisdata.dot.ca.gov/arcgis/rest/services/CHrailroad/"
DATA_DICT_AREAS_URL = f"{ESRI_BASE_URL}CA_HQ_Transit_Areas/FeatureServer"
DATA_DICT_STOPS_URL = f"{ESRI_BASE_URL}CA_HQ_Transit_Stops/FeatureServer"

HQTA_TRANSIT_AREAS_DICT = {
"dataset_name": "ca_hq_transit_areas",
"publish_entity": "Data & Digital Services / California Integrated Travel Project",

"abstract": "Public. EPSG: 4326",
"purpose": PURPOSE_AREAS,
"abstract": ABSTRACT,

"creation_date": "2022-02-08",
"beginning_date": open_data_dates()[0],
Expand Down
35 changes: 16 additions & 19 deletions open_data/metadata_speeds.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""
Speeds datasets metadata elements
"""
from gcs_to_esri import open_data_dates
from metadata_hqta import ESRI_BASE_URL
from update_vars import ESRI_BASE_URL

# Speeds data dictionary
KEYWORDS = [
'Transportation',
'Transit',
Expand All @@ -13,24 +15,19 @@
]


SEGMENT_PURPOSE = "All day and peak transit 20th, 50th, and 80th percentile speeds on stop segments estimated on a single day for all CA transit operators that provide GTFS real-time vehicle positions data."
SEGMENT_PURPOSE = "All day and peak transit speeds by segments for all CA operators that provide GTFS real-time vehicle positions data."

SEGMENT_METHODOLOGY = (
'''
This data was estimated by combining GTFS real-time vehicle positions to GTFS scheduled trips, shapes, stops, and stop times tables. GTFS shapes provides the route alignment path. Multiple trips may share the same shape, with a route typically associated with multiple shapes. Shapes are cut into segments at stop positions (stop_id-stop_sequence combination). A `stop segment` refers to the portion of shapes between the prior stop and the current stop. Vehicle positions are spatially joined to 35 meter buffered segments. Within each segment-trip, the first and last vehicle position observed are used to calculate the speed. Since multiple trips may occur over a segment each day, the multiple trip speeds provide a distribution. From this distribution, the 20th percentile, 50th percentile (median), and 80th percentile speeds are calculated. For all day speed metrics, all trips are used. For peak speed metrics, only trips with start times between 7 - 9:59 AM and 4 - 7:59 PM are used to find the 20th, 50th, and 80th percentile metrics.
Data processing notes: (a) GTFS RT trips whose vehicle position timestamps span 10 minutes or less are dropped. Incomplete data would lead to unreliable estimates of speed at the granularity we need. (b) Segment-trip speeds of over 70 mph are excluded. These are erroneously calculated as transit does not typically reach those speeds. (c) Other missing or erroneous calculations, either arising from only one vehicle position found in a segment (change in time or change in distance cannot be calculated).
'''
)
SEGMENT_ABSTRACT = "All day and peak transit 20th, 50th, and 80th percentile speeds on stop segments estimated on a single day for all CA transit operators that provide GTFS real-time vehicle positions data."

ROUTE_PURPOSE = "Average transit speeds by route-direction by time-of-day estimated on a single day for all CA transit operators that provide GTFS real-time vehicle positions data."
SEGMENT_METHODOLOGY = "This data was estimated by combining GTFS real-time vehicle positions to GTFS scheduled trips, shapes, stops, and stop times tables. GTFS shapes provides the route alignment path. Multiple trips may share the same shape, with a route typically associated with multiple shapes. Shapes are cut into segments at stop positions (stop_id-stop_sequence combination). A `stop segment` refers to the portion of shapes between the prior stop and the current stop. Vehicle positions are spatially joined to 35 meter buffered segments. Within each segment-trip, the first and last vehicle position observed are used to calculate the speed. Since multiple trips may occur over a segment each day, the multiple trip speeds provide a distribution. From this distribution, the 20th percentile, 50th percentile (median), and 80th percentile speeds are calculated. For all day speed metrics, all trips are used. For peak speed metrics, only trips with start times between 7 - 9:59 AM and 4 - 7:59 PM are used to find the 20th, 50th, and 80th percentile metrics. Data processing notes: (a) GTFS RT trips whose vehicle position timestamps span 10 minutes or less are dropped. Incomplete data would lead to unreliable estimates of speed at the granularity we need. (b) Segment-trip speeds of over 70 mph are excluded. These are erroneously calculated as transit does not typically reach those speeds. (c) Other missing or erroneous calculations, either arising from only one vehicle position found in a segment (change in time or change in distance cannot be calculated)."


ROUTE_PURPOSE = "Average transit speeds by route-direction and time-of-day estimated on a single day for all CA transit operators that provide GTFS real-time vehicle positions data."

ROUTE_ABSTRACT = "Provide average transit speeds, number of trips, and metrics related to scheduled annd real-time service minutes by route-direction and time-of-day."

ROUTE_METHODOLOGY = "This data was estimated by combining GTFS real-time vehicle positions with GTFS scheduled trips and shapes. GTFS real-time (RT) vehicle positions are spatially joined to GTFS scheduled shapes, so only vehicle positions traveling along the route alignment path are kept. A sample of five vehicle positions are selected (min, 25th percentile, 50th percentile, 75th percentile, max). The trip speed is calculated using these five vehicle positions. Each trip is categorized into a time-of-day. The average speed for a route-direction-time_of_day is calculated. Additional metrics are stored, such as the number of trips observed, the average scheduled service minutes, and the average RT observed service minutes. For convenience, we also provide a singular shape (common_shape_id) to associate with a route-direction. This is the shape that had the most number of trips for a given route-direction. Time-of-day is determined by the GTFS scheduled trip start time. The trip start hour (military time) is categorized based on the following: Owl (0-3), Early AM (4-6), AM Peak (7-9), Midday (10-14), PM Peak (15-19), and Evening (20-23). The start and end hours are inclusive (e.g., 4-6 refers to 4am, 5am, and 6am)."

ROUTE_METHODOLOGY = (
'''
This data was estimated by combining GTFS real-time vehicle positions with GTFS scheduled trips and shapes.
GTFS real-time (RT) vehicle positions are spatially joined to GTFS scheduled shapes, so only vehicle positions traveling along the route alignment path are kept. A sample of five vehicle positions are selected (min, 25th percentile, 50th percentile, 75th percentile, max). The trip speed is calculated using these five vehicle positions. Each trip is categorized into a time-of-day. The average speed for a route-direction-time_of_day is calculated. Additional metrics are stored, such as the number of trips observed, the average scheduled service minutes, and the average RT observed service minutes. For convenience, we also provide a singular shape (common_shape_id) to associate with a route-direction. This is the shape that had the most number of trips for a given route-direction.
Time-of-day is determined by the GTFS scheduled trip start time. The trip start hour (military time) is categorized based on the following: Owl (0-3), Early AM (4-6), AM Peak (7-9), Midday (10-14), PM Peak (15-19), and Evening (20-23). The start and end hours are inclusive (e.g., 4-6 refers to 4am, 5am, and 6am).
'''
)

DATA_DICT_SPEEDS_URL = f"{ESRI_BASE_URL}Speeds_By_Stop_Segments/FeatureServer"
DATA_DICT_ROUTE_SPEEDS_URL = f"{ESRI_BASE_URL}Speeds_By_Route_Time_of_Day/FeatureServer"
Expand All @@ -39,8 +36,8 @@
"dataset_name": "speeds_by_stop_segments",
"publish_entity": "Data & Digital Services / California Integrated Travel Project",

"abstract": "Public. EPSG: 4326",
"purpose": SEGMENT_PURPOSE,
"abstract": SEGMENT_ABSTRACT,

"creation_date": "2023-06-14",
"beginning_date": open_data_dates()[0],
Expand Down Expand Up @@ -69,8 +66,8 @@
"dataset_name": "speeds_by_route_time_of_day",
"publish_entity": "Data & Digital Services / California Integrated Travel Project",

"abstract": "Public. EPSG: 4326",
"purpose": ROUTE_PURPOSE,
"abstract": ROUTE_ABSTRACT,

"creation_date": "2023-06-14",
"beginning_date": open_data_dates()[0],
Expand Down
12 changes: 9 additions & 3 deletions open_data/metadata_traffic_ops.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""
Traffic Ops request for geospatial routes and stops
metadata elements
"""
from gcs_to_esri import open_data_dates
from metadata_hqta import ESRI_BASE_URL
from update_vars import ESRI_BASE_URL

# Traffic Ops routes and stops data dictionary
KEYWORDS = [
Expand All @@ -13,6 +17,8 @@

PURPOSE = "Provide all CA transit stops and routes (geospatial) from all transit operators."

ABSTRACT = "Provide compiled GTFS schedule data in geospatial format. Transit routes associates route information to shapes. Transit stops associates route information to stops."

METHODOLOGY = "This data was assembled from the General Transit Feed Specification (GTFS) schedule data. GTFS tables are text files, but these have been compiled for all operators and transformed into geospatial data, with minimal data processing. The transit routes dataset is assembled from two tables: (1) `shapes.txt`, which defines the route alignment path, and (2) `trips.txt` and `stops.txt`, for routes not found in `shapes.txt`. `shapes.txt` is an optional GTFS table with richer information than just transit stop longitude and latitude. The transit stops dataset is assembled from `stops.txt`, which contains information about the route, stop sequence, and stop longitude and latitude. References: https://gtfs.org/. https://gtfs.org/schedule/reference/#shapestxt. https://gtfs.org/schedule/reference/#stopstxt. https://gtfs.org/schedule/reference/#tripstxt."

DATA_DICT_ROUTES_URL = f"{ESRI_BASE_URL}CA_Transit_Routes/FeatureServer"
Expand All @@ -22,9 +28,9 @@
"dataset_name": "ca_transit_routes",
"publish_entity": "California Integrated Travel Project",

"abstract": "Public. EPSG: 4326",
"purpose": PURPOSE,

"abstract": ABSTRACT,

"creation_date": "2022-02-08",
"beginning_date": open_data_dates()[0],
"end_date": open_data_dates()[1],
Expand Down
26 changes: 14 additions & 12 deletions open_data/metadata_update_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
from typing import Literal

import validation_pro
from update_vars import DEFAULT_XML_TEMPLATE

METADATA_FOLDER = "metadata_xml/"
METADATA_FOLDER = "./xml/"

# This prefix keeps coming up, but xmltodict has trouble processing or replacing it
x = "ns0:"
Expand Down Expand Up @@ -60,8 +61,7 @@ def lift_necessary_dataset_elements(metadata_json: dict) -> dict:


def overwrite_default_with_dataset_elements(metadata_json: dict) -> dict:
DEFAULT_XML = f"./{METADATA_FOLDER}default_pro.xml"
default_template = xml_to_json(DEFAULT_XML)
default_template = xml_to_json(f"{METADATA_FOLDER}{DEFAULT_XML_TEMPLATE}")

# Grab the necessary elements from my dataset
necessary_elements = lift_necessary_dataset_elements(metadata_json[main])
Expand All @@ -83,8 +83,9 @@ def overwrite_default_with_dataset_elements(metadata_json: dict) -> dict:
class metadata_input(BaseModel):
dataset_name: str
publish_entity: str = "Data & Digital Services / California Integrated Travel Project"
abstract: str
purpose: str
abstract: str
public_access: Literal["Public", "Restricted"] = "Public"
creation_date: str
beginning_date: str
end_date: str
Expand All @@ -107,9 +108,8 @@ class metadata_input(BaseModel):
contact_email: str = "hello@calitp.org"
horiz_accuracy: str = "4 meters"
#edition: str
boilerplate_license: str = (
'''Public. License - Creative Commons 4.0 Attribution.
The data are made available to the public solely for informational purposes. Information provided in the Caltrans GIS Data Library is accurate to the best of our knowledge and is subject to change on a regular basis, without notice. While Caltrans makes every effort to provide useful and accurate information, we do not warrant the information Use Limitation - The data are made available to the public solely for informational purposes. Information provided in the Caltrans GIS Data Library is accurate to the best of our knowledge and is subject to change on a regular basis, without notice. While Caltrans makes every effort to provide useful and accurate information, we do not warrant the information to be authoritative, complete, factual, or timely. Information is provided on an "as is" and an "as available" basis. The Department of Transportation is not liable to any party for any cost or damages, including any direct, indirect, special, incidental, or consequential damages, arising out of or in connection with the access or use of, or the inability to access or use, the Site or any of the Materials or Services described herein.''')
boilerplate_desc: str = "The data are made available to the public solely for informational purposes. Information provided in the Caltrans GIS Data Library is accurate to the best of our knowledge and is subject to change on a regular basis, without notice. While Caltrans makes every effort to provide useful and accurate information, we do not warrant the information Use Limitation - The data are made available to the public solely for informational purposes. Information provided in the Caltrans GIS Data Library is accurate to the best of our knowledge and is subject to change on a regular basis, without notice. While Caltrans makes every effort to provide useful and accurate information, we do not warrant the information to be authoritative, complete, factual, or timely. Information is provided on an 'as is' and an 'as available' basis. The Department of Transportation is not liable to any party for any cost or damages, including any direct, indirect, special, incidental, or consequential damages, arising out of or in connection with the access or use of, or the inability to access or use, the Site or any of the Materials or Services described herein."
boilerplate_license: str = "License - Creative Commons 4.0 Attribution."


def fix_values_in_validated_dict(d: dict) -> dict:
Expand Down Expand Up @@ -183,13 +183,15 @@ def overwrite_id_info(metadata: dict, dataset_info: dict) -> dict:
maint_info = overwrite_contact_info(maint_info, d)

(id_info[f"{x}resourceConstraints"][0][f"{x}MD_Constraints"]
[f"{x}useLimitation"][key]) = d["boilerplate_license"]
(id_info[f"{x}resourceConstraints"][1][f"{x}MD_LegalConstraints"]
[f"{x}useLimitation"][key]) = d["boilerplate_license"]
[f"{x}useLimitation"][key]) = d["public_access"]
(id_info[f"{x}resourceConstraints"][1][f"{x}MD_LegalConstraints"]
[f"{x}useLimitation"][key]) = d["boilerplate_desc"]
(id_info[f"{x}resourceConstraints"][2][f"{x}MD_LegalConstraints"]
[f"{x}useLimitation"][key]) = d["boilerplate_license"]
(id_info[f"{x}resourceConstraints"][2][f"{x}MD_LegalConstraints"]
[f"{x}useConstraints"][f"{x}MD_RestrictionCode"][enum]) = "license"
(id_info[f"{x}resourceConstraints"][1][f"{x}MD_LegalConstraints"]
[f"{x}useConstraints"][f"{x}MD_RestrictionCode"][t]) = "license"
(id_info[f"{x}resourceConstraints"][2][f"{x}MD_LegalConstraints"]
[f"{x}useConstraints"][f"{x}MD_RestrictionCode"][t]) = "license"

return metadata

Expand Down
Loading

0 comments on commit 9b9e998

Please sign in to comment.