|
1 | 1 | from astropy.io import fits |
2 | 2 | import tensorflow as tf |
3 | 3 | import numpy as np |
4 | | -from src.data.data import read_spectra_data as read_data |
| 4 | +from src.data.tfrecords import read_spectra_data as read_data |
5 | 5 | from src.utilities import PlotGenSamples |
6 | 6 |
|
7 | 7 | def _plot(data, params_data, name, n=5): |
8 | 8 | p = PlotGenSamples(nrows=n, ncols=1) |
9 | 9 | p.plot_spectra(data[:n], params_data[0][:n], name) |
10 | 10 |
|
11 | | -batch_size = 512 |
12 | | -dataset_size = 255483 |
13 | | -files_path = '/fred/oz012/Bruno/data/spectra/boss/cmass/' |
14 | | -dataset = read_data(files_path+'spectra.tfrecord', 3500) |
| 11 | +batch_size = 1 |
| 12 | +dataset_size = 22791 |
| 13 | +files_path = '/fred/oz012/Bruno/data/spectra/qso_zWarning/' |
| 14 | +dataset = read_data(files_path+'spectra2_.tfrecord', 3500) |
15 | 15 | dataset = dataset.repeat(1).batch(batch_size) |
16 | 16 | nbatches = int(np.ceil(dataset_size/batch_size)) |
17 | 17 |
|
18 | 18 | iterator = dataset.make_initializable_iterator() |
19 | 19 | next_element = iterator.get_next() |
20 | 20 |
|
| 21 | +counter = 0 |
21 | 22 | with tf.Session() as sess: |
22 | 23 | sess.run(iterator.initializer) |
23 | | - for item in range(5): |
| 24 | + for item in range(2): |
24 | 25 | inputs, *params = sess.run(next_element) |
| 26 | + counter += 1 |
| 27 | + if counter%10000==0: |
| 28 | + print(counter) |
25 | 29 | _plot(inputs, params, name='tfrecord_data_'+str(item)) |
26 | 30 |
|
27 | | -""" |
28 | | -local_path = '/fred/oz012/Bruno/data/spectra/boss/loz/7415/spec-7415-57097-0197.fits' |
29 | | -with fits.open(local_path) as hdu: |
30 | | - flux_ = hdu[1].data['flux'].astype(np.float32) |
31 | | - lam_ = np.power( 10, hdu[1].data['loglam'] ).astype(np.float32) |
32 | | - |
33 | | - print(flux_) |
34 | | - print(min(flux_)) |
35 | | -""" |
0 commit comments