In [293]:
import pandas as pd
import pickle

In [292]:
schema = {}
schema["Relations"] = {"origin": ["year", "month", "day", "hour", "minute", "second", 
                                  "lat_deg", "is_south", "lat_min", "lon_deg", "is_east", 
                                  "lon_min", "depth", "amp_mag", "narr", "maxazgap", 
                                  "nearest", "rms", "az_err_max", "dip_err_max", 
                                  "size_err_max", "az_err_int", "dip_err_int", 
                                  "size_err_int", "coda_mag", "ev_loc_remark", 
                                  "size_err_min", "aux_analyst_remark", "aux_prog_remark", 
                                  "narr_S", "err_h", "err_v", "n_P_fm", "tot_amp_mag_wgt", 
                                  "tot_dur_mag_wgt", "med_abs_dif_amp_mag", 
                                  "med_abs_dif_dur_mag", "crustal_model", "authority", 
                                  "PS_data_src", "dur_data_src", "amp_data_src", 
                                  "primary_coda_dur_mag_type", "nass", 
                                  "primary_amp_mag_type", 
                                  "ext_mag_type", "ext_mag", "tot_ext_mag_wgt", 
                                  "alt_amp_mag_type", "alt_amp_mag", "tot_alt_amp_mag_wgt",
                                  "evid", "pref_mag_type", "pref_mag", "tot_pref_mag_wgt",
                                  "alt_coda_dur_mag_type", "alt_coda_dur_mag", 
                                  "tot_alt_coda_dur_mag_wgt", "info_version", 
                                  "revision_version"],
                       "arrival": ["sta", "net", "blank1", "comp", "chan",
                                   "blank2", "p_remark", "p_fm", "p_wgt_code",
                                   "year", "month", "day", "hour", "minute",
                                   "p_second", "p_residual", "p_wgt", "s_second",
                                   "s_remark", "blank3", "s_wgt_code",
                                   "s_residual", "amp", "amp_units", "s_wgt",
                                   "p_dt", "s_dt", "epi_dist", "emergence_angle",
                                   "amp_mag_wgt_code", "dur_mag_wgt_code",
                                   "period", "sta_remark", "coda_dur", "esaz",
                                   "sta_dur_mag", "sta_amp_mag", "p_importance",
                                   "s_importance", "data_src_code", "dur_mag_code",
                                   "amp_mag_code", "loc_code"]}
