Skip to content

Commit

Permalink
New argparse formatter
Browse files Browse the repository at this point in the history
Signed-off-by: Devansh Agarwal <[email protected]>
  • Loading branch information
devanshkv committed Nov 1, 2020
1 parent 20af781 commit b740198
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 13 deletions.
3 changes: 2 additions & 1 deletion bin/your_bandpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import argparse

from your import Your
from your.utils.misc import YourArgparseFormatter
from your.utils.plotter import save_bandpass


Expand Down Expand Up @@ -33,7 +34,7 @@ def bandpass(f, time=0, nspectra=8192, outname=None):
parser = argparse.ArgumentParser(
prog="your_bandpass.py",
description="Generate bandpass of data",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
formatter_class=YourArgparseFormatter,
)
parser.add_argument(
"-f",
Expand Down
3 changes: 2 additions & 1 deletion bin/your_candmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from your.candidate import Candidate, crop
from your.utils.gpu import gpu_dedisp_and_dmt_crop
from your.utils.misc import YourArgparseFormatter

logger = logging.getLogger()

Expand Down Expand Up @@ -154,7 +155,7 @@ def cand2h5(cand_val):
parser = argparse.ArgumentParser(
prog="your_candmaker.py",
description="Your candmaker! Make h5 candidates from the candidate csv files",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
formatter_class=YourArgparseFormatter,
)
parser.add_argument("-v", "--verbose", help="Be verbose", action="store_true")
parser.add_argument(
Expand Down
3 changes: 2 additions & 1 deletion bin/your_combine_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from your import Your
from your.formats.pysigproc import SigprocFile
from your.utils.misc import YourArgparseFormatter

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -509,7 +510,7 @@ def all_files(direct, nstart, nsamp, outdir):
parser = argparse.ArgumentParser(
prog="your_combine_mocks.py",
description="Combine two bands from mock spectrometer to a filterbank file.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
formatter_class=YourArgparseFormatter,
)
parser.add_argument("-v", "--verbose", help="Be verbose", action="store_true")
parser.add_argument(
Expand Down
4 changes: 2 additions & 2 deletions bin/your_h5plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import matplotlib
import pandas as pd
import pylab as plt
from rich.logging import RichHandler
from rich.progress import Progress

from your.utils.misc import YourArgparseFormatter
from your.utils.plotter import plot_h5

os.environ["HDF5_USE_FILE_LOCKING"] = "FALSE"
Expand All @@ -34,7 +34,7 @@ def mapper(save, detrend_ft, publication, mad_filter, out_dir, h5_file):
parser = argparse.ArgumentParser(
prog="your_h5plotter.py",
description="Plot candidate h5 files",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
formatter_class=YourArgparseFormatter,
)
parser.add_argument("-v", "--verbose", help="Be verbose", action="store_true")
parser.add_argument(
Expand Down
3 changes: 2 additions & 1 deletion bin/your_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from rich.logging import RichHandler

from your import Your
from your.utils.misc import YourArgparseFormatter


def nice_print(dic):
Expand All @@ -29,7 +30,7 @@ def read_header(f):
parser = argparse.ArgumentParser(
prog="your_header.py",
description="Read header from fits/fil files and print the your header",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
formatter_class=YourArgparseFormatter,
)
parser.add_argument(
"-f",
Expand Down
14 changes: 12 additions & 2 deletions bin/your_heimdall.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
import os
import textwrap
from datetime import datetime
from multiprocessing import Process

Expand All @@ -12,14 +13,23 @@

from your import Your
from your.utils.heimdall import HeimdallManager
from your.utils.misc import MyEncoder
from your.utils.misc import MyEncoder, YourArgparseFormatter
from your.writer import Writer

if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog="your_heimdall.py",
description="Your Heimdall Fetch FRB",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
formatter_class=YourArgparseFormatter,
epilog=textwrap.dedent(
"""\
`your_heimdall.py` allows you to run heimdall with a few extra things listed here.
- Use data in PSRFITS format, just run `your_heimdall.py -f *.fits`.
- Use the RFI mitigation algorithms provided in `your` by adding `rfi_your` to the command.
- Do sub-banded search with `--channel_start` and `--channel_end`.
- Give a channel mask as a text file using `--mask`.
"""
),
)
parser.add_argument("-v", "--verbose", help="Be verbose", action="count", default=0)
parser.add_argument("-f", "--files", help="filterbank or psrfits", nargs="+")
Expand Down
5 changes: 2 additions & 3 deletions bin/your_rfimask.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#!/usr/bin/env python3

import argparse
import logging
from datetime import datetime

import numpy as np
from rich.logging import RichHandler

from your import Your
from your.utils.misc import YourArgparseFormatter
from your.utils.plotter import save_bandpass
from your.utils.rfi import *

if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog="your_rfimask.py",
description="Make Bad channel mask",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
formatter_class=YourArgparseFormatter,
)
parser.add_argument("-f", "--files", help="filterbank or psrfits", nargs="+")
parser.add_argument(
Expand Down
3 changes: 2 additions & 1 deletion bin/your_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from rich.logging import RichHandler

from your import Your
from your.utils.misc import YourArgparseFormatter


# based on https://steemit.com/utopian-io/@hadif66/tutorial-embeding-scipy-matplotlib-with-tkinter-to-work-on-images-in-a-gui-framework
Expand Down Expand Up @@ -297,7 +298,7 @@ def save_figure(self):
parser = argparse.ArgumentParser(
prog="your_viewer.py",
description="Read fits/fil file and show the data",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
formatter_class=YourArgparseFormatter,
)
parser.add_argument(
"-f",
Expand Down
3 changes: 2 additions & 1 deletion bin/your_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from rich.logging import RichHandler

from your import Your
from your.utils.misc import YourArgparseFormatter
from your.writer import Writer

logger = logging.getLogger(__name__)
Expand All @@ -20,7 +21,7 @@
parser = argparse.ArgumentParser(
prog="your_writer.py",
description="Convert/Write files from any format to a single file in any format.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
formatter_class=YourArgparseFormatter,
)
parser.add_argument("-v", "--verbose", help="Be verbose", action="store_true")
parser.add_argument(
Expand Down
10 changes: 10 additions & 0 deletions your/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
logger = logging.getLogger(__name__)
from skimage.transform import resize

import argparse
import json
import os

Expand Down Expand Up @@ -158,3 +159,12 @@ def default(self, obj):
return obj.tolist()
else:
return super(MyEncoder, self).default(obj)

class YourArgparseFormatter(
argparse.ArgumentDefaultsHelpFormatter,
argparse.RawTextHelpFormatter
):
"""
Allows both Raw Text Formatting and Default Args
"""
pass

0 comments on commit b740198

Please sign in to comment.