-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver.py
More file actions
39 lines (30 loc) · 1.2 KB
/
driver.py
File metadata and controls
39 lines (30 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
Filename: driver.py
Author: Simran Suresh
Date: Nov, 2024
Description: Main driver function for running the objmap.py in parallel processing
"""
import pandas as pd
import csv
from datetime import datetime
from multiprocessing import Pool
from objmap import *
import concurrent.futures
# Read the grid points
gp = pd.read_csv('grid_setup/grid_50km_nplaea.csv')
# Function to apply to each combination
def proc(lat_lon_pair):
lat, lon,t = lat_lon_pair
(Og, Og_err) = objmap(lat, lon, t)
print(t.date(), lat, lon, Og, Og_err)
return t.date(), lat, lon, Og, Og_err
# Use ThreadPoolExecutor to parallelize computation and collect results
results = []
with concurrent.futures.ThreadPoolExecutor() as executor:
results = list(executor.map(proc, [(row['Latitude'], row['Longitude'],datetime(2011, 1, 1)) for _, row in list(gp.iterrows())]))
output_file = "results/grd_dh_2011_01.csv" # another run with distance sorted poiints selected within L1 L2
with open(output_file, mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["Datetime", "Latitude", "Longitude", "Dynamic_Height", "DH_error"])
writer.writerows(results)
print(f"Results written to {output_file}")