Example #1
0
def daynight_terminator(date, lons):
    """ Return the coordinates of day/night terminator for RTI plotting.

    Parameters
    ----------
    date : datetime.datetime
        a datetime.datetime object (assumed UTC)
    lons : list
        a numpy array of lons

    Returns
    -------
    lat
        the latitude of the day night terminator
    tau
        grenwich hour angle
    dec
        solar declination

    """
    import mpl_toolkits.basemap.solar as solar
    dg2rad = np.pi / 180.
    # compute greenwich hour angle and solar declination
    # from datetime object (assumed UTC).
    tau, dec = solar.epem(date)
    # compute day/night terminator from hour angle, declination.
    longitude = lons + tau
    lats = np.arctan(-np.cos(longitude * dg2rad) /
                     np.tan(dec * dg2rad)) / dg2rad
    return lats, tau, dec
Example #2
0
def daynight_terminator(date, lons):
    """ Return the coordinates of day/night terminator for RTI plotting.

    Parameters
    ----------
    date : datetime.datetime
        a datetime.datetime object (assumed UTC)
    lons : list
        a numpy array of lons

    Returns
    -------
    lat
        the latitude of the day night terminator
    tau
        grenwich hour angle
    dec
        solar declination

    """
    import mpl_toolkits.basemap.solar as solar
    import numpy as np

    dg2rad = np.pi / 180.
    # compute greenwich hour angle and solar declination
    # from datetime object (assumed UTC).
    tau, dec = solar.epem(date)
    # compute day/night terminator from hour angle, declination.
    longitude = lons + tau
    lats = np.arctan(
        -np.cos(longitude * dg2rad) / np.tan(dec * dg2rad)) / dg2rad
    return lats, tau, dec
Example #3
0
 def daynight_terminator(date, lons):
     """
     date is datetime object (assumed UTC).
     """
     import mpl_toolkits.basemap.solar as solar
     dg2rad = np.pi/180.
     # compute greenwich hour angle and solar declination
     # from datetime object (assumed UTC).
     tau, dec = solar.epem(date)
     # compute day/night terminator from hour angle, declination.
     longitude = lons + tau
     lats = np.arctan(-np.cos(longitude*dg2rad)/np.tan(dec*dg2rad))/dg2rad
     return lats,tau,dec
Example #4
0
 def daynight_terminator(date, lons):
     """
 date is datetime object (assumed UTC).
 """
     import mpl_toolkits.basemap.solar as solar
     dg2rad = np.pi / 180.
     # compute greenwich hour angle and solar declination
     # from datetime object (assumed UTC).
     tau, dec = solar.epem(date)
     # compute day/night terminator from hour angle, declination.
     longitude = lons + tau
     lats = np.arctan(-np.cos(longitude * dg2rad) /
                      np.tan(dec * dg2rad)) / dg2rad
     return lats, tau, dec
def daynight_terminator(date, lons):
    """Calculates the latitude, Greenwich Hour Angle, and solar declination from a given latitude and longitude.

    This routine is used by musicRTI for terminator calculations.

    **Args**:
        * **date** (datetime.datetime): UT date and time of terminator calculation.
        * **lons** (np.array): Longitudes of which to calculate the terminator.
    **Returns**:
        * **lats** (np.array): Latitudes of solar terminator.
        * **tau** (np.array): Greenwhich Hour Angle.
        * **dec** (np.array): Solar declination.

    Adapted from mpl_toolkits.basemap.solar by Nathaniel A. Frissell, Fall 2013
    """
    import mpl_toolkits.basemap.solar as solar
    dg2rad = np.pi/180.
    # compute greenwich hour angle and solar declination
    # from datetime object (assumed UTC).
    tau, dec = solar.epem(date)
    # compute day/night terminator from hour angle, declination.
    longitude = lons + tau
    lats = np.arctan(-np.cos(longitude*dg2rad)/np.tan(dec*dg2rad))/dg2rad
    return lats,tau,dec
Example #6
0
def daynight_terminator(date, lons):
    """ Return the coordinates of day/night terminator for RTI plotting.

    **Args**:
        * **date**: a datetime.datetime object (assumed UTC)
        * **lons**: a numpy array of lons

    **Returns**:
        *lat, the latitude of the day night terminator
        *tau, grenwich hour angle
        *dec, solar declination

    """

    import mpl_toolkits.basemap.solar as solar
    dg2rad = np.pi / 180.
    # compute greenwich hour angle and solar declination
    # from datetime object (assumed UTC).
    tau, dec = solar.epem(date)
    # compute day/night terminator from hour angle, declination.
    longitude = lons + tau
    lats = np.arctan(-np.cos(longitude * dg2rad) /
           np.tan(dec * dg2rad)) / dg2rad
    return lats, tau, dec
