Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 6
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, 
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
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