Пример #1
0
def globalcount_shuttered(band, trange, verbose=0, timestamplist=False):
    """
    Global event counts over the time range, exluding shuttered periods (due to
        no non-NULL data).

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param trange: Minimum and maximum time (in GALEX time) to consider.

    :type trange: list

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param timestamplist: Global event time stamps.

    :type timestamplist: list

    :returns: int -- Total global counts excluding shuttered periods.
    """

    try:
        t = (timestamplist if np.array(timestamplist).any() else
             np.array(gQuery.getArray(gQuery.uniquetimes(
                 band, trange[0], trange[1], flag=True),
                                      verbose=verbose),
                      dtype='float64')[:, 0] / gQuery.tscale)
    except IndexError:  # Shutter this whole time range.
        if verbose:
            print_inline('No data in {t0},{t1}'.format(t0=trange[0],
                                                       t1=trange[1]))
        return 0

    times = np.sort(np.unique(np.append(t, trange)))
    tranges = distinct_tranges(times, maxgap=0.05)
    nonnullevents, nullevents = 0, 0

    for trange in tranges:
        nullevents += gQuery.getValue(gQuery.deadtime2(band, trange[0],
                                                       trange[1]),
                                      verbose=verbose)

        nonnullevents += gQuery.getValue(gQuery.deadtime1(
            band, trange[0], trange[1]),
                                         verbose=verbose)

    return nullevents + nonnullevents
Пример #2
0
def globalcount_shuttered(band, trange, verbose=0, timestamplist=False):
    """
    Global event counts over the time range, exluding shuttered periods (due to
        no non-NULL data).

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param trange: Minimum and maximum time (in GALEX time) to consider.

    :type trange: list

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param timestamplist: Global event time stamps.

    :type timestamplist: list

    :returns: int -- Total global counts excluding shuttered periods.
    """

    try:
        t = (timestamplist if np.array(timestamplist).any() else
             np.array(gQuery.getArray(gQuery.uniquetimes(band, trange[0],
                                                         trange[1], flag=True),
                                      verbose=verbose),
                      dtype='float64')[:, 0]/gQuery.tscale)
    except IndexError: # Shutter this whole time range.
        if verbose:
            print_inline('No data in {t0},{t1}'.format(t0=trange[0], t1=trange[1]))
        return 0

    times = np.sort(np.unique(np.append(t, trange)))
    tranges = distinct_tranges(times, maxgap=0.05)
    nonnullevents, nullevents = 0, 0

    for trange in tranges:
        nullevents += gQuery.getValue(
            gQuery.deadtime2(band, trange[0], trange[1]), verbose=verbose)

        nonnullevents += gQuery.getValue(gQuery.deadtime1(band, trange[0],
                                                          trange[1]),
                                         verbose=verbose)

    return nullevents+nonnullevents
Пример #3
0
def stimcount_shuttered(band, trange, verbose=0, timestamplist=False):
    """
    Returns the stim count over a time range, excluding periods that the
        detector is considered shuttered (because of no non-NULL data).

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param trange: Minimum and maximum time (in GALEX time) to consider.

    :type trange: list

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param timestamplist: Global detector event timestamps.

    :type timestamplist: list

    :returns: int -- Total stim counts excluding shuttered time ranges.
    """

    try:
        t = (timestamplist if np.array(timestamplist).any() else
             np.array(gQuery.getArray(gQuery.uniquetimes(band, trange[0],
                                                         trange[1]),
                                      verbose=verbose),
                      dtype='float64')[:, 0]/gQuery.tscale)
    except IndexError: # Shutter this whole time range.
        if verbose:
            print_inline('No data in {t0},{t1}'.format(t0=trange[0], t1=trange[1]))
        return 0

    times = np.sort(np.unique(np.append(t, trange)))
    tranges = distinct_tranges(times, maxgap=0.05)
    stimcount = 0

    for trange in tranges:
        stimcount += (gQuery.getValue(gQuery.stimcount(band, trange[0],
                                                       trange[1]),
                                      verbose=verbose) +
                      gQuery.getValue(gQuery.stimcount(band, trange[0],
                                                       trange[1], null=False),
                                      verbose=verbose))

    return stimcount
