Beispiel #1
0
    def test_get_predictor_from_lines(self):
        BUGSAT1_TLE_LINES = (
            "1 40014U 14033E   14294.41438078  .00003468  00000-0  34565-3 0  3930",
            "2 40014  97.9781 190.6418 0032692 299.0467  60.7524 14.91878099 18425")

        predictor = sources.get_predictor_from_tle_lines(BUGSAT1_TLE_LINES)
        position = predictor.get_position(datetime.datetime(2019, 1, 1))
        self.assertEqual(position.position_ecef, (-5280.795613274576, -3977.487633239489, -2061.43227648734))
Beispiel #2
0
def get_satellite(index, station_names, satlist):
    line1, line2 = satlist[index]
    TLE_LINES = (line1, line2)
    predictor = get_predictor_from_tle_lines(TLE_LINES)

    lcd.set_cursor(0,0)
    lcd.message("{:<16s}".format(station_names[index]))

    return predictor, station_names[index]
Beispiel #3
0
    def get_predictor(self, for_date=None):
        """
        Build an orbit predictor for the satellite, using its known TLEs.
        """
        assert self.tles.exists()
        if for_date:
            best_tle = self.get_closest_tle(for_date)
        else:
            best_tle = self.tles.order_by('at').last()

        return get_predictor_from_tle_lines(best_tle.lines.split('\n'))
Beispiel #4
0
    def __init__(self, state, parameters, config, timeseries, deployment_days, id):
        """
        Constructs an individual satellite based on defined configuration.
        """
        self.state = state
        self.parameters = parameters
        self.config = config
        self.timeseries = timeseries
        self.deployment_days = deployment_days
        self.satstate = {'id': id}  # Crewstate is unique to this agent
        self.worked_today = False

        ########################--------------This should move to the weather_lookup.py in the future--------------################
        # load pre-defined orbit grids, this is unique for each satellite, a function should be created to automatically calculate
        # grid based on the TLE_file/ the name of satellites
        sg = self.parameters['methods']['satellite']['Satellite_grid']
        wd = self.parameters['working_directory']
        Dataset = nc.Dataset(wd+sg, 'r')
        self.satgrid = Dataset.variables['sat'][:]
        Dataset.close()

        # load cloud cover data
        cloud = self.parameters['methods']['satellite']['CloudCover']
        Dataset = nc.Dataset(wd + cloud, 'r')
        self.cloudcover = Dataset.variables['tcc'][:]
        Dataset.close()

        # build a satellite orbit object
        sat = self.parameters['methods']['satellite']['sat']
        tlefile = self.parameters['methods']['satellite']['TLE_file']
        TLEs = []
        with open(wd+tlefile) as f:
            for line in f:
                TLEs.append(line.rstrip())

        i = 0
        for x in TLEs:
            if x == sat:
                break
            i += 1
        TLE_LINES = (TLEs[i+1], TLEs[i+2])

        self.predictor = get_predictor_from_tle_lines(TLE_LINES)

 ###############################################################################################################################

        return
Beispiel #5
0
def sate_predictors():
    # First tle: The nominal case: LEO orbit sun-sync
    # Second tle: Beta angle with no-eclipse months
    predictors = {
        'nominal_newsat':
        ('1 45018U 20003C   20059.45818850  .00000954  00000-0  38528-4 0  9996',
         '2 45018  97.3318 127.6031 0014006 111.9460 248.3269 15.27107050  6765'
         ),
        'rare_ltan6':
        ('1 37673U 11024A   20058.76186510  .00000058  00000-0  16774-4 0  9995',
         '2 37673  98.0102  67.8905 0000719  69.0278 104.2216 14.72969019468543'
         ),
    }
    return {
        sate_name: get_predictor_from_tle_lines(tle)
        for sate_name, tle in predictors.items()
    }
def distCalculation():
	act = False
	flag = [0]*14
	dists_v = [0]*14
	i = 0
	
	with open('TLE.txt') as TLE:
		predictor = get_predictor_from_tle_lines(TLE)
		result = predictor.get_position(datetime.now())
		pos_ecef = result[1]
		#Rads
		lat, lon, h = ecef_to_llh(pos_ecef)
		#Degrees
		lat = lat*pi/180
		lon = lon*pi/180

		userLat = -22.412
		userLong = -45.46

		d = (sqrt(pow((userLat - lat)*60*1852, 2) + pow(userLong - lon*60*1852, 2))/1000);

		if(d > 20112):
			d = 40024 - d

		real_dist = sqrt(pow(d,2)+pow(h,2))
		if(real_dist < 14000):
			flag[i] = 1
			dists_v[i++] = real_dist
			act = True

	if(act):
		message = "Working....."
		
		password = "******"
		msgFrom = "*****@*****.**"
		msgTo = "*****@*****.**"
	 
		server = smtplib.SMTP('smtp.gmail.com: 587')
		server.starttls()
		 
		server.login(msgFrom, password)
			 
		server.sendmail(msgFrom, msgTo, message)
		server.quit()
Beispiel #7
0
def predict_path(satellite_id, tle, start_date, end_date, step_seconds):
    """
    Predict the positions of a satellite during a period of time, with certain step precision.
    """
    _, line1, line2 = split_tle(tle)
    predictor = get_predictor_from_tle_lines((line1, line2))

    assert start_date < end_date
    step = timedelta(seconds=step_seconds)

    # iterate over time, returning the position at each moment
    current_date = start_date
    while current_date <= end_date:
        # the predictor works with naive dates only
        naive_current_date = ensure_naive(current_date)
        lat, lon, elevation_km = predictor.get_position(naive_current_date).position_llh
        yield Position(lat, lon, elevation_km * 1000,
                       object_id=satellite_id, at_date=current_date)
        current_date += step
