Ejemplo n.º 1
0
# morning (civil) twilight
obs.twilight_morning_civil(time_obs)

# morning (astronomical) twilight
obs.twilight_morning_astronomical(time_obs)

# what is the moon illumination?
# returns a float, which is percentage of the moon illuminated
obs.moon_illumination(time_obs)

# what is the moon altitude and azimuth?
obs.moon_altaz(time_obs)

# Other sun-related convenience functions:
obs.noon(time_obs, which='nearest')
obs.midnight(time_obs, which='nearest')

# ==============
# Target objects
# ==============
'''
A target object defines a single observation target, with coordinates
and an optional name.
'''
from astroplan import FixedTarget

# Define a target.

from astropy.coordinates import SkyCoord
t1 = FixedTarget(name='Polaris',
Ejemplo n.º 2
0
def component_compare_daily_all(dataFrame, outliers=None):

    componentName = 'H'
    if dataFrame.empty:
        print('No data is available to plot')
        return

    import pytz
    import datetime
    import matplotlib.dates as mdates
    import helper_astro as astro
    from astroplan import Observer
    from datetime import datetime
    from astropy.time import Time
    import astropy.units as u
    import matplotlib.pyplot as plt

    print('Daily comparison graph is being generated.')

    dayDateTimeObj = dataFrame['Date_Time'][
        0]  # just get one of elements from 'Date_Time' list. Will be used to for certian calculations
    localTZ = dayDateTimeObj.tzinfo
    subaru = Observer(longitude=80.07 * u.deg,
                      latitude=6.97 * u.deg,
                      elevation=0 * u.m,
                      name="Subaru",
                      timezone=localTZ)

    noonTimeUTC = subaru.noon(Time(dayDateTimeObj),
                              which='next').to_datetime(pytz.timezone('UTC'))
    print('Local noon time (utc) : ' +
          noonTimeUTC.strftime('%Y-%m-%d %H:%M:%S %z'))
    noonTimeLocal = subaru.noon(Time(dayDateTimeObj),
                                which='next').to_datetime(localTZ)
    print('Local noon time (local time zone) : ' +
          noonTimeLocal.strftime('%Y-%m-%d %H:%M:%S %z'))
    sunRiseTimeLocal = subaru.sun_rise_time(Time(dayDateTimeObj),
                                            which="next").to_datetime(localTZ)
    sunRiseTimeLocalTwilight = subaru.sun_rise_time(Time(dayDateTimeObj),
                                                    which="next",
                                                    horizon=-6 *
                                                    u.deg).to_datetime(localTZ)
    sunSetTimeLocal = subaru.sun_set_time(Time(dayDateTimeObj),
                                          which='next').to_datetime(localTZ)
    print('Sun rise time (local time zone) : ' +
          sunRiseTimeLocal.strftime('%Y-%m-%d %H:%M:%S %z'))
    print('Sun set time (local time zone) : ' +
          sunSetTimeLocal.strftime('%Y-%m-%d %H:%M:%S %z'))

    fig, ax = plt.subplots()
    ax.plot(dataFrame['Date_Time'],
            dataFrame[componentName],
            label=componentName + ' Comp')
    hours = mdates.HourLocator(interval=1)
    h_fmt = mdates.DateFormatter('%d %H:%M:%S', localTZ)
    ax.xaxis.set_major_locator(hours)
    ax.xaxis.set_major_formatter(h_fmt)

    if outliers is not None:
        y_min, y_max = ax.get_ylim()
        outliers[componentName] = y_min
        kw = dict(marker='o', linestyle='none', color='r', alpha=0.3)
        ax.plot(outliers[componentName],
                label=componentName + '-outlier',
                **kw)

    moon_phase = astro.moon_get_moon_phase(dataFrame['Date_Time'][0])
    t = ax.text(0.03,
                0.9,
                'Lunar phase {:3.0f}%'.format(moon_phase * 100),
                horizontalalignment='left',
                verticalalignment='center',
                transform=ax.transAxes)
    t.set_bbox(dict(facecolor='red', alpha=0.5, edgecolor='red'))

    minValueIndex = dataFrame[componentName].idxmin()
    maxValueIndex = dataFrame[componentName].idxmax()

    print('Max value : ' + str(dataFrame.loc[maxValueIndex][componentName]) +
          ', at : ' + dataFrame.loc[maxValueIndex]['Date_Time'].strftime(
              '%Y-%m-%d %H:%M:%S %z'))
    print('Min value : ' + str(dataFrame.loc[minValueIndex][componentName]) +
          ', at : ' + dataFrame.loc[minValueIndex]['Date_Time'].strftime(
              '%Y-%m-%d %H:%M:%S %z'))

    yAxisMiddle = dataFrame.loc[minValueIndex][componentName] + (
        (dataFrame.loc[maxValueIndex][componentName] -
         dataFrame.loc[minValueIndex][componentName]) / 2)

    noonTimeRow = dataFrame[(dataFrame['Date_Time'] == noonTimeLocal.replace(
        second=0, microsecond=0))]
    print('Noon time value of ' + componentName +
          '-Component {:6.3f}'.format(noonTimeRow[componentName][0]))
    ax.axvline(x=noonTimeRow['Date_Time'][0], ls='--', c='orange')
    ax.text(noonTimeRow['Date_Time'][0],
            yAxisMiddle,
            'Local noon',
            rotation=90,
            ha='left',
            va='center')
    ax.axvline(x=sunRiseTimeLocal, ls='--', c='gray')
    ax.axvline(x=sunRiseTimeLocalTwilight, ls='--', c='gray')
    ax.text(sunRiseTimeLocal,
            dataFrame.loc[minValueIndex][componentName],
            'Sun rise',
            rotation=90,
            ha='left',
            va='bottom')
    ax.axvline(x=sunSetTimeLocal, ls='--', c='gray')
    ax.text(sunSetTimeLocal,
            dataFrame.loc[minValueIndex][componentName],
            'Sun set',
            rotation=90,
            ha='left',
            va='bottom')

    ax.axvline(x=dataFrame.loc[maxValueIndex]['Date_Time'], ls='--', c='green')
    ax.text(dataFrame.loc[maxValueIndex]['Date_Time'],
            yAxisMiddle,
            'Max value',
            rotation=90,
            ha='left',
            va='center')

    plt.xlabel('Time (hours)')
    plt.xticks(rotation=90)
    plt.ylabel(componentName + ' Component (nT)')
    plt.legend()
    plt.show()
    places = pd.DataFrame({'locations': names, 'coordinates': coordinates})
    return places

numDays = 365
oneDay = TimeDelta(1.0,format='jd')
firstDay = Time('2018-01-01 00:00:00',scale='utc')
allDays = [ firstDay + i*oneDay for i in range(numDays) ]

#places = get_places_fromlist(loc_names,loc_coord)
places = get_places(loc_names)

elevations = np.zeros((len(places.locations),len(allDays)))
for ind,(loc,coord) in enumerate(zip(places.locations,places.coordinates)):
    print(f"Computing sun elevations for {loc}")
    observer = Observer(location=coord)
    noons  = [ observer.noon(h,which=u'next') for h in allDays ]
    sunpos = [ observer.sun_altaz(h) for h in noons ]
    elevations[ind,:] = [ az.alt/u.deg for az in sunpos ]


df = pd.DataFrame([d.to_datetime() for d in allDays])
df.columns = [ 'Day' ]
dfelevs = pd.DataFrame(elevations.transpose(),columns=places.locations)
df = df.join(dfelevs).set_index('Day')

dfs = df.stack().reset_index()
dfs.columns = ['day','location','elevation']

p = ggplot(dfs,aes(x='day',y='elevation',color='location')) + geom_line()
p = p + ggtitle('Sun elevations by date and location')
p = p + xlab('Day of year') + ylab('Elevation (degrees)')
Ejemplo n.º 4
0
# morning (civil) twilight
obs.morning_civil(date=time_obs)

# morning (astronomical) twilight
obs.morning_astronomical(date=time_obs)

# what is the moon illumination?
# returns a float, which is percentage of the moon illuminated
obs.moon_illumination(date=time_obs)

# what is the moon altitude and azimuth?
obs.moon_altaz(date=time_obs)

# Other sun-related convenience functions:
obs.noon(date=time_obs, which='nearest')
obs.midnight(date=time_obs, which='nearest')

# ==============
# Target objects
# ==============
'''
A target object defines a single observation target, with coordinates
and an optional name.
'''
from astroplan import FixedTarget, airmass_plot

# Define a target.
t1 = FixedTarget(name='Polaris', ra='02:31:49.09', dec='+89:15:50.8')

# initializing from astropy entities directly