@@ -57,8 +57,7 @@ class Environment:
57
57
Environment.datum : string
58
58
The desired reference ellipsoid model, the following options are
59
59
available: "SAD69", "WGS84", "NAD83", and "SIRGAS2000". The default
60
- is "SIRGAS2000", then this model will be used if the user make some
61
- typing mistake
60
+ is "SIRGAS2000".
62
61
Environment.initial_east : float
63
62
Launch site East UTM coordinate
64
63
Environment.initial_north : float
@@ -74,7 +73,7 @@ class Environment:
74
73
Launch site E/W hemisphere
75
74
Environment.elevation : float
76
75
Launch site elevation.
77
- Environment.date : datetime
76
+ Environment.datetime_date : datetime
78
77
Date time of launch in UTC.
79
78
Environment.local_date : datetime
80
79
Date time of launch in the local time zone, defined by
@@ -276,49 +275,70 @@ def __init__(
276
275
timezone = "UTC" ,
277
276
max_expected_height = 80000.0 ,
278
277
):
279
- """Initialize Environment class, saving launch rail length,
280
- launch date, location coordinates and elevation. Note that
281
- by default the standard atmosphere is loaded until another
278
+ """Initializes the Environment class, capturing essential parameters of
279
+ the launch site, including the launch date, geographical coordinates,
280
+ and elevation. This class is designed to calculate crucial variables
281
+ for the Flight simulation, such as atmospheric air pressure, density,
282
+ and gravitational acceleration.
283
+
284
+ Note that the default atmospheric model is the International Standard
285
+ Atmosphere as defined by ISO 2533 unless specified otherwise in
286
+ :meth:`Environment.set_atmospheric_model`.
282
287
283
288
Parameters
284
289
----------
285
290
gravity : int, float, callable, string, array, optional
286
291
Surface gravitational acceleration. Positive values point the
287
- acceleration down. If None, the Somigliana formula is used to
288
- date : array, optional
289
- Array of length 4, stating (year, month, day, hour (UTC))
290
- of rocket launch. Must be given if a Forecast, Reanalysis
292
+ acceleration down. If None, the Somigliana formula is used.
293
+ See :meth:`Environment.set_gravity_model` for more information.
294
+ date : list or tuple, optional
295
+ List or tuple of length 4, stating (year, month, day, hour) in the
296
+ time zone of the parameter ``timezone``.
297
+ Alternatively, can be a ``datetime`` object specifying launch
298
+ date and time. The dates are stored as follows:
299
+
300
+ - :attr:`Environment.local_date`: Local time of launch in
301
+ the time zone specified by the parameter ``timezone``.
302
+
303
+ - :attr:`Environment.datetime_date`: UTC time of launch.
304
+
305
+ Must be given if a Forecast, Reanalysis
291
306
or Ensemble, will be set as an atmospheric model.
307
+ Default is None.
308
+ See :meth:`Environment.set_date` for more information.
292
309
latitude : float, optional
293
310
Latitude in degrees (ranging from -90 to 90) of rocket
294
311
launch location. Must be given if a Forecast, Reanalysis
295
312
or Ensemble will be used as an atmospheric model or if
296
- Open-Elevation will be used to compute elevation.
313
+ Open-Elevation will be used to compute elevation. Positive
314
+ values correspond to the North. Default value is 0, which
315
+ corresponds to the equator.
297
316
longitude : float, optional
298
- Longitude in degrees (ranging from -180 to 360 ) of rocket
317
+ Longitude in degrees (ranging from -180 to 180 ) of rocket
299
318
launch location. Must be given if a Forecast, Reanalysis
300
319
or Ensemble will be used as an atmospheric model or if
301
- Open-Elevation will be used to compute elevation.
320
+ Open-Elevation will be used to compute elevation. Positive
321
+ values correspond to the East. Default value is 0, which
322
+ corresponds to the Greenwich Meridian.
302
323
elevation : float, optional
303
324
Elevation of launch site measured as height above sea
304
325
level in meters. Alternatively, can be set as
305
326
'Open-Elevation' which uses the Open-Elevation API to
306
327
find elevation data. For this option, latitude and
307
328
longitude must also be specified. Default value is 0.
308
- datum : string
329
+ datum : string, optional
309
330
The desired reference ellipsoidal model, the following options are
310
331
available: "SAD69", "WGS84", "NAD83", and "SIRGAS2000". The default
311
- is "SIRGAS2000", then this model will be used if the user make some
312
- typing mistake.
332
+ is "SIRGAS2000".
313
333
timezone : string, optional
314
334
Name of the time zone. To see all time zones, import pytz and run
315
- print(pytz.all_timezones). Default time zone is "UTC".
335
+ `` print(pytz.all_timezones)`` . Default time zone is "UTC".
316
336
max_expected_height : float, optional
317
337
Maximum altitude in meters to keep weather data. The altitude must
318
338
be above sea level (ASL). Especially useful for visualization.
319
339
Can be altered as desired by doing `max_expected_height = number`.
320
340
Depending on the atmospheric model, this value may be automatically
321
- mofified .
341
+ modified .
322
342
323
343
Returns
324
344
-------
@@ -396,15 +416,57 @@ def set_date(self, date, timezone="UTC"):
396
416
397
417
Parameters
398
418
----------
399
- date : Datetime
400
- Datetime object specifying launch date and time.
419
+ date : list, tuple, datetime
420
+ List or tuple of length 4, stating (year, month, day, hour) in the
421
+ time zone of the parameter ``timezone``. See Notes for more
422
+ information.
423
+ Alternatively, can be a ``datetime`` object specifying launch
424
+ date and time.
401
425
timezone : string, optional
402
426
Name of the time zone. To see all time zones, import pytz and run
403
- print(pytz.all_timezones). Default time zone is "UTC".
427
+ `` print(pytz.all_timezones)`` . Default time zone is "UTC".
404
428
405
429
Returns
406
430
-------
407
431
None
432
+
433
+ Notes
434
+ -----
435
+ - If the ``date`` is given as a list or tuple, it should be in the same
436
+ time zone as specified by the ``timezone`` parameter. This local
437
+ time will be available in the attribute :attr:`Environment.local_date`
438
+ while the UTC time will be available in the attribute
439
+ :attr:`Environment.datetime_date`.
440
+
441
+ - If the ``date`` is given as a ``datetime`` object without a time zone,
442
+ it will be assumed to be in the same time zone as specified by the
443
+ ``timezone`` parameter. However, if the ``datetime`` object has a time
444
+ zone specified in its ``tzinfo`` attribute, the ``timezone``
445
+ parameter will be ignored.
446
+
447
+ Examples
448
+ --------
449
+
450
+ Let's set the launch date as an list:
451
+
452
+ >>> date = [2000, 1, 1, 13] # January 1st, 2000 at 13:00 UTC+1
453
+ >>> env = Environment()
454
+ >>> env.set_date(date, timezone="Europe/Rome")
455
+ >>> print(env.datetime_date) # Get UTC time
456
+ 2000-01-01 12:00:00+00:00
457
+ >>> print(env.local_date)
458
+ 2000-01-01 13:00:00+01:00
459
+
460
+ Now let's set the launch date as a ``datetime`` object:
461
+
462
+ >>> from datetime import datetime
463
+ >>> date = datetime(2000, 1, 1, 13, 0, 0)
464
+ >>> env = Environment()
465
+ >>> env.set_date(date, timezone="Europe/Rome")
466
+ >>> print(env.datetime_date) # Get UTC time
467
+ 2000-01-01 12:00:00+00:00
468
+ >>> print(env.local_date)
469
+ 2000-01-01 13:00:00+01:00
408
470
"""
409
471
# Store date and configure time zone
410
472
self .timezone = timezone
@@ -458,23 +520,66 @@ def set_location(self, latitude, longitude):
458
520
self .atmospheric_model_file , self .atmospheric_model_dict
459
521
)
460
522
461
- # Return None
462
-
463
- def set_gravity_model (self , gravity ):
464
- """Sets the gravity model to be used in the simulation based on the
465
- given user input to the gravity parameter.
523
+ def set_gravity_model (self , gravity = None ):
524
+ """Defines the gravity model based on the given user input to the
525
+ gravity parameter. The gravity model is responsible for computing the
526
+ gravity acceleration at a given height above sea level in meters.
466
527
467
528
Parameters
468
529
----------
469
- gravity : None or Function source
470
- If None, the Somigliana formula is used to compute the gravity
471
- acceleration. Otherwise, the user can provide a Function object
472
- representing the gravity model.
530
+ gravity : int, float, callable, string, list, optional
531
+ The gravitational acceleration in m/s² to be used in the
532
+ simulation, this value is positive when pointing downwards.
533
+ The input type can be one of the following:
534
+
535
+ - ``int`` or ``float``: The gravity acceleration is set as a\
536
+ constant function with respect to height;
537
+
538
+ - ``callable``: This callable should receive the height above\
539
+ sea level in meters and return the gravity acceleration;
540
+
541
+ - ``list``: The datapoints should be structured as\
542
+ ``[(h_i,g_i), ...]`` where ``h_i`` is the height above sea\
543
+ level in meters and ``g_i`` is the gravity acceleration in m/s²;
544
+
545
+ - ``string``: The string should correspond to a path to a CSV file\
546
+ containing the gravity acceleration data;
547
+
548
+ - ``None``: The Somigliana formula is used to compute the gravity\
549
+ acceleration.
550
+
551
+ This parameter is used as a :class:`Function` object source, check\
552
+ out the available input types for a more detailed explanation.
473
553
474
554
Returns
475
555
-------
476
556
Function
477
557
Function object representing the gravity model.
558
+
559
+ Notes
560
+ -----
561
+ This method **does not** set the gravity acceleration, it only returns
562
+ a :class:`Function` object representing the gravity model.
563
+
564
+ Examples
565
+ --------
566
+ Let's prepare a `Environment` object with a constant gravity
567
+ acceleration:
568
+
569
+ >>> g_0 = 9.80665
570
+ >>> env_cte_g = Environment(gravity=g_0)
571
+ >>> env_cte_g.gravity([0, 100, 1000])
572
+ [9.80665, 9.80665, 9.80665]
573
+
574
+ It's also possible to variate the gravity acceleration by defining
575
+ its function of height:
576
+
577
+ >>> R_t = 6371000
578
+ >>> g_func = lambda h : g_0 * (R_t / (R_t + h))**2
579
+ >>> env_var_g = Environment(gravity=g_func)
580
+ >>> g = env_var_g.gravity(1000)
581
+ >>> print(f"{g:.6f}")
582
+ 9.803572
478
583
"""
479
584
if gravity is None :
480
585
return self .somigliana_gravity .set_discrete (
@@ -500,7 +605,7 @@ def max_expected_height(self, value):
500
605
501
606
@funcify_method ("height (m)" , "gravity (m/s²)" )
502
607
def somigliana_gravity (self , height ):
503
- """Computes the gravity acceleration with the Somigliana formula.
608
+ """Computes the gravity acceleration with the Somigliana formula [1]_ .
504
609
An height correction is applied to the normal gravity that is
505
610
accurate for heights used in aviation. The formula is based on the
506
611
WGS84 ellipsoid, but is accurate for other reference ellipsoids.
@@ -514,6 +619,10 @@ def somigliana_gravity(self, height):
514
619
-------
515
620
Function
516
621
Function object representing the gravity model.
622
+
623
+ References
624
+ ----------
625
+ .. [1] https://en.wikipedia.org/wiki/Theoretical_gravity#Somigliana_equation
517
626
"""
518
627
a = 6378137.0 # semi_major_axis
519
628
f = 1 / 298.257223563 # flattening_factor
0 commit comments