Trees | Indices | Help |
|
---|
|
|
|||
FileFormatError Error object for data parsing error |
|
|||
list
|
|
||
float
|
|
||
Implementation utilities | |||
---|---|---|---|
str
|
|
||
|
|||
list
|
|
||
csv.DictReader
|
|
||
ET.ElementTree
|
|
||
Angle conversion utilities | |||
tuple of int objects for values
|
|
||
float
|
|
||
tuple
|
|
||
str
|
|
||
Coordinate conversion utilities | |||
tuple
|
|
||
str
|
|
||
float
|
|
||
float
|
|
||
tuple of float objects
|
|
||
str
|
|
||
tuple of float objects
|
|
||
Solar event utilities | |||
datetime.time or None
|
|
||
tuple of datetime.time
|
|
|
|||
__bug_report__ =
Address for use in messages |
|||
BODIES =
Body radii of various solar system objects |
|||
BODY_RADIUS = 6367 Default body radius to use for calculations |
|||
NAUTICAL_MILE = 1.852 Number of kilometres per nautical mile |
|||
STATUTE_MILE = 1.609 Number of kilometres per statute mile |
|||
LONGITUDE_FIELD = 20 Longitude field 1 multiplier |
|||
LATITUDE_FIELD = 10 Latitude field 1 multiplier |
|||
LONGITUDE_SQUARE = 2.0 Longitude field 2 multiplier |
|||
LATITUDE_SQUARE = 1.0 Latitude field 2 multiplier |
|||
LONGITUDE_SUBSQUARE = 0.0833333333333 Longitude field 3 multiplier |
|||
LATITUDE_SUBSQUARE = 0.0416666666667 Latitude field 3 multiplier |
|||
LONGITUDE_EXTSQUARE = 0.00833333333333 Longitude field 4 multiplier |
|||
LATITUDE_EXTSQUARE = 0.00416666666667 Latitude field 4 multiplier |
|||
Angle conversion utilities | |||
---|---|---|---|
COMPASS_NAMES =
|
|||
Solar event utilities | |||
ZENITH =
Sunrise/-set mappings from name to angle |
|
Return an empty string for display when value is >>> value_or_empty(None) '' >>> value_or_empty("test") 'test'
|
__repr__ methods
|
Prepare various input types for parsing >>> prepare_read(open("real_file")) ['This is a test file-type object\n'] >>> test_list = ['This is a test list-type object', 'with two elements'] >>> prepare_read(test_list) ['This is a test list-type object', 'with two elements']
|
Prepare various input types for CSV parsing >>> list(prepare_csv_read(open("real_file.csv"), ... ("type", "bool", "string"))) [{'bool': 'true', 'type': 'file', 'string': 'test'}] >>> test_list = ['James,Rowe', 'ell,caro'] >>> list(prepare_csv_read(test_list, ("first", "last"))) [{'last': 'Rowe', 'first': 'James'}, {'last': 'caro', 'first': 'ell'}]
|
Prepare various input types for XML parsing >>> prepare_xml_read(open("real_file.xml")).find("tag").text 'This is a test file-type object' >>> test_list = ['<xml>', '<tag>This is a test list</tag>', '</xml>'] >>> prepare_xml_read(test_list).find("tag").text 'This is a test list'
|
Convert decimal angle to degrees, minutes and possibly seconds >>> to_dms(52.015) (52, 0, 54.0) >>> to_dms(-0.221) (0, -13, -15.600000000000023) >>> to_dms(-0.221, style="dm") (0, -13.26) >>> to_dms(-0.221, style=None) Traceback (most recent call last): ... ValueError: Unknown style type `None'
|
Convert degrees, minutes and optionally seconds to decimal angle >>> "%.3f" % to_dd(52, 0, 54) '52.015' >>> "%.3f" % to_dd(0, -13, -15) '-0.221' >>> "%.3f" % to_dd(0, -13.25) '-0.221'
|
|
Convert angle in to direction name >>> angle_to_name(0) 'North' >>> angle_to_name(360) 'North' >>> angle_to_name(45) 'North-east' >>> angle_to_name(292) 'West' >>> angle_to_name(293) 'North-west' >>> angle_to_name(0, 4) 'North' >>> angle_to_name(360, 16) 'North' >>> angle_to_name(45, 4, True) 'NE' >>> angle_to_name(292, 16, True) 'WNW'
|
Parse ISO 6709 coordinate strings This function will parse ISO 6709-1983(E) "Standard representation of latitude, longitude and altitude for geographic point locations" elements. Unfortunately, the standard is rather convoluted and this implementation is incomplete, but it does support most of the common formats in the wild. The W3C has a simplified profile for ISO 6709 in Latitude, Longitude and Altitude format for geospatial information. It unfortunately hasn't received widespread support as yet, but hopefully it will grow just as the simplified ISO 8601 profile has. The following tests are from the examples contained in the wikipedia ISO 6709 page. >>> from_iso6709("+00-025/") # Atlantic Ocean (0.0, -25.0, None) >>> from_iso6709("+46+002/") # France (46.0, 2.0, None) >>> from_iso6709("+4852+00220/") # Paris (48.866666666666667, 2.3333333333333335, None) >>> from_iso6709("+48.8577+002.295/") # Eiffel Tower (48.857700000000001, 2.2949999999999999, None) >>> from_iso6709("+27.5916+086.5640+8850/") # Mount Everest (27.5916, 86.563999999999993, 8850.0) >>> from_iso6709("+90+000/") # North Pole (90.0, 0.0, None) >>> from_iso6709("+00-160/") # Pacific Ocean (0.0, -160.0, None) >>> from_iso6709("-90+000+2800/") # South Pole (-90.0, 0.0, 2800.0) >>> from_iso6709("+38-097/") # United States (38.0, -97.0, None) >>> from_iso6709("+40.75-074.00/") # New York City (40.75, -74.0, None) >>> from_iso6709("+40.6894-074.0447/") # Statue of Liberty (40.689399999999999, -74.044700000000006, None) The following tests are from the Latitude, Longitude and Altitude format for geospatial information page. >>> from_iso6709("+27.5916+086.5640+8850/") # Mount Everest (27.5916, 86.563999999999993, 8850.0) >>> from_iso6709("-90+000+2800/") # South Pole (-90.0, 0.0, 2800.0) >>> from_iso6709("+40.75-074.00/") # New York City (40.75, -74.0, None) >>> from_iso6709("+352139+1384339+3776/") # Mount Fuji (35.360833333333332, 138.72749999999999, 3776.0) >>> from_iso6709("+35.658632+139.745411/") # Tokyo Tower (35.658631999999997, 139.74541099999999, None) >>> from_iso6709("+35.658632+1/") # Broken Traceback (most recent call last): ... ValueError: Incorrect format for longitude `+1'
See Also: to_iso6709 |
Produce ISO 6709 coordinate strings This function will produce ISO 6709-1983(E) "Standard representation of latitude, longitude and altitude for geographic point locations" elements. The following tests are from the examples contained in the wikipedia ISO 6709 page. >>> to_iso6709(0.0, -25.0, None, "d") # Atlantic Ocean '+00-025/' >>> to_iso6709(46.0, 2.0, None, "d") # France '+46+002/' >>> to_iso6709(48.866666666666667, 2.3333333333333335, None, "dm") # Paris '+4852+00220/' >>> # The following test is skipped, because the example from wikipedia uses >>> # differing precision widths for latitude and longitude. Also, that >>> # degree of formatting flexibility is not seen anywhere else and adds >>> # very little. >>> to_iso6709(48.857700000000001, 2.2949999999999999, None) # Eiffel Tower # doctest: +SKIP '+48.8577+002.295/' >>> to_iso6709(27.5916, 86.563999999999993, 8850.0) # Mount Everest '+27.5916+086.5640+8850/' >>> to_iso6709(90.0, 0.0, None, "d") # North Pole '+90+000/' >>> to_iso6709(0.0, -160.0, None, "d") # Pacific Ocean '+00-160/' >>> to_iso6709(-90.0, 0.0, 2800.0, "d") # South Pole '-90+000+2800/' >>> to_iso6709(38.0, -97.0, None, "d") # United States '+38-097/' >>> to_iso6709(40.75, -74.0, None, precision=2) # New York City '+40.75-074.00/' >>> to_iso6709(40.689399999999999, -74.044700000000006, None) # Statue of Liberty '+40.6894-074.0447/' The following tests are from the Latitude, Longitude and Altitude format for geospatial information page. >>> to_iso6709(27.5916, 86.563999999999993, 8850.0) # Mount Everest '+27.5916+086.5640+8850/' >>> to_iso6709(-90.0, 0.0, 2800.0, "d") # South Pole '-90+000+2800/' >>> to_iso6709(40.75, -74.0, None, precision=2) # New York City '+40.75-074.00/' >>> to_iso6709(35.360833333333332, 138.72749999999999, 3776.0, "dms") # Mount Fuji '+352139+1384339+3776/' >>> to_iso6709(35.658631999999997, 139.74541099999999, None, precision=6) # Tokyo Tower '+35.658632+139.745411/'
See Also: from_iso6709 |
Convert angle in to distance along a great circle >>> "%.3f" % angle_to_distance(1) '111.125' >>> "%i" % angle_to_distance(360, "imperial") '24863' >>> "%i" % angle_to_distance(1.0/60, "nautical") '1' >>> "%i" % angle_to_distance(10, "baseless") Traceback (most recent call last): ... ValueError: Unknown units type `baseless'
|
Convert a distance in to an angle along a great circle >>> "%.3f" % round(distance_to_angle(111.212)) '1.000' >>> "%i" % round(distance_to_angle(24882, "imperial")) '360' >>> "%i" % round(distance_to_angle(60, "nautical")) '1'
|
Calculate geodesic latitude/longitude from Maidenhead locator >>> "%.3f, %.3f" % from_grid_locator("BL11bh16") '21.319, -157.904' >>> "%.3f, %.3f" % from_grid_locator("IO92va") '52.021, -0.208' >>> "%.3f, %.3f" % from_grid_locator("IO92") '52.021, -1.958'
|
Calculate Maidenhead locator from latitude and longitude >>> to_grid_locator(21.319, -157.904, "extsquare") 'BL11bh16' >>> to_grid_locator(52.021, -0.208, "subsquare") 'IO92va' >>> to_grid_locator(52.021, -1.958) 'IO92'
|
Parse latitude and longitude from string location >>> "%.3f;%.3f" % parse_location("52.015;-0.221") '52.015;-0.221' >>> "%.3f;%.3f" % parse_location("52.015,-0.221") '52.015;-0.221' >>> "%.3f;%.3f" % parse_location("52.015 -0.221") '52.015;-0.221' >>> "%.3f;%.3f" % parse_location("52.015N 0.221W") '52.015;-0.221' >>> "%.3f;%.3f" % parse_location("52.015 N 0.221 W") '52.015;-0.221' >>> "%.3f;%.3f" % parse_location("52d00m54s N 0d13m15s W") '52.015;-0.221' >>> "%.3f;%.3f" % parse_location("52d0m54s N 000d13m15s W") '52.015;-0.221' >>> "%.3f;%.3f" % parse_location('''52d0'54" N 000d13'15" W''') '52.015;-0.221'
|
Calculate sunrise or sunset for a specific location This function calculates the time sunrise or sunset, or optionally the beginning or end of a specified twilight period. Source: Almanac for Computers, 1990 published by Nautical Almanac Office United States Naval Observatory Washington, DC 20392 >>> sun_rise_set(52.015, -0.221, datetime.date(2007, 6, 15)) datetime.time(3, 40) >>> sun_rise_set(52.015, -0.221, datetime.date(2007, 6, 15), "set") datetime.time(20, 23) >>> sun_rise_set(52.015, -0.221, datetime.date(2007, 6, 15), timezone=60) datetime.time(4, 40) >>> sun_rise_set(52.015, -0.221, datetime.date(2007, 6, 15), "set", 60) datetime.time(21, 23) >>> sun_rise_set(52.015, -0.221, datetime.date(1993, 12, 11)) datetime.time(7, 58) >>> sun_rise_set(52.015, -0.221, datetime.date(1993, 12, 11), "set") datetime.time(15, 50) >>> sun_rise_set(89, 0, datetime.date(2007, 12, 21)) >>> sun_rise_set(52.015, -0.221, datetime.date(2007, 2, 21)) datetime.time(7, 4) >>> sun_rise_set(52.015, -0.221, datetime.date(2007, 1, 21)) datetime.time(7, 56)
|
Convenience function for calculating sunrise and sunset >>> sun_events(52.015, -0.221, datetime.date(2007, 6, 15)) (datetime.time(3, 40), datetime.time(20, 23)) >>> sun_events(52.015, -0.221, datetime.date(2007, 6, 15), 60) (datetime.time(4, 40), datetime.time(21, 23)) >>> sun_events(52.015, -0.221, datetime.date(1993, 12, 11)) (datetime.time(7, 58), datetime.time(15, 50)) >>> sun_events(52.015, -0.221, datetime.date(2007, 6, 15)) (datetime.time(3, 40), datetime.time(20, 23)) >>> sun_events(40.638611, -73.762222, datetime.date(2007, 6, 15)) # JFK (datetime.time(9, 23), datetime.time(0, 27)) >>> sun_events(49.016666, -2.5333333, datetime.date(2007, 6, 15)) # CDG (datetime.time(4, 5), datetime.time(20, 16)) >>> sun_events(35.549999, 139.78333333, datetime.date(2007, 6, 15)) # TIA (datetime.time(19, 25), datetime.time(9, 58)) Civil twilight starts/ends when the Sun's center is 6 degrees below the horizon. >>> sun_events(52.015, -0.221, datetime.date(2007, 6, 15), zenith="civil") (datetime.time(2, 51), datetime.time(21, 12)) >>> sun_events(40.638611, -73.762222, datetime.date(2007, 6, 15), ... zenith="civil") # JFK (datetime.time(8, 50), datetime.time(1, 0)) >>> sun_events(49.016666, -2.5333333, datetime.date(2007, 6, 15), ... zenith="civil") # CDG (datetime.time(3, 22), datetime.time(20, 59)) >>> sun_events(35.549999, 139.78333333, datetime.date(2007, 6, 15), ... zenith="civil") # TIA (datetime.time(18, 55), datetime.time(10, 28)) Nautical twilight starts/ends when the Sun's center is 12 degrees below the horizon. >>> sun_events(52.015, -0.221, datetime.date(2007, 6, 15), ... zenith="nautical") (datetime.time(1, 32), datetime.time(22, 31)) >>> sun_events(40.638611, -73.762222, datetime.date(2007, 6, 15), ... zenith="nautical") # JFK (datetime.time(8, 7), datetime.time(1, 44)) >>> sun_events(49.016666, -2.5333333, datetime.date(2007, 6, 15), ... zenith="nautical") # CDG (datetime.time(2, 20), datetime.time(22, 1)) >>> sun_events(35.549999, 139.78333333, datetime.date(2007, 6, 15), ... zenith="nautical") # TIA (datetime.time(18, 18), datetime.time(11, 6)) Astronomical twilight starts/ends when the Sun's centre is 18 degrees below the horizon. >>> sun_events(52.015, -0.221, datetime.date(2007, 6, 15), ... zenith="astronomical") (None, None) >>> sun_events(40.638611, -73.762222, datetime.date(2007, 6, 15), ... zenith="astronomical") # JFK (datetime.time(7, 14), datetime.time(2, 36)) >>> sun_events(49.016666, -2.5333333, datetime.date(2007, 6, 15), ... zenith="astronomical") # CDG (None, None) >>> sun_events(35.549999, 139.78333333, datetime.date(2007, 6, 15), ... zenith="astronomical") # TIA (datetime.time(17, 35), datetime.time(11, 49))
|
Generate an Xearth compatible marker file dump_xearth_markers() writes a simple Xearth marker file from a dictionary of trigpoints.Trigpoint objects. It expects a dictionary in one of the following formats. For support of Trigpoint that is: {500936: Trigpoint(52.066035, -0.281449, 37.0, "Broom Farm"), 501097: Trigpoint(52.010585, -0.173443, 97.0, "Bygrave"), 505392: Trigpoint(51.910886, -0.186462, 136.0, "Sish Lane")} And generates output of the form: 52.066035 -0.281449 "500936" # Broom Farm, alt 37m 52.010585 -0.173443 "501097" # Bygrave, alt 97m 51.910886 -0.186462 "205392" # Sish Lane, alt 136m Or similar to the following if the 52.066035 -0.281449 "Broom Farm" # 500936 alt 37m 52.010585 -0.173443 "Bygrave" # 501097 alt 97m 51.910886 -0.186462 "Sish Lane" # 205392 alt 136m Point objects should be provided in the following format: {"Broom Farm": Point(52.066035, -0.281449), "Bygrave": Point(52.010585, -0.173443), "Sish Lane": Point(51.910886, -0.186462)} And generates output of the form: 52.066035 -0.281449 "Broom Farm" 52.010585 -0.173443 "Bygrave" 51.910886 -0.186462 "Sish Lane" >>> from upoints.trigpoints import Trigpoint >>> markers = { ... 500936: Trigpoint(52.066035, -0.281449, 37.000000, "Broom Farm"), ... 501097: Trigpoint(52.010585, -0.173443, 97.000000, "Bygrave"), ... 505392: Trigpoint(51.910886, -0.186462, 136.000000, "Sish Lane") ... } >>> print("\n".join(dump_xearth_markers(markers))) 52.066035 -0.281449 "500936" # Broom Farm, alt 37m 52.010585 -0.173443 "501097" # Bygrave, alt 97m 51.910886 -0.186462 "505392" # Sish Lane, alt 136m >>> print("\n".join(dump_xearth_markers(markers, "name"))) 52.066035 -0.281449 "Broom Farm" # 500936, alt 37m 52.010585 -0.173443 "Bygrave" # 501097, alt 97m 51.910886 -0.186462 "Sish Lane" # 505392, alt 136m >>> print("\n".join(dump_xearth_markers(markers, "falseKey"))) Traceback (most recent call last): ... ValueError: Unknown name type `falseKey' >>> from upoints.point import Point >>> points = { ... "Broom Farm": Point(52.066035, -0.281449), ... "Bygrave": Point(52.010585, -0.173443), ... "Sish Lane": Point(51.910886, -0.186462) ... } >>> print("\n".join(dump_xearth_markers(points))) 52.066035 -0.281449 "Broom Farm" 52.010585 -0.173443 "Bygrave" 51.910886 -0.186462 "Sish Lane"
Note: xplanet also supports xearth marker files, and as such can use the output from this function. See Also: upoints.xearth.Xearths.import_locations |
Calculate earth radius for a given latitude This function is most useful when dealing with datasets that are very localised and require the accuracy of an ellipsoid model without the complexity of code necessary to actually use one. The results are meant to be used as a BODY_RADIUS replacement when the simple geocentric value is not good enough. The original use for calc_radius is to set a more accurate radius value for use with trigpointing databases that are keyed on the OSGB36 datum, but it has been expanded to cover other ellipsoids. >>> calc_radius(52.015) 6375.1660253118571 >>> calc_radius(0) 6335.4387009096872 >>> calc_radius(90) 6399.5939421215426 >>> calc_radius(52.015, "FAI sphere") 6371.0 >>> calc_radius(0, "Airy (1830)") 6335.0221785420217 >>> calc_radius(90, "International") 6399.9365538714392
|
|
BODIESBody radii of various solar system objects
|
COMPASS_NAMES
|
ZENITHSunrise/-set mappings from name to angle
|
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue May 20 12:41:05 2008 | http://epydoc.sourceforge.net |