示例#1
0
def fireballUpload(ffname, log=None):
    cfgname = '.config'
    config = cr.parse(cfgname)
    rmsdatadir = config.data_dir

    myloc = os.path.split(os.path.abspath(__file__))[0]
    filename = os.path.join(myloc, 'archive.key')
    with open(filename, 'r') as fin:
        key = fin.readline().split('=')[1].strip()
        secr = fin.readline().split('=')[1].strip()
        reg = fin.readline().split('=')[1].strip()
        targf = fin.readline().split('=')[1].strip()
    if targf[0] == '"':
        targf = targf[1:len(targf)-1]
    conn = boto3.Session(aws_access_key_id=key, aws_secret_access_key=secr) 
    s3 = conn.resource('s3', region_name=reg)

    dtstamp = ffname[10:25]
    ts = datetime.datetime.strptime(dtstamp,'%Y%m%d_%H%M%S')
    if ts.hour < 12:
        ts = ts + datetime.timedelta(days=-1)
    dirpat = ts.strftime('%Y%m%d')
    basarc = os.path.join(rmsdatadir, 'CapturedFiles')
    cap_dirs = [name for name in os.listdir(basarc) if (os.path.isdir(os.path.join(basarc, name)) and dirpat in name)]
    if len(cap_dirs) > 0:
        fldr = cap_dirs[0]
#        arch_dir = os.path.join(basarc, fldr)
        cap_dir = os.path.join(rmsdatadir, 'CapturedFiles', fldr)
        fbname = 'FR' + ffname[2:-5] + '.bin'
        uploadOneFile(cap_dir, fbname, s3, targf, '.fits', log)        
        uploadOneFile(cap_dir, ffname, s3, targf, '.fits', log)        
    else:
        print('unable to find source folder')
    return
