threeML.io package

Submodules

threeML.io.calculate_flux module

threeML.io.calculate_flux.calculate_point_source_flux(*args, **kwargs)[source]

threeML.io.configuration module

threeML.io.configuration.get_user_data_path()[source]

threeML.io.detect_notebook module

threeML.io.detect_notebook.is_inside_notebook()[source]

threeML.io.dict_with_pretty_print module

class threeML.io.dict_with_pretty_print.DictWithPrettyPrint[source]

Bases: collections.OrderedDict

A dictionary with a _repr_html method for the Jupyter notebook

display()[source]

threeML.io.download_from_ftp module

threeML.io.download_from_ftp.download_file_from_ftp(ftp_url, destination_directory)[source]
threeML.io.download_from_ftp.download_files_from_directory_ftp(ftp_url, destination_directory, filenames=None, namefilter=None)[source]

threeML.io.download_from_http module

class threeML.io.download_from_http.ApacheDirectory(url)[source]

Bases: object

Allows to interact with a directory listing like the one returned by an Apache server

property directories
download(remote_filename, destination_path: str, new_filename=None, progress=True, compress=False)[source]
download_all_files(destination_path, progress=True, pattern=None)[source]

Download all files in the current directory

Parameters
  • destination_path – the path for the destination directory in the local file system

  • progress – (True or False) whether to display progress or not

  • pattern – (default: None) If not None, only files matching this pattern (a regular expression) will be

downloaded :return: list of the downloaded files as absolute paths in the local file system

property files
exception threeML.io.download_from_http.HTTPError[source]

Bases: OSError

exception threeML.io.download_from_http.RemoteDirectoryNotFound[source]

Bases: OSError

threeML.io.file_utils module

threeML.io.file_utils.file_existing_and_readable(filename) → bool[source]
threeML.io.file_utils.fits_file_existing_and_readable(filename) → bool[source]

checks if a FITS file exists ignoring extension ({}) info

threeML.io.file_utils.get_random_unique_name()[source]

Returns a name which is random and (with extremely high probability) unique

Returns

random file name

threeML.io.file_utils.if_directory_not_existing_then_make(directory) → None[source]

If the given directory does not exists, then make it

Parameters

directory – directory to check or make

Returns

None

threeML.io.file_utils.path_exists_and_is_directory(path) → bool[source]
threeML.io.file_utils.sanitize_filename(filename, abspath: bool = False) → pathlib.Path[source]
threeML.io.file_utils.temporary_directory(prefix='', within_directory=None)[source]

This context manager creates a temporary directory in the most secure possible way (with no race condition), and removes it at the end.

Parameters
  • prefix – the directory name will start with this prefix, if specified

  • within_directory – create within a specific directory (assumed to exist). Otherwise, it will be created in the

default system temp directory (/tmp in unix) :return: the absolute pathname of the provided directory

threeML.io.file_utils.within_directory(directory)[source]

threeML.io.fits_file module

class threeML.io.fits_file.FITSExtension(data_tuple, header_tuple)[source]

Bases: object

classmethod from_fits_file_extension(fits_extension)[source]
property hdu
class threeML.io.fits_file.FITSFile(primary_hdu=None, fits_extensions=None)[source]

Bases: object

index_of(key)[source]

Get the index of an HDU from the HDUList.

keyint, str, tuple of (string, int) or an HDU object

The key identifying the HDU. If key is a tuple, it is of the form (name, ver) where ver is an EXTVER value that must match the HDU being searched for.

If the key is ambiguous (e.g. there are multiple ‘SCI’ extensions) the first match is returned. For a more precise match use the (name, ver) pair.

If even the (name, ver) pair is ambiguous (it shouldn’t be but it’s not impossible) the numeric index must be used to index the duplicate HDU.

When key is an HDU object, this function returns the index of that HDU object in the HDUList.

indexint

The index of the HDU in the HDUList.

ValueError

If key is an HDU object and it is not found in the HDUList.

KeyError

If an HDU specified by the key that is an extension number, extension name, or a tuple of extension name and version is not found in the HDUList.

info(output=None)[source]

Summarize the info of the HDUs in this HDUList.

Note that this function prints its results to the console—it does not return a value.

outputfile, bool, optional

