Skip to content

Instantly share code, notes, and snippets.

@msbentley
Last active October 24, 2017 07:28
Show Gist options
  • Save msbentley/80eac98f6c0ef29f657050db9f194b34 to your computer and use it in GitHub Desktop.
Save msbentley/80eac98f6c0ef29f657050db9f194b34 to your computer and use it in GitHub Desktop.
Example to take PDS4 file and map columns to a pandas dataframe
# pick one table from the FITS file
sixs_x_spectra = sc_six_hk_atti_fit['SIXS-X SPECTRA']
# Get the meta-data (does NOT include arrays (GROUP objects etc.)
# find the field names of the table
cols = [col['name'] for col in sixs_x_spectra.meta_data['Record_Binary']['Field_Binary']]
# create an empty DataFrame with these columns
sixs_x_data = pd.DataFrame([], columns=cols)
# loop over each column name and populate
for col in cols:
sixs_x_data[col] = sc_six_hk_atti_fit['SIXS-X SPECTRA'][col]
# perform any type conversions necessary, e.g. date strings to datetime objects
sixs_x_data['UTC'] = pd.to_datetime(sixs_x_data.UTC)
sixs_x_data['INTEGRATION_START_UTC'] = pd.to_datetime(sixs_x_data.INTEGRATION_START_UTC)
sixs_x_data.CALIB = sixs_x_data.CALIB.astype(bool)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment