Skip to content

Commit c218992

Browse files
ENH: adding exportEnvironment method
1 parent a1f8ae7 commit c218992

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

rocketpy/Environment.py

Lines changed: 53 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,57 @@ 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(self.pressure.getSource())[:,1].tolist(),
3360+
"atmosphericModelTemperatureProfile": ma.getdata(self.temperature.getSource())[:,1].tolist(),
3361+
"atmosphericModelWindVelocityXProfile": ma.getdata(self.windVelocityX.getSource())[:,1].tolist(),
3362+
"atmosphericModelWindVelocityYProfile": ma.getdata(self.windVelocityY.getSource())[:,1].tolist()
3363+
}
3364+
# for data in self.exportEnvDictionary:
3365+
# print(data, " ", type(self.exportEnvDictionary[data]))
3366+
3367+
# print(" ")
3368+
3369+
# open file for writing, "w"
3370+
f = open(filename+".json","w")
3371+
3372+
# write json object to file
3373+
f.write(json.dumps(self.exportEnvDictionary))
3374+
3375+
# close file
3376+
f.close()
3377+
print("Your file was saved, chekc it out: " + filename + ".json")
3378+
3379+
return None
3380+
33283381
# Auxiliary functions - Geodesic Coordinates
33293382
def geodesicToUtm(self, lat, lon, datum):
33303383
"""Function which converts geodetic coordinates, i.e. lat/lon, to UTM

0 commit comments

Comments
 (0)