示例#2
0
def view(ff):
    config = cr.parse(".config")
    
    ve = VideoExtraction.Extractor(config)
    ve.frames = np.empty((256, ff.nrows, ff.ncols))
    ve.compressed = ff.array
    
    points = np.array(ve.findPoints())
    
    plot(points, ff.nrows//config.f, ff.ncols//config.f)
示例#3
0
def view(ff):
    config = cr.parse(".config")

    ve = VideoExtraction.Extractor(config)
    ve.frames = np.empty((256, ff.nrows, ff.ncols))
    ve.compressed = ff.array

    points = np.array(ve.findPoints())

    plot(points, ff.nrows // config.f, ff.ncols // config.f)
示例#4
0
def manualRerun(dated_dir):
    """This function is used to manually rerun the Ukmon post processing script. 
    To invoke this function, open a Terminal window and run the following:

    *python ../ukmon-pitools/ukmonPostProc.py dated_dir*

    Args:
        dated_dir (str): This is the name of the folder to upload eg UK000F_20210512_202826_913898
    """
    config = cr.parse(os.path.expanduser('~/source/RMS/.config'))
    cap_dir = os.path.join(config.data_dir, 'CapturedFiles', dated_dir)
    arch_dir = os.path.join(config.data_dir, 'ArchivedFiles', dated_dir)
    rmsExternal(cap_dir, arch_dir, config)
示例#5
0
def installUkmonFeed(rmscfg='~/source/RMS/.config'):
    """ This function installs the UKMon postprocessing script into the RMS config file.
    It is called from the refreshTools script during initial installation and should never
    be called outside of that unless you're *certain* you know what you're doing. The script 
    alters the rms .config file. 

    """
    myloc = os.path.split(os.path.abspath(__file__))[0]
    newpath = os.path.join(myloc, 'ukmonPostProc.py')
    cfgname = os.path.expanduser(rmscfg)
    config = cr.parse(cfgname)
    esr = config.external_script_run
    extl = config.external_script_path

    print('checking parameters')
    if esr is True:
        if extl != newpath:
            print('saving current external script details')
            with open(os.path.join(myloc, 'extrascript'), 'w') as outf:
                outf.write(extl)

    print('updating RMS config file')
    with open(cfgname, 'r') as inf:
        lines = inf.readlines()
        with open('/tmp/new.config', 'w') as outf:
            for li in range(len(lines)):
                if 'auto_reprocess_external_script_run: ' in lines[li]:
                    lines[li] = 'auto_reprocess_external_script_run: true  \n'
                if 'external_script_path: ' in lines[li]:
                    lines[li] = 'external_script_path: {}  \n'.format(newpath)
                if 'external_script_run: ' in lines[
                        li] and 'auto_reprocess_' not in lines[li]:
                    lines[li] = 'external_script_run: true  \n'
                if 'auto_reprocess: ' in lines[li]:
                    lines[li] = 'auto_reprocess: true  \n'
            outf.writelines(lines)
    _, cfgbase = os.path.split(cfgname)
    bkpcnf = os.path.join(myloc, cfgbase + '.backup')
    print('backing up RMS config to {}'.format(bkpcnf))
    shutil.copyfile(cfgname, bkpcnf)
    shutil.copyfile('/tmp/new.config', cfgname)

    return
示例#6
0
        ftpdetectinfo_path_list += glob.glob(entry)

    # If therea are files given, notify the user
    if len(ftpdetectinfo_path_list) == 0:
        print('No valid FTPdetectinfo files given!')
        sys.exit()


    # Extract parent directory and station ID from path
    dir_path, ftpdetectinfo_name = os.path.split(ftpdetectinfo_path_list[0])
    spls = ftpdetectinfo_name.split('_')
    statID = spls[1]

    # Load the config file
    if os.path.isfile(os.path.join(dir_path, '.config')):
        config = cr.loadConfigFromDirectory('.config', dir_path)
    else:
        config = cr.loadConfigFromDirectory(cml_args.config, dir_path)

    if config.stationID != statID:
        # load the camera location details if needed
        print('looking for StationInfo file')
        lat, lon = getSiteInfo(ftpdetectinfo_path_list)
        if lat is not None:
            config.latitude = lat
        if lon is not None:
            config.longitude = lon

        print('Checking commandline args')
        if cml_args.latitude is not None:
            config.latitude = cml_args.latitude
示例#7
0
                            type=float,
                            help="Latitude in degrees (east is positive)")
    arg_parser.add_argument("longitude",
                            type=float,
                            help="Longitude in degrees (north is positive)")
    arg_parser.add_argument("height",
                            type=float,
                            help="Height to convert (in meters)")

    # Parse the command line arguments
    cml_args = arg_parser.parse_args()

    #########################

    # Load the config file
    config = cr.loadConfigFromDirectory(cml_args.config, ".")

    # Load latitude and longitude
    lat = cml_args.latitude
    lon = cml_args.longitude

    if not cml_args.inverse:
        print("Converting MSL height to WGS84 height")
        msl_height = cml_args.height
        wgs84_height = mslToWGS84Height(np.radians(lat), np.radians(lon),
                                        msl_height, config)
    else:
        print("Converting WGS84 height to MSL height")
        wgs84_height = cml_args.height
        msl_height = wgs84toMSLHeight(np.radians(lat), np.radians(lon),
                                      wgs84_height, config)
    # Init the command line arguments parser
    arg_parser = argparse.ArgumentParser(description="Detect stars and meteors in the given folder.")

    arg_parser.add_argument('dir_path', nargs=1, metavar='DIR_PATH', type=str, \
        help='Path to the folder with FF files.')

    arg_parser.add_argument('-c', '--config', nargs=1, metavar='CONFIG_PATH', type=str, \
        help="Path to a config file which will be used instead of the default one.")

    # Parse the command line arguments
    cml_args = arg_parser.parse_args()

    #########################

    # Load the config file
    config = cr.loadConfigFromDirectory(cml_args.config, cml_args.dir_path)


    ### Init the logger

    from RMS.Logger import initLogging
    initLogging(config, 'detection_')

    log = logging.getLogger("logger")

    ######


    # Run detection on the folder
    _, _, _, detector = detectStarsAndMeteorsDirectory(cml_args.dir_path[0], config)
示例#9
0
            if not os.path.isfile(ftpdetectinfo_path):
                print("The FTPdetectinfo file does not exist:",
                      ftpdetectinfo_path)
                print("Exiting...")
                sys.exit()

            # Parse the beg/end time
            dt_beg = datetime.datetime.strptime(tbeg, "%Y%m%d_%H%M%S")
            dt_end = datetime.datetime.strptime(tend, "%Y%m%d_%H%M%S")

            # Extract parent directory
            ftp_dir_path = os.path.dirname(ftpdetectinfo_path)

            # Load the config file
            config = cr.loadConfigFromDirectory('.', ftp_dir_path)

            # Compute the flux
            sol_data, flux_lm_6_5_data = computeFlux(config, ftp_dir_path, ftpdetectinfo_path, shower_code, \
                dt_beg, dt_end, dt, s, show_plots=False)

            # Add computed flux to the output list
            output_data += [[config.stationID, sol, flux]
                            for (sol, flux) in zip(sol_data, flux_lm_6_5_data)]

            # Make all stations the same color
            if config.stationID not in color_dict:

                # Generate a new color
                color = color_cycle[len(color_dict) % (len(color_cycle))]
                label = str(config.stationID)
示例#10
0
        help="""Disable requiring stars on images for generating the flat field.""")

    arg_parser.add_argument('-i', '--images', action="store_true", \
        help="""Use image files (bmp, png, jpg) for flat instead of FF files. Images of the file type with the higest frequency in the directory will be taken.""")

    # Parse the command line arguments
    cml_args = arg_parser.parse_args()

    #########################


    dir_path = cml_args.dir_path[0]


    # Load the configuration file
    config = cr.parse(".config")

    # Make the flat
    ff_median = makeFlat(dir_path, config, nostars=cml_args.nostars, use_images=cml_args.images)

    if ff_median is not None:

        # # Save the flat in the root directory
        # scipy.misc.imsave(config.flat_file, ff_median)
        # print('Flat saved to:', os.path.join(os.getcwd(), config.flat_file))


        # Save the flat in the input directory
        input_dir_flat = os.path.join(dir_path, config.flat_file)
        scipy.misc.imsave(input_dir_flat, ff_median)
        print('Flat saved to:', input_dir_flat)
