Example #1
0
def find_direction_flux(orbit, orbit_id, find='max', file_flux='flux_', folder='flux'):
	'''Find out the direction in which the flux is the maximum or minimum for a given orbit'''
	import numpy as np
	import TimeStepping as ts
	import parameters as param

	# Prepare the grid just like for the observability maps.
	resx = param.resx
	resy = param.resy

	ra_i = 0
	ra_f = 2.*np.pi

	dec_i = -np.pi/2.
	dec_f = np.pi/2.

	ra_step = (ra_f-ra_i)/resx
	dec_step = (dec_f-dec_i)/resy

	iterable = (ra_i + ra_step/2 + i*ra_step for i in range(resx))
	ras = np.fromiter(iterable, np.float)

	iterable = (dec_i + dec_step/2 + i*dec_step for i in range(resy))
	decs = np.fromiter(iterable, np.float)

	t_ini, t_end, a_ini, a_end = ts.orbit2times(orbit,orbit_id)

	t_ini = np.ceil(t_ini) # not sure it's useful.
	minute = t_ini

	if find == 'max' : sl = 0
	else: sl = 1e9
	
	dd = np.nan
	
	###########################################################################
	# Iterate on every time.
	while (minute <= t_end):
		# initialise the array for the current minute (ie. make sure nothing is left in the table from last time step.

#		value = np.zeros(resx*resy)

		try:
		# Try to load the fluxes for a given minute (minute goes from 0 to period whereas a_ini is the absolute time from 0:0:0.0 1/1/2018 in min
			ra, dec, S_sl = load_flux_file(int(minute+a_ini), file_flux, folder=folder)

		except IOError:
		# If not found it means that the satellite is over the SAA. Skip this step.
			minute +=1
			continue	

		# Maps the data to the full grid.
#		for i, target in enumerate(S_sl):
#			id_ra = find_nearest(ras,ra[i])
#			id_dec = find_nearest(decs,dec[i])
#			value[id_ra, id_dec] = S_sl[i]

		if find == 'max' and np.amax(S_sl) > sl: 
			sl = np.amax(S_sl)
			id_max = find_nearest(S_sl,sl)

			ra_f = ra[id_max]
			dec_f= dec[id_max]
			dd= minute+a_ini

		elif find == 'min' and np.amin(S_sl[np.where(S_sl>0)]) < sl: 
			sl = np.amin(S_sl[np.where(S_sl>0)])
			id_max = find_nearest(S_sl,sl)

			ra_f = ra[id_max]
			dec_f = dec[id_max]
			dd = minute+a_ini

		minute += 1
	return dd, ra_f, dec_f, sl
Example #2
0
def find_direction_flux(orbit,
                        orbit_id,
                        find='max',
                        file_flux='flux_',
                        folder='flux'):
    '''Find out the direction in which the flux is the maximum or minimum for a given orbit'''
    import numpy as np
    import TimeStepping as ts
    import parameters as param

    # Prepare the grid just like for the observability maps.
    resx = param.resx
    resy = param.resy

    ra_i = 0
    ra_f = 2. * np.pi

    dec_i = -np.pi / 2.
    dec_f = np.pi / 2.

    ra_step = (ra_f - ra_i) / resx
    dec_step = (dec_f - dec_i) / resy

    iterable = (ra_i + ra_step / 2 + i * ra_step for i in range(resx))
    ras = np.fromiter(iterable, np.float)

    iterable = (dec_i + dec_step / 2 + i * dec_step for i in range(resy))
    decs = np.fromiter(iterable, np.float)

    t_ini, t_end, a_ini, a_end = ts.orbit2times(orbit, orbit_id)

    t_ini = np.ceil(t_ini)  # not sure it's useful.
    minute = t_ini

    if find == 'max': sl = 0
    else: sl = 1e9

    dd = np.nan

    ###########################################################################
    # Iterate on every time.
    while (minute <= t_end):
        # initialise the array for the current minute (ie. make sure nothing is left in the table from last time step.

        #		value = np.zeros(resx*resy)

        try:
            # Try to load the fluxes for a given minute (minute goes from 0 to period whereas a_ini is the absolute time from 0:0:0.0 1/1/2018 in min
            ra, dec, S_sl = load_flux_file(int(minute + a_ini),
                                           file_flux,
                                           folder=folder)

        except IOError:
            # If not found it means that the satellite is over the SAA. Skip this step.
            minute += 1
            continue

        # Maps the data to the full grid.


