예제 #1
0
def crop(request,
         project_id=None,
         stack_ids=None,
         x_min=None,
         x_max=None,
         y_min=None,
         y_max=None,
         z_min=None,
         z_max=None,
         zoom_level=None,
         single_channel=None):
    """ Crops out the specified region of the stack. The region is expected to
    be given in terms of real world units (e.g. nm).
    """
    # Make sure tmp dir exists and is writable
    if not os.path.exists(crop_output_path) or not os.access(
            crop_output_path, os.W_OK):
        if request.user.is_superuser:
            err_message = "Please make sure your output folder (%s) exists " \
                    "is writable." % crop_output_path
        else:
            err_message = "Sorry, the output path for the cropping tool " \
                    "isn't set up correctly. Please contact an administrator."
        return json_error_response(err_message)

    # Make a list out of the stack ids
    string_list = stack_ids.split(",")
    stack_ids = [int(x) for x in string_list]

    # Get basic cropping parameters
    rotation_cw = float(request.GET.get('rotationcw', 0.0))

    # Should an output slice contain all channels of the source tiles
    # or only a single (the red) one?
    single_channel = bool(int(single_channel))

    # Crate a new cropping job
    job = CropJob(request.user, project_id, stack_ids, x_min, x_max, y_min,
                  y_max, z_min, z_max, rotation_cw, zoom_level, single_channel)

    # Parameter check
    errors = sanity_check(job)
    if len(errors) > 0:
        err_message = "Some problems with the cropping parameters were found: "
        for n, e in enumerate(errors):
            if n == 0:
                err_message += str(n + 1) + ". " + e
            else:
                err_message += ", " + str(n + 1) + ". " + e
        err_response = json_error_response(err_message)
        return err_response

    result = start_asynch_process(job)
    return result
예제 #2
0
def crop(request, project_id=None, stack_ids=None, x_min=None, x_max=None,
        y_min=None, y_max=None, z_min=None, z_max=None, zoom_level=None,
        single_channel=None):
    """ Crops out the specified region of the stack. The region is expected to
    be given in terms of real world units (e.g. nm).
    """
    # Make sure tmp dir exists and is writable
    if not os.path.exists( crop_output_path ) or not os.access( crop_output_path, os.W_OK ):
        if request.user.is_superuser:
            err_message = "Please make sure your output folder (%s) exists " \
                    "is writable." % crop_output_path
        else:
            err_message = "Sorry, the output path for the cropping tool " \
                    "isn't set up correctly. Please contact an administrator."
        return json_error_response(err_message)

    # Make a list out of the stack ids
    string_list = stack_ids.split(",")
    stack_ids = [int( x ) for x in string_list]

    # Get basic cropping parameters
    rotation_cw = float(request.GET.get('rotationcw', 0.0))

    # Should an output slice contain all channels of the source tiles
    # or only a single (the red) one?
    single_channel = bool(int(single_channel))

    # Crate a new cropping job
    job = CropJob(request.user, project_id, stack_ids, x_min, x_max,
        y_min, y_max, z_min, z_max, rotation_cw, zoom_level, single_channel)

    # Parameter check
    errors = sanity_check( job )
    if len(errors) > 0:
        err_message = "Some problems with the cropping parameters were found: "
        for n, e in enumerate( errors ):
            if n == 0:
                err_message += str( n+1 ) + ". " + e
            else:
                err_message += ", " + str( n+1 ) + ". " + e
        err_response = json_error_response( err_message )
        return err_response
        
    result = start_asynch_process( job )
    return result
예제 #3
0
 def inner_decorator(request, roles=roles, *args, **kwargs):
     p = Project.objects.get(pk=kwargs['project_id'])
     u = request.user
     
     # Check for admin privs in all cases.
     has_role = u.has_perm('can_administer', p)
     
     if not has_role:
         # Check the indicated role(s)
         if isinstance(roles, str):
             roles = [roles]
         for role in roles:
             if role == UserRole.Annotate:
                 has_role = u.has_perm('can_annotate', p)
             elif role == UserRole.Browse:
                 has_role = u.has_perm('can_browse', p)
             if has_role:
                 break
     
     if has_role:
         # The user can execute the function.
         return f(request, *args, **kwargs)
     else:
         return json_error_response("The user '%s' does not have a necessary role in the project %d" % (u.first_name + ' ' + u.last_name, int(kwargs['project_id'])))
