In [1]:
%pylab inline
from astropy.io import fits as pyfits
from astropy.table import Table,join
import numpy as np
from astropy.io.fits import Column
from datetime import datetime
import matplotlib.pyplot as plt
import requests

warnings.filterwarnings('ignore', category=RuntimeWarning, append=True)
warnings.filterwarnings('ignore', category=UserWarning, append=True);


Populating the interactive namespace from numpy and matplotlib

In [2]:
# Load data from Dropbox folder instead of clogging up Github

def download_from_dropbox(url):
    
    local_filename = "../{:}".format(url.split("/")[-1].split("?")[0])
    r = requests.get(url, stream=True)
    with open(local_filename, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024): 
            if chunk: # filter out keep-alive new chunks
                f.write(chunk)
                f.flush()
            
    return local_filename

In [15]:
# 3 tables:
# Table 1 - gz_hst_table_raw_and_weighted_votes.fits; contains all the vote data except for goods_full, but I hope to add that as soon as I get that data.
#votes_fname = download_from_dropbox("https://www.dropbox.com/s/drdl6mht4kh2d7m/gz_hst_table_raw_and_weighted_votes.fits?dl=1")
votes_fname = '/home/mel/Dropbox/gzhubble/hubble_files/catalog_debiasing_files/new_sb_method/gz_hst_table_raw_and_weighted_votes.fits'
votes_data = Table.read(votes_fname)

# Table 2 - lo_hi_limits.fits: just need low, high limits on p_features (2 columns). 
#lohi_fname = download_from_dropbox("https://www.dropbox.com/s/n1zxkqe3q9rx2ve/lo_hi_limits.fits?dl=1")
lohi_fname = '/home/mel/Dropbox/gzhubble/hubble_files/catalog_debiasing_files/new_sb_method/lo_hi_limits.fits'
lohi_data = Table.read(lohi_fname)

#Table 3 - gzh_t01_z_mu_categorized.fits, want z, mu, and category information (4 columns)
#meta_fname = download_from_dropbox("https://www.dropbox.com/s/hppphpzujretywn/gzh_t01_z_mu_categorized.fits?dl=1")
meta_fname = '/home/mel/Dropbox/gzhubble/hubble_files/catalog_debiasing_files/new_sb_method/gzh_t01_z_mu_categorized.fits'
meta_data = Table.read(meta_fname)

In [16]:
lohi_data.remove_column('Z_BEST')
lohi_data.remove_column('GZ_MU_I')
lohi_data.remove_column('OBJNO')
lohi_data.remove_column('survey_id')
lohi_data.remove_column('Table')
lohi_data.remove_column('t01_smooth_or_features_a02_features_or_disk_weighted_fraction')

meta_data.remove_column('OBJNO')
meta_data.remove_column('survey_id')
meta_data.remove_column('Table')
meta_data.remove_column('Correctable_Category')
meta_data.remove_column('t01_smooth_or_features_a02_features_or_disk_weighted_fraction')

In [17]:
#Join Table 2 and Table 3- will have z, mu, low/hi limits on p_features
lohi_meta = join(meta_data, lohi_data, keys='zooniverse_id',join_type='left')

In [18]:
meta_data[0]


Out[18]:
<Row index=0>
zooniverse_idZ_BESTGZ_MU_Icorrection_type
str10float64float64float64
AHZ20000010.88599997758919.74076327910.0

In [19]:
votes_data[0]


