UCBerkeleySETI / hyperseti

A SETI / technosignature search code to find intelligent life beyond Earth
https://hyperseti.readthedocs.io
10 stars 4 forks source link

test_hyperseti.py needs some help #43

Closed texadactyl closed 2 years ago

texadactyl commented 2 years ago

I created PR #42 while I was exporing the possibility of creating a .dat writer for the turbo_seti pipelines. I understand that the hyperseti paradigm is very different from turbo_seti.

I quickly found that the test_hyperseti functions are a bit more of a challenge. I changed the assert statements to if statements + some print-debug statements + a generic oops function to display where the encountered trouble was but keep on going (might have been a mistake).

I inserted some print-debug statements also in hyperseti/hits.pyalthough the pain probably started in test_hyperseti.py.

A stdout/stderr log based on the PR code follows.

python3 test/test_hyperseti.py
bshuf filter already loaded, skip it.
lz4 filter already loaded, skip it.
zfp filter already loaded, skip it.
<class 'hyperseti.data_array.DataArray'>
<DataArray: shape=(65, 1, 1024), dims=('drift_rate', 'feed_id', 'frequency')>
[[[5.4800777 5.656854  5.656854  ... 5.656854  5.656854  5.656854 ]]

 [[5.4800777 5.656854  5.656854  ... 5.656854  5.656854  5.656854 ]]

 [[5.4800777 5.656854  5.656854  ... 5.656854  5.656854  5.656854 ]]

 ...

 [[5.4800777 5.656854  5.656854  ... 5.4800777 5.4800777 5.4800777]]

 [[5.4800777 5.656854  5.656854  ... 5.4800777 5.4800777 5.4800777]]

 [[5.4800777 5.656854  5.656854  ... 5.4800777 5.4800777 5.4800777]]]
56.568542 320.0
max dedopp.data = 56.568542, sum test_data(freq.col=511) = 320.0
blimpy.waterfall INFO     __write_to_fil_light: Writing the spectra matrix for /mnt_home/texadactyl/hyperseti/test/test_data/synthetic.fil in one go.
blimpy.waterfall INFO     Conversion time: 0.00sec
After dedoppler, metadata = {'name': 'synthetic.fil', 'source': 'Synthetic', 'sky_coord': <SkyCoord (ICRS): (ra, dec) in deg
    (266.8125, -28.3831)>, 'feed_id_start': <Quantity 0.>, 'feed_id_step': <Quantity 0.>, 'frequency_start': <Quantity 1000. MHz>, 'frequency_step': <Quantity -1.e-06 MHz>, 'drift_rate_start': <Quantity -1. Hz / s>, 'drift_rate_step': <Quantity -0.03125 Hz / s>, 'boxcar_size': 1, 'n_integration': 32, 'integration_time': <Quantity 1. s>, 'obs_len': <Quantity 32. s>, 'output_dims': ('drift_rate', 'feed_id', 'frequency')}
dedopp.data: (65, 1, 1024)
After imshow_dedopp(), maxpixel = 32267, mdrift = 31, mchan = 523, optimal_drift = [[5.393019  5.5990314 4.7095222 ... 6.240512  6.3266597 6.0756645]], maxpixel_val = 359.7235412597656, frac_recovered = 0.17677671802851463
Inserted drift rate:  0.0 Hz / s    SUM: 2034.90
Recovered drift rate: [[5.393019  5.5990314 4.7095222 ... 6.240512  6.3266597 6.0756645]] Hz / s    SUM: 359.72