示例#11
0
    arg_parser.add_argument('-e',
                            '--detectend',
                            action="store_true",
                            help="""Detect stars and meteors at the
        end of the night, after capture finishes. """)

    arg_parser.add_argument('-r', '--resume', action="store_true", \
        help="""Resume capture into the last night directory in CapturedFiles. """)

    # Parse the command line arguments
    cml_args = arg_parser.parse_args()

    ######

    # Load the config file
    config = cr.loadConfigFromDirectory(cml_args.config, os.path.abspath('.'))

    # Initialize the logger
    initLogging(config)

    # Get the logger handle
    log = logging.getLogger("logger")

    log.info("Program start")
    log.info("Station code: {:s}".format(str(config.stationID)))

    # Change the Ctrl+C action to the special handle
    setSIGINT()

    # Make the data directories
    root_dir = os.path.abspath(config.data_dir)
示例#12
0
def FFtoFrames(file_path,
               out_dir,
               file_format,
               deinterlace_mode,
               first_frame=0,
               last_frame=255):
    #########################

    # Load the configuration file
    config = cr.parse(".config")

    # Read the deinterlace
    #   -1 - no deinterlace
    #    0 - odd first
    #    1 - even first

    if deinterlace_mode not in (-1, 0, 1):
        print('Unknown deinterlace mode:', deinterlace_mode)
        sys.exit()

    # Check if the file exists
    if not os.path.isfile(file_path):

        print('The file {:s} does not exist!'.format(file_path))
        sys.exit()

    # Check if the output directory exists, make it if it doesn't
    if not os.path.exists(out_dir):

        print('Making directory: out_dir')
        mkdirP(out_dir)

    # Open the FF file
    dir_path, file_name = os.path.split(file_path)
    ff = readFF(dir_path, file_name)

    # Take the FPS from the FF file, if available
    if hasattr(ff, 'fps'):
        fps = ff.fps

    # Take the FPS from the config file, if it was not given as an argument
    if fps is None:
        fps = config.fps

    # Try to read the number of frames from the FF file itself
    if ff.nframes > 0:
        nframes = ff.nframes

    else:
        nframes = 256

    # Construct a file name for saving
    if file_format == 'pngm':

        # If the METAL type PNG file is given, make the file name 'dump'
        file_name_saving = 'dump'

    else:

        file_name_saving = file_name.replace('.fits', '').replace('.bin', '')

    frame_name_time_list = []

    # Get the initial time of the FF file
    ff_dt = filenameToDatetime(file_name)

    # Go through all frames
    for i in range(first_frame, last_frame + 1):
        # Reconstruct individual frames

        frame = reconstructFrame(ff, i, avepixel=True)
        # Deinterlace the frame if necessary, odd first
        if deinterlace_mode == 0:

            frame_odd = deinterlaceOdd(frame)
            frame_name, frame_dt = saveFrame(frame_odd,
                                             i,
                                             out_dir,
                                             file_name_saving,
                                             file_format,
                                             ff_dt,
                                             fps,
                                             half_frame=0)
            frame_name_time_list.append([frame_name, frame_dt])

            frame_even = deinterlaceEven(frame)
            frame_name, frame_dt = saveFrame(frame_even,
                                             i,
                                             out_dir,
                                             file_name_saving,
                                             file_format,
                                             ff_dt,
                                             fps,
                                             half_frame=1)
            frame_name_time_list.append([frame_name, frame_dt])

        # Even first
        elif deinterlace_mode == 1:

            frame_even = deinterlaceEven(frame)
            frame_name, frame_dt = saveFrame(frame_even,
                                             i,
                                             out_dir,
                                             file_name_saving,
                                             file_format,
                                             ff_dt,
                                             fps,
                                             half_frame=0)
            frame_name_time_list.append([frame_name, frame_dt])

            frame_odd = deinterlaceOdd(frame)
            frame_name, frame_dt = saveFrame(frame_odd,
                                             i,
                                             out_dir,
                                             file_name_saving,
                                             file_format,
                                             ff_dt,
                                             fps,
                                             half_frame=1)
            frame_name_time_list.append([frame_name, frame_dt])

        # No deinterlace
        else:
            frame_name, frame_dt = saveFrame(frame, i - first_frame, out_dir,
                                             file_name_saving, file_format,
                                             ff_dt, fps)
            frame_name_time_list.append([frame_name, frame_dt])

    # If the frames are saved for METAL, the times have to be given in a separate file
    if file_format == 'pngm':

        with open(os.path.join(out_dir, 'frtime.txt'), 'w') as f:

            # Write all frames and times in a file
            for frame_name, frame_dt in frame_name_time_list:
                # 20180117:01:08:29.8342
                f.write('{:s} {:s}\n'.format(
                    frame_name, frame_dt.strftime("%Y%m%d:%H:%M:%S.%f")))

    return frame_name_time_list
    parser.add_argument('command',
                        metavar='command',
                        type=str,
                        nargs=1,
                        help=' | '.join(cmd_list))

    parser.add_argument(
        '-c',
        '--config',
        nargs=1,
        metavar='CONFIG_PATH',
        type=str,
        help=
        "Path to a config file which will be used instead of the default one.")

    args = parser.parse_args()
    cmd = args.command[0]

    if cmd not in cmd_list:
        print('Error: command "{}" not supported'.format(cmd))
        exit(1)

    config = cr.loadConfigFromDirectory(args.config, 'notused')

    if str(config.deviceID).isdigit():
        print('Error: this utility only works with IP cameras')
        exit(1)

    # Process the IP camera control command
    onvifCommand(config, cmd)