Out[19]:
<Row index=0 masked=True>
zooniverse_idsurvey_idTableRADECimagingtotal_counttotal_weightt01_smooth_or_features_a01_smooth_fractiont01_smooth_or_features_a01_smooth_weighted_fractiont01_smooth_or_features_a02_features_or_disk_fractiont01_smooth_or_features_a02_features_or_disk_weighted_fractiont01_smooth_or_features_a03_star_or_artifact_fractiont01_smooth_or_features_a03_star_or_artifact_weighted_fractiont01_smooth_or_features_total_countt01_smooth_or_features_total_weightt02_edgeon_a01_yes_fractiont02_edgeon_a01_yes_weighted_fractiont02_edgeon_a02_no_fractiont02_edgeon_a02_no_weighted_fractiont02_edgeon_total_countt02_edgeon_total_weightt03_bar_a01_bar_fractiont03_bar_a01_bar_weighted_fractiont03_bar_a02_no_bar_fractiont03_bar_a02_no_bar_weighted_fractiont03_bar_total_countt03_bar_total_weightt04_spiral_a01_spiral_fractiont04_spiral_a01_spiral_weighted_fractiont04_spiral_a02_no_spiral_fractiont04_spiral_a02_no_spiral_weighted_fractiont04_spiral_total_countt04_spiral_total_weightt05_bulge_prominence_a01_no_bulge_fractiont05_bulge_prominence_a01_no_bulge_weighted_fractiont05_bulge_prominence_a02_just_noticeable_fractiont05_bulge_prominence_a02_just_noticeable_weighted_fractiont05_bulge_prominence_a03_obvious_fractiont05_bulge_prominence_a03_obvious_weighted_fractiont05_bulge_prominence_a04_dominant_fractiont05_bulge_prominence_a04_dominant_weighted_fractiont05_bulge_prominence_total_countt05_bulge_prominence_total_weightt06_odd_a01_yes_fractiont06_odd_a01_yes_weighted_fractiont06_odd_a02_no_fractiont06_odd_a02_no_weighted_fractiont06_odd_total_countt06_odd_total_weightt07_rounded_a01_completely_round_fractiont07_rounded_a01_completely_round_weighted_fractiont07_rounded_a02_in_between_fractiont07_rounded_a02_in_between_weighted_fractiont07_rounded_a03_cigar_shaped_fractiont07_rounded_a03_cigar_shaped_weighted_fractiont07_rounded_total_countt07_rounded_total_weightt08_odd_feature_a01_ring_fractiont08_odd_feature_a01_ring_weighted_fractiont08_odd_feature_a02_lens_or_arc_fractiont08_odd_feature_a02_lens_or_arc_weighted_fractiont08_odd_feature_a03_disturbed_fractiont08_odd_feature_a03_disturbed_weighted_fractiont08_odd_feature_a04_irregular_fractiont08_odd_feature_a04_irregular_weighted_fractiont08_odd_feature_a05_other_fractiont08_odd_feature_a05_other_weighted_fractiont08_odd_feature_a06_merger_fractiont08_odd_feature_a06_merger_weighted_fractiont08_odd_feature_a07_dust_lane_fractiont08_odd_feature_a07_dust_lane_weighted_fractiont08_odd_feature_total_countt08_odd_feature_total_weightt09_bulge_shape_a01_rounded_fractiont09_bulge_shape_a01_rounded_weighted_fractiont09_bulge_shape_a02_boxy_fractiont09_bulge_shape_a02_boxy_weighted_fractiont09_bulge_shape_a03_no_bulge_fractiont09_bulge_shape_a03_no_bulge_weighted_fractiont09_bulge_shape_total_countt09_bulge_shape_total_weightt10_arms_winding_a01_tight_fractiont10_arms_winding_a01_tight_weighted_fractiont10_arms_winding_a02_medium_fractiont10_arms_winding_a02_medium_weighted_fractiont10_arms_winding_a03_loose_fractiont10_arms_winding_a03_loose_weighted_fractiont10_arms_winding_total_countt10_arms_winding_total_weightt11_arms_number_a01_1_fractiont11_arms_number_a01_1_weighted_fractiont11_arms_number_a02_2_fractiont11_arms_number_a02_2_weighted_fractiont11_arms_number_a03_3_fractiont11_arms_number_a03_3_weighted_fractiont11_arms_number_a04_4_fractiont11_arms_number_a04_4_weighted_fractiont11_arms_number_a05_more_than_4_fractiont11_arms_number_a05_more_than_4_weighted_fractiont11_arms_number_a06_cant_tell_fractiont11_arms_number_a06_cant_tell_weighted_fractiont11_arms_number_total_countt11_arms_number_total_weightt12_clumpy_a01_yes_fractiont12_clumpy_a01_yes_weighted_fractiont12_clumpy_a02_no_fractiont12_clumpy_a02_no_weighted_fractiont12_clumpy_total_countt12_clumpy_total_weightt13_bright_clump_a01_yes_fractiont13_bright_clump_a01_yes_weighted_fractiont13_bright_clump_a02_no_fractiont13_bright_clump_a02_no_weighted_fractiont13_bright_clump_total_countt13_bright_clump_total_weightt14_bright_clump_central_a01_yes_fractiont14_bright_clump_central_a01_yes_weighted_fractiont14_bright_clump_central_a02_no_fractiont14_bright_clump_central_a02_no_weighted_fractiont14_bright_clump_central_total_countt14_bright_clump_central_total_weightt15_clumps_arrangement_a01_line_fractiont15_clumps_arrangement_a01_line_weighted_fractiont15_clumps_arrangement_a02_chain_fractiont15_clumps_arrangement_a02_chain_weighted_fractiont15_clumps_arrangement_a03_cluster_fractiont15_clumps_arrangement_a03_cluster_weighted_fractiont15_clumps_arrangement_a04_spiral_fractiont15_clumps_arrangement_a04_spiral_weighted_fractiont15_clumps_arrangement_total_countt15_clumps_arrangement_total_weightt16_clumps_count_a02_2_fractiont16_clumps_count_a02_2_weighted_fractiont16_clumps_count_a03_3_fractiont16_clumps_count_a03_3_weighted_fractiont16_clumps_count_a04_4_fractiont16_clumps_count_a04_4_weighted_fractiont16_clumps_count_a05_more_than_4_fractiont16_clumps_count_a05_more_than_4_weighted_fractiont16_clumps_count_a06_cant_tell_fractiont16_clumps_count_a06_cant_tell_weighted_fractiont16_clumps_count_a01_1_fractiont16_clumps_count_a01_1_weighted_fractiont16_clumps_count_total_countt16_clumps_count_total_weightt17_clumps_symmetrical_a01_yes_fractiont17_clumps_symmetrical_a01_yes_weighted_fractiont17_clumps_symmetrical_a02_no_fractiont17_clumps_symmetrical_a02_no_weighted_fractiont17_clumps_symmetrical_total_countt17_clumps_symmetrical_total_weightt18_clumps_embedded_a01_yes_fractiont18_clumps_embedded_a01_yes_weighted_fractiont18_clumps_embedded_a02_no_fractiont18_clumps_embedded_a02_no_weighted_fractiont18_clumps_embedded_total_countt18_clumps_embedded_total_weight
str10str19str13float64float64str17int16float32float32float32float32float32float32float32int16float32float32float32float32float32int16float32float32float32float32float32int16float32float32float32float32float32int16float32float32float32float32float32float32float32float32float32int16float32float32float32float32float32int16float32float32float32float32float32float32float32int16float32float32float32float32float32float32float32float32float32float32float32float32float32float32float32int16float32float32float32float32float32float32float32int16float32float32float32float32float32float32float32int16float32float32float32float32float32float32float32float32float32float32float32float32float32int16float32float32float32float32float32int16float32float32float32float32float32int16float32float32float32float32float32int16float32float32float32float32float32float32float32float32float32int16float32float32float32float32float32float32float32float32float32float32float32float32float32int16float32float32float32float32float32int16float32float32float32float32float32int16float32
AHZ300000150000000goods_shallow189.48135162.2591072GOODS-N591579.2430.390.4150.3820.4150.2280.17123113.2410.00.01.01.01111.00.0910.0910.9090.9091111.00.00.01.01.01111.00.2730.2730.1820.1820.3640.3640.1820.1821111.00.4420.4470.5580.5539594.0010.0820.0630.8980.9170.020.0214948.0010.00.00.0480.0480.0710.0710.2860.2860.4760.4760.1190.1190.00.04242.00.00.00.00.00.00.000.00.00.00.00.00.00.000.00.00.00.00.00.00.00.00.00.00.00.00.000.00.7660.7660.2340.2344747.00.8530.8530.1470.1473434.00.8620.8620.1380.1382929.00.1360.1360.6360.6360.2270.2270.00.02222.00.3890.3890.4720.4720.00.00.00.00.0830.0830.0560.0563636.00.2860.2860.7140.7143535.00.5710.5710.4290.4293535.0

In [20]:
#strip Table names of blank spaces:
for i in range(0,len(votes_data)):
    votes_data['Table'][i]=votes_data['Table'][i].strip()

In [21]:
#join Table 1 (votes + Imaging) with the other stuff:
input_table=join(votes_data,lohi_meta,keys='zooniverse_id',join_type='left')

In [22]:
len(input_table)


Out[22]:
179564

In [23]:
#Set path for output
fname = '/home/mel/Dropbox/gzhubble/hubble_files/catalog_debiasing_files/new_sb_method/input_for_hubble_debiased_catalog.fits'

input_table.write(fname,overwrite=True)

In [ ]: