Code Monkey home page Code Monkey logo

nenupy-tf's Introduction

nenupytf

nenupy PyPI download month PyPI pyversions doc

Python3 package to read and analyze NenuFAR Time-Frequency data from UnDySPuTeD.

Installation

nenupytf can be installed via pip, the recommended tool for installing Python packages:

pip install nenupytf

Keep you up-to-date with the latest release and get the newest functionalities by regularly updating the package:

pip install nenupytf --upgrade

Quickstart

Observation informations

Prior to diving within the large data volume, one can quickly get a summary of the observation content with the command:

nenupytf-info --obs /path/to/observation_directory/

The output would look something like:

--------------- nenupytf ---------------
Info on /path/to/observation_directory/OBS_XXX_XXX_0.spectra
Lane: 0
Time: 2019-10-13T07:20:55.0000000 -- 2019-10-13T07:25:54.4404020
Frequency: 39.0625 -- 76.5625 MHz
Beams: [0]
----------------------------------------

displaying for each lane, the time and frequency range as well as the beam indices.

On can also display these informations on individual files by printing the instance of a Lane object:

from nenupytf.read import Lane
l = Lane('OBS_XXX_XXX_0.spectra')
print(l)

Selecting data

To select data from a specific file:

from nenupytf.read import Lane
l = Lane('OBS_XXX_XXX_0.spectra')
time_select = ['2019-10-13 07:25:50.4404020', '2019-10-13 07:25:54.4404020']
freq_select = [50, 54.97]
spec = l.select(time=time_select, freq=freq_select, beam=0, stokes='I')

The select() methods, returns a SpecData object, storing the time (in astropy.time.Time format), the frequency in MHz, and the Dynamic Spectrum (which is a 2D array). Besides, a SpecData object enables several cleaning or analysis methods specific to dynamic spectra.

Averaging on time and frequency may allow to see a full picture of the data. However it may take some time to process!

from nenupytf.read import Lane
l = Lane('OBS_XXX_XXX_0.spectra')
spec = l.average()

Of course, one can specify every parameter such as in the select() method. Besides, average() accepts df and dt, respectively the time bin (in seconds) and the frequency bin (in MHz):

from nenupytf.read import Lane
l = Lane('OBS_XXX_XXX_0.spectra')
time_select = ['2019-10-13 07:25:50.4404020', '2019-10-13 08:00:00.000']
freq_select = [30, 60]
t, f, d = l.average(df=2, dt=3, time=time_select, freq=freq_select, beam=0, stokes='I')

Command-line plot

To display a plot of the selection, simply run:

nenupytf-plot --obs /path/to/observation_directory/ --lane 0 --time 2019-10-13T07:25:50.4404020 2019-10-13T07:25:54.4404020 --freq 50 54.97 --stokes I

nenupy-tf's People

Contributors

alanloh avatar cedricdviou avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

nenupy-tf's Issues

Discontinuity in time selection

When selecting in time and displaying with DAS2 we seem to see a discontinuity in beteween time selections.
Need to check how tome range selections returns time and of there is no overlap / gap.

Flagging

Find a way to flagg the data on the dynamic spectrum level without filtering out astrophysical signal!

Replace np.datetime64 in SpecData

For some methods such as self.tmean(), np.datetime64 are used. Replace them according to the possible inputs and in any case with an astropy.time.Time object.

Concatenate SpecData in time

Override an opperator (maybe __or__(), as __and__() is for frequency concatenation) to allow for time concatenation.

Correct gain jumps at pointing switches

On the time and frequency averaged data (L1), correct for the known gain jumps at pointing switches and keep this information somewhere (it is likely to be stored within the ouptut FITS files).

Average dynamic spectrum

Add a method in Spectrum to average in time and frequency a dynamic spectrum selection.

For the frequency, modify directly within specdata.py and create a new method, something like self.frebin(...)...

Allow kwargs in display methods

Enable the possibility of kwargs inputs in display methods in order to control the plotting output.
For vmin, vmax and cmap maybe do somethign like:

if 'vmin' not in kwargs.keys():
    kwargs['vmin'] = np.percentile(specdata.amp, 5)

...

Convert L1 data to FITS

After first analysis steps (averaging, flagging, data selction on a small sample, correction of pointing switch gain jumps...) depending on the NenuFAR key project,
Create a FITS file with:

  • L1 data (n_time * n_freq * n_beam * n_stokes)

  • Time (n_time)

  • Freq (n_freq)

  • Beam (n_beam)

  • Stokes (n_stokes)

  • Weight table (n_time * n_freq * n_beam * n_stokes): containing 0-1 values representing how much data was flagged to get the averaged point.

  • pointing_switch_correction (n_time): table of correction to 'flatten' the data in time to compensate for the gain jumps due to analog pointing of the Mini-Arrays

  • metadata : this is still a question, do we rely on BST files? Do we copy the entire BST file headers and HDUs (other than data)? Do we select only the relevant informations...?

Frequency wrongly populated

Lane objects contains an error in _get_freq() which causes a shift in returned frequency, altough data is correct...

Background smoothing

Apply a smoothing over the medianed time and frequency to get a smoother backgorund estimation.

Averaging - size sometimes doesnt match

Bug for this case:

from nenupytf.read import Spectrum
s = Spectrum('/databf2/nenufar-tf/20190320_104900_20190320_125000_SUN_TRACKING_BHR')
spec = s.average(time=['2019-03-20T10:49:41.0000000', '2019-03-20T10:49:42.0000000'], freq=[30, 35], dt=0.01)

Improve correction

Use .reshape array before multiplying by the bandpass rather than using np.tile() on the bandpass. This should accelerate the process.

To test :

from nenupytf.read import Spectrum
s = Spectrum('/databf2/nenufar-tf/2019/11/20191122_094700_20191122_130000_SUN_TRACKING')
%prun spec = s.select(time=['2019-11-22T09:47:55.000000', '2019-11-22T09:48:10.000000'], beam=0)
        236338 function calls (236248 primitive calls) in 1.288 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.464    0.464    1.259    1.259 lane.py:297(select)
        1    0.324    0.324    0.554    0.554 stokes.py:92(correct)
       97    0.229    0.002    0.229    0.002 {method 'reduce' of 'numpy.ufunc' objects}

Averaging with dt=0.001 or lower doesnt work

Bug for e.g.:

from nenupytf.read import Spectrum
s = Spectrum('/databf2/nenufar-tf/20190320_104900_20190320_125000_SUN_TRACKING_BHR')
spec = s.average(time=['2019-03-20T10:49:41.0000000', '2019-03-20T10:49:42.0000000'], freq=[30, 35], dt=0.0001)

Display problem with plotdb

from nenupytf.read import Spectrum
from nenupytf.display import plotdb
s = Spectrum('')
spec = s.average(time=['2019-11-22T09:59:30.0000000', '2019-11-22T10:04:30.0000000'], df=0.1, dt=0.1, stokes='I')
plotdb(spec)

Compared to

import matplotlib.pyplot as plt
plt.imshow(spec.db.T, origin='lower', aspect='auto')
plt.show()

Update readme

Once the main functionnalities are working, edit the readme, making sure a standard user can find his way to use the package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.