|
7 | 7 | __license__ = "MIT"
|
8 | 8 |
|
9 | 9 | import bisect
|
| 10 | +import json |
10 | 11 | import re
|
11 | 12 | import warnings
|
12 | 13 | from datetime import datetime, timedelta
|
13 | 14 |
|
14 | 15 | import matplotlib.pyplot as plt
|
15 | 16 | import numpy as np
|
| 17 | +import numpy.ma as ma |
16 | 18 | import pytz
|
17 | 19 | import requests
|
18 | 20 |
|
@@ -3325,6 +3327,65 @@ def allInfoReturned(self):
|
3325 | 3327 | info["selectedEnsembleMember"] = self.ensembleMember
|
3326 | 3328 | return info
|
3327 | 3329 |
|
| 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 | + |
3328 | 3389 | # Auxiliary functions - Geodesic Coordinates
|
3329 | 3390 | def geodesicToUtm(self, lat, lon, datum):
|
3330 | 3391 | """Function which converts geodetic coordinates, i.e. lat/lon, to UTM
|
|
0 commit comments