write input parameters json for all polygons#
Poly id: int
olat, olon: origin for pyproj projection (center point)
plat1, plat2: lcc only (min and max of lat)
xmin, xmax, xsep = -124.0, 124.0, 2.0
ymin, ymax, ysep = -124.0, 124.0, 2.0
zmin, zmax, zsep = -4.0, 100.0, 1.0
cartesian grid bounds for velocity model - must encompass all stations, default valuesmin max for lon lat
import json
import pandas as pd
import os
def write_json(new_data, filename='cascadia_poly.json'):
if not os.path.exists(filename):
with open(filename, 'w') as file:
json.dump([], file) # Start with an empty list if the file doesn't exist
with open(filename, 'r+') as file:
file_data = json.load(file)
file_data.append(new_data)
file.seek(0)
json.dump(file_data, file, indent=4)
def create_dict_std_param(poly_id, min_lon, max_lon, min_lat, max_lat):
dictionary = {
"poly_id": poly_id,
"olon": (min_lon+max_lon)/2,
"olat": (min_lat+max_lat)/2,
"plat1": min_lat,
"plat2": max_lat,
"xmin": -124.0,
"xmax": 124.0,
"xsep": 2.0,
"ymin": -124.0,
"ymax": 124.0,
"ysep": 2.0,
"zmin": -4.0,
"zmax": 100.0,
"zsep": 1.0,
"minlon": min_lon,
"maxlon": max_lon,
"minlat": min_lat,
"maxlat": max_lat,
}
return dictionary
rectangles = [
[1, -125, 46.9, -122.4, 49.1],
[2, -122.6, 46.9, -120, 49.1],
[3, -125, 44.9, -122.4, 47.1],
[4, -122.6, 44.9, -120, 47.1],
[5, -125, 42.9, -122.4, 45.1],
[6, -122.6, 42.9, -120, 45.1],
[7, -125, 40.9, -122.4, 43.1],
[8, -122.6, 40.9, -120, 43.1],
[9, -125, 38.9, -122.4, 41.1],
[10, -122.6, 38.9, -120, 41.1]
]
# Creating DataFrame
df = pd.DataFrame(rectangles, columns=['poly_id', 'min_lon', 'min_lat', 'max_lon', 'max_lat'])
# Display the DataFrame
df
| poly_id | min_lon | min_lat | max_lon | max_lat | |
|---|---|---|---|---|---|
| 0 | 1 | -125.0 | 46.9 | -122.4 | 49.1 |
| 1 | 2 | -122.6 | 46.9 | -120.0 | 49.1 |
| 2 | 3 | -125.0 | 44.9 | -122.4 | 47.1 |
| 3 | 4 | -122.6 | 44.9 | -120.0 | 47.1 |
| 4 | 5 | -125.0 | 42.9 | -122.4 | 45.1 |
| 5 | 6 | -122.6 | 42.9 | -120.0 | 45.1 |
| 6 | 7 | -125.0 | 40.9 | -122.4 | 43.1 |
| 7 | 8 | -122.6 | 40.9 | -120.0 | 43.1 |
| 8 | 9 | -125.0 | 38.9 | -122.4 | 41.1 |
| 9 | 10 | -122.6 | 38.9 | -120.0 | 41.1 |
for i, row in df.iterrows():
write_json(create_dict_std_param(row.poly_id, row.min_lon, row.max_lon, row.min_lat, row.max_lat))
verify poly#
with open("cascadia_poly.json", 'r+') as file:
file_data = json.load(file)
file_data[0]
{'poly_id': 1.0,
'olon': -123.7,
'olat': 48.0,
'plat1': 46.9,
'plat2': 49.1,
'xmin': -124.0,
'xmax': 124.0,
'xsep': 2.0,
'ymin': -124.0,
'ymax': 124.0,
'ysep': 2.0,
'zmin': -4.0,
'zmax': 100.0,
'zsep': 1.0,
'minlon': -125.0,
'maxlon': -122.4,
'minlat': 46.9,
'maxlat': 49.1}