Esempio n. 1
0
def upload_common(request, url=None, file=None):
    df, original_filename = handle_upload(file=file, url=url)
    submittor = request.user if request.user.is_authenticated() else None
    pro = get_user_profile(submittor)
    json = request.json
    logmsg('upload: JSON', json)
    allow_commercial_use = json.get('allow_commercial_use', 'd')
    allow_modifications = json.get('allow_modifications', 'd')
    license, created = License.objects.get_or_create(
        default_license=pro.default_license,
        allow_commercial_use=allow_commercial_use,
        allow_modifications=allow_modifications,
    )
    publicly_visible = json.get('publicly_visible', 'y')

    subargs = dict(
        user=submittor,
        disk_file=df,
        original_filename=original_filename,
        license=license,
        publicly_visible=publicly_visible,
        via_api=True,
    )
    if url is not None:
        subargs.update(url=url)

    for key, typ in [
        ('scale_units', str),
        ('scale_type', str),
        ('scale_lower', float),
        ('scale_upper', float),
        ('scale_est', float),
        ('scale_err', float),
        ('center_ra', float),
        ('center_dec', float),
        ('radius', float),
        ('tweak_order', int),
        ('downsample_factor', int),
        ('use_sextractor', bool),
        ('crpix_center', bool),
        ('parity', int),
        ('image_width', int),
        ('image_height', int),
        ('positional_error', float),
    ]:
        if key in json:
            subargs[key] = typ(json[key])

    logmsg('upload: submission args:', subargs)

    sub = Submission(**subargs)
    sub.save()
    return HttpResponseJson({
        'status': 'success',
        'subid': sub.id,
        'hash': sub.disk_file.file_hash
    })
Esempio n. 2
0
def upload_common(request, url=None, file=None):
    df, original_filename = handle_upload(file=file, url=url)
    submittor = request.user if request.user.is_authenticated() else None

    json = request.json
    logmsg('upload: JSON', json)
    allow_commercial_use = json.get('allow_commercial_use', 'd')
    allow_modifications = json.get('allow_modifications', 'd')
    license,created = License.objects.get_or_create(
        default_license=submittor.get_profile().default_license,
        allow_commercial_use=allow_commercial_use,
        allow_modifications=allow_modifications,
    )
    publicly_visible = json.get('publicly_visible', 'y')

    subargs = dict(
        user=submittor,
        disk_file=df,
        original_filename=original_filename,
        license=license,
        publicly_visible=publicly_visible,
        via_api = True,
        )
    if url is not None:
        subargs.update(url=url)

    for key,typ in [('scale_units', str),
                    ('scale_type', str),
                    ('scale_lower', float),
                    ('scale_upper', float),
                    ('scale_est', float),
                    ('scale_err', float),
                    ('center_ra', float),
                    ('center_dec', float),
                    ('radius', float),
                    ('tweak_order', int),
                    ('downsample_factor', int),
                    ('use_sextractor', bool),
                    ('crpix_center', bool),
                    ('parity', int),
                    ('tweak_order', int),
                    ('image_width', int),
                    ('image_height', int),
                    ]:
        if key in json:
            subargs[key] = typ(json[key])

    logmsg('upload: submission args:', subargs)

    sub = Submission(**subargs)
    sub.save()
    return HttpResponseJson({'status': 'success',
                             'subid': sub.id,
                             'hash': sub.disk_file.file_hash}) 
