forked from PaulZC/pyBalloon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyb_drifter.py
91 lines (65 loc) · 2.99 KB
/
pyb_drifter.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
Method to determine trajectories for one starting position with different drift times.
"""
import numpy as np
import datetime
import os
import pyb_runner
import pyb_io
import param_file as p
#################################################################################################################
def drifter(ini_conditions=None, balloon=None, params=None, parachute=None, run=None, overwrite=False, drift_times=None):
"""
Method to calculate trajectories starting at the same location and time, but have different drift times
Arguments
=========
ini_conditions : tuple of strings
(Date of initial point, Initial time of trajectory, (latitude in degrees, longitude in degrees, altitude in km) of initial point
balloon : dict
Dictionary of balloon parameters, e.g. burtsradius, mass etc.
params : dictionary
Dictionary of parameters determining how the trajectory is calculated, e.g. with interpolation, descent_only etc.
parachute : dict
Dictionary of prachute parameters, e.g. area, drag coefficient
run : string
String indicating which run folder the results are to be stored in
overwrite : bool
If True, overwrite trajectory file with same name in folder
drift_time: array
Array of several drift times to check
"""
datestr, utc_hour, loc0 = ini_conditions
lat0, lon0, alt0 = loc0
out_dir = p.path + p.output_folder
if run == None:
now = datetime.datetime.now()
now_str = str(now.year) + str(now.month).zfill(2) + str(now.day).zfill(2)
files = [filename for filename in os.listdir(out_dir) if now_str in filename]
run = now_str + '_' + str(len(files))
params, balloon, parachute = pyb_io.set_params(datestr=datestr, utc_hour=utc_hour, params=params, balloon=balloon, parachute=parachute)
params['drift_time'] = drift_times
pyb_io.print_verbose(ini_conditions=ini_conditions, params=params, balloon=balloon, parachute=parachute)
params_dir = out_dir + run + '/'
if not os.path.exists(params_dir):
os.makedirs(params_dir)
pyb_io.write_verbose(params_dir=params_dir, params=params, balloon=balloon, parachute=parachute)
for drift_time in drift_times:
params[1] = drift_time
print('Running drift time: ' + str(drift_time) + ' minutes')
pyb_runner.basic_runner(ini_conditions=ini_conditions, params=params, balloon=balloon, parachute=parachute, run=run, overwrite=overwrite)
print('----------\n')
pyb_io.merge_kml(datestr=datestr, run=run, drift_times=drift_times)
#################################################################################################################
if __name__ == '__main__':
import sys
datestr = sys.argv[1]
utc_hour = float(sys.argv[2])
loc0 = float(sys.argv[3]), float(sys.argv[4]), float(sys.argv[5])
ini_conditions = (datestr, utc_hour, loc0)
if len(sys.argv) > 6:
run = sys.argv[6]
else:
run = None
drift_times = np.arange(0., 40., 10.)
drifter(ini_conditions=ini_conditions, run=run, drift_times=drift_times)
#################################################################################################################