Пример #1
0
def define_three_anchor_points(z: float, spectra_data, left_point,
                               middle_point, right_point):
    """ Defines the three anchor points used in the normalization graph.

    Parameters:
    -----------
    z: float
        Values from the data base of the redshift, DR9Q (for now..).
    spectra_data: list
        Current spectra data from files, DR9Q (for now...).
               
    Returns:
    --------
    tuple
        left_point, middle_point, right_point for wavelength_flux_error_for_points.
    """

    left_point = Range(left_point.start * (1 + z), left_point.end * (1 + z))
    middle_point = Range(middle_point.start * (1 + z),
                         middle_point.end * (1 + z))
    right_point = Range(right_point.start * (1 + z), right_point.end * (1 + z))

    left_point = wavelength_flux_error_for_points(left_point.start,
                                                  left_point.end, z,
                                                  spectra_data)

    middle_point = wavelength_flux_error_for_points(middle_point.start,
                                                    middle_point.end, z,
                                                    spectra_data)

    try:
        right_point = wavelength_flux_error_for_points(right_point.start,
                                                       right_point.end, z,
                                                       spectra_data)
    except:
        right_point = wavelength_flux_error_for_points(
            WAVELENGTH_OBSERVED_FOR_RIGHT_POINT_HIGH_REDSHIFT.start,
            WAVELENGTH_OBSERVED_FOR_RIGHT_POINT_HIGH_REDSHIFT.end, z,
            spectra_data)

    return [left_point, middle_point, right_point]
Пример #2
0
# do you want to use smoothed norm flux/error
# boxcar_size must always be an odd integer
want_to_smooth = 'no'
boxcar_size = 11

# plot all cases or only those with absorption
# and provide text file for all cases or only those with absorption
# yes for everything, no for only absorption
all_plot_and_text = 'yes'

# lower limit of absorption width to be flagged
BALNICITY_INDEX_LIMIT = 2000

# limits on velocity     min,   max
VELOCITY_LIMIT = Range(-30000, -60000.)

# range of spectra you are working with from the good_fit.csv file
STARTS_FROM, ENDS_AT = 1, 71

# what percentage value you want to go below the continuum
percent = 0.9

###############################################################################################################################
######################################## OUTPUT FILES #########################################################################

# set name of output .txt file with absorption values
ABSORPTION_VALUES = OUT_DIREC + "/" + 'EHVO_Renormalizations_BI' + str(
    BALNICITY_INDEX_LIMIT) + '.txt'

# set name of output pdf with plots
Пример #3
0
FINAL_INIT_PARAMS_FILE = SPEC_DIREC + "/" + "final_initial_parameters.txt"
PROCESSED_SPECTRA_FILE = SPEC_DIREC + "/" + "processed_spectra_filenames.txt"
FLAGGED_GRAPHS_FILE = SPEC_DIREC + "/" + "flagged_for_absorption_or_bad_normalization.txt"
FLAGGED_SNR_GRAPHS_FILE = SPEC_DIREC + "/" + "flagged_snr_in_ehvo_graphs.txt"
GOODNESS_OF_FIT_FILE = SPEC_DIREC + "/" + "chi_sq_values_all.csv"
BAD_NORMALIZATION_FLAGGED_FILE = SPEC_DIREC + "/" + "bad_normalization.csv"
GOOD_NORMALIZATION_FLAGGED_FILE = SPEC_DIREC + "/" + "good_normalization.csv"
NORM_FILE_EXTENSION = "norm.dr9"

ORIGINAL_PDF = PdfPages('original_graphs.pdf')  # create pdf
NORMALIZED_PDF = PdfPages('normalized_graphs.pdf')  # create pdf

#
STARTS_FROM, ENDS_AT = 1, 9

WAVELENGTH_RESTFRAME = Range(1200., 1800.)
WAVELENGTH_FOR_SNR = Range(1250., 1400.)
WAVELENGTH_RESTFRAME_FOR_LEFT_POINT = Range(1280., 1290.)
WAVELENGTH_RESTFRAME_FOR_MIDDLE_POINT = Range(1420., 1430.)
WAVELENGTH_RESTFRAME_FOR_RIGHT_POINT = Range(1690., 1710.)
WAVELENGTH_RESTFRAME_TEST_1 = Range(1315., 1325.)
WAVELENGTH_RESTFRAME_TEST_2 = Range(1350., 1360.)

column_index = ColumnIndexes(0, 1, 2)

b = 1250  # powerlaw
c = -0.5  # powerlaw


def powerlaw(wavelength, b, c) -> float:
    return b * (np.power(wavelength, c))
    def evaluate(self, function=None):
        end_time = self.offset

        if self.range_selector is not None:
            start_time = end_time - datetime.timedelta(
                seconds=self.range_selector.range_sec)
            bucket_size_sec = self.range_selector.bucket_sec

            # cannot group in influx with derivative
            if function == 'derivative' and bucket_size_sec is not None:
                bucket_size_sec = None
        else:
            function = 'last_force'
            start_time = end_time - datetime.timedelta(minutes=5)
            bucket_size_sec = None

        influx_result = influx_repo.query(self.name,
                                          self.dimensions,
                                          function=function,
                                          start_time=start_time,
                                          end_time=end_time,
                                          bucket_size=bucket_size_sec,
                                          group_by=['*'])

        # if we did a derivative, do binning here
        if function == 'derivative':
            function = None
            bucket_size_sec = self.range_selector.bucket_sec

        result = []
        # Change into a binned series if necessary
        if function is None and bucket_size_sec is not None:
            unix_start = int(
                (start_time - datetime.datetime(1970, 1, 1)).total_seconds() *
                1000)
            unix_end = int(
                (end_time - datetime.datetime(1970, 1, 1)).total_seconds() *
                1000)
            bins = [
                i for i in range(unix_start, unix_end, bucket_size_sec * 1000)
            ]

            # do not include start time in bin edges
            bins_inner_edges = bins[1:]
            for serie_tuple in influx_result:
                final_bins = list(bins)
                bin_data = [[] for _ in range(len(bins_inner_edges) + 1)]
                final_data = []
                bin_indexes = numpy.digitize(serie_tuple[1].f0,
                                             bins_inner_edges)

                for i in range(len(bin_indexes)):
                    bin_data[bin_indexes[i]].append(
                        (serie_tuple[1][i].f0, serie_tuple[1][i].f1))
                for i in range(len(bin_data)):
                    if len(bin_data[i]) > 0:
                        final_data.append(numpy.rec.array(bin_data[i]))
                    else:
                        del final_bins[i]
                result.append(
                    BinnedRange(serie_tuple[0], numpy.array(final_bins),
                                final_data))
        else:
            for serie_tuple in influx_result:
                result.append(Range(serie_tuple[0], serie_tuple[1]))

        return VectorRange(result)