示例#14
0
                     default=None)
    nmp.add_argument('--adir', type=str, \
                     help="subdirectory of ArchivedFiles with the most recent capture data. For example, US0006_20220306_020833_56612.", \
                     default=None)
    nmp.add_argument('--config', type=str, nargs=1, metavar='CONFIG_PATH', \
                     help="Path to a config file which will be used in place of the default one.")
    args = nmp.parse_args()

    if args.cdir is None:
        
        # Now want to do the same thing as "find . -type d -print | sort -r",
        # and take the first line to get the most recent directory.
        c_dir=os.path.expanduser("~/RMS_data/CapturedFiles")
        print (c_dir, ":")
        print ( sorted( os.listdir(c_dir), reverse=True)[0] )

    if args.adir is None:
        a_dir = os.path.expanduser("~/RMS_data/ArchivedFiles")
        print (a_dir, ":")
        print (sorted ( os.listdir(a_dir), reverse=True)[0] )

    # Now get the config object.
    config = cr.loadConfigFromDirectory(args.config, os.path.abspath('${HOME}/source/RMS'))

    print ("config data :")
    print (config.stationID)

    # Now call iStream.py with args c_dir, a_dir, config

    iStream.iStream.rmsExternal(c_dir, a_dir, config)
示例#15
0
                                                      config, flat_struct,
                                                      dark, mask)

    print(star_list)
    print(meteor_list)


