Beispiel #1
0
    def archetype_classification(self):
        io_functions.span_window()
        print('... determining archetype classification')

        [
            interface_main.archetype_classify_MC(spec)
            for spec in self.spectra_array
        ]

        ### prepare output table if it's reasonable
        if len(self.spectra_array) < 30:

            output_table = ['NAME', "GI", "GII", "GIII"]

            for spec in self.spectra_array:
                row = np.concatenate([[spec.get_name()],
                                      [
                                          spec.LL_DICT[key][0].round(0)
                                          for key in ["GI", "GII", "GIII"]
                                      ]])

                output_table = np.vstack([output_table, row])

            table = Texttable()

            table.add_rows(output_table)
            print(" ------  ARCHETYPE LIKELIHOODS -------")
            print(table.draw())

        return
Beispiel #2
0
    def generate_plots(self):
        io_functions.span_window()
        print("... generating plots")

        plot_functions.plot_spectra(self)

        print("... generating corner plots")
        plot_functions.plot_corner_array(self)

        return
Beispiel #3
0
    def generate_output_files(self):
        io_functions.span_window()
        print("... generating outputs")

        final = pd.concat(
            [spec.get_output_row() for spec in self.spectra_array])
        try:
            final.to_csv("output/" + self.io_params['output_name'] +
                         "_out.csv",
                         index=False)

        except:
            final.to_csv("output/" + self.io_params['output_name'] +
                         "1_out.csv",
                         index=False)
Beispiel #4
0
    def mcmc_determination(self, pool=20):
        ### Main iterative method for the mcmc_determination
        io_functions.span_window()
        print('... performing MCMC determinations')

        [spec.prepare_regions() for spec in self.spectra_array]

        [
            interface_main.mcmc_determination(spec, mode='COARSE', pool=pool)
            for spec in self.spectra_array
        ]

        print("... performing kde determinations")
        [
            interface_main.generate_kde_params(spec, mode="COARSE")
            for spec in self.spectra_array
        ]

        io_functions.span_window()

        print("... running refined mcmc")
        [
            interface_main.mcmc_determination(spec, mode='REFINE', pool=pool)
            for spec in self.spectra_array
        ]

        print("... finalizing kde determinations")
        [
            interface_main.generate_kde_params(spec, mode='REFINE')
            for spec in self.spectra_array
        ]

        io_functions.span_window()
        print("... complete")
        io_functions.span_window()
        return
Beispiel #5
0
import time

print(" Started CASPER and logging!")
sys.stdout=open('casper-output-log.txt', 'wt')

start_time = time.time()
print("... initializing spectra batch")
spec_batch = Batch(spectra_path, param_path, io_param_path)

################################################################################
### load spectra + params
spec_batch.load_params()
spec_batch.load_spectra(is_fits=True)
spec_batch.set_params()

io_functions.span_window()

#spec_batch.radial_correct()
spec_batch.build_frames()

io_functions.span_window()

################################################################################
#### Continuum normalization with GISIC
spec_batch.normalize()

################################################################################
#### Preliminaries
spec_batch.set_KP_bounds()
spec_batch.set_carbon_mode()
Beispiel #6
0
    def calibrate_temperatures(self, default=True, teff_sigma=250):
        ## Here is where we will use the (J-K)0 values from the param_file
        ## along with the surface gravity class, if known
        ## We'll eventually want to update to override sigma, I'l come back to that

        print("... determining photometric temperature")

        ### I don't think the spectra_array and the param_file are sorted the same
        ### so I need to be careful

        for i, row in self.param_file.iterrows():

            io_functions.span_window()

            spec = self.spectra_array[i]

            assert spec.name == row[
                'name'], 'Parameter error in calibrate_temperatures()'
            print("\t setting photometric temperature sigma: ", spec.T_SIGMA)

            CLASS = row['class'].strip()

            #### remember that there is a class definition here too
            if np.isfinite(spec.HARD_TEFF):
                print("\t setting hard teff:   ", spec.HARD_TEFF)
                spec.set_temp_frame(
                    TC.calibrate_temp_frame(float(spec.PHOTO_0['J-K']),
                                            float(spec.PHOTO_0['g-r']),
                                            CLASS=CLASS))

                spec.TEMP_FRAME.loc['ADOPTED', 'VALUE'] = spec.HARD_TEFF

                spec.set_temperature(spec.HARD_TEFF, spec.T_SIGMA, hard=True)

            else:
                spec.set_temp_frame(
                    TC.calibrate_temp_frame(float(spec.PHOTO_0['J-K']),
                                            float(spec.PHOTO_0['g-r']),
                                            CLASS=CLASS))

                spec.set_temperature(spec.TEMP_FRAME.loc['ADOPTED', 'VALUE'],
                                     sigma=spec.T_SIGMA)

        #### NOW ASSEMBLE THE OUTPUT TABLE

        HEADER = [
            'NAME', 'Bergeat', 'Hernandez', 'Casagrande', 'Fukugita', 'ADOPTED'
        ]

        if len(self.spectra_array) < 30:

            output_table = HEADER

            for spec in self.spectra_array:
                row = np.concatenate(
                    [[spec.get_name().split(".fits")[0]],
                     [
                         spec.TEMP_FRAME.loc[CURRENT].values[0]
                         for CURRENT in HEADER[1:]
                     ]])

                output_table = np.vstack([output_table, row])

            table = Texttable()

            table.add_rows(output_table)
            print(" ------  PHOTOMETRIC TEMPERATURES -------")
            print(table.draw())

        return