diff --git a/.github/workflows/python-request.yml b/.github/workflows/python-request.yml index 0e7bc7d..fea352c 100644 --- a/.github/workflows/python-request.yml +++ b/.github/workflows/python-request.yml @@ -44,6 +44,7 @@ jobs: flake8 pytest pytest-cov + pytest-xdist - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names @@ -53,7 +54,7 @@ jobs: - name: Test with pytest run: | pip install --no-deps . - pytest --verbose --capture=no --cov=./ --cov-report=xml \ + pytest -n 0 --cov=./ --cov-report=xml \ --username=${{ secrets.EARTHDATA_USERNAME }} \ --password=${{ secrets.EARTHDATA_PASSWORD }} - name: Archive code coverage results diff --git a/CODE_OF_CONDUCT.rst b/CODE_OF_CONDUCT.md similarity index 64% rename from CODE_OF_CONDUCT.rst rename to CODE_OF_CONDUCT.md index 7806e98..dd2dac5 100644 --- a/CODE_OF_CONDUCT.rst +++ b/CODE_OF_CONDUCT.md @@ -1,9 +1,6 @@ -=============== -Code of Conduct -=============== +# Code of Conduct -Our Pledge -########## +## Our Pledge We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body @@ -15,39 +12,37 @@ and orientation. We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. -Our Standards -############# +## Our Standards Examples of behavior that contributes to a positive environment for our community include: -* Demonstrating empathy and kindness toward other people -* Being respectful of differing opinions, viewpoints, and experiences -* Giving and gracefully accepting constructive feedback -* Accepting responsibility and apologizing to those affected by our mistakes, +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience -* Focusing on what is best not just for us as individuals, but for the +- Focusing on what is best not just for us as individuals, but for the overall community Examples of unacceptable behavior include: -* Offensive comments related to gender, gender identity and expression, sexual orientation, +- Offensive comments related to gender, gender identity and expression, sexual orientation, disability, mental illness, physical appearance, body size, race, or religion -* Deliberate misgendering or use of "dead" or rejected names -* The use of sexualized language or imagery, and sexual attention or +- Deliberate misgendering or use of "dead" or rejected names +- The use of sexualized language or imagery, and sexual attention or advances of any kind -* Trolling, insulting or derogatory comments, and personal or political attacks -* Public or private harassment -* Incitement or threats of violence towards any individual, +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Incitement or threats of violence towards any individual, including encouraging a person to commit suicide or to engage in self-harm -* Publishing others' private information, such as a physical or email +- Publishing others' private information, such as a physical or email address, without their explicit permission -* Advocating for, or encouraging, any of the above behavior -* Other conduct which could reasonably be considered inappropriate in a +- Advocating for, or encouraging, any of the above behavior +- Other conduct which could reasonably be considered inappropriate in a professional setting -Enforcement Responsibilities -############################ +## Enforcement Responsibilities Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in @@ -59,25 +54,21 @@ comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. -Enforcement -########### +## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the community leaders responsible for enforcement at -`@tsutterley `_. +Instances of abusive, harassing, or otherwise unacceptable behavior can be +reported to the organizational leaders responsible for enforcement. All complaints will be reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the reporter of any incident. -Enforcement Guidelines -###################### +## Enforcement Guidelines Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: -1. Correction -------------- +### 1. Correction **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. @@ -86,8 +77,7 @@ unprofessional or unwelcome in the community. clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. -2. Warning ----------- +### 2. Warning **Community Impact**: A violation through a single incident or series of actions. @@ -99,8 +89,7 @@ includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. -3. Temporary Ban ----------------- +### 3. Temporary Ban **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. @@ -111,26 +100,24 @@ private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. -4. Permanent Ban ----------------- +### 4. Permanent Ban **Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an +standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. **Consequence**: A permanent ban from any sort of public interaction within the community. -Attribution -########### +## Attribution -This code of conduct is adapted from the `Contributor Covenant `_ -`Code of Conduct `_ and -the `Geek Feminism `_ -`Community Anti-Harassment Policy `_. +This code of conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/) +[Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct.html) and +the [Geek Feminism](http://geekfeminism.wikia.com) +[Community Anti-Harassment Policy](http://geekfeminism.wikia.com/wiki/Community_anti-harassment/Policy). -Community Impact Guidelines were inspired by `Mozilla's code of conduct -enforcement ladder `_. +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). We have adapted these documents for our own use under the terms of the -`Creative Commons Attribution License `_. +[Creative Commons Attribution License](https://creativecommons.org/licenses/by/4.0/). diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md new file mode 100644 index 0000000..6c9a55f --- /dev/null +++ b/CONTRIBUTORS.md @@ -0,0 +1,6 @@ +- [Karen Alley (University of Manitoba)](https://umanitoba.ca/environment-earth-resources/dr-karen-alley-profile-page) +- [Kelly Brunt (NASA Goddard Space Flight Center)](https://science.gsfc.nasa.gov/sed/bio/kelly.m.brunt) +- [Susan Howard (Earth & Space Research)](https://www.esr.org/staff/susan-l-howard/) +- [Laurie Padman (Earth & Space Research)](https://www.esr.org/staff/laurence-padman/) +- [Matt Siegfried (Colorado School of Mines)](https://geophysics.mines.edu/project/siegfried-matthew/) +- [Tyler Sutterley (University of Washington)](http://psc.apl.uw.edu/people/investigators/tyler-sutterley/) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst deleted file mode 100644 index 07a3114..0000000 --- a/CONTRIBUTORS.rst +++ /dev/null @@ -1,6 +0,0 @@ -- `Karen Alley (University of Manitoba) `_ -- `Kelly Brunt (NASA Goddard Space Flight Center) `_ -- `Susan Howard (Earth \& Space Research) `_ -- `Laurie Padman (Earth \& Space Research) `_ -- `Matt Siegfried (Colorado School of Mines) `_ -- `Tyler Sutterley (University of Washington) `_ diff --git a/README.md b/README.md new file mode 100644 index 0000000..b4193b5 --- /dev/null +++ b/README.md @@ -0,0 +1,102 @@ +--- +substitutions: + Documentation Status: |- + ```{image} https://readthedocs.org/projects/timescale/badge/?version=latest + :target: https://timescale.readthedocs.io/en/latest/?badge=latest + ``` + License: |- + ```{image} https://img.shields.io/github/license/pyTMD/timescale + :target: https://github.com/pyTMD/timescale/blob/main/LICENSE + ``` + PyPI: |- + ```{image} https://img.shields.io/pypi/v/timescale.svg + :target: https://pypi.python.org/pypi/timescale/ + ``` + commits-since: |- + ```{image} https://img.shields.io/github/commits-since/pyTMD/timescale/latest + :target: https://github.com/pyTMD/timescale/releases/latest + ``` + conda-forge: |- + ```{image} https://img.shields.io/conda/vn/conda-forge/timescale + :target: https://anaconda.org/conda-forge/timescale + ``` + zenodo: |- + ```{image} https://zenodo.org/badge/681330279.svg + :target: https://zenodo.org/badge/latestdoi/681330279 + ``` +--- + +# timescale + +{{ License }} +{{ Documentation Status }} +{{ PyPI }} +{{ conda-forge }} +{{ commits-since }} +{{ zenodo }} + +Python tools for time and astronomical calculations + +For more information: see the documentation at [timescale.readthedocs.io](https://timescale.readthedocs.io/) + +## Installation + +From PyPI: + +```bash +python3 -m pip install timescale +``` + +Using `conda` or `mamba` from conda-forge: + +```bash +conda install -c conda-forge timescale +``` + +```bash +mamba install -c conda-forge timescale +``` + +Development version from GitHub: + +```bash +python3 -m pip install git+https://github.com/pyTMD/timescale.git +``` + +## Dependencies + +- [dateutil: powerful extensions to datetime](https://dateutil.readthedocs.io/en/stable/) +- [lxml: processing XML and HTML in Python](https://pypi.python.org/pypi/lxml) +- [numpy: Scientific Computing Tools For Python](https://www.numpy.org) +- [scipy: Scientific Tools for Python](https://www.scipy.org/) + +## References + +> T. C. Sutterley, T. Markus, T. A. Neumann, M. R. van den Broeke, J. M. van Wessem, and S. R. M. Ligtenberg, +> "Antarctic ice shelf thickness change from multimission lidar mapping", *The Cryosphere*, +> 13, 1801-1817, (2019). [doi: 10.5194/tc-13-1801-2019](https://doi.org/10.5194/tc-13-1801-2019) + +## Download + +The program homepage is: + + + +A zip archive of the latest version is available directly at: + + + +## Disclaimer + +This package includes software developed at NASA Goddard Space Flight Center (GSFC) and the University of Washington Applied Physics Laboratory (UW-APL). +It is not sponsored or maintained by the Universities Space Research Association (USRA), AVISO or NASA. +The software is provided here for your convenience but *with no guarantees whatsoever*. + +## Contributing + +This project contains work and contributions from the [scientific community](./CONTRIBUTORS.rst). +If you would like to contribute to the project, please have a look at the [open issues](https://github.com/pyTMD/timescale/issues) and [discussions board](https://github.com/pyTMD/timescale/discussions). + +## License + +The content of this project is licensed under the [Creative Commons Attribution 4.0 Attribution license](https://creativecommons.org/licenses/by/4.0/) and the source code is licensed under the [MIT license](LICENSE). diff --git a/doc/source/getting_started/Code-of-Conduct.rst b/doc/source/getting_started/Code-of-Conduct.rst index 89ef3ba..eea72ab 100644 --- a/doc/source/getting_started/Code-of-Conduct.rst +++ b/doc/source/getting_started/Code-of-Conduct.rst @@ -1 +1,2 @@ -.. include:: ../../../CODE_OF_CONDUCT.rst \ No newline at end of file +.. include:: ../../../CODE_OF_CONDUCT.md + :parser: commonmark \ No newline at end of file diff --git a/doc/source/getting_started/Contributing.rst b/doc/source/getting_started/Contributing.rst index a04ecdc..37c5348 100644 --- a/doc/source/getting_started/Contributing.rst +++ b/doc/source/getting_started/Contributing.rst @@ -4,12 +4,14 @@ Contribution Guidelines ``timescale`` is an open source project. We welcome any help in maintaining and developing the software and documentation. -Anyone at any career stage and with any level of coding experience can contribute towards the development of ``timescale``. +Anyone at *any career stage and with any level of coding experience* can contribute towards the development of ``timescale``. Please read our `code of conduct <./Code-of-Conduct.html>`_ before contributing to ``timescale`` development. You will be recognized for your work by being listed as one of the `project contributors <../project/Contributors.html>`_. -If you have found a problem in ``timescale``, or you would like to suggest an improvement or modification, -please submit a `GitHub issue `_ and we will get back to you. +.. note:: + + If you have found a problem in ``timescale``, or you would like to suggest an improvement or modification, + please submit a `GitHub issue `_ and we will get back to you. Ways to Contribute ------------------ @@ -34,10 +36,10 @@ If not, *please* submit a new issue so that we are made aware of the problem. Please provide as much detail as possible when writing the description of your bug report. Providing information and examples will help us resolve issues faster. -Contributing Code or Examples ------------------------------ +Contributing Code +----------------- We follow a standard Forking Workflow for code changes and additions. -Submitted code goes through the pull request process for `continuous integration (CI) testing <./Contributing.html#continuous-integration>`_ and comments. +Submitted code goes through the pull request process for `continuous integration (CI) testing <../project/Testing.html#continuous-integration>`_ and comments. General Guidelines ^^^^^^^^^^^^^^^^^^ @@ -65,19 +67,6 @@ Adding Examples Examples may be in the form of executable scripts or interactive Jupyter Notebooks Fully working (but unrendered) examples should be submitted with the same steps as above. -Continuous Integration -^^^^^^^^^^^^^^^^^^^^^^ -We use `GitHub Actions `_ continuous integration (CI) services to build and test the project on Linux (Ubuntu) and Mac Operating Systems. -The configuration files for this service are in the `GitHub workflows `_ directory. -The workflows rely on the `environment.yml `_ and `requirements-dev.txt `_ files to install the required dependencies. - -The GitHub Actions jobs include: - -* Updating `leap second `_ and `delta time `_ files -* Running `flake8 `_ to check the code for style and compilation errors -* Running the test suite on multiple combinations of OS and Python version -* Uploading source and wheel distributions to `PyPI `_ (on releases) - Semantic Commit Messages ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -96,5 +85,5 @@ where ```` is one of the following: - ``docs``: changing the documentation - ``style``: changing the line order or adding comments - ``refactor``: changing the names of variables or programs -- ``ci``: changing the `continuous integration <./Contributing.html#continuous-integration>`_ configuration files or scripts -- ``test``: adding or updating `continuous integration tests <./Contributing.html#continuous-integration>`_ +- ``ci``: changing the `continuous integration <../project/Testing.html#continuous-integration>`_ configuration files or scripts +- ``test``: adding or updating `continuous integration tests <../project/Testing.html#continuous-integration>`_ \ No newline at end of file diff --git a/doc/source/getting_started/Getting-Started.rst b/doc/source/getting_started/Getting-Started.rst index 25ebd71..1e24486 100644 --- a/doc/source/getting_started/Getting-Started.rst +++ b/doc/source/getting_started/Getting-Started.rst @@ -76,4 +76,7 @@ There are a few different ways to create a ``Timescale`` object: ts = timescale.from_julian(JD) ``Timescale`` objects can be used to convert epochs, convert to different time standards, convert to ``datetime`` arrays, and other time conversions. -See the `API Reference <../api_reference/time.html#timescale.time.Timescale>`_ for more information. + +.. tip:: + + See the `API Reference <../api_reference/time.html#timescale.time.Timescale>`_ for more information. diff --git a/doc/source/index.rst b/doc/source/index.rst index 3264676..0b57560 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -110,6 +110,7 @@ Project Details project/Contributors.rst project/Licenses.rst + project/Testing.rst project/Citations.rst .. toctree:: diff --git a/doc/source/project/Citations.rst b/doc/source/project/Citations.rst index c182b5c..8955139 100644 --- a/doc/source/project/Citations.rst +++ b/doc/source/project/Citations.rst @@ -10,7 +10,7 @@ Program (NPP) at NASA Goddard Space Flight Center (GSFC), administered by Universities Space Research Association (USRA) under contract with NASA. It is currently supported under the NASA Cryospheric Sciences Program (Grant Number 80NSSC22K0379). -If you have used ``timescale`` in your work, please consider citing our library: +.. admonition:: Please consider citing our library T. C. Sutterley, K. Alley, K. Brunt, S. Howard, L. Padman, and M. Siegfried, "timescale: Python tools for time and astronomical calculations", (2023). @@ -41,8 +41,10 @@ Disclaimer This package includes software developed at NASA Goddard Space Flight Center (GSFC) and the University of Washington Applied Physics Laboratory (UW-APL). It is not sponsored or maintained by the Universities Space Research Association (USRA), AVISO or NASA. -Outputs from this software should be used for scientific or technical purposes only. -This software should not be used for coastal navigation or any application that may risk life or property. + +.. warning:: + Outputs from this software should be used for scientific or technical purposes only. + This software should not be used for coastal navigation or *any application that may risk life or property*. .. |auml| unicode:: U+00E4 .. LATIN SMALL LETTER A WITH DIAERESIS .. |uuml| unicode:: U+00FC .. LATIN SMALL LETTER U WITH DIAERESIS diff --git a/doc/source/project/Contributors.rst b/doc/source/project/Contributors.rst index 518e8b9..4dab9c9 100644 --- a/doc/source/project/Contributors.rst +++ b/doc/source/project/Contributors.rst @@ -2,4 +2,5 @@ Contributors ============ -.. include:: ../../../CONTRIBUTORS.rst +.. include:: ../../../CONTRIBUTORS.md + :parser: commonmark \ No newline at end of file diff --git a/doc/source/project/Licenses.rst b/doc/source/project/Licenses.rst index dcdb4d5..91ab4dd 100644 --- a/doc/source/project/Licenses.rst +++ b/doc/source/project/Licenses.rst @@ -2,8 +2,8 @@ Licenses ======== -License -======= +MIT License +=========== The source code of ``timescale`` is licensed under a MIT license: diff --git a/doc/source/project/Testing.rst b/doc/source/project/Testing.rst new file mode 100644 index 0000000..0be5299 --- /dev/null +++ b/doc/source/project/Testing.rst @@ -0,0 +1,53 @@ +======= +Testing +======= + +``timescale`` uses the ``pytest`` framework to run tests and verify outputs. +Running the test suite requires a `dev installation <../getting_started/Install.html>`_ of the ``timescale`` package to include all of the optional dependencies. + +.. code-block:: bash + + python -m pip install --editable '.[dev]' + +Running the Test Suite +^^^^^^^^^^^^^^^^^^^^^^ + +Using the ``pytest`` command: + +.. code-block:: bash + + pytest --directory test/ + +The test suite is run in verbose mode as a default. + +Coverage Reports +^^^^^^^^^^^^^^^^ + +Coverage reports can be generated using the ``pytest-cov`` plugin (which is installed with the dev installation). + +.. code-block:: bash + + pytest --cov timescale --cov-report=term + +Parallelization +^^^^^^^^^^^^^^^ + +As a default, the ``pytest`` suite is run in parallel using the ``pytest-xdist`` plugin (which is also installed with the dev installation). +To run in series and disable parallelization, set the number of processes to 0: + +.. code-block:: bash + + pytest --n 0 + +Continuous Integration +^^^^^^^^^^^^^^^^^^^^^^ +We use `GitHub Actions `_ continuous integration (CI) services to build and test the project on Linux (Ubuntu) and Mac Operating Systems. +The configuration files for this service are in the `GitHub workflows `_ directory. +The workflows use ``mamba`` and the `environment.yml `_ file to install the required dependencies and build the environment. + +The GitHub Actions jobs include: + +* Updating `leap second `_ and `delta time `_ files +* Running `flake8 `_ to check the code for style and compilation errors +* Running the test suite on multiple combinations of OS and Python version +* Uploading source and wheel distributions to `PyPI `_ (on releases) diff --git a/pyproject.toml b/pyproject.toml index 2485cc9..ea58872 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ authors = [ ] maintainers = [{ name = "timescale contributors" }] license = {file = "LICENSE"} -readme = "README.rst" +readme = {file = "README.md", content-type = "text/markdown"} requires-python = "~=3.6" dependencies = [ @@ -60,7 +60,7 @@ Issues = "https://github.com/pyTMD/timescale/issues" [project.optional-dependencies] doc = ["docutils", "fontconfig", "freetype", "graphviz", "numpydoc", "sphinx", "sphinx-argparse>=0.4", "sphinx_rtd_theme"] -dev = ["flake8", "pytest>=4.6", "pytest-cov"] +dev = ["flake8", "pytest>=4.6", "pytest-cov", "pytest-xdist"] [tool.setuptools.packages.find] exclude = ["test*", "run*"] @@ -68,6 +68,7 @@ exclude = ["test*", "run*"] [tool.pytest.ini_options] minversion = "6.0" norecursedirs = ".git" +addopts = "-n auto --verbose --capture=no" python_files = [ "test*.py" ] diff --git a/timescale/__init__.py b/timescale/__init__.py index 3fe0077..14db22d 100644 --- a/timescale/__init__.py +++ b/timescale/__init__.py @@ -16,7 +16,7 @@ def from_deltatime(*args, **kwargs): """Wrapper for ``timescale.time.Timescale().from_deltatime`` """ - return timescale.time.Timescale().from_deltatime(*args, **kwargs) + return timescale.time.Timescale.from_deltatime(*args, **kwargs) # Julian dates def from_julian(ut1, **kwargs): return timescale.time.Timescale(ut1 - 2400000.5) @@ -31,23 +31,23 @@ def from_besselian(B, **kwargs): def from_calendar(*args, **kwargs): """Wrapper for ``timescale.time.Timescale().from_calendar`` """ - return timescale.time.Timescale().from_calendar(*args, **kwargs) + return timescale.time.Timescale.from_calendar(*args, **kwargs) # datetime arrays def from_datetime(*args, **kwargs): """Wrapper for ``timescale.time.Timescale().from_datetime`` """ - return timescale.time.Timescale().from_datetime(*args, **kwargs) + return timescale.time.Timescale.from_datetime(*args, **kwargs) # range of dates def from_range(start, end, *args, **kwargs): """Wrapper for creating a ``Timescale`` object from a range of dates """ d = timescale.time.date_range(start, end, *args, **kwargs) - return timescale.time.Timescale().from_datetime(d) + return timescale.time.Timescale.from_datetime(d) # list of timescale objects def from_list(*args, **kwargs): """Wrapper for ``timescale.time.Timescale().from_list`` """ - return timescale.time.Timescale().from_list(*args, **kwargs) + return timescale.time.Timescale.from_list(*args, **kwargs) # get version information __version__ = timescale.version.version diff --git a/timescale/time.py b/timescale/time.py index cc6a24d..dbe4311 100755 --- a/timescale/time.py +++ b/timescale/time.py @@ -718,15 +718,16 @@ class Timescale: # degrees to arcseconds deg2asec = 3600.0 - def __init__(self, MJD=None): + def __init__(self, MJD=None, leaps=None): # leap seconds - self.leaps = None + self.leaps = leaps # modified Julian Days self.MJD = MJD # iterator self.__index__ = 0 - def from_deltatime(self, + @classmethod + def from_deltatime(cls, delta_time: np.ndarray, epoch: str | tuple | list | np.ndarray, standard: str = 'UTC' @@ -752,7 +753,7 @@ def from_deltatime(self, GPS_Time = convert_delta_time(delta_time, epoch1=epoch, epoch2=_gps_epoch, scale=1.0) # calculate difference in leap seconds from start of epoch - self.leaps = count_leap_seconds(GPS_Time) - \ + leaps = count_leap_seconds(GPS_Time) - \ count_leap_seconds(np.atleast_1d(GPS_Epoch_Time)) elif (standard.upper() == 'LORAN'): # LORAN time is ahead of GPS time by 9 seconds @@ -761,7 +762,7 @@ def from_deltatime(self, GPS_Time = convert_delta_time(delta_time - 9.0, epoch1=epoch, epoch2=_gps_epoch, scale=1.0) # calculate difference in leap seconds from start of epoch - self.leaps = count_leap_seconds(GPS_Time) - \ + leaps = count_leap_seconds(GPS_Time) - \ count_leap_seconds(np.atleast_1d(GPS_Epoch_Time)) elif (standard.upper() == 'TAI'): # TAI time is ahead of GPS time by 19 seconds @@ -770,19 +771,20 @@ def from_deltatime(self, GPS_Time = convert_delta_time(delta_time-19.0, epoch1=epoch, epoch2=_gps_epoch, scale=1.0) # calculate difference in leap seconds from start of epoch - self.leaps = count_leap_seconds(GPS_Time) - \ + leaps = count_leap_seconds(GPS_Time) - \ count_leap_seconds(np.atleast_1d(GPS_Epoch_Time)) elif (standard.upper() == 'GLONASS'): # GLONASS time is ahead of UTC time by 3 hours - self.leaps = 3.0*3600.0 + leaps = 3.0*3600.0 else: - self.leaps = 0.0 + leaps = 0.0 # convert time to days relative to Modified Julian days in UTC - self.MJD = convert_delta_time(delta_time - self.leaps, - epoch1=epoch, epoch2=_mjd_epoch, scale=(1.0/self.day)) - return self + MJD = convert_delta_time(delta_time - leaps, + epoch1=epoch, epoch2=_mjd_epoch, scale=(1.0/86400.0)) + return cls(MJD=MJD, leaps=leaps) - def from_calendar(self, + @classmethod + def from_calendar(cls, year: np.ndarray, month: np.ndarray, day: np.ndarray, @@ -817,14 +819,15 @@ def from_calendar(self, second = np.array(second, dtype=np.float64) # calculate date in Modified Julian Days (MJD) from calendar date # MJD: days since November 17, 1858 (1858-11-17T00:00:00) - self.MJD = 367.0*year - \ + MJD = 367.0*year - \ np.floor(1.75*(year + np.floor((month + 9.0)/12.0))) - \ np.floor(0.75*(np.floor((year + (month - 9.0)/7.0)/100.0) + 1.0)) + \ np.floor(275.0*month/9.0) + day + hour/24.0 + minute/1440.0 + \ second/86400.0 + 1721028.5 - _jd_mjd - return self + return cls(MJD=MJD) - def from_datetime(self, dtime: np.ndarray): + @classmethod + def from_datetime(cls, dtime: np.ndarray): """ Reads a ``datetime`` array and converts into a ``Timescale`` object @@ -835,10 +838,11 @@ def from_datetime(self, dtime: np.ndarray): """ # convert delta time array from datetime object # to days relative to 1992-01-01T00:00:00 - self.MJD = convert_datetime(dtime, epoch=_mjd_epoch)/self.day - return self + MJD = convert_datetime(dtime, epoch=_mjd_epoch)/86400.0 + return cls(MJD=MJD) - def from_list(self, temp): + @classmethod + def from_list(cls, temp): """ Reads a list of ``Timescale`` objects and converts into a single ``Timescale`` object @@ -849,8 +853,8 @@ def from_list(self, temp): list of ``Timescale`` objects """ # convert list of timescale objects to a single timescale object - self.MJD = np.array([t.MJD for t in temp]) - return self + MJD = np.array([t.MJD for t in temp]) + return cls(MJD=MJD) def to_calendar(self): """