Skip to content

Commit

Permalink
Merge branch 'enh/env_analysis_euroc' into enh/env_analysis_wind_dire…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
Gui-FernandesBR authored Sep 22, 2022
2 parents c7a5123 + 7ecf051 commit 2492116
Show file tree
Hide file tree
Showing 5 changed files with 385 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/user/requirements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The following packages are needed in order to run RocketPy:
- timezonefinder
- simplekml
- ipywidgets >= 7.6.3
- json


All of these packages, with the exception of netCDF4, should be automatically installed when RocketPy is installed using either ``pip`` or ``conda``.
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ requests
pytz
timezonefinder
simplekml
json
61 changes: 61 additions & 0 deletions rocketpy/Environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
__license__ = "MIT"

import bisect
import json
import re
import warnings
from datetime import datetime, timedelta

import matplotlib.pyplot as plt
import numpy as np
import numpy.ma as ma
import pytz
import requests

Expand Down Expand Up @@ -3325,6 +3327,65 @@ def allInfoReturned(self):
info["selectedEnsembleMember"] = self.ensembleMember
return info

def exportEnvironment(self, filename="environment"):
"""Export important attributes of Environment class so it can be used
again in further siulations by using the customAtmosphere atmospheric
model.
Parameters
----------
filename
Return
------
None
"""

# TODO: in the future, allow the user to select which format will be used (json, csv, etc.). Default must be JSON.
# TODO: add self.exportEnvDictionary to the documentation
# TODO: find a way to documennt the workaround I've used on ma.getdata(self...
self.exportEnvDictionary = {
"railLength": self.rL,
"gravity": self.g,
"date": [self.date.year, self.date.month, self.date.day, self.date.hour],
"latitude": self.lat,
"longitude": self.lon,
"elevation": self.elevation,
"datum": self.datum,
"timeZone": self.timeZone,
"maxExpectedHeight": float(self.maxExpectedHeight),
"atmosphericModelType": self.atmosphericModelType,
"atmosphericModelFile": self.atmosphericModelFile,
"atmosphericModelDict": self.atmosphericModelDict,
"atmosphericModelPressureProfile": ma.getdata(
self.pressure.getSource()
).tolist(),
"atmosphericModelTemperatureProfile": ma.getdata(
self.temperature.getSource()
).tolist(),
"atmosphericModelWindVelocityXProfile": ma.getdata(
self.windVelocityX.getSource()
).tolist(),
"atmosphericModelWindVelocityYProfile": ma.getdata(
self.windVelocityY.getSource()
).tolist(),
}

f = open(filename + ".json", "w")

# write json object to file
f.write(
json.dumps(self.exportEnvDictionary, sort_keys=False, indent=4, default=str)
)

# close file
f.close()
print("Your Environment file was saved, check it out: " + filename + ".json")
print(
"You can use it in the future by using the customAtmosphere atmospheric model."
)

return None

# Auxiliary functions - Geodesic Coordinates
def geodesicToUtm(self, lat, lon, datum):
"""Function which converts geodetic coordinates, i.e. lat/lon, to UTM
Expand Down
Loading

0 comments on commit 2492116

Please sign in to comment.