dr_test 0.0: mdrift = 31, mchan = 523
****************************** Assertion FAILED at line 97 !!
dr_test 0.0: max optimal_drift = 359.7235412597656
dr_test 0.0: 1.01*np.abs(metadata['drift_rate_step'].value = 0.0315625
****************************** Assertion FAILED at line 106 !!
Is 1.001 >= frac_recovered >= 0.825 ? frac_recovered = 0.17677671802851463
****************************** Assertion FAILED at line 112 !!
blimpy.waterfall INFO     __write_to_fil_light: Writing the spectra matrix for /mnt_home/texadactyl/hyperseti/test/test_data/synthetic.fil in one go.
blimpy.waterfall INFO     Conversion time: 0.00sec
After dedoppler, metadata = {'name': 'synthetic.fil', 'source': 'Synthetic', 'sky_coord': <SkyCoord (ICRS): (ra, dec) in deg
    (266.8125, -28.3831)>, 'feed_id_start': <Quantity 0.>, 'feed_id_step': <Quantity 0.>, 'frequency_start': <Quantity 1000. MHz>, 'frequency_step': <Quantity -1.e-06 MHz>, 'drift_rate_start': <Quantity -1. Hz / s>, 'drift_rate_step': <Quantity -0.03125 Hz / s>, 'boxcar_size': 1, 'n_integration': 32, 'integration_time': <Quantity 1. s>, 'obs_len': <Quantity 32. s>, 'output_dims': ('drift_rate', 'feed_id', 'frequency')}
dedopp.data: (65, 1, 1024)
After imshow_dedopp(), maxpixel = 36363, mdrift = 35, mchan = 523, optimal_drift = [[9.132555  7.550178  7.2725673 ... 7.7452145 9.132409  9.46066  ]], maxpixel_val = 268.7881774902344, frac_recovered = 0.16090259978919494
Inserted drift rate:  0.1 Hz / s    SUM: 1670.50
Recovered drift rate: [[9.132555  7.550178  7.2725673 ... 7.7452145 9.132409  9.46066  ]] Hz / s    SUM: 268.79

dr_test 0.1: mdrift = 35, mchan = 523
****************************** Assertion FAILED at line 97 !!
dr_test 0.1: max optimal_drift = 268.7881774902344
dr_test 0.1: 1.01*np.abs(metadata['drift_rate_step'].value = 0.0315625
****************************** Assertion FAILED at line 106 !!
Is 1.001 >= frac_recovered >= 0.825 ? frac_recovered = 0.16090259978919494
****************************** Assertion FAILED at line 112 !!
blimpy.waterfall INFO     __write_to_fil_light: Writing the spectra matrix for /mnt_home/texadactyl/hyperseti/test/test_data/synthetic.fil in one go.
blimpy.waterfall INFO     Conversion time: 0.03sec
After dedoppler, metadata = {'name': 'synthetic.fil', 'source': 'Synthetic', 'sky_coord': <SkyCoord (ICRS): (ra, dec) in deg
    (266.8125, -28.3831)>, 'feed_id_start': <Quantity 0.>, 'feed_id_step': <Quantity 0.>, 'frequency_start': <Quantity 1000. MHz>, 'frequency_step': <Quantity -1.e-06 MHz>, 'drift_rate_start': <Quantity -1. Hz / s>, 'drift_rate_step': <Quantity -0.03125 Hz / s>, 'boxcar_size': 1, 'n_integration': 32, 'integration_time': <Quantity 1. s>, 'obs_len': <Quantity 32. s>, 'output_dims': ('drift_rate', 'feed_id', 'frequency')}
dedopp.data: (65, 1, 1024)
After imshow_dedopp(), maxpixel = 49675, mdrift = 48, mchan = 523, optimal_drift = [[8.729185  9.032316  8.608066  ... 7.5744076 7.1326866 8.373544 ]], maxpixel_val = 266.0753479003906, frac_recovered = 0.17299858893039147
Inserted drift rate:  0.5 Hz / s    SUM: 1538.02
Recovered drift rate: [[8.729185  9.032316  8.608066  ... 7.5744076 7.1326866 8.373544 ]] Hz / s    SUM: 266.08

dr_test 0.5: mdrift = 48, mchan = 523
****************************** Assertion FAILED at line 97 !!
dr_test 0.5: max optimal_drift = 266.0753479003906
dr_test 0.5: 1.01*np.abs(metadata['drift_rate_step'].value = 0.0315625
****************************** Assertion FAILED at line 106 !!
Is 1.001 >= frac_recovered >= 0.825 ? frac_recovered = 0.17299858893039147
****************************** Assertion FAILED at line 112 !!
blimpy.waterfall INFO     __write_to_fil_light: Writing the spectra matrix for /mnt_home/texadactyl/hyperseti/test/test_data/synthetic.fil in one go.
blimpy.waterfall INFO     Conversion time: 0.00sec
After dedoppler, metadata = {'name': 'synthetic.fil', 'source': 'Synthetic', 'sky_coord': <SkyCoord (ICRS): (ra, dec) in deg
    (266.8125, -28.3831)>, 'feed_id_start': <Quantity 0.>, 'feed_id_step': <Quantity 0.>, 'frequency_start': <Quantity 1000. MHz>, 'frequency_step': <Quantity -1.e-06 MHz>, 'drift_rate_start': <Quantity -1. Hz / s>, 'drift_rate_step': <Quantity -0.03125 Hz / s>, 'boxcar_size': 1, 'n_integration': 32, 'integration_time': <Quantity 1. s>, 'obs_len': <Quantity 32. s>, 'output_dims': ('drift_rate', 'feed_id', 'frequency')}
dedopp.data: (65, 1, 1024)
After imshow_dedopp(), maxpixel = 24075, mdrift = 23, mchan = 523, optimal_drift = [[5.04603   6.302264  4.7610254 ... 6.612774  6.786233  5.885635 ]], maxpixel_val = 258.6223449707031, frac_recovered = 0.15950799194051488
Inserted drift rate:  -0.25 Hz / s  SUM: 1621.38
Recovered drift rate: [[5.04603   6.302264  4.7610254 ... 6.612774  6.786233  5.885635 ]] Hz / s    SUM: 258.62

dr_test -0.25: mdrift = 23, mchan = 523
****************************** Assertion FAILED at line 97 !!
dr_test -0.25: max optimal_drift = 258.6223449707031
dr_test -0.25: 1.01*np.abs(metadata['drift_rate_step'].value = 0.0315625
****************************** Assertion FAILED at line 106 !!
Is 1.001 >= frac_recovered >= 0.825 ? frac_recovered = 0.15950799194051488
****************************** Assertion FAILED at line 112 !!
blimpy.waterfall INFO     __write_to_fil_light: Writing the spectra matrix for /mnt_home/texadactyl/hyperseti/test/test_data/synthetic.fil in one go.
blimpy.waterfall INFO     Conversion time: 0.00sec
After dedoppler, metadata = {'name': 'synthetic.fil', 'source': 'Synthetic', 'sky_coord': <SkyCoord (ICRS): (ra, dec) in deg
    (266.8125, -28.3831)>, 'feed_id_start': <Quantity 0.>, 'feed_id_step': <Quantity 0.>, 'frequency_start': <Quantity 1000. MHz>, 'frequency_step': <Quantity -1.e-06 MHz>, 'drift_rate_start': <Quantity -1. Hz / s>, 'drift_rate_step': <Quantity -0.03125 Hz / s>, 'boxcar_size': 1, 'n_integration': 32, 'integration_time': <Quantity 1. s>, 'obs_len': <Quantity 32. s>, 'output_dims': ('drift_rate', 'feed_id', 'frequency')}
dedopp.data: (65, 1, 1024)
After imshow_dedopp(), maxpixel = 15883, mdrift = 15, mchan = 523, optimal_drift = [[3.3807323 5.160872  5.6698303 ... 5.16032   5.825094  5.429008 ]], maxpixel_val = 271.9976806640625, frac_recovered = 0.17652844360663703
Inserted drift rate:  -0.5 Hz / s   SUM: 1540.82
Recovered drift rate: [[3.3807323 5.160872  5.6698303 ... 5.16032   5.825094  5.429008 ]] Hz / s    SUM: 272.00

dr_test -0.5: mdrift = 15, mchan = 523
****************************** Assertion FAILED at line 97 !!
dr_test -0.5: max optimal_drift = 271.9976806640625
dr_test -0.5: 1.01*np.abs(metadata['drift_rate_step'].value = 0.0315625
****************************** Assertion FAILED at line 106 !!
Is 1.001 >= frac_recovered >= 0.825 ? frac_recovered = 0.17652844360663703
****************************** Assertion FAILED at line 112 !!
test/test_hyperseti.py:118: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
  plt.show()
Total power in frame: 320.0
MAXHOLD recovered power: 160.0
dedopp recovered power (boxcar 1): 40.0 and maxhold_res = 160.0
****************************** Assertion FAILED at line 163 !!
dedopp recovered power (boxcar 2): 60.0 and np.sum(bg) : 320.0
****************************** Assertion FAILED at line 177 !!
test/test_hyperseti.py:186: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
  plt.show()
blimpy.waterfall INFO     __write_to_fil_light: Writing the spectra matrix for /mnt_home/texadactyl/hyperseti/test/test_data/synthetic.fil in one go.
blimpy.waterfall INFO     Conversion time: 0.01sec
--- Run dedoppler() then hitsearch() ---
DEBUG hitsearch incoming metadata: {'name': 'synthetic.fil', 'source': 'Synthetic', 'sky_coord': <SkyCoord (ICRS): (ra, dec) in deg
    (266.8125, -28.3831)>, 'boxcar_size': 16, 'n_integration': 32, 'integration_time': <Quantity 1. s>, 'obs_len': <Quantity 32. s>, 'input_dims': ('drift_rate', 'feed_id', 'frequency'), 'drift_rate_start': <Quantity -1. Hz / s>, 'drift_rate_step': <Quantity -0.03125 Hz / s>, 'feed_id_start': <Quantity 0.>, 'feed_id_step': <Quantity 0.>, 'frequency_start': <Quantity 1000. MHz>, 'frequency_step': <Quantity -1.e-06 MHz>}
DEBUG hitsearch incoming dedopp: (65, 1, 4096), 1st 3 in 1st column: [-11.011711 -11.29988  -11.54392 ]
DEBUG hitsearch drift_trials: (65,), 1st 3: [-11.011711 -11.29988  -11.54392 ]
DEBUG min_fdistance = 32, min_ddistance = 16
DEBUG intensity = [7749.9854], fcoords = [2056], dcoords = [33]
DEBUG hitsearch: driftrate_peaks: [-0.]
DEBUG hitsearch: frequency_peaks: [999.997944] MHz
hitsearch: results type <class 'dict'>, value: {'drift_rate': array([-0.], dtype=float32), 'f_start': <Quantity [999.997944] MHz>, 'snr': array([7749.9854], dtype=float32), 'driftrate_idx': array([33]), 'channel_idx': array([2056]), 'beam_idx': 0, 'boxcar_size': 16, 'n_integration': 32}
Traceback (most recent call last):
  File "test/test_hyperseti.py", line 311, in <module>
    test_hitsearch()
  File "test/test_hyperseti.py", line 210, in test_hitsearch
    hits0 = hitsearch(dedopp, threshold=1000)
  File "/home/texadactyl/.local/lib/python3.7/site-packages/hyperseti-0.0.1-py3.7.egg/hyperseti/utils.py", line 163, in inner
    output = func(*args, **kwargs)
  File "/home/texadactyl/.local/lib/python3.7/site-packages/hyperseti-0.0.1-py3.7.egg/hyperseti/utils.py", line 69, in inner
    output = func(*new_args, **kwargs)
  File "/home/texadactyl/.local/lib/python3.7/site-packages/hyperseti-0.0.1-py3.7.egg/hyperseti/hits.py", line 155, in hitsearch
    df = pd.DataFrame.from_dict(results)
  File "/home/texadactyl/.local/lib/python3.7/site-packages/pandas/core/frame.py", line 1593, in from_dict
    return cls(data, index=index, columns=columns, dtype=dtype)
  File "/home/texadactyl/.local/lib/python3.7/site-packages/pandas/core/frame.py", line 614, in __init__
    mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)
  File "/home/texadactyl/.local/lib/python3.7/site-packages/pandas/core/internals/construction.py", line 465, in dict_to_mgr
    arrays, data_names, index, columns, dtype=dtype, typ=typ, consolidate=copy
  File "/home/texadactyl/.local/lib/python3.7/site-packages/pandas/core/internals/construction.py", line 124, in arrays_to_mgr
    arrays = _homogenize(arrays, index, dtype)
  File "/home/texadactyl/.local/lib/python3.7/site-packages/pandas/core/internals/construction.py", line 590, in _homogenize
    val, index, dtype=dtype, copy=False, raise_cast_failure=False
  File "/home/texadactyl/.local/lib/python3.7/site-packages/pandas/core/construction.py", line 564, in sanitize_array
    data = np.asarray(data)
  File "cupy/core/core.pyx", line 1188, in cupy.core.core.ndarray.__array__
TypeError: Implicit conversion to a NumPy array is not allowed. Please use `.get()` to construct a NumPy array explicitly.
texadactyl commented 2 years ago

New approach.