I am writing a Python program to generate some maps in Google Earth, I am using a colleague's script written in Perl and I came to a point where there is this Great Circle call:
#r = great_circle_destination($long, $lat, $bearing, $dist);
What is the equivalent for Python? Is there a module like this:
use Math::Trig ':great_cricle';
I'm pretty sure there's no such thing in the standard library. I'm pretty sure there'd be a python GIS library that have similar functions, but there are many different ways to do this calculation depending on which model of the earth you uses (e.g. spherical earth or ellipsoid earth or something more complex), so you probably would want to check out the source code of the Perl module and translate that to python.
If you want to implement it yourself, you might want to look in this page for a formula for Destination point given distance and bearing from start point: http://www.movable-type.co.uk/scripts/latlong.html
It shouldn't be too difficult to translate that formula to python:
R = ... Radius of earth ...
def great_circle_destination(lon1, lat1, bearing, dist):
lat2 = math.asin( math.sin(lat1)*math.cos(dist/R) +
math.cos(lat1)*math.sin(dist/R)*math.cos(bearing) )
lon2 = lon1 + math.atan2(math.sin(bearing)*math.sin(dist/R)*math.cos(lat1),
math.cos(dist/R)-math.sin(lat1)*math.sin(lat2)
return lon2, lat2
Related
I have a cyclical signal I would like to model. I would like to allow the signal to be able to stretch and compress in time, and I do not know the exact profile.
At the moment, I am modelling the phase progression as a random walk, and capturing the cyclical nature by defining the mean likelihood as a sum of sines and cosines on the phase, where the weights on the cosines are parameters to be fitted.
i.e.
y = N(f(phase),sigma) = N(sum_i(a_i*sin(phase) + b_i*cos(phase)),sigma)
(i.e. latex image of above)
This seems to work to some extent, but I would like to change the definition of f so that it does not rely on sums of sin and cos.
I was looking at Gaussian Processes, and thinking that there could be a solution to this there - but I can't figure out how (if it's possible) to define the y in terms of phase when using GP.
There is an example on the pymc github site:
y_obs = pm.gp.GP('y_obs', cov_func=f_cov, sigma=s2_n, observed={'X':X, 'Y':y})
The problem here is that X is defined as observed, while I need to model it as a random variable.
I tried this form:
y_obs = pm.gp.GP('y_obs', X = phase , cov_func=f_cov, sigma=s2_n, observed={ 'Y':y})
But that leads to an error:
File "/home/person/.conda/envs/mcmcx/lib/python3.6/site-packages/pymc3/distributions/distribution.py", line 56, in __init__
raise TypeError("Expected int elements in shape")
I am new to HB/GP/pymc3... and even stackoverflow. Apologies if the question is off.
I am running a polynomial regression using scikit-learn. I have a large number of variables (23 to be precise) which I am trying to regress using polynomial regression with degree 2.
interaction_only = True, keeps only the interaction terms such as X1*Y1, X2*Y2, and so on.
I want only the other terms i.e, X1, X12, Y1, Y12, and so on.
Is there a function to get this?
There is no such function, because the transormation can be easily expressed with numpy itself.
X = ...
new_X = np.hstack((X, X**2))
and analogously if you want to add everything up to degree k
new_X = np.hstack((X**(i+1) for i in range(k)))
I know this thread is super old. But for folks like me who just getting started can use petsy. Checkout the answer discussed here ->
how to the remove interaction-only columns from sklearn.preprocessing.PolynomialFeatures
I am using the interpolate package from scipy. In the documentation of the splprep function, it says that amongst the return values, there is also the variable "fp" that contains the residuals of the spline fit.
http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.splprep.html
I don't know how to retrieve the fp value because I cannot call the function with more than two return variables.
Here is some sample code I use:
from scipy import interpolate
[tck_poly, u] = interpolate.splprep([[1.,2.,3.,4.,5.]])
Does anybody know how to get this residual or another easy way to determine the fit quality?
Specify full_output=True:
(tck, u), fp, ier, msg = interpolate.splprep([[1.,2.,3.,4.,5.]], full_output=True)
Is there a command in sympy to simplify sinh(x)+cosh(x) to exp(x)? If I issue
from sympy import *
x = Symbol('x')
(sinh(x)+cosh(x)).simplify()
I just get sinh(x)+cosh(x) back, but I want to see exp(x) instead.
Even assuming that the simplify function in sympy was very good, what you suggest may not have worked, because what is "simple" is not rigorously defined.
I think what you want is the functionality present in .rewrite:
In [1]: (sinh(x)+cosh(x)).rewrite(exp)
Out[1]:
x
e
You can use .rewrite for many other transformations including gamma <-> combinatorics and inverse trig <-> logarithms.
I have locations coordinates in the form of latitude, longitude such as: 23⁰ 39' 24.8" N & 58⁰ 11' 36.5" E , see the pic below. But in my work place I use ArcGIS and it seems that doesn't support degree (latitude, longitude) form coordinates. I am planning now to write a C++ code to convert degree form to UTM notation, for example 23⁰ 39' 24.8" N & 58⁰ 11' 36.5E" to 2616726 N & 621702 E. I would like to know how can do such conversion?'
PS: E = East, N= North.
Wikipedia explains how to do this. Google earth can use decimal degree notiation.
Edit: looking at your picture i think you want to convert to UTM? Wikipedia also has this formula.
(note: check Wikipedias formulas with some other source before using)
Adding to rve's answer, you can implement the lat/long -> UTM conversion by following the equations on Wikipedia.
Alternatively, you could download and install an open-source geodesy package such as GeographicLib to do the conversion for you.
A third option is to borrow code directly from GeographicLib or another open-source package, such as this navsat_conversions file. Be sure to give credit to the original author(s) if you do this.