gwadama.ioo#

Input & Output Operations

Everything related to input data retrieval and output files.

class gwadama.ioo.CoReManager(db_path)[source]#

Bases: object

Manage easily usual tasks of Watpy’s CoRe_db instances.

Ad-hoc manager to automate and make easier usual tasks in Watpy, including metadata and strain downloads, and spatial projection.

Attributes:
cdbwatpy.coredb.coredb.CoRe_db

Instance of CoRe_db from which everything is managed.

db_pathPath

Folder where is or will be stored CoRe database. Refer to ‘watpy.coredb.coredb.CoRe_db’ for more details.

eosset

All EOS found available.

metadataDataFrame

Metadata from all simulations in ‘cdb’ collected in a single DF.

downloadeddict

3-Level dictionary containing the path to existing strains (saved as TXT files), their eccentricity and radius of extraction. Tree-format:

txt_files[simkey][run] = {

‘file’: ‘path/to/file.txt’, ‘eccentricity’: ecc, ‘r_extraction’: rext

}

NOTE: ONLY KEEPS 1 RUN PER SIMULATION FOR NOW

Methods

cast_to_float(string)

Cast a string to float, considering '' also a NaN.

count_runs([filters])

Count total number of runs in the database.

download_mode22(simkeys[, keep_h5, ...])

Download ONLY the optimum strains Rh_22.

gen_strain(skey, distance, inclination, phi)

Build strain from time-domain mode 22 in mass rescaled, geom.

get_runkey_lowest_eccentricity(skey)

Find the run with the lowest eccentricity for a given simulation.

load_sim(skey)

Load a previously downloaded gw simulation.

sw_Y22(i, phi)

Spin-weighted spherical harmonic mode lm = 22.

filter_by

filter_multiple

show

__init__(db_path)[source]#

Initialize the manager.

Parameters:
db_pathstr

Folder where is or will be stored CoRe database. Refer to ‘watpy.coredb.coredb.CoRe_db’ for more details.

static cast_to_float(string)[source]#

Cast a string to float, considering ‘’ also a NaN.

count_runs(filters=[])[source]#

Count total number of runs in the database.

Parameters:
filterslist of lists

Format: [[key0, value0], [key1, value1], …]

download_mode22(simkeys, keep_h5=False, overwrite=False, prot='https', lfs=False, verbose=True)[source]#

Download ONLY the optimum strains Rh_22.

Downloads each simulation, keeps the strains with the lowest eccentricity and highest extraction point ‘r’ in a TXT file, updates the database ‘self.downloaded’, and (optional) removes the original HDF5 file from CoRe to free up space.

Parameters:
simkeyslist

List of simulation keys (‘db_keys’ in watpy) to download.

keep_h5bool

If False (default) removes the HDF5 file downloaded by watpy.

overwritebool

If False (default) and a certain simulation in ‘simkeys’ is already present in ‘self.downloaded’, skip it. Otherwise downloads everything again.

verbosebool

If True (default), print which simulations are downloaded and which are skipped.

prot, lfs

Refer to ‘watpy.coredb.coredb.CoRe_db.sync’.

fields_float = ['id_mass', 'id_rest_mass', 'id_mass_ratio', 'id_ADM_mass', 'id_ADM_angularmomentum', 'id_gw_frequency_Hz', 'id_gw_frequency_Momega22', 'id_kappa2T', 'id_Lambda', 'id_eccentricity', 'id_mass_starA', 'id_rest_mass_starA', 'id_mass_starB', 'id_rest_mass_starB']#
filter_by(key, value)[source]#
filter_multiple(filters)[source]#
gen_strain(skey, distance, inclination, phi)[source]#

Build strain from time-domain mode 22 in mass rescaled, geom. units.

get_runkey_lowest_eccentricity(skey)[source]#

Find the run with the lowest eccentricity for a given simulation.

Return the key of the run and the value of its eccentricity for which this parameter is the lowest among all runs of the ‘skey’ simulation.

If a simulation has multiple runs with the same eccentricity (typically all values set to 0 or NAN) it will pick the first run in the list.

If there are one or more runs with eccentricity = NAN, the first one will be returned.

Parameters:
skeystr

Key (database_key) of the simulation.

Returns:
run_keystr

Key of the run.

eccfloat

Eccentricity of the run.

header_gw_txt = 'u/M:0 Reh/M:1 Imh/M:2 Redh/M:3 Imdh/M:4 Momega:5 A/M:6 phi:7 t:8'#
load_sim(skey)[source]#

Load a previously downloaded gw simulation.

show(key, to_float=False, to_file=None)[source]#
static sw_Y22(i, phi)[source]#

Spin-weighted spherical harmonic mode lm = 22.

Ref: Ajith et al., 2011

gwadama.ioo.save_experiment_results(file: str, *, parameters: dict, results: dict, sep=';', start_index: int = 0, return_dataframe=False)[source]#

Save (update) experiment results to a CSV using pandas.DataFrame.

Parameters and results are saved as columns in a Pandas DataFrame, in a new row of an existing CSV file, or as the first row if the file does not exists. Each row represents an experiment. Parameters’ keys may change depending on the experiment; when adding a new key or omitting one, the corresponding place in the CSV file will be filled with NaN.

Results are inserted at the beginning of the DataFrame’s columns, and their keys must not change between experiments.

If there is a complex parameter structure, it is recommended to provide a flattened version with new and simpler keys.

Parameters:
filestr

Path to the CSV file. If the file already exists, loads it and appends the experiment data to the end of the DataFrame, and updates the file. If the file does not exist, creates it.

parametersdict

Experiment settings and hyper-parameters. They must be registered in a flat dictionary.

resultsdict

Experiment results, tipically the LOSS overall statistics. For example: ``` results = {

‘loss max’: 0.3, ‘loss_mean’: 0.1, ‘loss_median’: 0.08, ‘loss_min’: 0.001

They will be inserted at the beginning of the DataFrame’s columns.

sepstr

Column separator in the CSV file. ‘;’ by default.

start_indexint

Index of the first row in the experiment (and the CSV file) when creating a new file. If the file already exists, this is ignored. 0 by default.

return_dataframebool

If True, return the DataFrame instance. False by default.

Returns:
dfpandas.DataFrame, optional

The pandas DataFrame instance, only returned if ‘return_dataframe’ is True.

gwadama.ioo.save_to_hdf5(file: str, *, data: dict, metadata: dict) None[source]#

Save nested dictionary of NumPy arrays to HDF5 file with metadata.

Parameters:
file: str

Path to the HDF5 file.

data: dict

Nested dictionary containing NumPy arrays.

metadata: dict

Nested dictionary containing metadata for arrays.