Metadata-Version: 2.4
Name: GBconfusion
Version: 0.1.1
Summary: Tools for galactic confusion estimation with LISA
Author-email: Alice Cravioglio <acravioglio@gmail.com>
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: numpy
Requires-Dist: scipy
Requires-Dist: astropy
Requires-Dist: matplotlib
Requires-Dist: fastgb
Requires-Dist: pycbc
Requires-Dist: h5py
Requires-Dist: argparse
Requires-Dist: lisaorbits
Requires-Dist: pandas
Requires-Dist: pathlib
Requires-Dist: tqdm

## Description

This package provides the tools to estimate the confusion noise PSD generated by galactic binaries. Starting from a source catalog of the binaries, it generates waveforms using the `FastGB` code. Then, the confusion is estimated through an iterative subtraction process of the loudest sources. The outputs are: a set of resolved binaries, the resiual confusion noise PSD, and the parameters of the run. 

The following settings can be modified if needed:
- TDI generation 1.5 or 2.0 (default: 1.5)
- Time of observation (default: 4 years)
- LISA sampling time (default: 5 seconds)
- SNR threshold (default: 7)
- Median filter size for PSD smoothing (default: 2000)
- Instrumental noise (default: TDI A/E channel)
- Distance cut (default: None)

During the pre-processing of the catalog (waveform generation step), there is the possibility to apply a pre-exclusion of weak sources, based on an approximate SNR calculation. This is done through the argument `snr_preselection` (default: 0.001). It is recommended to use a pre-selection SNR not higher than 0.001, to avoid excluding possibly resolvable sources. Pre-excluded sources will be skipped during the waveform generation, and their contribution to the noise automatically added to the PSD.

## Installation

Run 

```
pip install GBconfusion
```

## Usage

**Step 1:** Pre-process binary catalog

```
python -m GBconfusion.preprocess_catalog  --filepath  --output  --T_obs  --delta_t  --tdi  --snr_preselection  --batch_size  --keys
```

**Step 2:** Load the processed data

```
from GBconfusion import load_waveforms

data = load_waveform(output_filepath, distance_cut=None)
```

**Step 3:** Setup the data for the iteration and run it

```
from GBconfusion import setup, run_iterative_separation
from GBconfusion import optimal_snr_AE
from GBconfusion import noise_psd_AE

snr_threshold = 7
tdi = 2.0
T_obs = data['T_obs']
filter_size = 2000
max_iterations = 50
results_filename = 'results_filename'

state = setup(data, snr_calculator = lambda source:optimal_snr_AE(source["A"], source["E"], source["psd_total"], T_obs=T_obs), 
              psd_instrumental=noise_psd_AE, 
              snr_threshold=snr_threshold,
              tdi = tdi,
              filter_size=filter_size)

results = run_iterative_separation(state,
                                   max_iterations=max_iterations, 
                                   filter_size=filter_size, 
                                   print_progress=True, 
                                   plot= False, 
                                   save_results=False, 
                                   output_file= results_filename)

resolved_sources = results["data"]["resolved_table"]
freqs = results["data"]["global_fr"]
psd_final = list(results["data"]["psd_iter"].values())[-1]

```
**Optional:** Load results from hdf5 file if  ```save_results = True ```

```

from GBconfusion.load_run import load_run

results = load_run(results_filepath)

```
