Skip to content

Commit 4b42c9e

Browse files
committed
DOC: clarify timezones and dates Environment docs.
1 parent 95b61ef commit 4b42c9e

File tree

1 file changed

+76
-23
lines changed

1 file changed

+76
-23
lines changed

rocketpy/environment/environment.py

Lines changed: 76 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Environment:
7373
Launch site E/W hemisphere
7474
Environment.elevation : float
7575
Launch site elevation.
76-
Environment.date : datetime
76+
Environment.datetime_date : datetime
7777
Date time of launch in UTC.
7878
Environment.local_date : datetime
7979
Date time of launch in the local time zone, defined by
@@ -281,7 +281,7 @@ def __init__(
281281
for the Flight simulation, such as atmospheric air pressure, density,
282282
and gravitational acceleration.
283283
284-
Note that the default atmospheric model is the International Standard
284+
Note that the default atmospheric model is the International Standard
285285
Atmosphere as defined by ISO 2533 unless specified otherwise in
286286
:meth:`Environment.set_atmospheric_model`.
287287
@@ -292,22 +292,33 @@ def __init__(
292292
acceleration down. If None, the Somigliana formula is used.
293293
See :meth:`Environment.set_gravity_model` for more information.
294294
date : array, optional
295-
Array of length 4, stating (year, month, day, hour (UTC))
296-
of rocket launch. Must be given if a Forecast, Reanalysis
295+
Array 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
297306
or Ensemble, will be set as an atmospheric model.
307+
Default is None.
308+
See :meth:`Environment.set_date` for more information.
298309
latitude : float, optional
299310
Latitude in degrees (ranging from -90 to 90) of rocket
300311
launch location. Must be given if a Forecast, Reanalysis
301312
or Ensemble will be used as an atmospheric model or if
302313
Open-Elevation will be used to compute elevation. Positive
303-
values correspond to the North. Default value is 0, which
314+
values correspond to the North. Default value is 0, which
304315
corresponds to the equator.
305316
longitude : float, optional
306317
Longitude in degrees (ranging from -180 to 360) of rocket
307318
launch location. Must be given if a Forecast, Reanalysis
308319
or Ensemble will be used as an atmospheric model or if
309320
Open-Elevation will be used to compute elevation. Positive
310-
values correspond to the East. Default value is 0, which
321+
values correspond to the East. Default value is 0, which
311322
corresponds to the Greenwich Meridian.
312323
elevation : float, optional
313324
Elevation of launch site measured as height above sea
@@ -321,7 +332,7 @@ def __init__(
321332
is "SIRGAS2000".
322333
timezone : string, optional
323334
Name of the time zone. To see all time zones, import pytz and run
324-
print(pytz.all_timezones). Default time zone is "UTC".
335+
``print(pytz.all_timezones)``. Default time zone is "UTC".
325336
max_expected_height : float, optional
326337
Maximum altitude in meters to keep weather data. The altitude must
327338
be above sea level (ASL). Especially useful for visualization.
@@ -405,15 +416,57 @@ def set_date(self, date, timezone="UTC"):
405416
406417
Parameters
407418
----------
408-
date : Datetime
409-
Datetime object specifying launch date and time.
419+
date : array, Datetime
420+
Array 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.
410425
timezone : string, optional
411426
Name of the time zone. To see all time zones, import pytz and run
412-
print(pytz.all_timezones). Default time zone is "UTC".
427+
``print(pytz.all_timezones)``. Default time zone is "UTC".
413428
414429
Returns
415430
-------
416431
None
432+
433+
Notes
434+
-----
435+
- If the ``date`` is given as an array, 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 array:
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
417470
"""
418471
# Store date and configure time zone
419472
self.timezone = timezone
@@ -479,23 +532,23 @@ def set_gravity_model(self, gravity=None):
479532
simulation, this value is positive when pointing downwards.
480533
The input type can be one of the following:
481534
482-
- ``int`` or ``float``: The gravity acceleration is set as a
483-
constant function with respect to height;
535+
- ``int`` or ``float``: The gravity acceleration is set as a\
536+
constant function with respect to height;
484537
485-
- ``callable``: This callable should receive the height above
486-
sea level in meters and return the gravity acceleration;
538+
- ``callable``: This callable should receive the height above\
539+
sea level in meters and return the gravity acceleration;
487540
488-
- ``array``: The datapoints should be structured as
489-
``[(h_i,g_i), ...]`` where ``h_i`` is the height above sea
490-
level in meters and ``g_i`` is the gravity acceleration in m/s²;
541+
- ``array``: 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²;
491544
492-
- ``string``: The string should correspond to a path to a CSV file
493-
containing the gravity acceleration data;
545+
- ``string``: The string should correspond to a path to a CSV file\
546+
containing the gravity acceleration data;
494547
495-
- ``None``: The Somigliana formula is used to compute the gravity
496-
acceleration.
548+
- ``None``: The Somigliana formula is used to compute the gravity\
549+
acceleration.
497550
498-
This parameter is used as a :class:`Function` object source, check
551+
This parameter is used as a :class:`Function` object source, check\
499552
out the available input types for a more detailed explanation.
500553
501554
Returns
@@ -552,7 +605,7 @@ def max_expected_height(self, value):
552605

553606
@funcify_method("height (m)", "gravity (m/s²)")
554607
def somigliana_gravity(self, height):
555-
"""Computes the gravity acceleration with the Somigliana formula.
608+
"""Computes the gravity acceleration with the Somigliana formula [1]_.
556609
An height correction is applied to the normal gravity that is
557610
accurate for heights used in aviation. The formula is based on the
558611
WGS84 ellipsoid, but is accurate for other reference ellipsoids.

0 commit comments

Comments
 (0)