def __init__(self, bus_num): self.bus_num = bus_num self.read_interval = READ_INTERVAL self.utc_time = -1 self.utc_date = -1 self.utc = -1 self.position_status = 'invalid' self.mode = 'invalid' self.latitude = -1 self.longitude = -1 self.quality = 'invalid' self.num_satellites = -1 self.horizontal_dilution = -1 self.altitude = -1 self.geoid_undulation = -1 self.speed_over_ground = -1 self.course_over_ground = -1 self.geomag = geomag.GeoMag() self.magnetic_declination = -14.42 #declination at MIT # initialize i2c bus try: self.ZOEM8 = initBus(bus_num) except: print('No i2c device detected on bus{:2d}!'.format(bus_num)) exit(1) print('i2c bus initialized on bus{:2d}.'.format(bus_num))
def run_command(command=None): if command=="go_to_sun": timezone = "UTC" #%z doesn't work so using %Z - UTC, EST, obstime = "2018-11-01 11:00:00"+" "+timezone format = "%Y-%m-%d %H:%M:%S %Z" #Various versions of Python 2.7 have bug with %z, use an updated Python version obstime = datetime.strptime(obstime, format) latitude = -77.2013705 longitude = 39.1434406 current_height= 0 #Elevation in meters result_alt, result_azi = suntr.get_azimuth(obstime, latitude, longitude, current_height) #Get Magnetic Declination (angle devation from True ) path = os.path.dirname(inspect.getfile(geomag)) COF_File= os.path.join(path,"WMM.COF") gm = geomag.GeoMag(COF_File) mag = gm.GeoMag(latitude,longitude) declination = mag.dec # -6.1335150785195536 return "Command was "+command+"\nAzimuth: "+str(result_azi)+" Altitude:"+str(result_alt)+ " Declination:"+str(declination) else: return "Command not found"
def hello(name= None): if request.method == "POST": try: longitude = request.form['longitude'] latitude = request.form['latitude'] start_time = request.form['result-start-time'] end_time = request.form['result-end-time'] interval = request.form['interval'] #return "long: "+str(longitude)+" and lat:"+str(latitude)+" start time:"+str(start_time)+" end_time"+str(end_time)+" inteval:"+str(interval) except: return "Input data was not formatted properly." current_height=0 longitude=float(longitude) latitude=float(latitude) delta=0 start_datetime=datetime.strptime(start_time+" UTC","%Y-%m-%d %H:%M %Z") end_datetime=datetime.strptime(end_time+" UTC","%Y-%m-%d %H:%M %Z") new_datetime = start_datetime +timedelta(0,int(interval)) # days, seconds, then other fields. all_values="" list_of_dates=[] while(new_datetime<end_datetime): new_date=datetime.strftime(new_datetime, "%Y-%m-%d %H:%M:%S") new_datetime=start_datetime+timedelta(0,delta) #increment the time by seconds list_of_dates.append(new_datetime) delta=delta+int(interval) path = os.path.dirname(inspect.getfile(geomag)) COF_File= os.path.join(path,"WMM.COF") gm = geomag.GeoMag(COF_File) total=len(list_of_dates)-1 for index in range(0,len(list_of_dates)): print("At "+str(((index*1.0)/total)*100)+"%") current_date=list_of_dates[index] result_alt, result_azi = suntr.get_azimuth(current_date, latitude, longitude, current_height) #Get magnetic delictionation mag = gm.GeoMag(latitude,longitude) declination = mag.dec # -6.1335150785195536 current_value= str(current_date)+",Altitude:"+str(result_alt)+",Azimuth"+str(result_azi)+",Magnetic Declination:"+str(declination) print str(current_value) all_values=all_values+current_value+"<br>" print("start_time: "+str(start_time)) result = suntr.get_azimuth(start_time, latitude, longitude, current_height) return str(all_values) else: return render_template('grab_data.html', name=name)
def __init__(self): signal.signal(signal.SIGINT, self.exit_signal) self.zmq_context = zmq.Context() self.setup_subscriber() self.mag_declination = -14.42 #declination at MIT #setup flatbuffers self.fb_builder = flatbuffers.Builder(1024) #setup magnetic declination self.geomag = geomag.GeoMag() #setup gps self.latitude = 42.358456 #MIT coordinates self.longitude = -71.087589
def geobmazm_to_magbmazm(rad, bmazm, alt=300., time=None, stay_in_geo=False): """ Convert bmazm from geo to mag by adding the magnetic declanation angle. bmazm : float bmazm of a certain beam in geo. 0 degree shows the geo north direction 180 degree shows the geo south direction alt : float, default to 300. [km] altitude value at which coords. conversions take place. time : datetime.datetime Needed for geo to mlt conversion. Default to None. stay_in_geo : bool if set to True no coords. conversion is done. Calculation would be in geo Return ------ mag_bmazm : float bmazm (in degrees) with respect to the magnetic pole """ from geomag import geomag from datetime import date rad_lat, rad_lon = rad_loc_dict[rad] rad_lon = rad_lon % 360 gm = geomag.GeoMag() if stay_in_geo: new_bmazm = (round(bmazm, 2)) % 360 else: # convert bmazm from geo to mag by adding # the magnetic declanation angle mg = gm.GeoMag(rad_lat, rad_lon, h=alt, time=time) new_bmazm = (round(bmazm - mg.dec, 2)) % 360 return new_bmazm
def geobmazm_to_magazm(rad, bmazm, latc, lonc, alt=300., time=None, stay_in_geo=False): """ calculates the LOS vel direction (in degrees) with respect to mag (or geo) pole for each vector in each range-beam cell. bmazm : float bmazm of a certain beam in geo. 0 degree shows the geo north direction 180 degree shows the geo south direction latc : list center geo latitudes of range-gates cells along a beam. lonc : list center geo longitudes of range-beam cells along a beam. alt : float, default to 300. [km] altitude value at which coords. conversions take place. time : datetime.datetime Needed for geo to mlt conversion. Default to None. stay_in_geo : bool if set to True no coords. conversion is done. Calculation would be in geo Return ------ azm_txt : string LOS vel. azm values (in degrees) at the positions of latc and lonc in mag (or geo) coords. """ from geomag import geomag from datetime import date import numpy as np import json rad_lat, rad_lon = rad_loc_dict[rad] rad_lon = rad_lon % 360 azm_lst = [] gm = geomag.GeoMag() for i in range(len(latc)): # calculate the los vel angle in geo using spherical trigonometry. Then angles are defined # in the same way as those in spherical trigonometry section in mathworld #B = np.deg2rad(np.abs(bmazm)) # catch nan value if np.isnan(latc[i]): azm_lst.append(np.nan) continue b_prime = np.deg2rad(90. - latc[i]) a_prime = np.deg2rad(90. - rad_lat) AB_dellon = np.deg2rad(np.abs(lonc[i] - rad_lon)) c_prime = np.arccos(np.sin(np.deg2rad(rad_lat)) * np.sin(np.deg2rad(latc[i])) +\ np.cos(np.deg2rad(rad_lat)) * np.cos(np.deg2rad(latc[i])) * np.cos(AB_dellon)) s_prime = 1. / 2 * (a_prime + b_prime + c_prime) if round(np.rad2deg(a_prime), 5) == round(np.rad2deg(s_prime), 5): A = np.pi else: A = 2 * np.arcsin(np.sqrt((np.sin(s_prime - b_prime) * np.sin(s_prime - c_prime)) /\ (np.sin(b_prime) * np.sin(c_prime)))) losvel_dir = np.sign(bmazm) * (180 - np.rad2deg(A)) if stay_in_geo: azm_mag = (round(losvel_dir, 2)) % 360 else: # convert losvel_dir from geo to mag by adding # the magnetic declanation angle to the los vel angle in geo mg = gm.GeoMag(latc[i], lonc[i], h=alt, time=time) azm_mag = (round(losvel_dir - mg.dec, 2)) % 360 azm_lst.append(azm_mag) # # convert the list entries to a comma seperated strings # azm_txt =",".join([str(x) for x in azm_lst]) azm_txt = json.dumps(azm_lst) return azm_txt