Ejemplo n.º 1
0
def main(*args):
    if len(sys.argv) >= 3:
        kind = sys.argv[1]
        main_dir = sys.argv[2]

        processed_dir = main_dir + '_processed'
        averages_dir = main_dir + '_average'

    if len(sys.argv) >= 4:
        test_dir = sys.argv[3]

        test_processed_dir = test_dir + '_processed'

    if kind == 'process':
        process_and_save_images(main_dir, processed_dir)
    elif kind == 'average':
        if not os.path.exists(root(processed_dir)):
            process_and_save_images(main_dir, processed_dir)

        process_and_save_averages(processed_dir, averages_dir)
    elif kind == 'test_sets':
        if not os.path.exists(root(processed_dir)):
            process_and_save_images(main_dir, processed_dir)

        if not os.path.exists(root(averages_dir)):
            process_and_save_averages(processed_dir, averages_dir)

        if not os.path.exists(root(test_processed_dir)):
            process_and_save_images(test_dir, test_processed_dir)

        results = execute_test_set(averages_dir, test_processed_dir)
        print results
Ejemplo n.º 2
0
def process_and_save_images(source_dir, dest_dir):
    for number, name, image in iterate_images_folder(source_dir):
        processed = binarize_image(image)
        
        save_dir = root(dest_dir, number)
        if not os.path.exists(save_dir):
            os.makedirs(save_dir)

        processed.save(root(save_dir, name))
Ejemplo n.º 3
0
def process_and_save_averages(source_dir, dest_dir):
    images_dict = {}
    
    for number, name, image in iterate_images_folder(source_dir):
        if not number in images_dict:
            images_dict[number] = []

        images_dict[number].append(image)

    averages = calculate_image_averages(images_dict)
    
    for key in averages:
        save_dir = root(dest_dir, key)
        if not os.path.exists(save_dir):
            os.makedirs(save_dir)
        averages[key].save(root(save_dir, key + '.jpg'))
Ejemplo n.º 4
0
def get_average_images(dirname):
    dirname = root(dirname)

    averages = {}

    for number, name, image in iterate_images_folder(dirname):
        averages[number] = image

    return averages
 def drive_with_alignment(self, position):
     p = utils.clamp(
         utils.root(-position * robotmap.drive_power_constant, 3), -.5, .5)
     print("{}, {}".format(p, -p * robotmap.drive_power_side_ratio))
     tolerance = 3
     if -position > tolerance:
         self.drivetrain.teleop_drive_robot(left_speed=p *
                                            robotmap.drive_power_side_ratio,
                                            right_speed=-p)
     elif -position < -tolerance:
         self.drivetrain.teleop_drive_robot(left_speed=p,
                                            right_speed=-p *
                                            robotmap.drive_power_side_ratio)
     else:
         self.drivetrain.teleop_drive_robot(left_speed=-0.4,
                                            right_speed=-0.4)
     self.line_detect_failsafe_checker()
Ejemplo n.º 6
0
def download_nccos(y2003, y2007):

    dirname = os.path.join(root(), "nccos")
    if not os.path.isdir(dirname):
        os.mkdir(dirname)

    url = "https://www.nodc.noaa.gov/cgi-bin/OAS/prd/download/1329.1.1.tar.gz"
    out_zip = os.path.join(dirname, os.path.basename(url))
    out = os.path.join(dirname, "NOSbenthic")

    if not os.path.exists(out_zip) and not os.path.exists(out):
        os.system(f"curl {url} --output {out_zip}")
        os.system(f"tar -xvzf {out_zip}")
        os.system(f"mv {out_zip} {out}")

    if y2003:
        download_nccos2003()
    if y2007:
        download_nccos2007()