if __name__ == '__main__':
    ### COMMAND LINE ARGUMENTS
    # Init the command line arguments parser
    arg_parser = argparse.ArgumentParser(
        description="Analyses a UFO avi with RMS.")

    arg_parser.add_argument('ff_path', nargs='+', metavar='FILE_PATH', type=str, \
        help='Full path and name of the file to analyse')

    arg_parser.add_argument('-c', '--config', nargs=1, metavar='CONFIG_PATH', type=str, \
        help="Path to a config file which will be used instead of the default one.")

    # Parse the command line arguments
    cml_args = arg_parser.parse_args()

    #########################

    ff_directory, ff_name = os.path.split(cml_args.ff_path[0])

    print(ff_directory, ff_name)
    config = cr.loadConfigFromDirectory(cml_args.config[0], ff_directory)
    print("loaded config \n\n\n")

    AnalyseUFOwithRMS(config, ff_directory, ff_name)
示例#16
0
        log.info('Ending program')

        # Stop the upload manager
        if upload_manager is not None:
            if upload_manager.is_alive():
                upload_manager.stop()
                log.info('Closing upload manager...')

        sys.exit()


if __name__ == "__main__":

    # Load the configuration file
    config = cr.parse(".config")

    ### COMMAND LINE ARGUMENTS

    # Init the command line arguments parser
    arg_parser = argparse.ArgumentParser(
        description=""" Starting capture and compression.
        """)

    # Add a mutually exclusive for the parser (the arguments in the group can't be given at the same)
    arg_group = arg_parser.add_mutually_exclusive_group()

    arg_group.add_argument('-d',
                           '--duration',
                           metavar='DURATION_HOURS',
                           help="""Start capturing right away, 
示例#17
0
if __name__ == "__main__":

    import argparse

    import RMS.ConfigReader as cr

    ### PARSE INPUT ARGUMENTS ###

    # Init the command line arguments parser
    arg_parser = argparse.ArgumentParser(
        description=""" Generate the calibration report.
        """)

    arg_parser.add_argument('dir_path',
                            type=str,
                            help="Path to the folder of the night.")

    arg_parser.add_argument('-c', '--config', nargs=1, metavar='CONFIG_PATH', type=str, \
        help="Path to a config file which will be used instead of the default one.")

    # Parse the command line arguments
    cml_args = arg_parser.parse_args()

    #############################

    # Load the config file
    config = cr.loadConfigFromDirectory(cml_args.config, cml_args.dir_path)

    generateCalibrationReport(config, cml_args.dir_path, show_graphs=True)
示例#18
0
    exit(0)





if __name__ == '__main__':

    # list of supported commands
    cmd_list = ['reboot', 'GetHostname', 'GetDeviceInformation']

    # command line argument parser
    parser = argparse.ArgumentParser(description='Controls ONVIF-Compatible IP camera')
    parser.add_argument('command', metavar='command', type=str, nargs=1, help=' | '.join(cmd_list))
    args = parser.parse_args()
    cmd = args.command[0]

    if not cmd in cmd_list:
        print('Error: command "{}" not supported'.format(cmd))
        exit(1)

    config = cr.parse('.config')

    if config.deviceID.isdigit():
        print('Error: this utility only works with IP cameras')
        exit(1)
    
    
    # Process the IP camera control command
    onvifCommand(config, cmd)