Skip to content

Commit cee6336

Browse files
Merge branch 'enh/env_analysis_wind_direction' of https://github.com/rocketpy-team/rocketpy into enh/env_analysis_wind_direction
2 parents c39617c + d4babbe commit cee6336

File tree

7 files changed

+338
-6
lines changed

7 files changed

+338
-6
lines changed
Binary file not shown.
Binary file not shown.

docs/user/requirements.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The following packages are needed in order to run RocketPy:
2727
- timezonefinder
2828
- simplekml
2929
- ipywidgets >= 7.6.3
30+
- jsonpickle
3031

3132

3233
All of these packages, with the exception of netCDF4, should be automatically installed when RocketPy is installed using either ``pip`` or ``conda``.
@@ -49,6 +50,7 @@ The packages needed can be installed via ``pip`` by running the following lines
4950
pip install pytz
5051
pip install timezonefinder
5152
pip install simplekml
53+
pip install jsonpickle
5254
5355
Installing Required Packages Using ``conda``
5456
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ requests
88
pytz
99
timezonefinder
1010
simplekml
11+
jsonpickle

rocketpy/Environment.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
__license__ = "MIT"
88

99
import bisect
10+
import json
1011
import re
1112
import warnings
1213
from datetime import datetime, timedelta
1314

1415
import matplotlib.pyplot as plt
1516
import numpy as np
17+
import numpy.ma as ma
1618
import pytz
1719
import requests
1820

@@ -3325,6 +3327,65 @@ def allInfoReturned(self):
33253327
info["selectedEnsembleMember"] = self.ensembleMember
33263328
return info
33273329

3330+
def exportEnvironment(self, filename="environment"):
3331+
"""Export important attributes of Environment class so it can be used
3332+
again in further siulations by using the customAtmosphere atmospheric
3333+
model.
3334+
Parameters
3335+
----------
3336+
filename
3337+
3338+
Return
3339+
------
3340+
None
3341+
"""
3342+
3343+
# TODO: in the future, allow the user to select which format will be used (json, csv, etc.). Default must be JSON.
3344+
# TODO: add self.exportEnvDictionary to the documentation
3345+
# TODO: find a way to documennt the workaround I've used on ma.getdata(self...
3346+
self.exportEnvDictionary = {
3347+
"railLength": self.rL,
3348+
"gravity": self.g,
3349+
"date": [self.date.year, self.date.month, self.date.day, self.date.hour],
3350+
"latitude": self.lat,
3351+
"longitude": self.lon,
3352+
"elevation": self.elevation,
3353+
"datum": self.datum,
3354+
"timeZone": self.timeZone,
3355+
"maxExpectedHeight": float(self.maxExpectedHeight),
3356+
"atmosphericModelType": self.atmosphericModelType,
3357+
"atmosphericModelFile": self.atmosphericModelFile,
3358+
"atmosphericModelDict": self.atmosphericModelDict,
3359+
"atmosphericModelPressureProfile": ma.getdata(
3360+
self.pressure.getSource()
3361+
).tolist(),
3362+
"atmosphericModelTemperatureProfile": ma.getdata(
3363+
self.temperature.getSource()
3364+
).tolist(),
3365+
"atmosphericModelWindVelocityXProfile": ma.getdata(
3366+
self.windVelocityX.getSource()
3367+
).tolist(),
3368+
"atmosphericModelWindVelocityYProfile": ma.getdata(
3369+
self.windVelocityY.getSource()
3370+
).tolist(),
3371+
}
3372+
3373+
f = open(filename + ".json", "w")
3374+
3375+
# write json object to file
3376+
f.write(
3377+
json.dumps(self.exportEnvDictionary, sort_keys=False, indent=4, default=str)
3378+
)
3379+
3380+
# close file
3381+
f.close()
3382+
print("Your Environment file was saved, check it out: " + filename + ".json")
3383+
print(
3384+
"You can use it in the future by using the customAtmosphere atmospheric model."
3385+
)
3386+
3387+
return None
3388+
33283389
# Auxiliary functions - Geodesic Coordinates
33293390
def geodesicToUtm(self, lat, lon, datum):
33303391
"""Function which converts geodetic coordinates, i.e. lat/lon, to UTM

0 commit comments

Comments
 (0)