Tried using PyEphem sample codes below:
import ephem
import datetime
import math
name = "SPOT 6";
line1 = "1 38755U 12047A 15104.74620640 .00000406 00000-0 96954-4 0 9999";
line2 = "2 38755 98.1581 172.5167 0001084 90.6537 269.4779 14.58589040138138";
spot6 = ephem.readtle(name, line1, line2)
spot6.compute('2015/4/15')
print('\nLat:%s, Long:%s' % (spot6.sublat, spot6.sublong))
Lat:-70:19:25.5, Long:126:16:41.2
How to interpret the above lat/long coordinates? If converted to lat/long in degree decimal, what will it be?
You can convert an angle, whose float value is in radians, to degrees by using the degree symbol in PyEphem:
from ephem import degree
print(spot6.sublat / degree)
print(spot6.sublong / degree)
This will print the decimal equivalents to the degree measurements that PyEphem was printing in arcminutes and arcseconds:
-70.3237369775
126.278121979
Related
I have a plot that I need to change the date format along the x-axis to 'YYYY-mm' format. The plot looks like this:
The code looks like this -
import matplotlib.dates as mdates
import datetime
from matplotlib.dates import DateFormatter
def mean_absolute_percentage_error(y_true, y_pred):
y_true, y_pred = np.array(y_true), np.array(y_pred)
return np.mean(np.abs((y_true - y_pred) / y_true)) * 100
mape = mean_absolute_percentage_error(testarray.monthly_flow, testarray.predicted).round(2) # PRINT MAPE
print(mape)
fpm = (1+mape/100) #'fitted plus mape -- fpm
fmm = (1-mape/100) #'fitted minus mape -- fmm
years = mdates.YearLocator() # every year
months = mdates.MonthLocator() # every month
plus_mape = fitted_series2.multiply(other=fpm)
minus_mape= fitted_series2.multiply(other=fmm)
# Plot WITH MAPE +/-
fig,ax = plt.subplots()
ax.plot(df2.monthly_flow[-24:])
ax.plot(fitted_series2[:12], color='darkgreen')
ax.plot(plus_mape[:12], color='black',linestyle='dotted')
ax.plot(minus_mape[:12], color='black',linestyle='dotted')
ax.fill_between(lower_series.index[:12],
lower_series[:12],
upper_series[:12],
color='k',
alpha=.15)
plt.title("SARIMAX Forecast of Monthly Col River Flow")
plt.show()
date_form = DateFormatter('%YYYY-%mm')
ax.xaxis.set_major_formatter(date_form)
plt.show()
And, despite using the 'major_formatter' with the date format specified, it does nothing as you can see with the above plot. I'm not sure what else to do. Thank you for suggestions,
CLS
REM Declare Varibles
DIM MILES, YARDS, FEET, INCHES AS DOUBLE
DIM KM, METER, TINCH AS DOUBLE
DIM CM, TMETER AS DOUBLE
REM INPUT THE DATA
INPUT "ENTER THE DISTANCE IN MILES", MILES
INPUT "ENTER THE DISTANCE IN YARDS", YARDS
INPUT "ENTER THE DISTANCE IN FEET", FEET
INPUT "ENTER THE DISTANCE IN INCHES", INCHES
REM CONVERT INTO TOTAL INCHES
TINCH = 63360 * MILES + 36 * YARDS + 12 * FEET + INCHES
REM CONVERT INTO TOTAL METER
TMETER = TINCH / 39.37
REM CONVERT TO KILOMETER
KM = INT(TMETER / 1000)
REM CONVERT TO METER
METER = INT(TMETER - KM * 1000)
REM CONVERT TO CENTIMETER
CM = (TMETER - (KM * 1000) - METER) * 100
REM PRINT DETAILS
PRINT "KILOMETER", KM
PRINT "METER", METER
PRINT "CENTIMETER", CM;
Classic QBasic did not have the round function so you need to bring your own.
FUNCTION round# (num AS DOUBLE, dp AS INTEGER)
'WARNING: USE "#" at the end of constant values,
'or else you will get rounding errors:
' "num = .45" >> "num = .449999988079071
' "num = .45#" >> "num = .45"
DIM exp1 AS LONG, num2 AS LONG
exp1 = 10 ^ dp: num2 = num * exp1: round# = num2 / exp1
PRINT num
END FUNCTION
Borrowed this from, qbasicnews.com
If I remember correctly, you can use the PRINT USING statement.
cm_number = 73.53315
PRINT USING "##.##"; cm_number
OUTPUT: 73.53
"#" - represent digits,
"." - represents the decimal point position
Click here for a more detailed explanation.
I am trying to convert some data with the indicated measurements package, but I'm not succeeding on it.
My data:
Long Lat
62ᵒ36.080 58ᵒ52.940
61ᵒ28.020 54ᵒ59.940
62ᵒ07.571 56ᵒ48.873
62ᵒ04.929 57ᵒ33.605
63ᵒ01.419 60ᵒ30.349
63ᵒ09.555 61ᵒ29.199
63ᵒ43.499 61ᵒ23.590
64ᵒ34.175 62ᵒ30.304
63ᵒ16.342 59ᵒ16.437
60ᵒ55.090 54ᵒ49.269
61ᵒ28.013 54ᵒ59.928
62ᵒ07.868 56ᵒ48.040
62ᵒ04.719 57ᵒ32.120
62ᵒ36.083 58ᵒ51.766
63ᵒ01.644 60ᵒ30.714
64ᵒ33.897 62ᵒ30.772
63ᵒ43.604 61ᵒ23.426
63ᵒ09.288 61ᵒ29.888
63ᵒ16.722 59ᵒ16.204
What I'm trying:
library(measurements)
library(readxl)
coord = read.table('coord_converter.txt', header = T, stringsAsFactors = F)
# change the degree symbol to a space
lat = gsub('°','', coord$Lat)
long = gsub('°','', coord$Long)
# convert from decimal minutes to decimal degrees
lat = measurements::conv_unit(lat, from = 'deg_dec_min', to = 'dec_deg')
long = measurements::conv_unit(long, from = 'deg_dec_min', to = 'dec_deg')
What I'm getting with this penultimate line:
Warning messages:
In split(as.numeric(unlist(strsplit(x, " "))) * c(3600, 60), f = rep(1:length(x), : NAs introduced by coercion
In as.numeric(unlist(strsplit(x, " "))) * c(3600, 60) : longer object length is not a multiple of shorter object length
In split.default(as.numeric(unlist(strsplit(x, " "))) * c(3600, : data length is not a multiple of split variable
Can someone point my mistake or make a suggestion of how to proceed?
Thank you!
I think the issue here was that after gsub call, degrees and minutes were not space delimited, as required by measurements::conv_unit.
For example, this works fine (for this reproducible example I also changed "ᵒ" to "°"):
library(measurements)
#read your data
txt <-
"Long Lat
62°36.080 58°52.940
61°28.020 54°59.940
62°07.571 56°48.873
62°04.929 57°33.605
63°01.419 60°30.349
63°09.555 61°29.199
63°43.499 61°23.590
64°34.175 62°30.304
63°16.342 59°16.437
60°55.090 54°49.269
61°28.013 54°59.928
62°07.868 56°48.040
62°04.719 57°32.120
62°36.083 58°51.766
63°01.644 60°30.714
64°33.897 62°30.772
63°43.604 61°23.426
63°09.288 61°29.888
63°16.722 59°16.204"
coord <- read.table(text = foo, header = TRUE, stringsAsFactors = F)
# change the degree symbol to a space
lat = gsub('°',' ', coord$Lat)
long = gsub('°',' ', coord$Long)
# convert from decimal minutes to decimal degrees
lat = measurements::conv_unit(lat, from = 'deg_dec_min', to = 'dec_deg')
long = measurements::conv_unit(long, from = 'deg_dec_min', to = 'dec_deg')
yields...
> cbind(long, lat)
long lat
[1,] "62.6013333333333" "58.8823333333333"
[2,] "61.467" "54.999"
[3,] "62.1261833333333" "56.81455"
[4,] "62.08215" "57.5600833333333"
[5,] "63.02365" "60.5058166666667"
[6,] "63.15925" "61.48665"
[7,] "63.7249833333333" "61.3931666666667"
[8,] "64.5695833333333" "62.5050666666667"
[9,] "63.2723666666667" "59.27395"
[10,] "60.9181666666667" "54.82115"
[11,] "61.4668833333333" "54.9988"
[12,] "62.1311333333333" "56.8006666666667"
[13,] "62.07865" "57.5353333333333"
[14,] "62.6013833333333" "58.8627666666667"
[15,] "63.0274" "60.5119"
[16,] "64.56495" "62.5128666666667"
[17,] "63.7267333333333" "61.3904333333333"
[18,] "63.1548" "61.4981333333333"
[19,] "63.2787" "59.2700666666667"
I tried to use the pyephem library to get the lat, long of a particular satellite. However, when I compare this to what was outputted by Orbitron, the latitude was different. Why is this different?
Output from my code:
Lat: -50.675605
Lon: -153.489527
Orbitron:
Lat : 50.8527ー S
Lon: 153.4899ー W
Here is my code:
import numpy as np
import ephem
import datetime
import functions
from datetime import timedelta, datetime
from math import degrees
name_ = "SATELLITE"
tle1 = "1 41463U 98067HT 16264.56991668 .00008327 00000-0 11928-3 0 9991"
tle2 = "2 41463 51.6441 300.8543 0000382 62.9562 67.6735 15.57105765 22715"
sat = ephem.readtle(name_,tle1,tle2)
strDate = "2016-09-21 10:05:47"
date_obj = datetime.strptime(strDate,'%Y-%m-%d %H:%M:%S')
date_ = date_obj + timedelta(hours=-9)
sat.compute(date_)
print("longitude: %f - latitude: %f" % (degrees(sat.sublong), degrees(sat.sublat)))
Recently, the MPCORB database changed its standard epoch. Then pyephem failed to calculate the position of asteroids.
Take Asteroid 2001 BP25 on 2015-11-23.55 UT as an example. With the old and new standard epochs, I calculated its position as follows:
import ephem
import datetime
tobs = ephem.Date( datetime.datetime(2015, 11, 23, 13, 12, 13) ) # observation time
obj = ephem.readdb( "2001 BP25 0,e,3.47304,134.76688,294.08950,2.4271529,0.26065039,0.2231376,330.92520,06/27.0/2015,2000,H 16.0,0.15" ) # old orbital elements
obj.compute( tobs )
print "With old orbital elements, ra = %.6f deg, dec = %.5f deg" % ( obj.a_ra, obj.a_dec )
obj = ephem.readdb( "2001 BP25 0,e,3.47303,134.76696,294.10956,2.4270882,0.26066081,0.2231111,23.04368,01/12.0/2016,2000,H 16.1,0.15" ) # new orbital elements
obj.compute( tobs )
print "With new orbital elements, ra = %.6f deg, dec = %.5f deg" % ( obj.a_ra, obj.a_dec )
Then I obtained the following output:
With old orbital elements, ra = 1.879871 deg, dec = 0.30927 deg
With new orbital elements, ra = 1.891992 deg, dec = 0.30874 deg
The online IAU MP checker confirmed the coordinates calculated with the old orbital elements.
Therefore, I am wondering: is there some constant in pyephem that should be changed for the new standard epoch?
Happily, this issue was resolved, but I only just realized that the resolution had not been posted back here on Stack Overflow. It turns out that the translation routine that the Asker was using to convert the database into XEphem format was using a constant for the epoch, instead of using the epoch from the original file itself. Fixing the translation also resolved the difference in coordinates — the details were worked out here:
https://github.com/brandon-rhodes/pyephem/issues/89