Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
makedeclinationtable.py
Go to the documentation of this file.
1#!/usr/bin/env python
2'''Create magnetic declination table from UTM coordinates in degrees
3Requires `pip install docopt numpy utm`
4
5Usage:
6 makedeclinationtable.py <easting> <northing> <zone> <letter>
7
8Arguments:
9 easting UTM Easting of the site
10 northing UTM Northing of the site
11 zone UTM zone
12 letter UTM letter
13'''
14from docopt import docopt
15import requests
16import json
17import utm
18
19#convert date to timestamp (float).
20#Taken from https://stackoverflow.com/questions/8777753/converting-datetime-date-to-utc-timestamp-in-python
21
22#from datetime import datetime, date, timezone
23import datetime
24import calendar
25import sys
26def gettimestamp(year, month, day):
27 d = datetime.date(year, month, day)
28 ts = calendar.timegm(d.timetuple())
29 if sys.version_info < (3,12,0):
30 dt = datetime.datetime.utcfromtimestamp(ts)
31 fts = dt.replace(tzinfo=datetime.timezone.utc).timestamp()
32 else:
33 dt = datetime.datetime.fromtimestamp(ts, datetime.UTC)
34 fts = dt.timestamp()
35 return int(fts)
36
37args = docopt(__doc__, version='0.1')
38easting = args['<easting>']
39northing = args['<northing>']
40zone = args['<zone>']
41letter = args['<letter>']
42latitude, longitude = utm.to_latlon(float(easting), float(northing), int(zone), letter)
43print("#lat long",latitude,longitude)
44
45model = 'IGRF' #data for 1590-2024
46day = 1
47key = 'zNEw7' #access key
48
49for year in range(2000,2030,1):
50 for month in range(1,13,1):
51 request_text = 'https://www.ngdc.noaa.gov/geomag-web/calculators/calculateDeclination?lat1='+str(latitude) + \
52 '&lon1='+str(longitude) + \
53 '&model='+model + \
54 '&startYear='+str(year) + \
55 '&startMonth='+str(month) + \
56 '&startDay='+str(day) + \
57 '&resultFormat=json' + \
58 '&key='+key
59# print(request_text)
60 x = requests.get(request_text)
61# print(x)
62 y = json.loads(x.text)
63 result = y['result'][0]
64 declination = result['declination']
65 print("(*this)[", gettimestamp(year,month, day), "] = ", declination, ";")
66
void print(const TH1 &h1, std::ostream &out)
Print histogram parameters.
gettimestamp(year, month, day)