A file-like object to write the output to. If False, does not output to a file and instead returns a list of tuples representing the HDU info. Writes to sys.stdout by default.

writeto(*args, **kwargs)[source]

Write the HDUList to a new file.

fileobjstr, file-like or pathlib.Path

File to write to. If a file object, must be opened in a writeable mode.

output_verifystr

Output verification option. Must be one of "fix", "silentfix", "ignore", "warn", or "exception". May also be any combination of "fix" or "silentfix" with "+ignore", +warn, or +exception" (e.g. ``"fix+warn"). See verify for more info.

overwritebool, optional

If True, overwrite the output file if it exists. Raises an OSError if False and the output file exists. Default is False.

Changed in version 1.3: overwrite replaces the deprecated clobber argument.

checksumbool

When True adds both DATASUM and CHECKSUM cards to the headers of all HDU’s written to the file.

threeML.io.get_heasarc_table_as_pandas module

threeML.io.get_heasarc_table_as_pandas.get_heasarc_table_as_pandas(heasarc_table_name, update=False, cache_time_days=1)[source]

Obtain a a VO table from the HEASARC archives and return it as a pandas table indexed by object/trigger names. The heasarc_table_name values are the ones referenced at:

https://heasarc.gsfc.nasa.gov/docs/archive/vo/

In order to speed up the processing of the tables, 3ML can cache the XML table in a cache that is updated every cache_time_days. The cache can be forced to update, i.e, reload from the web, by setting update to True.

Parameters
  • heasarc_table_name – the name of a HEASARC browse table

  • update – force web read of the table and update cache

  • cache_time_days – number of days to hold the current cache

Returns

pandas DataFrame with results and astropy table

threeML.io.network module

threeML.io.network.internet_connection_is_active()[source]

Check that a internet connection is working by trying contacting the following host:

threeML.io.package_data module

threeML.io.package_data.get_path_of_data_dir() → pathlib.Path[source]
threeML.io.package_data.get_path_of_data_file(data_file) → pathlib.Path[source]
threeML.io.package_data.get_path_of_user_dir() → pathlib.Path[source]

Returns the path of the directory containing the user data (~/.threeML)

Returns

an absolute path

threeML.io.progress_bar module

threeML.io.results_table module

class threeML.io.results_table.ResultsTable(parameter_paths, values, negative_errors, positive_errors, units)[source]

Bases: object

display(key_formatter=<function long_path_formatter>)[source]
property frame

threeML.io.rich_display module

threeML.io.rich_display.fallback_display(x)[source]

threeML.io.serialization module

threeML.io.serialization.pickle_bayesian_analysis(bs)[source]
threeML.io.serialization.pickle_joint_likelihood(jl)[source]

threeML.io.suppress_stdout module

threeML.io.suppress_stdout.suppress_stdout()[source]

Temporarily suppress the output from a function

Returns

None

threeML.io.table module

class threeML.io.table.NumericMatrix(data=None, masked=False, names=None, dtype=None, meta=None, copy=True, rows=None, copy_indices=True, units=None, descriptions=None, **kwargs)[source]

Bases: threeML.io.table.Table

class threeML.io.table.Table(data=None, masked=False, names=None, dtype=None, meta=None, copy=True, rows=None, copy_indices=True, units=None, descriptions=None, **kwargs)[source]

Bases: astropy.table.table.Table

threeML.io.uncertainty_formatter module

threeML.io.uncertainty_formatter.get_uncertainty_tokens(x)[source]

Split the given uncertainty in number, error and exponent.

Parameters

x – an uncertainty instance

Returns

number, error and exponent

threeML.io.uncertainty_formatter.interval_to_errors(value, low_bound, hi_bound)[source]

Convert error intervals to errors

Parameters
  • value – central value

  • low_bound – interval low bound

  • hi_bound – interval high bound

Returns

(error minus, error plus)

threeML.io.uncertainty_formatter.uncertainty_formatter(value, low_bound, hi_bound)[source]

Gets a value and its error in input, and returns the value, the uncertainty and the common exponent with the proper number of significant digits in a string like (4.2 -0.023 +5.23) x 10^5

Parameters
  • value

  • error – a positive value

Returns

string representation of interval

Module contents