Beispiel #8
0
def calc_ground_track(id):
    cred_file = "secret.json"
    setting_file = "settings.json"
    g_credentials, g_settings = initialiaze_app(cred_file, setting_file)
    start_t = datetime.datetime.now()
    tle_lines = get_tle(id, g_credentials)
    print(f"PROCESSING TLE: {tle_lines}", file=sys.stderr)

    predictor = get_predictor_from_tle_lines(tle_lines)

    start_time = datetime.datetime.utcnow()
    n_points = int(request.args.get("n-points") or g_settings["n-points"])
    time_resolution = str(
        request.args.get("time-resolution")
        or g_settings["time-resolution"]) + "S"

    latlon = ""
    if request.args.get("cache") is not None:
        #cached version
        predictor_c = CacheablePredictor(predictor)
        latlon = predict_gt_cacheable(predictor_c, time_resolution, n_points)
    else:
        latlon = predict_gt(predictor, start_time, time_resolution, n_points)

    # DEAD CODE for cartopy
    '''
    fig = FigureWidget()
    ax = plt.axes(projection=ccrs.PlateCarree())
    ax.stock_img()

    plt.plot(latlon["lon"], latlon["lat"], 'k',
            transform=ccrs.Geodetic())

    plt.show(fig)
    print("latitude:",lat,"longitude:",lon)
    '''

    end_t = datetime.datetime.now()
    duration_req = (end_t - start_t).seconds
    print(
        f"SERVING THE REQUEST for {n_points} points and resolution of {time_resolution} took || {duration_req} seconds ||",
        file=sys.stderr)
    return jsonify(latlon.to_dict(orient='split'))
Beispiel #9
0
def predict_passes(satellite_id, tle, target, start_date, end_date, min_tca_elevation=None,
                   min_sun_elevation=None):
    """
    Predict the passes of a satellite over a location on TCA between two dates.
    """
    _, line1, line2 = split_tle(tle)
    predictor = get_predictor_from_tle_lines((line1, line2))
    location = target.as_op_location()

    start_date = ensure_naive(start_date)
    end_date = ensure_naive(end_date)

    # this is done like this, because orbit_predictor interprets max_elevation_gt=None as
    # an angle and explodes
    extra_filters = {}
    if min_tca_elevation is not None:
        extra_filters['max_elevation_gt'] = min_tca_elevation

    passes_iterator = predictor.passes_over(location, start_date, limit_date=end_date,
                                            **extra_filters)

    for pass_ in passes_iterator:
        azimuth_elevation = sun_azimuth_elevation(
            location.latitude_deg, location.longitude_deg, pass_.max_elevation_date,
        )

        if min_sun_elevation is not None and azimuth_elevation.elevation < min_sun_elevation:
            # Sun is too low, skip this pass
            continue

        yield Pass(
            satellite_id=satellite_id,
            target_id=target.object_id,
            aos=make_aware(pass_.aos, timezone=pytz.utc),
            los=make_aware(pass_.los, timezone=pytz.utc),
            tca=make_aware(pass_.max_elevation_date, timezone=pytz.utc),
            tca_elevation=pass_.max_elevation_deg,
            sun_azimuth=azimuth_elevation.azimuth,
            sun_elevation=azimuth_elevation.elevation,
        )
Beispiel #10
0
def _calculate_series(
    location: Location, tle: Sequence[str], aos: datetime, los: datetime,
    time_step: timedelta
) -> Tuple[Sequence[datetime], Sequence[float], Sequence[float]]:
    '''Calculate data for plot diagrams'''
    date_series: List[datetime] = []
    azimuth_series: List[float] = []
    elevation_series: List[float] = []

    location = PredictLocation("server", *location)
    predictor = get_predictor_from_tle_lines(tle)

    date: datetime = aos
    while (date <= los):
        position = predictor.get_position(date)
        az, el = location.get_azimuth_elev_deg(position)

        date_series.append(date)
        azimuth_series.append(az)
        elevation_series.append(el)

        date += time_step

    return date_series, azimuth_series, elevation_series
Beispiel #11
0
 def get_predictor(self):
     self.predictor = get_predictor_from_tle_lines((self.tle_1, self.tle_2))
     return self.predictor
Beispiel #12
0
import pyproj
#import orbit-predictor
from orbit_predictor.sources import EtcTLESource
#from orbit_predictor.locations import brazil
from orbit_predictor.sources import get_predictor_from_tle_lines
import datetime
from datetime import datetime

TLE_LINES = (
    "1 25544U 98067A   20292.96180177  .00000594  00000-0  18740-4 0  9996",
    "2 25544  51.6435  96.0270 0001354  46.8738  91.3465 15.49312758251202")

now = datetime.now()
'''
ano,mes,dia = now.strftime("%Y"),now.strftime("%m"),now.strftime("%d")
h,m,s = now.strftime("%H"),now.strftime("%M"),now.strftime("%S")
'''
predictor = get_predictor_from_tle_lines(TLE_LINES)
pre = predictor.get_position(now)

x = pre[1][0]
y = pre[1][1]
z = pre[1][2]

ecef = pyproj.Proj(proj='geocent', ellps='WGS84', datum='WGS84')
lla = pyproj.Proj(proj='latlong', ellps='WGS84', datum='WGS84')
lon, lat, alt = pyproj.transform(ecef, lla, x, y, z, radians=False)

print(lat, lon, alt)
 def _get_satellite_tle(self):
     request = requests.get(self.satellite_tle_url)
     tle = request.content.decode('utf-8')
     lines = tle.split("\n")
     predictor = get_predictor_from_tle_lines(tuple(lines[1:3]))
     return predictor.get_next_pass(self.location)