def parse(argv): """ This function accept a list of strings, create and fill a parser istance and return a populated namespace Parameters ---------- argv: list of strings list to be parsed output: namespace --------- """ import argparse as ap import argparse_custom as apc description = """Subtract from the first three columns of the input files the three floats. If they are not provided they will be computed from the files themselves. """ p = ap.ArgumentParser(description=description, formatter_class=ap.ArgumentDefaultsHelpFormatter) p.add_argument( "ifname", action="store", nargs='+', type=ap.FileType('r'), help="Input file name(s), containing z in one of the columns") p = apc.version_verbose(p, '1') p, group = apc.insert_or_replace(p) p, group = apc.overwrite_or_skip(p) p.add_argument("--rescale", action="store", type=float, nargs=3, help="""Values to subtract from the first three columns""") p.add_argument("-o", "--offset", action="store", type=float, default=0, help="""Extra offset to add to 'rescale'""") p.add_argument("--fmt", default="%7.6e", action=apc.StoreFmt, nargs='+', help="Format of the output files") description = """Parameters related to the parallel computation""" p, parallel = apc.parallel_group(p, description=description) return p.parse_args(args=argv)
def parse(argv): """ This function accept a list of strings, create and fill a parser istance and return a populated namespace Parameters ---------- argv: list of strings list to be parsed output: namespace --------- """ import argparse as ap import argparse_custom as apc description = """ Read one or more files and extract a part of the file according to the constraints given. Examples: %(prog)s 'c3 < 4' filename %(prog)s '(c3 < 4) | (c3 > 8)' filename %(prog)s '(c4 > 8) & (c4 < 4)' filename WARNING: The constraint is evaluated with 'eval' and no check is done upon local or global variables.""" p = ap.ArgumentParser(description=description, formatter_class=ap.RawDescriptionHelpFormatter) #p.add_argument("column", action="store", type=int, help="Column to check") p.add_argument("constr", action="store", help="""Constraints to be applied to the desired column""") p.add_argument("ifname", nargs='+', action=apc.file_exists(), help="Input file name(s)") p = apc.version_verbose(p, '1.0') p, group = apc.insert_or_replace(p, print_def=True) p, group = apc.overwrite_or_skip(p) p, pandas = apc.pandas_group(p) p.add_argument("--fmt", default="%7.6e", action=apc.StoreFmt, nargs='+', help="Format of the output files. (default: %(default)s)") description = """Parameters related to the parallel computation""" p, parallel = apc.parallel_group(p, description=description) return p.parse_args(args=argv)
def parse(argv): """ This function accept a list of strings, create and fill a parser istance and return a populated namespace Parameters ---------- argv: list of strings list to be parsed output: namespace --------- """ import argparse as ap import argparse_custom as apc description = "Move or swap some column in a (list of) file(s)." p = ap.ArgumentParser(description=description, ) p.add_argument("from_cols", action="store", type=apc.int_or_list, help="""Column(s) to copy. (if more than one, give them as a string of integers separated by spaces)""") p.add_argument("to_cols", action="store", type=apc.int_or_list, help="""Where to copy the column(s). (if more than one, give them as a string of integers separated by spaces)""") p.add_argument("ifname", action=apc.file_exists(), nargs='+', help="""Input file name(s)""") p = apc.version_verbose(p, '0.1') p.add_argument("-s", "--swap", action="store_true", help="Swap 'from' with 'to'") p.add_argument("--substitute", action="store", type=float, help="""If given, substitutes the content of the columns 'from_cols' not contained in 'to_cols' with '%(dest)s'. This is executed only if 'swap' is *False* and after moving""") p, group = apc.insert_or_replace(p, print_def=True) p, group = apc.overwrite_or_skip(p) p, pandas = apc.pandas_group(p) p.add_argument("--fmt", default="%7.6e", action=apc.StoreFmt, nargs='+', help="Format of the output files. (default: %(default)s)") description = """Parameters related to the parallel computation""" p, parallel = apc.parallel_group( p, description=description ) return p.parse_args(args=argv)
def parse(argv): """ This function accept a list of strings, create and fill a parser istance and return a populated namespace Parameters ---------- argv: list of strings list to be parsed output: namespace --------- """ import argparse as ap import argparse_custom as apc description = """Execute operations between columns and save in a column. Example: c3+c6-1: add column 3 to column 6 and subtract 1. """ p = ap.ArgumentParser( description=description, #formatter_class=apc.RawDescrArgDefHelpFormatter) formatter_class=ap.ArgumentDefaultsHelpFormatter) p.add_argument("operation", action="store", help="""Operation to execute between columns.""") p.add_argument( "to_col", action="store", type=int, help="""Column where the operation is saved. If it is larger than the number of columns, the result is appended""") p.add_argument("ifname", nargs='+', action=apc.file_exists(), help="""Input file name(s)""") p = apc.version_verbose(p, '0.1') p.add_argument( "-s", "--substitute", action="store", type=float, help="""If given, substitutes the content of the columns used for the operation with '%(dest)s'. This is executed before copying the result of the operation to the desired column""") p, group = apc.insert_or_replace(p) p, group = apc.overwrite_or_skip(p) p, pandas = apc.pandas_group(p) p.add_argument("--fmt", default="%7.6e", action=apc.StoreFmt, nargs='+', help="Format of the output files.") description = """Parameters related to the parallel computation""" p, parallel = apc.parallel_group(p, description=description) return p.parse_args(args=argv)
def parse(argv): """ This function accept a list of strings, create and fill a parser istance and return a populated namespace Parameters ---------- argv: list of strings list to be parsed output: namespace --------- """ import argparse as ap import argparse_custom as apc description = """Given a table of 'z,n(z)', subsitute a column in the catalogue(s) with the value of n(z), using the values of z from an other column of the same file """ p = ap.ArgumentParser(description=description, formatter_class=ap.ArgumentDefaultsHelpFormatter) p.add_argument("noz", action="store", type=ap.FileType('r'), help="File containing a table of z, n(z)") p.add_argument( "ifname", nargs='+', action=apc.file_exists(), help="""Input file name(s), containing z in one of the columns""") p = apc.version_verbose(p, '1') p, group = apc.insert_or_replace(p) p, group = apc.overwrite_or_skip(p) p.add_argument("-z", "--z-column", action="store", type=int, default="-1", help="Column in the catalogue with the redshift.") p.add_argument("-n", "--nz-column", action="store", type=int, default="5", help="Column in the catalogue in which n(z) is saved.") p.add_argument("--zn-file-col", action="store", type=int, nargs=2, default=[0, 1], help="""Columns in 'noz' containing z and n(z).""") p.add_argument("--fmt", default="%7.6e", action=apc.StoreFmt, nargs='+', help="Format of the output files") description = """Parameters related to the parallel computation""" p, parallel = apc.parallel_group(p, description=description) return p.parse_args(args=argv)
def parse(argv): """ This function accept a list of strings, create and fill a parser istance and return a populated namespace Parameters ---------- argv: list of strings list to be parsed output: namespace --------- """ import argparse as ap import argparse_custom as apc description = """ Convert the file from ra, dec, redshift into cartesian coordinates assuming a cosmology. The name of the output file name is derived from the input one and the modification can be set with the options. ra, dec and redshift are by default assumed to be in the first three columns, and all the following columns are by default copied after x, y and z. If the number of columns in the input file (or in the ones read) is more than 8 the exceding ones are cut. Redshift is copied in the last column. The output file has the structure x y z w bias n(x,y,z) n_b(z) M redshift (The columns that are not present in the input file are filled with 1, except the redshift)""" p = ap.ArgumentParser(description=description, formatter_class=ap.ArgumentDefaultsHelpFormatter) p.add_argument("ifname", nargs='+', action=apc.file_exists(), help="""Input file name(s), containing ra and dec in the first two columns""") p = apc.version_verbose( p, '1' ) p, group = apc.insert_or_replace(p) p, group = apc.overwrite_or_skip(p) p, pandas = apc.pandas_group(p) description="""Cosmology to use to convert ra, dec and z in distances. h0=1 is equivalent to have the distance in Mpc/h with any other value of h0""" p, cosmo = apc.cosmology_group( p, description=description, h0_def=1. ) cosmo.add_argument("--zrange", action="store", nargs=2, type=float, help="""Lower and upper limit for the redshift. If this option is given the distance is computed only ones and then interpolated in the values in the files""") cosmo.add_argument("--nbins", action="store", type=int, default='500', help='Number of bins in redshift.') p.add_argument('--negative-z', action='store', choices=[None, 'skip', 'tozero'], default=None, help="""If *None* no check on negative redshifts, otherwise either skip the corresponding lines or set to 0""") p.add_argument("--fmt", default="%7.6e", action=apc.StoreFmt, nargs='+', help="Format of the output files") p.add_argument("--usecols", action="store", nargs="+", type=int, help="""Read the selected columns. By default read all the columns.If thi option is used, make sure the the first three columns read in are ra, dec and redshift.""") description = """Parameters related to the parallel computation""" p, parallel = apc.parallel_group( p, description=description ) return p.parse_args(args=argv)
def parse(argv): """ This function accept a list of strings, create and fill a parser istance and return a populated namespace Parameters ---------- argv: list of strings list to be parsed output: namespace --------- """ import argparse as ap import argparse_custom as apc description = """ Computes N(z) and n(z) from one column in a (set of) file(s) and save it (them) for each file and/or computes the mean and save it. Weights can be applied. When the 'area' is not specified, a standard histogram is produced. The output files have the following structure: bin_center bin_lower bin_upper hist (std) std is added only if the mean is required """ p = ap.ArgumentParser(description=description, formatter_class=apc.RawDescrArgDefHelpFormatter) int_or_oper = """If integer, the given column is considered. Operations between columns can be performed preceding the column number with a c: e.g. c3+c6-1 add columns 3 and 6 and subtract 1 from the result. only after the histogram is created""" p.add_argument("column", action="store", type=apc.int_or_str, help="""Columns containing the redshift (or whatever variable for the histogram). """ + int_or_oper) p.add_argument("ifname", nargs='+', action=apc.file_exists(), help="""Input file name(s)""") p, group = apc.insert_or_replace(p) p, group = apc.overwrite_or_skip(p) p = apc.version_verbose(p, '0.1') p.add_argument( "-w", "--weight", action="store", type=apc.int_or_str, help="""Weight for the histogram. Operation permitted as for 'column' If boolean expressions like '(c3==1)&(c6==0)', the weight is interpreted as 1 if *True*, as 0 if *False*""") p.add_argument("-n", "--nbins", action="store", type=int, default='50', help="Number of bins per histogram.") p.add_argument( "--range", action="store", nargs=2, type=float, help="""Lower and upper range of the bins. Computed from the first file if any of the following are required: i) the mean; ii) n(z) [so the area needs to be computed]; iii) pandas and chunks """) p.add_argument("--mean", action="store", type=apc.outfile, help="""Save the mean in file '%(dest)s'""") p.add_argument("--mean-only", action="store_true", help="Only the mean of the histograms is saved") p, pandas = apc.pandas_group(p) description = """ If the area of the survey is given, the effective volume per bin is computed and the histogram of n(z) is returned. 'h0=1' is equivalent to requiring the volume to be in (Mpc/h)^3. For performance reasons, if the range is not given it will be computed as for when the mean is requested""" p, cosmo = apc.cosmology_group(p, description=description, h0_def=1) cosmo.add_argument("-a", "--area", type=float, action="store", help="Area of the survey in steradians") p.add_argument("--fmt", default="%7.6e", action=apc.StoreFmt, nargs='+', help="Format of the output files") description = """Parameters related to the parallel computation""" p, parallel = apc.parallel_group(p, description=description) return p.parse_args(args=argv)
def parse(argv): """ This function accept a list of strings, create and fill a parser istance and return a populated namespace Parameters ---------- argv: list of strings list to be parsed output: namespace --------- """ import argparse as ap import argparse_custom as apc description = """Read two columns c1, c2 from 'replacement' file, then replace in 'column' of the input file(s) c1 -> c2.""" p = ap.ArgumentParser(description=description, formatter_class=ap.ArgumentDefaultsHelpFormatter) p.add_argument("column", action="store", type=int, help="Column to substitute") p.add_argument("replacement", action=apc.file_exists(), help="""File containing the substitution to do.""") p.add_argument("ifname", nargs='+', action=apc.file_exists(), help="Input file name(s)") p = apc.version_verbose(p, '1.0') p, group = apc.insert_or_replace(p, print_def=True) p, group = apc.overwrite_or_skip(p) p.add_argument("-c", "--repl-columns", nargs='+', action=apc.required_length(1, 2), type=int, default=[0, 1], help="""Columns to read from 'replacement' file. If only one column is read, the content of 'column' in 'ifname' is casted to int.""") p, pandas = apc.pandas_group(p) p.add_argument("--fmt", default="%7.6e", action=apc.StoreFmt, nargs='+', help="Format of the output files. (default: %(default)s)") description = """Parameters related to the parallel computation""" p, parallel = apc.parallel_group(p, description=description) return p.parse_args(args=argv)
def parse(argv): """ This function accept a list of strings, create and fill a parser istance and return a populated namespace Parameters ---------- argv: list of strings list to be parsed output: namespace --------- """ import argparse as ap import argparse_custom as apc description = """Give a list of fits files, read some of the columns into a numpy array and then save them into ascii files. Operations between colums permitted but numbers are interpreted as such and not columns. Permitted operations: {0} """.format(permitted_operations) p = ap.ArgumentParser(description=description, formatter_class=ap.ArgumentDefaultsHelpFormatter) p.add_argument( "ifname", nargs='+', action=apc.file_exists(), help="Input file name(s), containing z in one of the columns") p = apc.version_verbose(p, '1') p, group = apc.insert_or_replace(p) p, group = apc.overwrite_or_skip(p) finfo = p.add_argument_group(title="file information", description="""Get information from the fits files""") finfo.add_argument("--show-columns", action="store_true", help="""Print on screen the info for the first file in 'ifname'""") finfo.add_argument("--all-files", action="store_true", help="""Show the info of all the files. Ignored if '--show-columns' not used.""") finfo.add_argument( "--tofile", action="store", type=ap.FileType("w"), help="""Write the output to file '%(dest)s' instead than to stdout. Ignored if '--show-columns' not used.""") p.add_argument( "-c", "--columns", nargs='+', default=["RA", "DEC", "Z"], help="""Read the given column(s). Can be: integer, string and lists. Operations permitted for string entry like 'a+b-1': 'a' and 'b' are column name and '1' a number.""") p.add_argument("--fmt", action=apc.StoreFmt, nargs='+', default="%7.6e", help="Format of the output files.") description = """Parameters related to the parallel computation""" p, parallel = apc.parallel_group(p, description=description) return p.parse_args(args=argv)