schema["Attributes"] = {"year":                     {"dtype": int,
                                                     "width": 4,
                                                     "null":  -999},
                        "month":                    {"dtype": int,
                                                     "width": 2,
                                                     "null":  -9},
                        "day":                      {"dtype": int,
                                                     "width": 2,
                                                     "null":  -9},
                        "hour":                     {"dtype": int,
                                                     "width": 2,
                                                     "null":  -9},
                        "minute":                   {"dtype": int,
                                                     "width": 2,
                                                     "null":  -9},
                        "second":                   {"dtype": float,
                                                     "width": 4,
                                                     "null":  -999,
                                                     "const": 1e-2},
                        "lat_deg":                  {"dtype": int,
                                                     "width": 2,
                                                     "null":  -9},
                        "is_south":                 {"dtype": bool,
                                                     "width": 1,
                                                     "null":  False},
                        "lat_min":                  {"dtype": float,
                                                     "width": 4,
                                                     "null":  -999,
                                                     "const": 1e-2},
                        "lon_deg":                  {"dtype": int,
                                                     "width": 3,
                                                     "null":  -99},
                        "is_east":                  {"dtype": bool,
                                                     "width": 1,
                                                     "null":  False},
                        "lon_min":                  {"dtype": float,
                                                     "width": 4,
                                                     "null":  -999,
                                                     "const": 1e-2},
                        "depth" :                   {"dtype": float,
                                                     "width": 5,
                                                     "null":  -9999,
                                                     "const": 1e-2},
                        "amp_mag":                  {"dtype": float,
                                                     "width": 3,
                                                     "null":  -999,
                                                     "const": 1e-2},
                        "narr":                     {"dtype": int,
                                                     "width": 3,
                                                     "null":  -99},
                        "maxazgap":                 {"dtype": int,
                                                     "width": 3,
                                                     "null":  -99},
                        "nearest":                  {"dtype": int,
                                                     "width": 3,
                                                     "null":  -99},
                        "rms":                      {"dtype": float,
                                                     "width": 4,
                                                     "null":  -999,
                                                     "const": 1e-2},
                        "az_err_max":               {"dtype": int,
                                                     "width": 3,
                                                     "null":  -99},
                        "dip_err_max":              {"dtype": int,
                                                     "width": 2,
                                                     "null":  -9},
                        "size_err_max":             {"dtype": float,
                                                     "width": 4,
                                                     "null":  -999,
                                                     "const": 1e-2},
                        "az_err_int":               {"dtype": int,
                                                     "width": 3,
                                                     "null":  -99},
                        "dip_err_int":              {"dtype": int,
                                                     "width": 2,
                                                     "null":  -9},
                        "size_err_int":             {"dtype": float,
                                                     "width": 4,
                                                     "null":  -999,
                                                     "const": 1e-2},
                        "coda_mag":                 {"dtype": float,
                                                     "width": 3,
                                                     "null":  -990,
                                                     "const": 1e-2},
                        "ev_loc_remark":            {"dtype": str,
                                                     "width": 3,
                                                     "null":  "-"},
                        "size_err_min":             {"dtype": float,
                                                     "width": 4,
                                                     "null":  -999,
                                                     "const": 1e-2},
                        "aux_analyst_remark":       {"dtype": str,
                                                     "width": 1,
                                                     "null":  "-"},
                        "aux_prog_remark":          {"dtype": str,
                                                     "width": 1,
                                                     "null":  "-"},
                        "narr_S":                   {"dtype": int,
                                                     "width": 3,
                                                     "null":  -99},
                        "err_h":                    {"dtype": float,
                                                     "width": 4,
                                                     "null":  -999,
                                                     "const": 1e-2}, 
                        "err_v":                    {"dtype": float,
                                                     "width": 4,
                                                     "null":  -999,
                                                     "const": 1e-2},
                        "n_P_fm":                   {"dtype": int,
                                                     "width": 3,
                                                     "null":  -99},
                        "tot_amp_mag_wgt":          {"dtype": float,
                                                     "width": 4,
                                                     "null":  -999,
                                                     "const": 1e-1},
                        "tot_dur_mag_wgt":          {"dtype": float,
                                                     "width": 4,
                                                     "null":  -999,
                                                     "const": 1e-1},
                        "med_abs_dif_amp_mag":      {"dtype": float,
                                                     "width": 3,
                                                     "null":  -99,
                                                     "const": 1e-2},
                        "med_abs_dif_dur_mag":      {"dtype": float,
                                                     "width": 3,
                                                     "null":  -99,
                                                     "const": 1e-2},
                        "crustal_model":            {"dtype": str,
                                                     "width": 3,
                                                     "null":  "-"},
                        "authority":                {"dtype": str,
                                                     "width": 1,
                                                     "null":  "-"},
                        "PS_data_src":              {"dtype": str,
                                                     "width": 1,
                                                     "null":  "-"},
                        "dur_data_src":             {"dtype": str,
                                                     "width": 1,
                                                     "null":  "-"},
                        "amp_data_src":             {"dtype": str,
                                                     "width": 1,
                                                     "null":  "-"},
                        "primary_coda_dur_mag_type":{"dtype": str,
                                                     "width": 1,
                                                     "null":  "-"},
                        "nass":                     {"dtype": int,
                                                     "width": 3,
                                                     "null":  -99},
                        "primary_amp_mag_type":     {"dtype": str,
                                                     "width": 1,
                                                     "null":  "-"},
                        "ext_mag_type":             {"dtype": str,
                                                     "width": 1,
                                                     "null":  "-"},
                        "ext_mag":                  {"dtype": float,
                                                     "width": 3,
                                                     "null":  -99,
                                                     "const": 1e-2},
                        "tot_ext_mag_wgt":          {"dtype": float,
                                                     "width": 3,
                                                     "null":  -99,
                                                     "const": 1e-1},
                        "alt_amp_mag_type":         {"dtype": str,
                                                     "width": 1,
                                                     "null":  "-"},
                        "alt_amp_mag":              {"dtype": float,
                                                     "width": 3,
                                                     "null":  -99,
                                                     "const": 1e-2},
                        "tot_alt_amp_mag_wgt":      {"dtype": float,
                                                     "width": 3,
                                                     "null":  -99,
                                                     "const": 1e-1},
                        "evid":                     {"dtype": int,
                                                     "width": 10,
                                                     "null":  -999999999}, 
                        "pref_mag_type":            {"dtype": str,
                                                     "width": 1,
                                                     "null":  "-"},
                        "pref_mag":                 {"dtype": float,
                                                     "width": 3,
                                                     "null":  -99,
                                                     "const": 1e-2},
                        "tot_pref_mag_wgt":         {"dtype": float,
                                                     "width": 4,
                                                     "null":  -999,
                                                     "const": 1e-1},
                        "alt_coda_dur_mag_type":    {"dtype": str,
                                                     "width": 1,
                                                     "null":  "-"},
                        "alt_coda_dur_mag":         {"dtype": float,
                                                     "width": 3,
                                                     "null":  -999,
                                                     "const": 1e-2},
                        "tot_alt_coda_dur_mag_wgt": {"dtype": float,
                                                     "width": 4,
                                                     "null":  -999,
                                                     "const": 1e-2},
                        "info_version":             {"dtype": str,
                                                     "width": 1,
                                                     "null":  "-"},
                        "revision_version":         {"dtype": str,
                                                     "width": 1,
                                                     "null":  "-"},
                        "sta":                      {"dtype": str,
                                                     "width": 5,
                                                     "null": "-"}, 
                        "net":                      {"dtype": str,
                                                     "width": 2,
                                                     "null": "-"}, 
                        "blank1":                   {"dtype": str,
                                                     "width": 1,
                                                     "null": " "}, 
                        "comp":                     {"dtype": str,
                                                     "width": 1,
                                                     "null": "-"}, 
                        "chan":                     {"dtype": str,
                                                     "width": 3,
                                                     "null": "-"},
                        "blank2":                   {"dtype": str,
                                                     "width": 1,
                                                     "null": " "}, 
                        "p_remark":                 {"dtype": str,
                                                     "width": 2,
                                                     "null": "-"}, 
                        "p_fm":                     {"dtype": str,
                                                     "width": 1,
                                                     "null": "-"}, 
                        "p_wgt_code":               {"dtype": str,
                                                     "width": 1,
                                                     "null": 0},
#                         "year":                     {"dtype": str,
#                                                      "width": 4,
#                                                      "null": -999}, 
#                         "month":                    {"width": 2,
#                                                      "null": -9}, 
#                         "day":                      {"width": 2,
#                                                      "null": -9}, 
#                         "hour":                     {"width": 2,
#                                                      "null": -9}, 
#                         "minute":                   {"width": 2,
#                                                      "null": -9},           
                        "p_second":                 {"dtype": float,
                                                     "width": 5,
                                                     "null": -9999,
                                                     "const": 1e-2}, 
                        "p_residual":               {"dtype": float,
                                                     "width": 4,
                                                     "null": -999,
                                                     "const": 1e-2}, 
                        "p_wgt":                    {"dtype": float,
                                                     "width": 3,
                                                     "null": -99,
                                                     "const": 1e-2}, 
                        "s_second":                 {"dtype": float,
                                                     "width": 5,
                                                     "null": -9999,
                                                     "const": 1e-2},
                        "s_remark":                 {"dtype": str,
                                                     "width": 2,
                                                     "null": "-"}, 
                        "blank3":                   {"dtype": str,
                                                     "width": 1,
                                                     "null": " "}, 
                        "s_wgt_code":               {"dtype": int,
                                                     "width": 1,
                                                     "null": 0},
                        "s_residual":               {"dtype": float,
                                                     "width": 4,
                                                     "null": -999,
                                                     "const": 1e-2}, 
                        "amp":                      {"dtype": float,
                                                     "width": 7,
                                                     "null": -999999,
                                                     "const": 1e-2}, 
                        "amp_units":                {"dtype": int,
                                                     "width": 2,
                                                     "null": -1}, 
                        "s_wgt":                    {"dtype": float,
                                                     "width": 3,
                                                     "null": -99,
                                                     "const": 1e-2},
                        "p_dt":                     {"dtype": float,
                                                     "width": 4,
                                                     "null": -999,
                                                     "const": 1e-2}, 
                        "s_dt":                     {"dtype": float,
                                                     "width": 4,
                                                     "null": -999,
                                                     "const": 1e-2}, 
                        "epi_dist":                 {"dtype": float,
                                                     "width": 4,
                                                     "null": -999,
                                                     "const": 1e-1}, 
                        "emergence_angle":          {"dtype": int,
                                                     "width": 3,
                                                     "null": -99},
                        "amp_mag_wgt_code":         {"dtype": int,
                                                     "width": 1,
                                                     "null": 0}, 
                        "dur_mag_wgt_code":         {"dtype": int,
                                                     "width": 1,
                                                     "null": 0},
                        "period":                   {"dtype": float,
                                                     "width": 3,
                                                     "null": -99,
                                                     "const": 1e-2}, 
                        "sta_remark":               {"dtype": str,
                                                     "width": 1,
                                                     "null": "-"}, 
                        "coda_dur":                 {"dtype": int,
                                                     "width": 4,
                                                     "null": -999}, 
                        "esaz":                     {"dtype": int,
                                                     "width": 3,
                                                     "null": -99},
                        "sta_dur_mag":              {"dtype": float,
                                                     "width": 3,
                                                     "null": -99,
                                                     "const": 1e-2}, 
                        "sta_amp_mag":              {"dtype": float,
                                                     "width": 3,
                                                     "null": -99,
                                                     "const": 1e-2}, 
                        "p_importance":             {"dtype": float,
                                                     "width": 4,
                                                     "null": -999,
                                                     "const": 1e-3},
                        "s_importance":             {"dtype": float,
                                                     "width": 4,
                                                     "null": -999,
                                                     "const": 1e-3}, 
                        "data_src_code":            {"dtype": str,
                                                     "width": 1,
                                                     "null": "-"}, 
                        "dur_mag_code":             {"dtype": str,
                                                     "width": 1,
                                                     "null": "-"},
                        "amp_mag_code":             {"dtype": str,
                                                     "width": 1,
                                                     "null": "-"}, 
                        "loc_code":                 {"dtype": str,
                                                     "width": 2,
                                                     "null": "-"}
    
}

In [299]:
with open("../data/schemas/hypoinverse2000.pkl", "wb") as outf:
    pickle.dump(schema, outf)