def main(location_filename, start_date, end_date, time_step, output_path, hide=False): coordinates_krakow = reader.read_location(filename=location_filename) location = EarthLocation(**coordinates_krakow) date = time.compute_time(date_start=start_date, date_end=end_date, time_step=time_step, location=location, only_night=True) moon_position = moon.compute_moon_position(date=date, location=location) moon_phase = moon.compute_moon_phase(date=date) fig_1 = plt.figure() fig_2 = plt.figure() fig_3 = plt.figure() fig_4 = plt.figure() axis_1 = fig_1.add_subplot(111) axis_2 = fig_2.add_subplot(111) axis_3 = fig_3.add_subplot(111, projection='polar') axis_4 = fig_4.add_subplot(111) display.plot_azimuth(date, moon_position.az, axes=axis_1, label='Moon') display.plot_elevation(date, moon_position.alt, axes=axis_2, label='Moon') display.plot_trajectory(moon_position.az, moon_position.alt, axes=axis_3, label='Moon') display.plot_moon_phase(date=date, phase=moon_phase, axes=axis_4, label='Moon') if not hide: plt.show() if output_path is not None: fig_1.savefig(os.path.join(output_path, 'moon_azimuth.png')) fig_2.savefig(os.path.join(output_path, 'moon_elevation.png')) fig_3.savefig(os.path.join(output_path, 'moon_trajectory.png')) fig_4.savefig(os.path.join(output_path, 'moon_phase.png'))
def main(sources_filename, location_filename, environment_filename, start_date, end_date, time_step, output_path, use_moon): sources = reader.read_catalog(sources_filename) coordinates = reader.read_location(filename=location_filename) location = EarthLocation(**coordinates) alt_trees, az_trees = reader.read_environmental_limits( environment_filename) alt_trees = alt_trees * u.deg az_trees = az_trees * u.deg env_limits = interpolate_environmental_limits(alt_trees, az_trees) start_date = Time(start_date) # time should be 00:00 end_date = Time(end_date) # time should be 00:00 date = time.compute_time(date_start=start_date, date_end=end_date, time_step=time_step, location=location, only_night=True) moon_position = moon.compute_moon_position(date=date, location=location) moon_elevation = moon_position.alt moon_phase = moon.compute_moon_phase(date=date) sun_position = sun.compute_sun_position(date=date, location=location) sun_elevation = sun_position.alt observability = compute_observability(sun_elevation, moon_elevation, moon_phase, use_moon=use_moon) source_visibility = np.zeros((len(sources), len(date))) for i, source in tqdm(enumerate(sources), total=len(sources), desc='Source'): temp = gamma_source.compute_source_position(date=date, location=location, ra=source['ra'], dec=source['dec']) source_elevation = temp.alt source_azimuth = temp.az is_above_trees = is_above_environmental_limits(source_elevation, source_azimuth, env_limits) moon_separation = temp.separation(moon_position) temp = is_above_trees * np.sin(source_elevation) temp *= observability * (moon_separation > 10 * u.deg) temp *= source['weight'] source_visibility[i] = temp availability, schedule = find_quality_schedule(source_visibility) filename = os.path.join( output_path, 'schedule_{}_{}.txt'.format(start_date.isot, end_date.isot)) write_schedule(schedule, sources, date, filename)
def main(location_filename, start_date, end_date, time_step, output_path, hide=False): coordinates = reader.read_location(filename=location_filename) location = EarthLocation(**coordinates) start_date = Time(start_date) # time should be 00:00 end_date = Time(end_date) # time should be 00:00 hours = np.arange(0, 1, time_step.to(u.day).value) * u.day hours = hours.to(u.hour) date = time.compute_time(date_start=start_date, date_end=end_date, time_step=time_step, only_night=False) days = date.reshape(-1, len(hours)) days = days.datetime days = date2num(days[:, 0]) extent = [days.min(), days.max(), hours.value.min(), hours.value.max()] moon_position = moon.compute_moon_position(date=date, location=location) moon_elevation = moon_position.alt moon_phase = moon.compute_moon_phase(date=date) sun_position = sun.compute_sun_position(date=date, location=location) sun_elevation = sun_position.alt observability = compute_observability(sun_elevation, moon_elevation, moon_phase) observability = observability.reshape(-1, len(hours)) moon_elevation = moon_elevation.reshape(-1, len(hours)) moon_phase = moon_phase.reshape(-1, len(hours)) sun_elevation = sun_elevation.reshape(-1, len(hours)) fig_1 = plt.figure() axes_1 = fig_1.add_subplot(111) fig_2 = plt.figure() axes_2 = fig_2.add_subplot(111) fig_3 = plt.figure() axes_3 = fig_3.add_subplot(111) fig_4 = plt.figure() axes_4 = fig_4.add_subplot(111) plot_sun_2d(sun_elevation, coordinates, extent=extent, axes=axes_1) plot_source_2d(observability, coordinates, extent=extent, c_label='Observability []', vmin=0, vmax=1, axes=axes_2) plot_source_2d(moon_elevation.value, coordinates, extent=extent, vmin=-90, vmax=90, c_label='Moon elevation [deg]', cmap=plt.get_cmap('RdYlGn_r'), axes=axes_3) plot_source_2d(moon_phase, coordinates, extent=extent, c_label='Moon phase []', vmin=0, vmax=1, cmap=plt.get_cmap('RdYlGn_r'), axes=axes_4) if output_path is not None: fig_1.savefig(os.path.join(output_path, 'sun_elevation.png')) fig_2.savefig(os.path.join(output_path, 'observability.png')) fig_3.savefig(os.path.join(output_path, 'moon_elevation.png')) fig_4.savefig(os.path.join(output_path, 'moon_phase.png')) if not hide: plt.show()
def main(sources_filename, location_filename, environment_filename, start_date, end_date, time_step, output_path, use_moon, hide=False, threshold=0.5): sources = reader.read_catalog(sources_filename) coordinates = reader.read_location(filename=location_filename) location = EarthLocation(**coordinates) alt_trees, az_trees = reader.read_environmental_limits( environment_filename) alt_trees = alt_trees * u.deg az_trees = az_trees * u.deg env_limits = interpolate_environmental_limits(alt_trees, az_trees) date = time.compute_time(date_start=start_date, date_end=end_date, time_step=time_step, location=location, only_night=True) moon_position = moon.compute_moon_position(date=date, location=location) moon_elevation = moon_position.alt moon_phase = moon.compute_moon_phase(date=date) sun_position = sun.compute_sun_position(date=date, location=location) sun_elevation = sun_position.alt observability = compute_observability(sun_elevation, moon_elevation, moon_phase, use_moon=use_moon) fig_1 = plt.figure() axes_1 = fig_1.add_subplot(111) fig_2 = plt.figure() axes_2 = fig_2.add_subplot(111) color = iter(cm.rainbow(np.linspace(0, 1, num=len(sources)))) for i, source in tqdm(enumerate(sources), total=len(sources), desc='Source'): c = next(color) temp = gamma_source.compute_source_position(date=date, location=location, ra=source['ra'], dec=source['dec']) source_elevation = temp.alt source_azimuth = temp.az is_above_trees = is_above_environmental_limits(source_elevation, source_azimuth, env_limits) moon_separation = temp.separation(moon_position) source_visibility = is_above_trees * np.sin(source_elevation) source_visibility *= observability * (moon_separation > 10 * u.deg) source_visibility *= source['weight'] if np.any(source_visibility >= threshold): label = source['name'] plot_elevation(date, source_elevation, axes=axes_1, color=c, label=label) plot_source(date, source_visibility, axes=axes_2, color=c, y_label='visibility []', ylim=[threshold, 1], label=label) lines_1 = axes_1.get_lines() lines_2 = axes_2.get_lines() labelLines(lines_1, fontsize=10, align=True) labelLines(lines_2, fontsize=10, align=True) if output_path is not None: fig_1.savefig(os.path.join(output_path, 'elevation.png')) fig_2.savefig(os.path.join(output_path, 'visibility.png')) if not hide: plt.show()
fig_3.savefig(os.path.join(output_path, 'moon_trajectory.png')) fig_4.savefig(os.path.join(output_path, 'moon_phase.png')) def entry(): kwargs = docopt(__doc__) kwargs = convert_commandline_arguments(kwargs) main(**kwargs) if __name__ == '__main__': location_filename = 'digicamscheduling/config/' + 'location_krakow.txt' coordinates_krakow = reader.read_location(filename=location_filename) location = EarthLocation(**coordinates_krakow) start_date = Time('2018-07-27 12:00') end_date = Time('2018-07-28 12:00') time_steps = 1 * u.min date = time.compute_time(date_start=start_date, date_end=end_date, time_step=time_steps, location=location, only_night=True) moon_position = moon.compute_moon_position(date=date, location=location) moon_phase = moon.compute_moon_phase(date=date) fig_1 = plt.figure() fig_2 = plt.figure() fig_3 = plt.figure() fig_4 = plt.figure()
def main(sources_filename, location_filename, environment_filename, start_date, end_date, time_step, output_path, hide=False): sources = reader.read_catalog(sources_filename) coordinates = reader.read_location(filename=location_filename) location = EarthLocation(**coordinates) alt_trees, az_trees = reader.read_environmental_limits( environment_filename) alt_trees = alt_trees * u.deg az_trees = az_trees * u.deg env_limits = interpolate_environmental_limits(alt_trees, az_trees) start_date = Time(start_date) # time should be 00:00 end_date = Time(end_date) # time should be 00:00 hours = np.arange(0, 1, time_step.to(u.day).value) * u.day hours = hours.to(u.hour) date = time.compute_time(date_start=start_date, date_end=end_date, time_step=time_step, only_night=False) days = date.reshape(-1, len(hours)) days = days.datetime days = date2num(days[:, 0]) extent = [days.min(), days.max(), hours.value.min(), hours.value.max()] moon_position = moon.compute_moon_position(date=date, location=location) moon_elevation = moon_position.alt moon_phase = moon.compute_moon_phase(date=date) sun_position = sun.compute_sun_position(date=date, location=location) sun_elevation = sun_position.alt observability = compute_observability(sun_elevation, moon_elevation, moon_phase, use_moon=True) for i, source in tqdm(enumerate(sources), total=len(sources), desc='Source'): temp = gamma_source.compute_source_position(date=date, location=location, ra=source['ra'], dec=source['dec']) source_elevation = temp.alt source_azimuth = temp.az is_above_trees = environement.is_above_environmental_limits( source_elevation, source_azimuth, env_limits) moon_separation = temp.separation(moon_position) source_visibility = is_above_trees * np.sin(source_elevation) source_visibility *= observability * (moon_separation > 10 * u.deg) source_elevation = source_elevation.reshape(-1, len(hours)) source_visibility = source_visibility.reshape(-1, len(hours)) fig_1 = plt.figure() axes_1 = fig_1.add_subplot(111) fig_2 = plt.figure() axes_2 = fig_2.add_subplot(111) plot_source_2d(source_elevation, coordinates, source=source, extent=extent, axes=axes_1, vmin=-90, vmax=90, c_label='elevation [deg]') plot_source_2d(source_visibility, coordinates, source=source, extent=extent, vmin=0, vmax=1, axes=axes_2, c_label='visibility []') if output_path is not None: filename = os.path.join(output_path, source['name']) fig_1.savefig(filename + '_elevation.png') fig_2.savefig(filename + '_visibility.png') if not hide: plt.show()