astrobase.checkplot.pkl_io module

This contains utility functions that support the checkplot.pkl input/output functionality.

astrobase.checkplot.pkl_io._base64_to_file(b64str, outfpath, writetostrio=False)[source]

This converts the base64 encoded string to a file.

Parameters:
  • b64str (str) – A base64 encoded strin that is the output of base64.b64encode.
  • outfpath (str) – The path to where the file will be written. This should include an appropriate extension for the file (e.g. a base64 encoded string that represents a PNG should have its outfpath end in a ‘.png’) so the OS can open these files correctly.
  • writetostrio (bool) – If this is True, will return a StringIO object with the binary stream decoded from the base64-encoded input string b64str. This can be useful to embed these into other files without having to write them to disk.
Returns:

If writetostrio is False, will return the output file’s path as a str. If it is True, will return a StringIO object directly. If writing the file fails in either case, will return None.

Return type:

str or StringIO object

astrobase.checkplot.pkl_io._read_checkplot_picklefile(checkplotpickle)[source]

This reads a checkplot gzipped pickle file back into a dict.

NOTE: the try-except is for Python 2 pickles that have numpy arrays in them. Apparently, these aren’t compatible with Python 3. See here:

http://stackoverflow.com/q/11305790

The workaround is noted in this answer:

http://stackoverflow.com/a/41366785

Parameters:checkplotpickle (str) – The path to a checkplot pickle file. This can be a gzipped file (in which case the file extension should end in ‘.gz’)
Returns:This returns a checkplotdict.
Return type:dict
astrobase.checkplot.pkl_io._write_checkplot_picklefile(checkplotdict, outfile=None, protocol=None, outgzip=False)[source]

This writes the checkplotdict to a (gzipped) pickle file.

Parameters:
  • checkplotdict (dict) – This the checkplotdict to write to the pickle file.
  • outfile (None or str) –

    The path to the output pickle file to write. If outfile is None, writes a (gzipped) pickle file of the form:

    checkplot-{objectid}.pkl(.gz)

    to the current directory.

  • protocol (int) –

    This sets the pickle file protocol to use when writing the pickle:

    If None, will choose a protocol using the following rules:

    • 4 -> default in Python >= 3.4 - fast but incompatible with Python 2
    • 3 -> default in Python 3.0-3.3 - mildly fast
    • 2 -> default in Python 2 - very slow, but compatible with Python 2/3

    The default protocol kwarg is None, this will make an automatic choice for pickle protocol that’s best suited for the version of Python in use. Note that this will make pickles generated by Py3 incompatible with Py2.

  • outgzip (bool) – If this is True, will gzip the output file. Note that if the outfile str ends in a gzip, this will be automatically turned on.
Returns:

The absolute path to the written checkplot pickle file. None if writing fails.

Return type:

str