Skip to content

Commit 05fb76b

Browse files
committed
fixed dependencies
1 parent 5e97b59 commit 05fb76b

8 files changed

Lines changed: 104 additions & 57 deletions

File tree

campyros/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ def __init__(
222222
lat,
223223
variable_wind=True,
224224
default_wind=[0, 0, 0],
225-
launch_datetime=(date.today()-timedelta(days=2)).strftime("%Y%m%d %H:%M"),
226-
cache_Wind=False
225+
launch_datetime=(date.today() - timedelta(days=2)).strftime("%Y%m%d %H:%M"),
226+
cache_Wind=False,
227227
):
228228
self.rail_length = rail_length
229229
self.rail_yaw = rail_yaw
@@ -235,7 +235,7 @@ def __init__(
235235
variable=variable_wind,
236236
default=default_wind,
237237
datetime=launch_datetime,
238-
cache=cache_Wind
238+
cache=cache_Wind,
239239
)
240240

241241

campyros/statistical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def run_itteration(self, id, save_loc, debug=False):
250250
* np.random.normal(1, self.launch_site_vars["lat"][1]),
251251
variable_wind=bool(self.launch_site_vars["variable_wind"]),
252252
launch_datetime=self.launch_site_vars["launch_datetime"],
253-
cache_Wind=True
253+
cache_Wind=True,
254254
)
255255

256256
###Parachute

campyros/tests/test.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22
import sys, os, json
3-
from datetime import date,timedelta,datetime
3+
from datetime import date, timedelta, datetime
44

55
sys.path.append(
66
"/".join(
@@ -204,11 +204,13 @@ def test_parachute(self):
204204
)
205205

206206
def test_stats(self):
207-
with open("campyros/tests/test_stats.json",'r') as f:
208-
stat_dat=json.load(f)
209-
stat_dat["launch_site"]["launch_datetime"]=(date.today()-timedelta(days=2)).strftime("%Y%m%d %H:%M")
210-
with open("campyros/tests/test_stats.json",'w') as f:
211-
json.dump(stat_dat,f)
207+
with open("campyros/tests/test_stats.json", "r") as f:
208+
stat_dat = json.load(f)
209+
stat_dat["launch_site"]["launch_datetime"] = (
210+
date.today() - timedelta(days=2)
211+
).strftime("%Y%m%d %H:%M")
212+
with open("campyros/tests/test_stats.json", "w") as f:
213+
json.dump(stat_dat, f)
212214
stats_model = stats.StatisticalModel("campyros/tests/test_stats.json")
213215
ran = stats_model.run_model(test_mode=True, num_cpus=1)
214216
print(ran)
@@ -223,15 +225,16 @@ def test_stats(self):
223225
)
224226

225227
def test_wind(self):
226-
wind1=wind.Wind((date.today()-timedelta(days=1)).strftime("%Y%m%d %H:%M"))
227-
wind1_val=wind1.get_wind(239,923,292728238)
228-
self.assertIsInstance(wind1_val,type(np.array([0.0,0.0])))
229-
self.assertEqual(3,len(wind1_val))
230-
231-
wind2=wind.Wind(variable=False)
232-
wind2_val=wind2.get_wind(-239,-923,-292728238)
233-
self.assertEqual(0,wind2_val[0])
234-
self.assertEqual(0,wind2_val[1])
228+
wind1 = wind.Wind((date.today() - timedelta(days=1)).strftime("%Y%m%d %H:%M"))
229+
wind1_val = wind1.get_wind(239, 923, 292728238)
230+
self.assertIsInstance(wind1_val, type(np.array([0.0, 0.0])))
231+
self.assertEqual(3, len(wind1_val))
232+
233+
wind2 = wind.Wind(variable=False)
234+
wind2_val = wind2.get_wind(-239, -923, -292728238)
235+
self.assertEqual(0, wind2_val[0])
236+
self.assertEqual(0, wind2_val[1])
237+
235238

236239
if __name__ == "__main__":
237240
unittest.main()

campyros/wind.py

Lines changed: 77 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import getgfs, dateutil.parser, pickle, warnings
22
from datetime import datetime, date, timedelta
3-
from pathlib import Path
3+
from pathlib import Path
44
import numpy as np
55

66
__copyright__ = """
@@ -22,10 +22,17 @@
2222
2323
"""
2424

25-
Path("data/wind").mkdir(parents=True,exist_ok=True)
25+
Path("data/wind").mkdir(parents=True, exist_ok=True)
26+
2627

2728
class Wind:
28-
def __init__(self,datetime=(date.today()-timedelta(days=2)).strftime("%Y%m%d %H:%M"),default=np.array([0,0,0]),variable=True,cache=False):
29+
def __init__(
30+
self,
31+
datetime=(date.today() - timedelta(days=2)).strftime("%Y%m%d %H:%M"),
32+
default=np.array([0, 0, 0]),
33+
variable=True,
34+
cache=False,
35+
):
2936
"""Initites wind object so wind for some position can be searched
3037
3138
Note
@@ -36,17 +43,16 @@ def __init__(self,datetime=(date.today()-timedelta(days=2)).strftime("%Y%m%d %H:
3643
datetime (string): datetime of flight, can be in 'any' format as long as datetime parser can work it out (for now this will need to be UTC)
3744
cache (bool, optional): cache lat/long/time profile, useful for stats models where downloading for each run is a bottle neck. Defaults to False.
3845
"""
39-
self.launch_time=dateutil.parser.parse(datetime).timestamp()
40-
self.cache=cache
41-
self.default=default
42-
self.variable=variable
46+
self.launch_time = dateutil.parser.parse(datetime).timestamp()
47+
self.cache = cache
48+
self.default = default
49+
self.variable = variable
4350

44-
self.forecast=getgfs.Forecast("0p25","1hr")
45-
self.profiles={}#(lat,long,datetime):interp profile
46-
self.points=[]#tuples (lat,long,forecast)
51+
self.forecast = getgfs.Forecast("0p25", "1hr")
52+
self.profiles = {} # (lat,long,datetime):interp profile
53+
self.points = [] # tuples (lat,long,forecast)
4754