Пример #5
0
#Calculates absorption(BALnicity) for a list of spectra
import numpy as np
from matplotlib import pyplot as plt
from scipy import signal
from matplotlib.backends.backend_pdf import PdfPages
import os
import sys
from data_types import Range

VELOCITY_LIMIT = Range(-60000., -30000)

BI = 0  #change it to BI
BALNICITY_INDEX_LIMIT = 2000  #lower limit of absorption width

# Necessary data from Verner table
WAVELENGTH_CIV_EMIT_LIMIT = Range(1548.1950, 1550.7700)  #never used?
AVERAGE_CIV_DOUBLET = 1549.0524  #weighted average
AVERAGE_SiIV_DOUBLET = 1396.747  # weighted average; individuals: 1402.770, 1393.755
AVERAGE_NV_DOUBLET = 1240.15  # weighted average; individuals: 1242.80, 1238.82
AVERAGE_OVI_DOUBLET = 1033.8160  # weighted average; individuals: 1037.6167, 1031. 9261
CII_EMITTED = 1335.313  # (weighted average); individuals:
OI_EMITTED = 1303.4951  # weighted average; individuals pag 20 in Verner Table

non_trough_count = 100
boxcar_size = 5
deltav = 0  #change in velocity
part = 0
count2 = 0  # variable initialization to get into vmin/vmax loop

SPECDIREC, OUTPUT_SPEC = os.getcwd() + "/files/", os.getcwd() + "/files/"
NORM_FILE_EXTENSION = "norm.dr9"
Пример #6
0
based on code prepared by Abdul Khatri and Paola Rodriguez Hidalgo

Notes
-----
    All the functions made to plot the spectra and indicate where CIV, CII, and OI would be *if* the EHVO absorption found was 
    due to SiIV.
"""

########################################### IMPORTS ############################################################################
from matplotlib import pyplot as plt
import numpy as np
from data_types import Range
import random as ran

######################################## VERNER TABLE CONSTANTS ################################################################
WAVELENGTH_CIV_EMIT_LIMIT = Range(1548.1950, 1550.7700)                                    #never used?
AVERAGE_CIV_DOUBLET = 1549.0524 #weighted average
AVERAGE_SiIV_DOUBLET = 1396.747 # weighted average; individuals: 1402.770, 1393.755
AVERAGE_NV_DOUBLET = 1240.15 # weighted average; individuals: 1242.80, 1238.82             # not used
AVERAGE_OVI_DOUBLET=1033.8160 # weighted average; individuals: 1037.6167, 1031. 9261        # also not used
CII_EMITTED = 1335.313 # (weighted average); individuals:
OI_EMITTED = 1303.4951 # weighted average; individuals pag 20 in Verner Table
###############################################################################################################################


def draw_abs_figure(spectra_count_abs, spectra_index, velocity, flux_normalized, error, savefile_name, spectra_name, redshift, snr, max_peak):
    """ Makes a flux vs velocity graph, that also has the error vs velocity on the same graph. Has text that identifies 
    what the graph number is, what the spectra name is, the signal to noise ratio, and the redshift value used.
    
    Parameters
    ----------
Пример #7
0
val1 = 0.10

## VALUE USED IN TEST 2
val2 = 0.05

BOXCAR_SIZE = 11  ## MUST BE ODD

## INITIAL PARAMETERS OF POWERLAW
b = 1250
c = -0.5

#############################################################################################
####################################### DO NOT CHANGE #######################################

## RANGES OF WAVELENGTHS IN THE SPECTRA
WAVELENGTH_RESTFRAME = Range(1200., 1800.)
WAVELENGTH_FOR_SNR = Range(1250., 1400.)
WAVELENGTH_RESTFRAME_FOR_LEFT_POINT = Range(1280., 1290.)
WAVELENGTH_RESTFRAME_FOR_MIDDLE_POINT = Range(1440., 1450.)
WAVELENGTH_RESTFRAME_FOR_RIGHT_POINT = Range(1690., 1710.)
WAVELENGTH_RESTFRAME_TEST_1 = Range(1315., 1325.)
WAVELENGTH_RESTFRAME_TEST_2 = Range(1350., 1360.)
WAVELENGTH_RESTFRAME_TESTS = Range(1650., 1700.)

#############################################################################################

#############################################################################################
######################################## OUTPUT FILES #######################################
### Add in STARTS_FROM and ENDS_AT to files?? e.g. "log_" + STARTS_FROM + "-" + ENDS_AT + ".txt"

## TEXT OUTPUT FILES