Fix three decimal
Browse files
app.py
CHANGED
|
@@ -175,44 +175,39 @@ def get_wayback_data():
|
|
| 175 |
"""Fetches and parses Wayback imagery data from ArcGIS."""
|
| 176 |
try:
|
| 177 |
url = "https://wayback.maptiles.arcgis.com/arcgis/rest/services/World_Imagery/MapServer/WMTS/1.0.0/WMTSCapabilities.xml"
|
| 178 |
-
response = requests.get(url
|
| 179 |
-
response.raise_for_status()
|
|
|
|
|
|
|
| 180 |
root = ET.fromstring(response.content)
|
| 181 |
-
|
| 182 |
-
# Define the namespaces found in the XML document
|
| 183 |
ns = {
|
| 184 |
-
"wmts": "
|
| 185 |
-
"ows": "
|
|
|
|
| 186 |
}
|
| 187 |
-
|
| 188 |
# Use a robust XPath to find all 'Layer' elements anywhere in the document.
|
| 189 |
-
|
| 190 |
-
|
|
|
|
| 191 |
layer_data = []
|
| 192 |
for layer in layers:
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
"ResourceURL_Template": template
|
| 203 |
-
})
|
| 204 |
-
|
| 205 |
-
if not layer_data:
|
| 206 |
-
print("Warning: No valid layers with titles and resource URLs found in Wayback XML response.")
|
| 207 |
-
return pd.DataFrame()
|
| 208 |
|
| 209 |
wayback_df = pd.DataFrame(layer_data)
|
| 210 |
-
|
| 211 |
-
wayback_df["date"] = pd.to_datetime(wayback_df["Title"].str.extract(r"(\d{4}-\d{2}-\d{2})")[0], errors="coerce")
|
| 212 |
-
# Drop rows where date could not be parsed
|
| 213 |
-
wayback_df.dropna(subset=['date'], inplace=True)
|
| 214 |
wayback_df.set_index("date", inplace=True)
|
| 215 |
-
return wayback_df
|
|
|
|
| 216 |
except requests.exceptions.RequestException as e:
|
| 217 |
print(f"Could not fetch Wayback data from URL: {e}")
|
| 218 |
return pd.DataFrame()
|
|
@@ -452,6 +447,7 @@ def calculate_indices(
|
|
| 452 |
|
| 453 |
result_df = pd.DataFrame(result_rows).set_index('daterange')
|
| 454 |
result_df.index = result_df.index.str.split('-').str[0] # Use start year as index for plotting
|
|
|
|
| 455 |
|
| 456 |
# Create plots
|
| 457 |
plots = []
|
|
|
|
| 175 |
"""Fetches and parses Wayback imagery data from ArcGIS."""
|
| 176 |
try:
|
| 177 |
url = "https://wayback.maptiles.arcgis.com/arcgis/rest/services/World_Imagery/MapServer/WMTS/1.0.0/WMTSCapabilities.xml"
|
| 178 |
+
response = requests.get(url)
|
| 179 |
+
response.raise_for_status() # Ensure request was successful
|
| 180 |
+
|
| 181 |
+
# Parse XML
|
| 182 |
root = ET.fromstring(response.content)
|
| 183 |
+
|
|
|
|
| 184 |
ns = {
|
| 185 |
+
"wmts": "https://www.opengis.net/wmts/1.0",
|
| 186 |
+
"ows": "https://www.opengis.net/ows/1.1",
|
| 187 |
+
"xlink": "https://www.w3.org/1999/xlink",
|
| 188 |
}
|
| 189 |
+
|
| 190 |
# Use a robust XPath to find all 'Layer' elements anywhere in the document.
|
| 191 |
+
# This is less brittle than specifying the full path.
|
| 192 |
+
layers = root.findall(".//wmts:Contents/wmts:Layer", ns)
|
| 193 |
+
|
| 194 |
layer_data = []
|
| 195 |
for layer in layers:
|
| 196 |
+
title = layer.find("ows:Title", ns)
|
| 197 |
+
identifier = layer.find("ows:Identifier", ns)
|
| 198 |
+
resource = layer.find("wmts:ResourceURL", ns) # Tile URL template
|
| 199 |
+
|
| 200 |
+
title_text = title.text if title is not None else "N/A"
|
| 201 |
+
identifier_text = identifier.text if identifier is not None else "N/A"
|
| 202 |
+
url_template = resource.get("template") if resource is not None else "N/A"
|
| 203 |
+
|
| 204 |
+
layer_data.append({"Title": title_text, "ResourceURL_Template": url_template})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
wayback_df = pd.DataFrame(layer_data)
|
| 207 |
+
wayback_df["date"] = pd.to_datetime(wayback_df["Title"].str.extract(r"(\d{4}-\d{2}-\d{2})").squeeze(), errors="coerce")
|
|
|
|
|
|
|
|
|
|
| 208 |
wayback_df.set_index("date", inplace=True)
|
| 209 |
+
return wayback_df
|
| 210 |
+
|
| 211 |
except requests.exceptions.RequestException as e:
|
| 212 |
print(f"Could not fetch Wayback data from URL: {e}")
|
| 213 |
return pd.DataFrame()
|
|
|
|
| 447 |
|
| 448 |
result_df = pd.DataFrame(result_rows).set_index('daterange')
|
| 449 |
result_df.index = result_df.index.str.split('-').str[0] # Use start year as index for plotting
|
| 450 |
+
result_df = result_df.round(3)
|
| 451 |
|
| 452 |
# Create plots
|
| 453 |
plots = []
|