Example #7
0
    def __init__(self,
                 sTime,
                 eTime,
                 gme_param,
                 oversamp_T=datetime.timedelta(minutes=1),
                 plot_info=None,
                 comment=None,
                 parent=None):

        # Save the input plot_info to override default data later.
        _plot_info = plot_info
        plot_info = {}
        plot_info['sTime'] = sTime
        plot_info['eTime'] = eTime

        if 'omni' in gme_param:
            ind_class = gme.ind.readOmni(sTime, eTime, res=1)
            omni_list = []
            omni_time = []
            for xx in ind_class:
                tmp = {}

                #                tmp['res']          = xx.res
                #                tmp['timeshift']    = xx.timeshift
                #                tmp['al']           = xx.al
                #                tmp['au']           = xx.au
                #                tmp['asyd']         = xx.asyd
                #                tmp['asyh']         = xx.asyh
                #                tmp['symd']         = xx.symd
                #                tmp['beta']         = xx.beta
                #                tmp['bye']          = xx.bye
                #                tmp['bze']          = xx.bze
                #                tmp['e']            = xx.e
                #                tmp['flowSpeed']    = xx.flowSpeed
                #                tmp['vxe']          = xx.vxe
                #                tmp['vye']          = xx.vye
                #                tmp['vzy']          = xx.vzy
                #                tmp['machNum']      = xx.machNum
                #                tmp['np']           = xx.np
                #                tmp['temp']         = xx.temp
                #                tmp['time']         = xx.time

                tmp['ae'] = xx.ae
                tmp['bMagAvg'] = xx.bMagAvg
                tmp['bx'] = xx.bx
                tmp['bym'] = xx.bym
                tmp['bzm'] = xx.bzm
                tmp['pDyn'] = xx.pDyn
                tmp['symh'] = xx.symh
                tmp['flowSpeed'] = xx.flowSpeed
                tmp['np'] = xx.np
                tmp['temp'] = xx.temp

                omni_time.append(xx.time)
                omni_list.append(tmp)

            omni_df_raw = pd.DataFrame(omni_list, index=omni_time)
            del omni_time
            del omni_list

            self.omni_df_raw = omni_df_raw
            self.omni_df = omni_df_raw.resample('T')
            self.omni_df = self.omni_df.interpolate()

        plot_info['x_label'] = 'Date [UT]'
        if gme_param == 'ae':
            # Read data with DavitPy routine and place into numpy arrays.
            ind_class = gme.ind.readAe(sTime, eTime, res=1)
            ind_data = [(x.time, x.ae) for x in ind_class]

            df_raw = pd.DataFrame(ind_data, columns=['time', 'raw'])
            df_raw = df_raw.set_index('time')

            plot_info['title'] = 'Auroral Electrojet (AE) Index'
            plot_info['symbol'] = 'Auroral Electrojet (AE) Index'
            plot_info['gme_label'] = 'AE Index [nT]'

        elif (gme_param == 'omni_by'):
            df_raw = pd.DataFrame(omni_df_raw['bym'])

            plot_info['symbol'] = 'OMNI By GSM'
            plot_info['gme_label'] = 'OMNI By GSM [nT]'

        elif gme_param == 'omni_bz':
            df_raw = pd.DataFrame(omni_df_raw['bzm'])

            plot_info['symbol'] = 'OMNI Bz GSM'
            plot_info['gme_label'] = 'OMNI Bz GSM [nT]'

        elif gme_param == 'omni_flowSpeed':
            df_raw = pd.DataFrame(omni_df_raw['flowSpeed'])

            plot_info['symbol'] = 'OMNI v'
            plot_info['gme_label'] = 'OMNI v [km/s]'

        elif gme_param == 'omni_np':
            df_raw = pd.DataFrame(omni_df_raw['np'])

            plot_info['symbol'] = 'OMNI Np'
            plot_info['gme_label'] = 'OMNI Np [N/cm^3]'

        elif gme_param == 'omni_pdyn':
            df_raw = pd.DataFrame(omni_df_raw['pDyn'])

            plot_info['symbol'] = 'OMNI pDyn'
            plot_info['gme_label'] = 'OMNI pDyn [nPa]'

        elif gme_param == 'omni_symh':
            df_raw = pd.DataFrame(omni_df_raw['symh'])

            plot_info['title'] = 'OMNI Sym-H'
            plot_info['symbol'] = 'OMNI Sym-H'
            plot_info['gme_label'] = 'OMNI Sym-H\n[nT]'
        elif gme_param == 'omni_bmagavg':
            df_raw = pd.DataFrame(omni_df_raw['bMagAvg'])
            plot_info['symbol'] = 'OMNI |B|'
            plot_info['gme_label'] = 'OMNI |B| [nT]'
        elif gme_param == 'solar_dec':
            times = []
            taus = []
            decs = []

            curr_time = sTime
            while curr_time < eTime:
                tau, dec = solar.epem(curr_time)

                times.append(curr_time)
                taus.append(tau)
                decs.append(dec)

                curr_time += datetime.timedelta(days=1)

            df_raw = pd.DataFrame(decs, index=times)
            plot_info['symbol'] = 'Solar Dec.'
            plot_info['gme_label'] = 'Solar Dec.'

        if plot_info.get('title') is None:
            plot_info['title'] = '{}'.format(gme_param.upper())

        if _plot_info is not None:
            plot_info.update(_plot_info)

        # Enforce sTime, eTime
        tf = np.logical_and(df_raw.index >= sTime, df_raw.index < eTime)
        df_raw = df_raw[tf].copy()
        df_raw.columns = ['raw']

        if parent is None:
            # This section is for compatibility with code that only uses
            # the single level GmeDataSet.

            # Resample data.
            df_rsmp = df_raw.resample(oversamp_T)
            df_rsmp = df_rsmp.interpolate()
            df_rsmp.columns = ['processed']

            self.ind_df_raw = df_raw
            self.sTime = sTime
            self.eTime = eTime
            self.ind_df = df_rsmp
            self.ind_times = df_rsmp.index.to_pydatetime()
            self.ind_vals = df_rsmp['processed']
        else:
            # This section is for attributes of the new container-style
            # GmeObject class.
            self.data = df_raw['raw']
            self.data.name = gme_param

        self.parent = parent
        self.gme_param = gme_param
        self.history = {datetime.datetime.now(): comment}
        self.plot_info = plot_info
        self.metadata = plot_info  #Create alias for compatibility with other code.