def recreate_star(star_dir): """Create a Star from a given directory. Parameters ---------- star_dir :`pathlib.Path` The directory in which to find the star's files. Returns ------- None. """ tqdm.write(f'Creating {star_dir.stem}') try: Star(star_dir.stem, star_dir, load_data=False) except PickleFilesNotFoundError: newstar_dir = Path('/Volumes/External Storage/data_output') /\ star_dir.stem tqdm.write('Using external storage files.') Star(star_dir.stem, new_star_dir, load_data=False, output_dir=star_dir)
def get_star(star_path, verbose=False, recreate=False): """Return a varconlib.star.Star object based on its name. Parameters ---------- star_path : str A string representing the name of the directory where the HDF5 file containing a `star.Star`'s data can be found. Optional -------- verbose : bool, Default: False If *True*, write out additional information. recreate : bool, Default: False If *True*, first recreate the star from observations before returning it. This will only work on stars which already have an HDF5 file saved, and will not create new ones. Returns ------- `star.Star` A Star object from the directory. Note that this will only use already- existing stars, it will not create ones which do not already exist from their observations. """ assert star_path.exists(), FileNotFoundError('Star directory' f' {star_path}' ' not found.') # Flip boolean value, since to recreate (True) the star requires setting its # load_data argument to False. recreate = not recreate try: return Star(star_path.stem, star_path, load_data=recreate) except IndexError: vprint(f'Excluded {star_path.stem}.') pass except HDF5FileNotFoundError: vprint(f'No HDF5 file for {star_path.stem}.') pass except AttributeError: vprint(f'Affected star is {star_path.stem}.') raise except PickleFilesNotFoundError: vprint(f'No pickle files found for {star_path.stem}') pass
def get_star(star_path, verbose=False): """Return a varconlib.star.Star object based on its name. Parameters ---------- star_path : str A string representing the name of the directory where the HDF5 file containing a `star.Star`'s data can be found. Optional -------- verbose : bool, Default: False If *True*, write out additional information. Returns ------- `star.Star` A Star object from the directory. Note that this will only use already- existing stars, it will not create ones which do not already exist from their observations. """ assert star_path.exists(), FileNotFoundError('Star directory' f' {star_path}' ' not found.') try: return Star(star_path.stem, star_path, load_data=True) except IndexError: if verbose: tqdm.write(f'Excluded {star_path.stem}.') pass except HDF5FileNotFoundError: if verbose: tqdm.write(f'No HDF5 file for {star_path.stem}.') pass except AttributeError: if verbose: tqdm.write(f'Affected star is {star_path.stem}.') raise
def create_transition_model_corrected_arrays(star_dir): """ Create the transition model-corrected arrays for a Star from a given directory. Parameters ---------- star_dir : `pathlib.Path` The directory in which to find the star's files. Returns ------- None. """ tqdm.write(f'Working on {star_dir.stem}') star = Star(star_dir.stem, star_dir, load_data=True) star.createTransitionModelCorrectedArrays(model_func='quadratic', n_sigma=2.5) star.createPairSeparationArrays() star.saveDataToDisk()
def main(): """Run the main routine for this script. Returns ------- None. """ main_dir = Path(args.main_dir[0]) if not main_dir.exists(): raise FileNotFoundError(f'{main_dir} does not exist!') tqdm.write(f'Looking in main directory {main_dir}') rv_diff_list = [] app_mag_list = [] tqdm.write('Collecting stars...') for star_dir in tqdm(args.star_names): star_path = main_dir / star_dir star = Star(star_path.stem, star_path, load_data=True) vprint(f'Collecting info from {star_dir}.') rv = star.radialVelocity berv_list = star.bervArray rv_diff = [d.to(u.km / u.s) for d in berv_list - rv] app_mag = [star.apparentMagnitude] * len(rv_diff) vprint(f'Added {len(rv_diff)} observations.') rv_diff_list.extend(rv_diff) app_mag_list.extend(app_mag) tqdm.write(f'Found {len(rv_diff_list)} total observations.') # plot_histogram(rv_diff_list) plot_apparent_magnitude(rv_diff_list, app_mag_list)
axis.set_ylim(bottom=-0.5, top=len(stars_to_use) - 0.5) axis.xaxis.set_minor_locator(ticker.MultipleLocator(base=5)) axis.axvline(x=0, linestyle='--', color='Black', linewidth=3, zorder=100) axis.xaxis.set_tick_params(which='major', width=2, length=6) axis.xaxis.set_tick_params(which='minor', width=1.5, length=4) ax_dict[pairs_to_use[0]].set_yticks(range(0, len(stars_to_use))) labels = [] stars = [] pair_means = {} pair_stds = {} pair_mean_errors = {} for star_label in stars_to_use: tqdm.write(f'Analysing {star_label}') star = Star(star_label, f'/Users/dberke/data_output/{star_label}') stars.append(star) pre_slice = slice(None, star.fiberSplitIndex) num_obs = star.getNumObs(pre_slice) if star.name != "Vesta": labels.append(star.name) # + f'\n #obs: {num_obs}') else: labels.append('Sun\n(Vesta)') for label in pairs_to_use: col_index = star.p_index(label) means = star.pairSeparationsArray[pre_slice, col_index] errors = star.pairSepErrorsArray[pre_slice, col_index]
tqdm.write(f'Found {len(transitions_list)} individual transitions.') # Read the list of chosen pairs. with open(vcl.final_pair_selection_file, 'r+b') as f: pairs_list = pickle.load(f) tqdm.write(f'Found {len(pairs_list)} transition pairs (total) in list.') # Initialize Star objects from the given directories. if args.recreate_stars: tqdm.write('Creating stars from directories...') tqdm.write('Reading in first star...') star1 = Star(name=data_dir1.name, star_dir=data_dir1, suffix=args.suffix, transitions_list=transitions_list, pairs_list=pairs_list, load_data=args.recreate_stars) tqdm.write('Reading in second star...') star2 = Star(name=data_dir2.name, star_dir=data_dir2, suffix=args.suffix, transitions_list=transitions_list, pairs_list=pairs_list, load_data=args.recreate_stars) if args.compare_pairs or args.sort_blended: # Create a plot comparing the two stars. tqdm.write('Creating plot...') if (star1.fiberSplitIndex not in (0, None))\
return [ star.name, str(star.temperature.value), str(star.metallicity), str(star.logg), str(star.absoluteMagnitude), str(star.apparentMagnitude), str(star.numObsPre), str(star.numObsPost) ] # Get star directories starting with H or V. star_dirs = [Path(s) for s in glob(str(vcl.output_dir) + '/[HV]*')] stars = [Star(s.stem, s) for s in tqdm(star_dirs)] categories = { 'SP1': { 'temperature': 100 * u.K, 'metallicity': 0.1, 'logg': 0.2 }, 'SP2': { 'temperature': 200 * u.K, 'metallicity': 0.2, 'logg': 0.3 }, 'SP3': { 'temperature': 300 * u.K, 'metallicity': 0.3,
from varconlib.miscellaneous import remove_nans from varconlib.star import Star parser = argparse.ArgumentParser(description='Compare the values between pre-' ' and post-fiber change observations in' ' various ways.') parser.add_argument('star_name', action='store', type=str, help='The name of the star (directory) where the star to be' ' used is.') args = parser.parse_args() plots_dir = vcl.output_dir / 'pair_result_plots' star = Star(args.star_name, vcl.output_dir / args.star_name) # KS stands for the 2-sided Kolmogorov-Smirnov test, TT for Welch's t-test. ks_p_values = [] ks_stats = [] tt_p_values = [] tt_stats = [] # !!! Need to check if star hasObsPost before making post_slice. pre_slice = slice(None, star.fiberSplitIndex) post_slice = slice(star.fiberSplitIndex, None) for pair_label, num in tqdm(star._pair_bidict.items()):
tqdm.write('Matching stars...') for name in tqdm(names): for row in data: if row[0] == name: if 'HD' not in name: try: name = hd_dict[name] except KeyError: continue elif name == 'HD68978A': name = hd_dict[name] path = Path(f'/Users/dberke/data_output/{name}') # tqdm.write(str(path)) if path.exists(): try: star = Star(name, path, load_data=True) except HDF5FileNotFoundError: continue matched_star_names.add(name) # tqdm.write(f'Matched {name} ({row[0]})') num_matched_stars += 1 teff_list.append(float(row[1])) logg_list.append(float(row[2])) feh_list.append(float(row[3])) teff_err_list.append(float(row[4])) logg_err_list.append(float(row[5])) feh_err_list.append(float(row[6])) casagrande_teff.append(star.temperature.value) casagrande_logg.append(star.logg) casagrande_feh.append(star.metallicity)