48-
49-
def get_wind(self,lat,long,alt,flight_time=0):
55+
def get_wind(self, lat, long, alt, flight_time=0):
5056
"""[summary]
5157
5258
Args:
@@ -58,36 +64,72 @@ def get_wind(self,lat,long,alt,flight_time=0):
5864
Returns:
5965
tuple: returns u and v components of wind
6066
"""
61-
if self.variable==True:
62-
lat=[float(self.forecast.coords["lat"]["resolution"])*n+float(self.forecast.coords["lat"]["minimum"]) for n in range(0,int(self.forecast.coords["lat"]["grads_size"]))][self.forecast.value_to_index("lat",lat)]
63-
long=[float(self.forecast.coords["lon"]["resolution"])*n+float(self.forecast.coords["lon"]["minimum"]) for n in range(0,int(self.forecast.coords["lon"]["grads_size"]))][self.forecast.value_to_index("lon",long)]
64-
request_timestamp=self.launch_time+flight_time
65-
request_datetime=datetime.fromtimestamp(request_timestamp).strftime("%Y-%m-%d %H:%M")
66-
forecast_to_use=self.forecast.datetime_to_forecast(request_datetime)
67-
if (lat,long, forecast_to_use) not in self.points:
68-
if self.cache==False or not Path("data/wind/%s_%s_%s.pkl"%(lat,long,forecast_to_use)).is_file():
67+
if self.variable == True:
68+
lat = [
69+
float(self.forecast.coords["lat"]["resolution"]) * n
70+
+ float(self.forecast.coords["lat"]["minimum"])
71+
for n in range(0, int(self.forecast.coords["lat"]["grads_size"]))
72+
][self.forecast.value_to_index("lat", lat)]
73+
long = [
74+
float(self.forecast.coords["lon"]["resolution"]) * n
75+
+ float(self.forecast.coords["lon"]["minimum"])
76+
for n in range(0, int(self.forecast.coords["lon"]["grads_size"]))
77+
][self.forecast.value_to_index("lon", long)]
78+
request_timestamp = self.launch_time + flight_time
79+
request_datetime = datetime.fromtimestamp(request_timestamp).strftime(
80+
"%Y-%m-%d %H:%M"
81+
)
82+
forecast_to_use = self.forecast.datetime_to_forecast(request_datetime)
83+
if (lat, long, forecast_to_use) not in self.points:
84+
if (
85+
self.cache == False
86+
or not Path(
87+
"data/wind/%s_%s_%s.pkl" % (lat, long, forecast_to_use)
88+
).is_file()
89+
):
6990
try:
70-
self.profiles[(lat,long,forecast_to_use)]=self.forecast.get_windprofile(request_datetime,lat,long)
71-
self.points.append((lat,long,forecast_to_use))
91+
self.profiles[
92+
(lat, long, forecast_to_use)
93+
] = self.forecast.get_windprofile(request_datetime, lat, long)
94+
self.points.append((lat, long, forecast_to_use))
7295
except Exception as e:
73-
warnings.warn("Wind could not be found - defaults used, gfspy gave the message:")
96+
warnings.warn(
97+
"Wind could not be found - defaults used, gfspy gave the message:"
98+
)
7499
print(e)
75100
return self.default
76-
77-
if self.cache==True:
78-
with open("data/wind/%s_%s_%s.pkl"%(lat,long,forecast_to_use),"wb") as dump_file:
79-
pickle.dump(self.profiles[(lat,long,forecast_to_use)],dump_file)
101+
102+
if self.cache == True:
103+
with open(
104+
"data/wind/%s_%s_%s.pkl" % (lat, long, forecast_to_use),
105+
"wb",
106+
) as dump_file:
107+
pickle.dump(
108+
self.profiles[(lat, long, forecast_to_use)], dump_file
109+
)
80110
else:
81-
with open("data/wind/%s_%s_%s.pkl"%(lat,long,forecast_to_use),"rb") as dump_file:
82-
self.profiles[(lat,long,forecast_to_use)]=pickle.load(dump_file)
83-
self.points.append((lat,long,forecast_to_use))
84-
85-
return np.array([self.profiles[(lat,long,forecast_to_use)][0](alt),self.profiles[(lat,long,forecast_to_use)][1](alt),0])
111+
with open(
112+
"data/wind/%s_%s_%s.pkl" % (lat, long, forecast_to_use), "rb"
113+
) as dump_file:
114+
self.profiles[(lat, long, forecast_to_use)] = pickle.load(
115+
dump_file
116+
)
117+
self.points.append((lat, long, forecast_to_use))
118+
119+
return np.array(
120+
[
121+
self.profiles[(lat, long, forecast_to_use)][0](alt),
122+
self.profiles[(lat, long, forecast_to_use)][1](alt),
123+
0,
124+
]
125+
)
86126
else:
87127
return self.default
88-
if __name__=="__main__":
89-
w=Wind("20210428 15:00",cache=True)
90-
print(w.get(2938,29328,20866566))
128+
129+
130+
if __name__ == "__main__":
131+
w = Wind("20210428 15:00", cache=True)
132+
print(w.get(2938, 29328, 20866566))
91133
"""times=np.linspace(0,60*60*12,1000)
92134
x=[]
93135
for t in times:
-2.44 KB
Binary file not shown.
-2.44 KB
Binary file not shown.

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ thermo
66
gas_dynamics
77
pandas
88
numexpr
9-
requests
9+
requests
10+
getgfs>=1.0.0

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name="CamPyRoS",
10-
version="1.0",
10+
version="1.1",
1111
author="Jago Strong-Wright & Daniel Gibbons",
1212
author_email="jagoosw@protonmail.com",
1313
packages=find_packages(),
@@ -20,7 +20,8 @@
2020
"gas_dynamics",
2121
"pandas",
2222
"numexpr",
23-
"requests"
23+
"requests",
24+
"getgfs>=1.0.0"
2425
],
2526
description="Cambridge Python Rocketry Simulator",
2627
)

0 commit comments

Comments
 (0)