Esempio n. 3
0
def upload_common(request, url=None, file=None):
    json = request.json
    logmsg('upload: JSON', json)
    # Handle X,Y coordinate lists
    if 'x' in json and 'y' in json:
        import numpy as np
        from astrometry.util.fits import fits_table
        # Turns out the easiest way to interface this with the rest of the code
        # is to just write a FITS table...
        try:
            x = np.array([float(v) for v in json['x']])
            y = np.array([float(v) for v in json['y']])
        except:
            return HttpResponseErrorJson(
                'Failed to parse JSON "x" and "y" values -- should be lists of floats'
            )
        if len(x) != len(y):
            return HttpResponseErrorJson(
                '"x" and "y" lists must be the same length')
        T = fits_table()
        T.x = x
        T.y = y
        temp_file_path = tempfile.mktemp()
        T.writeto(temp_file_path)
        df = DiskFile.from_file(temp_file_path,
                                collection=Image.ORIG_COLLECTION)
        original_filename = 'json-xy'
    else:
        df, original_filename = handle_upload(file=file, url=url)
    submittor = request.user if request.user.is_authenticated() else None
    pro = get_user_profile(submittor)
    allow_commercial_use = json.get('allow_commercial_use', 'd')
    allow_modifications = json.get('allow_modifications', 'd')
    mylicense, _ = License.objects.get_or_create(
        default_license=pro.default_license,
        allow_commercial_use=allow_commercial_use,
        allow_modifications=allow_modifications,
    )
    publicly_visible = json.get('publicly_visible', 'y')

    subargs = dict(
        user=submittor,
        disk_file=df,
        original_filename=original_filename,
        license=mylicense,
        publicly_visible=publicly_visible,
        via_api=True,
    )
    if url is not None:
        subargs.update(url=url)

    for key, typ in [
        ('scale_units', str),
        ('scale_type', str),
        ('scale_lower', float),
        ('scale_upper', float),
        ('scale_est', float),
        ('scale_err', float),
        ('center_ra', float),
        ('center_dec', float),
        ('radius', float),
        ('tweak_order', int),
        ('downsample_factor', int),
        ('use_sextractor', bool),
        ('crpix_center', bool),
        ('invert', bool),
        ('parity', int),
        ('image_width', int),
        ('image_height', int),
        ('positional_error', float),
    ]:
        if key in json:
            subargs[key] = typ(json[key])

    logmsg('upload: submission args:', subargs)

    sub = Submission(**subargs)
    sub.save()
    return HttpResponseJson({
        'status': 'success',
        'subid': sub.id,
        'hash': sub.disk_file.file_hash
    })
Esempio n. 4
0
def upload_common(request, url=None, file=None):
    json = request.json
    logmsg('upload: JSON', json)
    # Handle X,Y coordinate lists
    if 'x' in json and 'y' in json:
        import numpy as np
        from astrometry.util.fits import fits_table
        # Turns out the easiest way to interface this with the rest of the code
        # is to just write a FITS table...
        try:
            x = np.array([float(v) for v in json['x']])
            y = np.array([float(v) for v in json['y']])
        except:
            return HttpResponseErrorJson('Failed to parse JSON "x" and "y" values -- should be lists of floats')
        if len(x) != len(y):
            return HttpResponseErrorJson('"x" and "y" lists must be the same length')
        T = fits_table()
        T.x = x
        T.y = y
        temp_file_path = tempfile.mktemp()
        T.writeto(temp_file_path)
        df = DiskFile.from_file(temp_file_path,
                                collection=Image.ORIG_COLLECTION)
        original_filename = 'json-xy'
    else:
        df, original_filename = handle_upload(file=file, url=url)
    submittor = request.user if request.user.is_authenticated() else None
    pro = get_user_profile(submittor)
    allow_commercial_use = json.get('allow_commercial_use', 'd')
    allow_modifications = json.get('allow_modifications', 'd')
    license,created = License.objects.get_or_create(
        default_license=pro.default_license,
        allow_commercial_use=allow_commercial_use,
        allow_modifications=allow_modifications,
    )
    publicly_visible = json.get('publicly_visible', 'y')

    subargs = dict(
        user=submittor,
        disk_file=df,
        original_filename=original_filename,
        license=license,
        publicly_visible=publicly_visible,
        via_api = True,
        )
    if url is not None:
        subargs.update(url=url)

    for key,typ in [('scale_units', str),
                    ('scale_type', str),
                    ('scale_lower', float),
                    ('scale_upper', float),
                    ('scale_est', float),
                    ('scale_err', float),
                    ('center_ra', float),
                    ('center_dec', float),
                    ('radius', float),
                    ('tweak_order', int),
                    ('downsample_factor', int),
                    ('use_sextractor', bool),
                    ('crpix_center', bool),
                    ('parity', int),
                    ('image_width', int),
                    ('image_height', int),
                    ('positional_error', float),
                    ]:
        if key in json:
            subargs[key] = typ(json[key])

    logmsg('upload: submission args:', subargs)

    sub = Submission(**subargs)
    sub.save()
    return HttpResponseJson({'status': 'success',
                             'subid': sub.id,
                             'hash': sub.disk_file.file_hash})