예제 #4
0
def crop(request: HttpRequest, project_id=None) -> JsonResponse:
    """ Crops out the specified region of the stack. The region is expected to
    be given in terms of real world units (e.g. nm).
    """
    stack_ids = get_request_list(request.POST, "stack_ids", [], int)
    x_min = float(request.POST['min_x'])
    y_min = float(request.POST['min_y'])
    z_min = float(request.POST['min_z'])
    x_max = float(request.POST['max_x'])
    y_max = float(request.POST['max_y'])
    z_max = float(request.POST['max_z'])
    zoom_level = float(request.POST['zoom_level'])
    single_channel = get_request_bool(request.POST, 'single_channel', False)
    rotation_cw = float(request.GET.get('rotationcw', 0.0))

    # Make sure tmp dir exists and is writable
    if not os.path.exists(crop_output_path) or not os.access(
            crop_output_path, os.W_OK):
        if request.user.is_superuser:
            err_message = "Please make sure your output folder (%s) exists " \
                    "is writable." % crop_output_path
        else:
            err_message = "Sorry, the output path for the cropping tool " \
                    "isn't set up correctly. Please contact an administrator."
        return json_error_response(err_message)

    # Use first reachable stack mirrors
    stack_mirror_ids = []
    for sid in stack_ids:
        stack_mirrors = StackMirror.objects.select_related('stack').filter(
            stack_id=sid)
        for sm in stack_mirrors:
            # If mirror is reachable use it right away
            tile_source = get_tile_source(sm.tile_source_type)
            try:
                req = requests.head(tile_source.get_canary_url(sm),
                                    allow_redirects=True,
                                    verify=verify_ssl)
                reachable = req.status_code == 200
            except Exception as e:
                logger.error(e)
                reachable = False
            if reachable:
                stack_mirror_ids.append(sm.id)
                break
        if not reachable:
            raise ValueError(
                "Can't find reachable stack mirror for stack {}".format(sid))

    # Crate a new cropping job
    job = CropJob(request.user, project_id, stack_mirror_ids, x_min, x_max,
                  y_min, y_max, z_min, z_max, rotation_cw, zoom_level,
                  single_channel)

    # Parameter check
    errors = sanity_check(job)
    if len(errors) > 0:
        err_message = "Some problems with the cropping parameters were found: "
        for n, errtxt in enumerate(errors):
            if n == 0:
                err_message += str(n + 1) + ". " + errtxt
            else:
                err_message += ", " + str(n + 1) + ". " + errtxt
        err_response = json_error_response(err_message)
        return err_response

    result = start_asynch_process(job)
    return result
예제 #5
0
def crop(request, project_id=None):
    """ Crops out the specified region of the stack. The region is expected to
    be given in terms of real world units (e.g. nm).
    """
    stack_ids = get_request_list(request.POST, "stack_ids", [], int)
    x_min = float(request.POST['min_x'])
    y_min = float(request.POST['min_y'])
    z_min = float(request.POST['min_z'])
    x_max = float(request.POST['max_x'])
    y_max = float(request.POST['max_y'])
    z_max = float(request.POST['max_z'])
    zoom_level = float(request.POST['zoom_level'])
    single_channel = request.POST['single_channel'] == 'true'
    rotation_cw = float(request.GET.get('rotationcw', 0.0))

    # Make sure tmp dir exists and is writable
    if not os.path.exists( crop_output_path ) or not os.access( crop_output_path, os.W_OK ):
        if request.user.is_superuser:
            err_message = "Please make sure your output folder (%s) exists " \
                    "is writable." % crop_output_path
        else:
            err_message = "Sorry, the output path for the cropping tool " \
                    "isn't set up correctly. Please contact an administrator."
        return json_error_response(err_message)

    # Use first reachable stack mirrors
    stack_mirror_ids = []
    for sid in stack_ids:
        stack_mirrors = StackMirror.objects.select_related('stack').filter(stack_id=sid);
        for sm in stack_mirrors:
            # If mirror is reachable use it right away
            tile_source = get_tile_source(sm.tile_source_type)
            try:
                req = requests.head(tile_source.get_canaray_url(sm))
                reachable = req.status_code == 200
            except :
                reachable = False
            if reachable:
                stack_mirror_ids.append(sm.id)
                break
        if not reachable:
            raise ValueError("Can't find reachable stack mirror for stack {}".format(sid))

    # Crate a new cropping job
    job = CropJob(request.user, project_id, stack_mirror_ids, x_min, x_max,
            y_min, y_max, z_min, z_max, rotation_cw, zoom_level, single_channel)

    # Parameter check
    errors = sanity_check( job )
    if len(errors) > 0:
        err_message = "Some problems with the cropping parameters were found: "
        for n, e in enumerate( errors ):
            if n == 0:
                err_message += str( n+1 ) + ". " + e
            else:
                err_message += ", " + str( n+1 ) + ". " + e
        err_response = json_error_response( err_message )
        return err_response

    result = start_asynch_process( job )
    return result