Orbitron and Pyephem has different output (Lat and Long) - pyephem

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)))

Related

Changing Date Format X-Axis Matplotlib

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,

How to Double Parse A String and Round It to 2 Decimal Places

I want the String values that are added from
List<String> priceStringList
and converted into Doubles to
List<double> doubleList
to only have 2 decimal places.
for (int j = 0; j < priceStringList.length; j++) {
var doubleData = double.parse(priceStringList[j]);
doubleList.add(doubleData);
}
Sample data for doubleList after the for loop include:
[3.429, 3.44, 3.49, 3.41683, 3.35501, 3.02, 3.06, 3.17947,...
But I want the values to only include the first 2 digits after the decimal point. I tried using
var doubleData = Math.Round(double.parse(priceStringList[j]), 2);
but I get an error stating "Undefined name 'Math'".
EDIT I have already added import 'dart:math';
Try this:
double roundDouble(double value, int places){
double mod = pow(10.0, places);
return ((value * mod).round().toDouble() / mod);
}
var doubleData = roundDouble(double.parse(priceStringList[j]), 2);
To call Math you have to import it as Math, for example:
import 'dart:math' as Math;

How to calculate hour to day in NetCDf file using scala

is there a method to convert the unit from hours to days in this dataset ?
double time(time) ;
time:units = "hours since 1800-01-01 00:00:0.0" ;
time:long_name = "Time" ;
time:delta_t = "0000-01-00 00:00:00" ;
time:avg_period = "0000-01-00 00:00:00" ;
time:standard_name = "time" ;
time:axis = "T" ;
time:actual_range = 1569072., 1895592. ;
If you can use Python, it's an easy process:
The first step is to convert the numeric dates to a datetime object using netCDF4 num2date.
The second step is to compute the number of days between each datetime object and the time stamp (or original date) in the time variable (i.e. 1800-01-01).
import netCDF4
import datetime
ncfile = netCDF4.Dataset('./precip.mon.mean.nc', 'r')
time = ncfile.variables['time']
# Convert from numeric times to datetime objects
dates = netCDF4.num2date(time[:], time.units)
# Compute number of days since the original date
orig_date = datetime.datetime(1800,1,1)
days_since = [(t - orig_date).days for t in dates]

How to interpret PyEphem lat/long

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

how can i calculate the difference between two dates from the user input?

This is my code so far:
import datetime
from time import strptime
leapyear = 0
isValid = False
while not isValid:
in_date = input(" Please in put a year in the format dd/mm/yyyy ")
try:
d = strptime(in_date, '%d/%m/%Y')
isValid=True
except:
print ("This is not in the right format")
date = datetime.date.today().strftime("%d/""%m/""%Y")
in_date = in_date.split('/')
date = date.split('/')
in_date = [int(i) for i in in_date]
date = [int(i) for i in date]
date_f = [str(i) for i in date]
date_f = '/'.join(date_f)
in_date_f = [str(i) for i in in_date]
in_date_f = '/'.join(in_date_f)
newdate = []
in_date[0], in_date[2] = in_date[2], in_date[0]
date[0], date[2] = date[2], date[0]
z = "/"
if in_date > date:
newdate.insert((0),(in_date[2] % date[2]))
newdate.insert((1),(in_date[1] % date[1]))
newdate.insert((2),(in_date[0] % date[0]))
print("Current Date:", date_f)
print("you are:", newdate[2],"year(s)",newdate[1],"month(s) and",newdate[0],"days away from:",in_date_f)
else:
print("Please input a date thats higher than todays.")
At the moment i have taken today's date and then taken away that from the user input date which has to be higher than the current date. but this gives the wrong answer because it hasnt taken in the fact of the days in a month the and the months in a year.
how would i go about doing that?
datetime objects are subtractable and comparable, so there is no problem in doing:
userDate = strptime(in_date, '%d/%m/%Y')
if userDate > datetime.datetime.today():
# ...
or
if userDate.date() > datetime.datetime.today().date():
# ....
or to calculate the difference:
diff = userDate - datetime.datetime.today()