Ejemplo n.º 7
0
def download_nccos2007():
    dirname = os.path.join(root(), "nccos", "2007")
    if not os.path.isdir(dirname):
        os.mkdir(dirname)

    baseurl = "https://cdn.coastalscience.noaa.gov/datasets/e97/2007"
    tailurls = [
        # labels
        "aap/AccuracyAssessment.zip",
        "gvp/GroundValidation.zip",
        "shapes_benthic/Habitat_GIS_Data.zip",
        "shapes_shoreline/Shorelines.zip",
        # misc.
        "other/MHI_digital_elevation_model_hillshade_GIS_data.zip",
        # islands
        "mosaics/Hawaii_IKONOS.zip",
        "mosaics/Oahu_IKONOS.zip",
        "mosaics/Maui_IKONOS.zip",
        "mosaics/Kauai_IKONOS.zip",
        "mosaics/Lanai_IKONOS.zip",
        "mosaics/Molokai_IKONOS.zip",
        "mosaics/Niihau_IKONOS.zip",
        "mosaics/Kahoolawe_IKONOS.zip",
        "mosaics/Kaula_IKONOS.zip",
        "mosaics/MHI_satellite_image_mosaic_files-land.zip"
    ]

    for tailurl in tailurls:

        basename = os.path.dirname(tailurl)

        url = os.path.join(baseurl, tailurl)
        out = os.path.join(dirname, os.path.basename(tailurl))

        if not os.path.exists(out) and not os.path.exists(
                os.path.splitext(out)[0]):
            os.system(f"curl {url} --output {out}")
            os.system(f"unzip {out} -d {os.path.splitext(out)[0]}")
Ejemplo n.º 8
0
def parse_saml_metadata(source):
    validation = dict()
    validation['error'] = None
    validation['md_expires'] = None
    validation['crt_expires'] = None

    try:
        t = utils.parse_xml(source)
        t = utils.root(t)

        # XSD validation
        utils.validate_document(t)

        # Expiration check
        validation['md_expires'] = utils.metadata_expiration(t)

        # Certificate expiration
        # Everybody seems to use expired TSC's
        #validation['crt_expires'] = utils.certificate_expiration(t)

    except Exception as ex:
        validation['error'] = ex

    return validation
Ejemplo n.º 9
0
# Django settings for growler project.

import utils

ROOT = utils.root(__file__)
MODULE = utils.module(__file__)


DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', '*****@*****.**'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': ROOT('db.sqlite3'),                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
Ejemplo n.º 10
0
from utils import root


TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    )

TEMPLATE_DIRS = (
    root('templates/')
    )

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'django.core.context_processors.tz',
    'django.core.context_processors.request',
    'django.contrib.messages.context_processors.messages',
    'cghub.apps.core.context_processors.settings',
    )
Ejemplo n.º 11
0
from utils import root


TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    )

TEMPLATE_DIRS = (
    root('templates/')
    )
 def test_roots(self):
     # À compléter...
     self.assertEqual(type(utils.root(1, 1, 1)), tuple)
Ejemplo n.º 13
0
from utils import root


STATIC_ROOT = ''

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    root('static'),
    )

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    )
Ejemplo n.º 14
0
def firstnames():
    filename = os.path.join(utils.root(), 'names', 'firstnames.csv')
    return utils.loadfile(filename, _format='split')
Ejemplo n.º 15
0
def city_data():
    filename = os.path.join(utils.root(), 'addresses', 'cityinfo.json')
    return utils.loadfile(filename, _format='json')
Ejemplo n.º 16
0
# Django settings for election project.
from datetime import datetime
import utils

ROOT = utils.root(__file__)
MODULE = utils.module(__file__)

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('Your Name', '*****@*****.**'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE':
        'django.db.backends.',  # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '',  # Or path to database file if using sqlite3.
        'USER': '',  # Not used with sqlite3.
        'PASSWORD': '',  # Not used with sqlite3.
        'HOST':
        '',  # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',  # Set to empty string for default. Not used with sqlite3.
    }
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
Ejemplo n.º 17
0
SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = root('media')

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = '/media/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = root('static')

# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'