Пример #4
0
def stimcount_shuttered(band, trange, verbose=0, timestamplist=False):
    """
    Returns the stim count over a time range, excluding periods that the
        detector is considered shuttered (because of no non-NULL data).

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param trange: Minimum and maximum time (in GALEX time) to consider.

    :type trange: list

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param timestamplist: Global detector event timestamps.

    :type timestamplist: list

    :returns: int -- Total stim counts excluding shuttered time ranges.
    """

    try:
        t = (timestamplist if np.array(timestamplist).any() else np.array(
            gQuery.getArray(gQuery.uniquetimes(band, trange[0], trange[1]),
                            verbose=verbose),
            dtype='float64')[:, 0] / gQuery.tscale)
    except IndexError:  # Shutter this whole time range.
        if verbose:
            print_inline('No data in {t0},{t1}'.format(t0=trange[0],
                                                       t1=trange[1]))
        return 0

    times = np.sort(np.unique(np.append(t, trange)))
    tranges = distinct_tranges(times, maxgap=0.05)
    stimcount = 0

    for trange in tranges:
        stimcount += (gQuery.getValue(
            gQuery.stimcount(band, trange[0], trange[1]), verbose=verbose) +
                      gQuery.getValue(gQuery.stimcount(
                          band, trange[0], trange[1], null=False),
                                      verbose=verbose))

    return stimcount
Пример #5
0
def exposure(band, trange, verbose=0):
    """
    Calculate the effective exposure time in a period, in seconds, accounting
        for shutter and deadtime. Does not account for actual sky coverage of
        the telescope during the time period queried (see: compute_exptime()
        below).

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param trange: Minimum and maximum time (in GALEX time) to consider.

    :type trange: list

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :returns: float -- The effective exposure time, in seconds.
    """

    rawexpt = trange[1] - trange[0]

    if rawexpt == 0.:
        return 0.

    try:
        t = (np.array(gQuery.getArray(gQuery.uniquetimes(
            band, trange[0], trange[1], flag=True),
                                      verbose=verbose),
                      dtype='float64')[:, 0] / gQuery.tscale)
    except IndexError:  # Shutter this whole time range.
        if verbose:
            print_inline('No data in {t0},{t1}'.format(t0=trange[0],
                                                       t1=trange[1]))
        return 0.

    shutter = compute_shutter(band, trange, verbose=verbose, timestamplist=t)

    deadtime = empirical_deadtime(band,
                                  trange,
                                  verbose=verbose,
                                  timestamplist=t)

    return (rawexpt - shutter) * (1. - deadtime)
Пример #6
0
def compute_shutter(band,
                    trange,
                    verbose=0,
                    shutgap=0.05,
                    timestamplist=False):
    """
    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param trange: Minimum and maximum time (in GALEX time) to consider.

    :type trange: list

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param shutgap: Amount of time, in seconds, that defines the minimum gap in
        observation that corresponds to a 'shutter' (not a true exposure time).

    :type shutgap: float

    :param timestamplist: Global event time stamps.

    :type timestamplist: list

    :returns: numpy.ndarray -- The total shutter time, in seconds, during the
        specified time range.
    """

    try:
        t = (timestamplist if np.array(timestamplist).any() else
             np.array(gQuery.getArray(gQuery.uniquetimes(
                 band, trange[0], trange[1], flag=True),
                                      verbose=verbose),
                      dtype='float64')[:, 0] / gQuery.tscale)
    except IndexError:  # Shutter this whole time range if there's no data
        return trange[1] - trange[0]

    t = np.sort(np.unique(np.append(t, trange)))
    ix = np.where(t[1:] - t[:-1] >= shutgap)

    return np.array(t[1:] - t[:-1])[ix].sum()
Пример #7
0
def exposure(band, trange, verbose=0):
    """
    Calculate the effective exposure time in a period, in seconds, accounting
        for shutter and deadtime. Does not account for actual sky coverage of
        the telescope during the time period queried (see: compute_exptime()
        below).

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param trange: Minimum and maximum time (in GALEX time) to consider.

    :type trange: list

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :returns: float -- The effective exposure time, in seconds.
    """

    rawexpt = trange[1]-trange[0]

    if rawexpt == 0.:
        return 0.

    try:
        t = (np.array(gQuery.getArray(
            gQuery.uniquetimes(band, trange[0], trange[1], flag=True),
            verbose=verbose), dtype='float64')[:, 0]/gQuery.tscale)
    except IndexError: # Shutter this whole time range.
        if verbose:
            print_inline('No data in {t0},{t1}'.format(t0=trange[0], t1=trange[1]))
        return 0.

    shutter = compute_shutter(band, trange, verbose=verbose, timestamplist=t)

    deadtime = empirical_deadtime(band, trange, verbose=verbose, timestamplist=t)

    return (rawexpt-shutter)*(1.-deadtime)
