Beispiel #1
0
 def test_read_list(self):
     appconfig = config.AppConfig(configfile=self.conffile())
     assert_that(appconfig.read("testsection1.key3"), contains("lval1", "lval2", "lval3"))
Beispiel #2
0
 def test_read_values(self):
     appconfig = config.AppConfig(configfile=self.conffile())
     assert_that(appconfig.read("testsection1.key1"), equal_to("val1"))
     assert_that(appconfig.read("testsection1.key2"), equal_to(1.2))
     assert_that(appconfig.read("testsection2.s2key1"), equal_to("someval"))
Beispiel #3
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog=textwrap.dedent('''
Below is a list of environment variables that can be set at the shell level 
to override default behaviour (e.g. export MOP.PREFETCH.NUMBER=5 
would set gui to only pre-fetch 5 observation sets, lowering the number
of simultaneously open files):


''' + str(config.AppConfig('env.json'))))

    parser.add_argument("task",
                        choices=tasks.task_list,
                        help="The task to perform.")
    parser.add_argument("input",
                        help="The directory with files to be processed.")
    parser.add_argument("-o",
                        "--output",
                        required=False,
                        default=tempfile.gettempdir(),
                        help="The directory where any local output files will "
                        "be placed.")
    parser.add_argument("--dbimages",
                        default="vos:OSSOS/dbimages",
                        help="VOSpace location of images to show.")
    parser.add_argument("--dry-run",
                        dest="dry_run",
                        action="store_true",
                        help="Do a dry run, where no results are sent to "
                        "VOSpace.")
    parser.add_argument("--debug",
                        action="store_true",
                        help="wx inspection tool will be launched.")
    parser.add_argument("--verbose", action="store_true")
    parser.add_argument(
        "--name-filter",
        dest="name_filter",
        help="A filter to apply to object names when loading from a directory."
    )
    parser.add_argument(
        "--skip-previous",
        action="store_true",
        dest="skip_previous",
        help=
        "Don't show me observation that are already in the input files, TRACKS only"
    )
    parser.add_argument("--username",
                        dest="username",
                        help="Your CADC username")
    parser.add_argument('--zoom', dest='zoom', default=1)
    parser.add_argument('--version',
                        action='version',
                        version=f'%(prog)s {__version__}')

    args = parser.parse_args()

    if args.dry_run and args.output == tempfile.gettempdir():
        # Don't use tempdir as default for dry runs, use the input directory
        output = args.input
    else:
        output = args.output

    if args.debug:
        logger.set_debug()
    if args.verbose:
        logger.set_verbose()

    storage.DBIMAGES = args.dbimages

    launch_app(args.task, args.input, output, args.dry_run, args.debug,
               args.name_filter, args.username, args.skip_previous, args.zoom)