#		for i, target in enumerate(S_sl):
#			id_ra = find_nearest(ras,ra[i])
#			id_dec = find_nearest(decs,dec[i])
#			value[id_ra, id_dec] = S_sl[i]

        if find == 'max' and np.amax(S_sl) > sl:
            sl = np.amax(S_sl)
            id_max = find_nearest(S_sl, sl)

            ra_f = ra[id_max]
            dec_f = dec[id_max]
            dd = minute + a_ini

        elif find == 'min' and np.amin(S_sl[np.where(S_sl > 0)]) < sl:
            sl = np.amin(S_sl[np.where(S_sl > 0)])
            id_max = find_nearest(S_sl, sl)

            ra_f = ra[id_max]
            dec_f = dec[id_max]
            dd = minute + a_ini

        minute += 1
    return dd, ra_f, dec_f, sl
Example #3
0
def compare_two_orbits(orbit_ref, orbit_val, orbit_id, p=0.05, file_flux='flux_', folder='flux',shift=0, return_max=False, return_direction=False):
	'''compare_two_orbits returns the maximum difference between them in relative terms. Unit : - (ie. 0.05 means 5%)'''
	import numpy as np
	import TimeStepping as ts
	import parameters as param

	# Prepare the grid just like for the observability maps.
	resx = param.resx
	resy = param.resy

	ra_i = 0
	ra_f = 2.*np.pi

	dec_i = -np.pi/2.
	dec_f = np.pi/2.

	ra_step = (ra_f-ra_i)/resx
	dec_step = (dec_f-dec_i)/resy

	iterable = (ra_i + ra_step/2 + i*ra_step for i in range(resx))
	ras = np.fromiter(iterable, np.float)

	iterable = (dec_i + dec_step/2 + i*dec_step for i in range(resy))
	decs = np.fromiter(iterable, np.float)
	
	t_ini2, t_end2, a_ini2, a_end2 = ts.orbit2times(orbit_ref,orbit_id)
	references=ts.LoadReferences(a_ini2, a_end2,ras,decs,file_flux=file_flux,folder=folder)
	if t_end2 == 99: shift+=1

	t_ini, t_end, a_ini, a_end = ts.orbit2times(orbit_val,orbit_id)
	error_max = 0
	second_chance= False
	count_error  = True

	t_ini = np.ceil(t_ini) # not sure it's useful.
	minute = t_ini

	sl_max = 0

	###########################################################################
	# Iterate on every time.
	while (minute <= t_end):
		# initialise the array for the current minute (ie. make sure nothing is left in the table from last time step.

		value = np.zeros([resx,resy])

		try:		
			ref = references[minute,:,:]
		except IndexError:
			minute = t_end+1
			continue

		try:
		# Try to load the fluxes for a given minute (minute goes from 0 to period whereas a_ini is the absolute time from 0:0:0.0 1/1/2018 in min
			ra, dec, S_sl = load_flux_file(int(minute+a_ini+shift), file_flux, folder=folder)

		except IOError:
		# If not found it means that the satellite is (propably) over the SAA. Skip this step.
			minute +=1
			continue	

		# Maps the data to the full grid.
		for i, target in enumerate(S_sl):
			id_ra = find_nearest(ras,ra[i])
			id_dec = find_nearest(decs,dec[i])
			value[id_ra, id_dec] = S_sl[i]

		if np.amax(value) > sl_max: 
			sl_max = np.amax(value)

		# Mask all targets that are not in each array.
		value[np.where(value-ref==value)] = 0
		ref[np.where(value==0)] = 0

		# Proceed with computation of mag, then their relative difference
		diff = ts.DeltaMagnitude(value,ref)

		# Select all points that are on both arrays and if we output the flags, do it ;)
		tostats = diff[np.where(diff>0)]

		err = np.amax(diff)
		# Verify that no more than number_illegal points are different than p % of the reference
		if (diff[np.where(diff>p)]).shape[0] > 0:
			# Well, that's illegal. Is it a problem of indicies ?
			# We give a second chance to the code :
			if not (second_chance):
				second_chance = True
				minute -= 1
				shift += 1
			else:
				second_chance = False
				count_error = False
				# print the flag i for illegal as we already had a second chance.
				shift -= 1
		else:
			# Do not take into account if there are values > p and their # is less then the number_illegal.
			diff[np.where(diff>p)]=0
			second_chance = False

		# Record the maximum error, but if there is another run, dismiss.
		if error_max < np.amax(diff) and count_error : 
			error_max = err
		del value
		if not count_error : count_error = True
		minute += 1

	###########################################################################
	# Treats the whole orbit

	if return_max: return error_max, sl_max
	else:	return error_max