Пример #8
0
def compute_shutter(band, trange, verbose=0, shutgap=0.05,
                    timestamplist=False):
    """
    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param trange: Minimum and maximum time (in GALEX time) to consider.

    :type trange: list

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param shutgap: Amount of time, in seconds, that defines the minimum gap in
        observation that corresponds to a 'shutter' (not a true exposure time).

    :type shutgap: float

    :param timestamplist: Global event time stamps.

    :type timestamplist: list

    :returns: numpy.ndarray -- The total shutter time, in seconds, during the
        specified time range.
    """

    try:
        t = (timestamplist if np.array(timestamplist).any() else
             np.array(gQuery.getArray(gQuery.uniquetimes(band, trange[0],
                                                         trange[1], flag=True),
                                      verbose=verbose),
                      dtype='float64')[:, 0]/gQuery.tscale)
    except IndexError: # Shutter this whole time range if there's no data
        return trange[1]-trange[0]

    t = np.sort(np.unique(np.append(t, trange)))
    ix = np.where(t[1:]-t[:-1] >= shutgap)

    return np.array(t[1:]-t[:-1])[ix].sum()
Пример #9
0
def get_valid_times(band, skypos, trange=None, detsize=1.1, verbose=0,
                    skyrange=None):
    """
    Given a sky position and (optional) extent, return all of the times
        periods containing spatially intersecting observations.

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param skypos: The right ascension and declination, in degrees.

    :type skypos: list

    :param trange: Minimum and maximum time (in GALEX time) to consider.

    :type trange: list

    :param detsize: The effective detector diameter, in degrees.

    :type detsize: float

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param skyrange: Values in degrees RA and Dec of a box around skypos that
        defines the extent of the region of interest.

    :type skyrange: list

    :returns: numpy.ndarray -- A sorted set of unique time stamps.
    """

    if not np.array(trange).tolist():
        trange = [1, 1000000000000]

    if len(np.shape(trange)) == 2:
        trange = trange[0]

    # Assembles sky positions on a grid within the targeted region.
    # [Future]: This is probably not an optimally efficient way to check an
    # entire region of sky for data, but it's not hugely dumb and does work...
    skypos_list = [skypos]
    if skyrange:
        # This massive construction with the hstack and separate calls to
        # linspace is to ensure that skypos (i.e. the target position) is
        # always uniquely searched.
        # In a perfect world, you would probably divice detsize by 2. The
        # detsize is divided by 3 to make sure to oversample the search just a
        # little bit.
        for r in np.unique(
                np.hstack([np.linspace(skypos[0],
                                       skypos[0]+skyrange[0]/2.,
                                       np.ceil(skyrange[0]/(detsize/3.)),
                                       endpoint=True),
                           np.linspace(skypos[0], skypos[0]-skyrange[0]/2.,
                                       np.ceil(skyrange[0]/(detsize/3.)),
                                       endpoint=True)])):
            for d in np.unique(
                    np.hstack([np.linspace(skypos[1],
                                           skypos[1]+skyrange[1]/2.,
                                           np.ceil(skyrange[1]/(detsize/3.)),
                                           endpoint=True),
                               np.linspace(skypos[1], skypos[1]-skyrange[1]/2.,
                                           np.ceil(skyrange[1]/(detsize/3.)),
                                           endpoint=True)])):
                skypos_list += [[r, d]]

    times = []
    for skypos in skypos_list:
        try:
            times = (list(times) +
                     list(np.array(gQuery.getArray(
                         gQuery.exposure_ranges(band, skypos[0], skypos[1],
                                                t0=trange[0], t1=trange[1],
                                                detsize=detsize),
                         verbose=verbose), dtype='float64')[:, 0]/tscale))
        except IndexError:
            if verbose:
                print("No exposure time available at {pos}".format(pos=skypos))
            return np.array([], dtype='float64')
        except TypeError:
            print("Is one of the inputs malformed?")
            raise
        except:
            raise

    # The following section should account for the fact that the use of band
    # in gQuery.exposure_ranges() doesn't seem to work like it should.
    # Specifically, it often returns time ranges as valid for FUV when there
    # are not actually any global events recorded by that detector.
    newtimes = []
    try:
        aspranges = distinct_tranges(np.sort(np.unique(times)))
    except IndexError:
        return np.array([], dtype='float64')
    except:
        raise

    for trange in aspranges:
        photontimes = (np.array(gQuery.getArray(
            gQuery.uniquetimes(band, trange[0], trange[1], flag=0)),
                                dtype='float64').flatten()/1000.)
        ix = np.where((photontimes.flatten() >= trange[0]) &
                      (photontimes.flatten() < trange[1]+1))
        if len(ix[0]):
            newtimes += np.arange(trange[0], trange[1]+1).tolist()

    return np.sort(np.unique(newtimes))
