File: examples.rst

package info (click to toggle)
pyhamtools 0.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,012 kB
  • sloc: xml: 307,301; python: 3,493; makefile: 152
file content (80 lines) | stat: -rw-r--r-- 2,494 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

Examples
========

Almost each class / function in the reference section has an example. For the sake of convenience, some examples are shown below to give you a quick understanding how PyHamTools work.

Calculate Shortpath and Longpath Heading between two locators
-------------------------------------------------------------

.. code-block:: none

   >>> from pyhamtools.locator import calculate_heading, calculate_heading_longpath
   >>> calculate_heading("JN48QM", "QF67bf")
   74.3136
   
   >>> calculate_heading_longpath("JN48QM", "QF67bf")
   254.3136


Calculate Distance between two WGS84 Coordinates
------------------------------------------------

.. code-block:: none

   >>> from pyhamtools.locator import calculate_distance, latlong_to_locator
   >>> locator1 = latlong_to_locator(48.52, 9.375)
   >>> locator2 = latlong_to_locator(-32.77, 152.125)
   >>> distance = calculate_distance(locator1, locator2)
   >>> print("%.1fkm" % distance)
   16466.4km
   
Calculate Sunrise and Sunset for JN48QM on the 1. January 2015
--------------------------------------------------------------


.. code-block:: none

   >>> from pyhamtools.locator import calculate_sunrise_sunset
   >>> from datetime import datetime
   >>> my_locator = "JN48QM"
   >>> my_date = datetime(year=2015, month=1, day=1)
   >>> data = calculate_sunrise_sunset(my_locator, my_date)
   >>> print "Sunrise: " + data['sunrise'].strftime("%H:%MZ") + ", Sunset: " + data['sunset'].strftime("%H:%MZ")
   Sunrise: 07:14Z, Sunset: 16:15Z


Decode a Callsign and get Country name, ADIF ID, Latitude & Longitude
---------------------------------------------------------------------

In this example we will use AD1C's Country-files.com database to perform the lookup.

First we need to instantiate a LookupLib object for Country-files.com database. The latest database will be downloaded automatically.

.. code-block:: none

   >>> from pyhamtools import LookupLib, Callinfo
   >>> my_lookuplib = LookupLib(lookuptype="countryfile")
   
   
Next, a Callinfo object needs to be instantiated. The lookuplib object will be injected on construction.

.. code-block:: none

   >>> cic = Callinfo(my_lookuplib)


Now we can query the information conveniently through our Callinfo object:

.. code-block:: none

   >>> cic.get_all("DH1TW")
   {
       'country': 'Fed. Rep. of Germany',
       'adif': 230,
       'continent': 'EU',
       'latitude': 51.0,
       'longitude': 10.0,
       'cqz': 14,
       'ituz': 28
   }