Beispiel #4
0
def main():

    description = (
        "Given two directories containing astrometric observations build"
        "file that reports the newly measured astrometry.")

    epilog = """This script is intended to provide a simple way of gathering a list of new astrometry for reporting.
Astrometry is reported to the a central service for distribution (dbase fro the OSSOS project, or the
Minor Planet Center, for example). These central system do not want previously reported astrometry in
new submission files. Also, when a line of astrometry needs to be changed there is, nominally, a separate channel
for this reporting.  This script attempts to provide an automated approach to creating these reports.

In addition to the reported astrometry, each file should also contain some comments on the nature of the observations
being submitted. This script, being part of the OSSOS pipeline, provides these comments in a way that is consistent
with the expectations of the OSSOS reporting structure.  The script should build these comments in a reasonably
auto-magical way.
"""

    app_config = config.AppConfig()
    parser = argparse.ArgumentParser(description=description, epilog=epilog)
    parser.add_argument(
        "existing_astrometry_directory",
        help=("Directory containing previously reported astrometry."
              "Files can be in dbase ast, gui ast or OSSOS mpc format"))
    parser.add_argument("--idx_filename",
                        default=None,
                        help="File that has the MOP/OSSOS name mapping index.")
    parser.add_argument(
        "new_astrometry_directory",
        help=
        ("Directory containing astrometry to be searched for new lines to report."
         "Files should be in gui ast format."
         "Only observations from a single observatory should be present in these files."
         ))
    parser.add_argument("report_file",
                        help="Name of file that new lines will be reported to")
    parser.add_argument(
        "--rename",
        action="store_true",
        help=
        "Rename objects in new measurement files based on the name of the file"
    )
    parser.add_argument(
        "--new_name_regex",
        default='.*\.ast',
        help="Only load new observations where provisional name matches")
    parser.add_argument(
        "--existing_name_regex",
        default='.*\.ast',
        help="Only load existing observations where provisional name matches")
    parser.add_argument(
        "--start_date",
        type=mpc.get_date,
        help="Include observations taken on or after this date in report.")
    parser.add_argument(
        "--end_date",
        type=mpc.get_date,
        help="Include observation taken on or before this date in report.")
    parser.add_argument("--replacement",
                        action='store_true',
                        help="select replacement lines")
    parser.add_argument(
        "--tolerance",
        default=1,
        help=
        """tolerance is a flag, if 1 then only report lines that have different
                        positions and/flux, if -1 then any change cuases a report line"""
    )
    parser.add_argument("--COD",
                        default=None,
                        help="Observatory code for report file.")
    parser.add_argument("-q", action="store_true", help="Run quiet")
    parser.add_argument("--OBS",
                        action="append",
                        help="Names of observers, multiple allowed")
    parser.add_argument("--MEA",
                        action="append",
                        help="Names of measures, multiple allowed")
    parser.add_argument("--TEL",
                        default=app_config.read("TELESCOPE"),
                        action="store")
    parser.add_argument("--NET",
                        default=app_config.read("ASTROMETRIC_NETWORK"),
                        action="store")

    args = parser.parse_args()
    tolerance = Angle(float(args.tolerance) * units.arcsec)

    logger = logging.getLogger('reporter')
    if args.q:
        logger.setLevel(logging.CRITICAL)

    if args.idx_filename is None:
        args.idx_filename = os.path.dirname(
            args.existing_astrometry_directory) + "/idx/file.idx"

    idx = mpc.Index(args.idx_filename)

    existing_observations = {}
    os.path.walk(args.existing_astrometry_directory, load_observations,
                 (existing_observations, args.existing_name_regex, False))
    logger.info("Loaded existing observations for {} objects.\n".format(
        len(existing_observations)))

    new_observations = {}
    os.path.walk(args.new_astrometry_directory, load_observations,
                 (new_observations, args.new_name_regex, args.rename))
    logger.info("Loaded new observations for {} objects.\n".format(
        len(new_observations)))

    report_observations = {}
    for frame1 in new_observations:
        for name1 in new_observations[frame1]:
            observation1 = new_observations[frame1][name1]
            logger.warning("Checking {}".format(observation1.to_string()))
            assert isinstance(observation1, mpc.Observation)
            if ((args.start_date is None
                 or args.start_date.jd < observation1.date.jd)
                    and (args.end_date is None
                         or args.end_date.jd > observation1.date.jd)):
                report = True
                replacement = False
                if frame1 in existing_observations:
                    for name2 in existing_observations[frame1]:
                        observation2 = existing_observations[frame1][name2]
                        assert isinstance(observation2, mpc.Observation)
                        replacement = False
                        if idx.is_same(observation2.provisional_name,
                                       observation1.provisional_name):
                            if ((tolerance < 0
                                 and observation1 != observation2) or
                                (observation1.mag != observation2.mag
                                 or observation1.ra != observation2.ra
                                 or observation1.dec != observation2.dec)):
                                if not observation2.discovery:
                                    replacement = True
                                else:
                                    print("discovery")
                            else:
                                report = False
                            break
                if report and replacement == args.replacement:
                    logger.warning("Adding {} on {} to report".format(
                        name1, observation1.date))
                    report_observations[name1] = report_observations.get(
                        name1, [])
                    report_observations[name1].append(observation1)

    if not len(report_observations) > 0:
        logger.warning("No observations matched criterion.")
        sys.exit(0)

    if args.report_file == "-":
        outfile = sys.stdout
    else:
        outfile = open(args.report_file, 'w')

    full_observation_list = []
    for name in report_observations:
        full_observation_list.extend(report_observations[name])

    observers = args.OBS is not None and len(args.OBS) > 0 and args.OBS or None
    measurers = args.MEA is not None and len(args.MEA) > 0 and args.MEA or None
    network = len(args.NET) > 0 and args.NET or None
    telescope = len(args.TEL) > 0 and args.TEL or None

    outfile.write(
        mpc.make_tnodb_header(full_observation_list,
                              observers=observers,
                              measurers=measurers,
                              telescope=telescope,
                              astrometric_network=network))
    outfile.write("\n")

    for name in report_observations:
        # sorted("This is a test string from Andrew".split(), key=str.lower)
        report_observations[name].sort(key=lambda x: x.date.jd)
        for observation in report_observations[name]:
            if name in rename_map:
                observation.provisional_name = rename_map[name]
            outfile.write(observation.to_tnodb() + "\n")
        outfile.write("\n")
    outfile.close()
Beispiel #5
0
    if not len(report_observations) > 0:
        logger.warning("No observations matched criterion.")
        sys.exit(0)

    if args.report_file == "-":
        outfile = sys.stdout
    else:
        outfile = open(args.report_file, 'w')

    observations = []
    for name in report_observations:
        observations.extend(report_observations[name])


    app_config = config.AppConfig()
    outfile.write(mpc.make_tnodb_header(observations, observers=app_config.read("OBSERVERS"),
                                        measurers=app_config.read("MEASURERS"),
                                        telescope=app_config.read("TELESCOPE"),
                                        astrometric_network=app_config.read("ASTROMETRIC_NETWORK")))
    outfile.write("\n")

    for name in report_observations:
        #sorted("This is a test string from Andrew".split(), key=str.lower)
        report_observations[name].sort(key=lambda x: x.date.jd)
        for observation in report_observations[name]:
            outfile.write(observation.to_tnodb() + "\n")
        outfile.write("\n")
    outfile.close()