Пример #10
0
def get_valid_times(band,
                    skypos,
                    trange=None,
                    detsize=1.1,
                    verbose=0,
                    skyrange=None):
    """
    Given a sky position and (optional) extent, return all of the times
        periods containing spatially intersecting observations.

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param skypos: The right ascension and declination, in degrees.

    :type skypos: list

    :param trange: Minimum and maximum time (in GALEX time) to consider.

    :type trange: list

    :param detsize: The effective detector diameter, in degrees.

    :type detsize: float

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param skyrange: Values in degrees RA and Dec of a box around skypos that
        defines the extent of the region of interest.

    :type skyrange: list

    :returns: numpy.ndarray -- A sorted set of unique time stamps.
    """

    if not np.array(trange).tolist():
        trange = [1, 1000000000000]

    if len(np.shape(trange)) == 2:
        trange = trange[0]

    # Assembles sky positions on a grid within the targeted region.
    # [Future]: This is probably not an optimally efficient way to check an
    # entire region of sky for data, but it's not hugely dumb and does work...
    skypos_list = [skypos]
    if skyrange:
        # This massive construction with the hstack and separate calls to
        # linspace is to ensure that skypos (i.e. the target position) is
        # always uniquely searched.
        # In a perfect world, you would probably divice detsize by 2. The
        # detsize is divided by 3 to make sure to oversample the search just a
        # little bit.
        for r in np.unique(
                np.hstack([
                    np.linspace(skypos[0],
                                skypos[0] + skyrange[0] / 2.,
                                np.ceil(skyrange[0] / (detsize / 3.)),
                                endpoint=True),
                    np.linspace(skypos[0],
                                skypos[0] - skyrange[0] / 2.,
                                np.ceil(skyrange[0] / (detsize / 3.)),
                                endpoint=True)
                ])):
            for d in np.unique(
                    np.hstack([
                        np.linspace(skypos[1],
                                    skypos[1] + skyrange[1] / 2.,
                                    np.ceil(skyrange[1] / (detsize / 3.)),
                                    endpoint=True),
                        np.linspace(skypos[1],
                                    skypos[1] - skyrange[1] / 2.,
                                    np.ceil(skyrange[1] / (detsize / 3.)),
                                    endpoint=True)
                    ])):
                skypos_list += [[r, d]]

    times = []
    for skypos in skypos_list:
        try:
            times = (list(times) + list(
                np.array(gQuery.getArray(gQuery.exposure_ranges(
                    band,
                    skypos[0],
                    skypos[1],
                    t0=trange[0],
                    t1=trange[1],
                    detsize=detsize),
                                         verbose=verbose),
                         dtype='float64')[:, 0] / tscale))
        except IndexError:
            if verbose:
                print("No exposure time available at {pos}".format(pos=skypos))
            return np.array([], dtype='float64')
        except TypeError:
            print("Is one of the inputs malformed?")
            raise
        except:
            raise

    # The following section should account for the fact that the use of band
    # in gQuery.exposure_ranges() doesn't seem to work like it should.
    # Specifically, it often returns time ranges as valid for FUV when there
    # are not actually any global events recorded by that detector.
    newtimes = []
    try:
        aspranges = distinct_tranges(np.sort(np.unique(times)))
    except IndexError:
        return np.array([], dtype='float64')
    except:
        raise

    for trange in aspranges:
        photontimes = (np.array(gQuery.getArray(
            gQuery.uniquetimes(band, trange[0], trange[1], flag=0)),
                                dtype='float64').flatten() / 1000.)
        ix = np.where((photontimes.flatten() >= trange[0])
                      & (photontimes.flatten() < trange[1] + 1))
        if len(ix[0]):
            newtimes += np.arange(trange[0], trange[1] + 1).tolist()

    return np.sort(np.unique(newtimes))