Skip to main content

Switch Gregorian date to GNSS calendar (GPS & BDS).

Project description

This module contains functions for converting between Gregorian date, day of year and GNSS calendar, now support GNSS calendar for GPS and BDS.

There are 3 functions for converting between Gregorian date and day of year (doy):

date2doy(date)
date2yrdoy(date)
yrdoy2date(year, doy)

Using them like:

>>> from datetime import date

>>> date2doy(date(2017, 5, 17))
137

>>> date2yrdoy(date(2017, 5, 17))
(2017, 137)

>>> yrdoy2date(2017, 137)
datetime.date(2017, 5, 17)

There are 4 functions for converting between Gregorian date and GNSS calendars (GPS or BDS):

date2gpswd(date)
date2bdswd(date)
gpswd2date(gpsweek, dayofweek)
bdswd2date(bdsweek, dayofweek)

Using them like:

>>> from datetime import date

>>> date2gpswd(date(2017, 5, 17))
(1949, 3)

>>> date2bdswd(date(2017, 5, 17))
(593, 3)

>>> gpswd2date(1949, 3)
datetime.date(2017, 5, 17)

>>> bdswd2date(593, 3)
datetime.date(2017, 5, 17)

There are 4 functions for converting between year, day of year (doy) and GNSS calendars (GPS or BDS):

yrdoy2gpswd(year, doy)
yrdoy2bdswd(year, doy)
gpswd2yrdoy(gpsweek, dayofweek)
bdswd2yrdoy(bdsweek, dayofweek)

Using them like:

>>> yrdoy2gpswd(2017, 137)
(1949, 3)

>>> yrdoy2bdswd(2017, 137)
(593, 3)

>>> gpswd2yrdoy(1949, 3)
(2017, 137)

>>> bdswd2yrdoy(593, 3)
(2017, 137)

There are also 2 functions for converting between GPS calendar and BDS calendar:

gpsw2bdsw(gpsweek)
bdsw2gpsw(bdsweek)

Using them like:

>>> gpsw2bdsw(1949)
593

>>> bdsw2gpsw(593)
1949

Where the type of date is datetime.date and others are int or tuple of int.

Zero point of GPS and BDS are also given as module level constains in Gregorian date.

Examples

import gnsscal
from datetime import date

# Convert Gregorian date to GPS calendar
today = date.today()
gpsweek, days = gnsscal.date2gpswd(today)

# Convert GPS week to BDS week
gpsweek = 1812
bdsweek = gnsscal.gpsw2bdsw(gpsweek)

# Get zero point of GPS and BDS calendar
gps_zero = gnsscal.GPS_START_DATE
bds_zero = gnsscal.BDS_START_DATE

CLI mode

You can also using gnsscal in CLI mode:

$ python -m gnsscal [options]

Set input date using the optional arguments:

-h, --help                          show this help message and exit
-v, --version                       show program's version number and exit
-date <year> <month> <day>          year, month, day
-ydoy <year> <doy>                  year, day of year
-gpswd <GPS week> <day of week>     GPS week, day of week
-bdswd <BDS week> <day of week>     BDS week, day of week

Example, typing this command in terminal:

$ python -m gnsscal -date 2017 5 17

Then it will print:

Gregorian date: 2017-05-17
year, doy: 2017, 137
GPS week: 1949, 3
BDS week: 0593, 3

Installation

The module can be installed using pip:

$ pip install gnsscal

Test

Test gnsscal.py using command:

$ python test_gnsscal.py

License

Released under BSD, see LICENSE for more details.

For comments and suggestions, please send email to: jiangyingming(at)live.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gnsscal-1.1.2.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

gnsscal-1.1.2-py2.py3-none-any.whl (5.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file gnsscal-1.1.2.tar.gz.

File metadata

  • Download URL: gnsscal-1.1.2.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.4

File hashes

Hashes for gnsscal-1.1.2.tar.gz
Algorithm Hash digest
SHA256 0ab49d9c33f3aab96b3957cdf10a8f2ea599bebb432999ab92364f975c8a9269
MD5 89adca0b6a5bfcde9fbe49f0aafcccc6
BLAKE2b-256 b19117d5bda72351749ad1e17fa63fce213f15ebd925c30b388377d1f8db6398

See more details on using hashes here.

File details

Details for the file gnsscal-1.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: gnsscal-1.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.4

File hashes

Hashes for gnsscal-1.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cead16c57576eab35e97f4d5a40eb9fe7feacaddaa68f744455e81ffc0a2ac2a
MD5 201e2f65f199692de31c6a868d8a81ba
BLAKE2b-256 6d32322b3e895d0022120a9bdc9505d1c906ac1671d3687b408bf248b2e5973f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page