Example #4
0
def compare_two_orbits(orbit_ref,
                       orbit_val,
                       orbit_id,
                       p=0.05,
                       file_flux='flux_',
                       folder='flux',
                       shift=0,
                       return_max=False,
                       return_direction=False):
    '''compare_two_orbits returns the maximum difference between them in relative terms. Unit : - (ie. 0.05 means 5%)'''
    import numpy as np
    import TimeStepping as ts
    import parameters as param

    # Prepare the grid just like for the observability maps.
    resx = param.resx
    resy = param.resy

    ra_i = 0
    ra_f = 2. * np.pi

    dec_i = -np.pi / 2.
    dec_f = np.pi / 2.

    ra_step = (ra_f - ra_i) / resx
    dec_step = (dec_f - dec_i) / resy

    iterable = (ra_i + ra_step / 2 + i * ra_step for i in range(resx))
    ras = np.fromiter(iterable, np.float)

    iterable = (dec_i + dec_step / 2 + i * dec_step for i in range(resy))
    decs = np.fromiter(iterable, np.float)

    t_ini2, t_end2, a_ini2, a_end2 = ts.orbit2times(orbit_ref, orbit_id)
    references = ts.LoadReferences(a_ini2,
                                   a_end2,
                                   ras,
                                   decs,
                                   file_flux=file_flux,
                                   folder=folder)
    if t_end2 == 99: shift += 1

    t_ini, t_end, a_ini, a_end = ts.orbit2times(orbit_val, orbit_id)
    error_max = 0
    second_chance = False
    count_error = True

    t_ini = np.ceil(t_ini)  # not sure it's useful.
    minute = t_ini

    sl_max = 0

    ###########################################################################
    # Iterate on every time.
    while (minute <= t_end):
        # initialise the array for the current minute (ie. make sure nothing is left in the table from last time step.

        value = np.zeros([resx, resy])

        try:
            ref = references[minute, :, :]
        except IndexError:
            minute = t_end + 1
            continue

        try:
            # Try to load the fluxes for a given minute (minute goes from 0 to period whereas a_ini is the absolute time from 0:0:0.0 1/1/2018 in min
            ra, dec, S_sl = load_flux_file(int(minute + a_ini + shift),
                                           file_flux,
                                           folder=folder)

        except IOError:
            # If not found it means that the satellite is (propably) over the SAA. Skip this step.
            minute += 1
            continue

        # Maps the data to the full grid.
        for i, target in enumerate(S_sl):
            id_ra = find_nearest(ras, ra[i])
            id_dec = find_nearest(decs, dec[i])
            value[id_ra, id_dec] = S_sl[i]

        if np.amax(value) > sl_max:
            sl_max = np.amax(value)

        # Mask all targets that are not in each array.
        value[np.where(value - ref == value)] = 0
        ref[np.where(value == 0)] = 0

        # Proceed with computation of mag, then their relative difference
        diff = ts.DeltaMagnitude(value, ref)

        # Select all points that are on both arrays and if we output the flags, do it ;)
        tostats = diff[np.where(diff > 0)]

        err = np.amax(diff)
        # Verify that no more than number_illegal points are different than p % of the reference
        if (diff[np.where(diff > p)]).shape[0] > 0:
            # Well, that's illegal. Is it a problem of indicies ?
            # We give a second chance to the code :
            if not (second_chance):
                second_chance = True
                minute -= 1
                shift += 1
            else:
                second_chance = False
                count_error = False
                # print the flag i for illegal as we already had a second chance.
                shift -= 1
        else:
            # Do not take into account if there are values > p and their # is less then the number_illegal.
            diff[np.where(diff > p)] = 0
            second_chance = False

        # Record the maximum error, but if there is another run, dismiss.
        if error_max < np.amax(diff) and count_error:
            error_max = err
        del value
        if not count_error: count_error = True
        minute += 1

    ###########################################################################
    # Treats the whole orbit

    if return_max: return error_max, sl_max
    else: return error_max