Exemplo n.º 1
0
def fieldObjectAdd(request):
    '''add a field object to the database'''
    FOForm = modelform_factory(FieldObject,fields=['target','ra','dec','isTarget'])
    form = FOForm(request.POST)
    if form.is_valid():
        obj = form.save()
        return okJSONResponse({'id':obj.id, 'ra':str(obj.ra),'dec':str(obj.dec), 'isTarget':obj.isTarget})
    else:
        return errorJSONResponse(form.errors)
Exemplo n.º 2
0
def fieldObjectAddTarget(request):
    '''add the target object to the list of coordinates for that target'''
    try:
        targ = Target.objects.get(pk=request.POST['target'])
        fobj = FieldObject(target=targ, ra=targ.ra, dec=targ.dec,isTarget=True)
        fobj.save() 
        return okJSONResponse(FieldObject2dict(fobj))
    except Exception as e:
        logger.debug(e)
        return errorJSONResponse("targetID must be supplied and a valid target")
Exemplo n.º 3
0
def applyWCS(path):
    '''apply world coordinate system to 
    images'''
    try:
        improc = SecondPassProcessor(path)
        improc.applyWCS()
        return okJSONResponse()
    except Exception as e:
        #an unexpected exception
        logger.debug(traceback.format_exc())  #log the traceback
        raise e
Exemplo n.º 4
0
def applyWCS(path):
    '''apply world coordinate system to 
    images'''
    try:
        improc = SecondPassProcessor(path)
        improc.applyWCS()
        return okJSONResponse()
    except Exception as e:
        #an unexpected exception
        logger.debug(traceback.format_exc()) #log the traceback
        raise e
Exemplo n.º 5
0
def subZeroDark(path):
    '''subtract zeros and darks from the object files in a folder'''
    try:
        improc = FirstPassProcessor(path)
        logger.info("Processing object files in " + path)
        improc.zero_and_dark_subtract()
        return okJSONResponse()
    except ValueError as e:
        return errorJSONResponse(str(e))
    except Exception as e:
        #an unexpected exception
        logger.debug(traceback.format_exc())  #log the traceback
        raise e
Exemplo n.º 6
0
def makeFlats(path):
    '''make master flats from a folder'''
    try:
        improc = FirstPassProcessor(path)
        logger.info("Making flats at path " + path)
        improc.makeFlats()
        return okJSONResponse()
    except ValueError as e:
        return errorJSONResponse(str(e))
    except Exception as e:
        #an unexpected exception
        logger.debug(traceback.format_exc())  #log the traceback
        raise e
Exemplo n.º 7
0
def makeFlats(path):
    '''make master flats from a folder'''
    try:
        improc = FirstPassProcessor(path)
        logger.info("Making flats at path " + path)
        improc.makeFlats()
        return okJSONResponse()
    except ValueError as e:
        return errorJSONResponse(str(e))
    except Exception as e:
        #an unexpected exception
        logger.debug(traceback.format_exc()) #log the traceback
        raise e
Exemplo n.º 8
0
def subZeroDark(path):
    '''subtract zeros and darks from the object files in a folder'''
    try:
        improc = FirstPassProcessor(path)
        logger.info("Processing object files in "+path)
        improc.zero_and_dark_subtract()
        return okJSONResponse()
    except ValueError as e:
        return errorJSONResponse(str(e))
    except Exception as e:
        #an unexpected exception
        logger.debug(traceback.format_exc()) #log the traceback
        raise e
Exemplo n.º 9
0
def uploadCoordFile(request,targetID):
    '''upload a coordinate file for a target'''
    try:
        f = request.FILES['coords']
        result = []
        with transaction.commit_on_success():
            for ra,dec in parseCoords(f):
                logger.info("Adding object at {0} {1}".format(ra,dec))
                obj = FieldObject(target_id=targetID,ra=ra,dec=dec,isTarget=False)
                obj.save()
                result.append(FieldObject2dict(obj))
        return okJSONResponse(result)
    except Exception as ex:
        return errorJSONResponse(str(ex))
Exemplo n.º 10
0
def firstPass(path):
    '''perform the first pass over the folder
    i.e. create calibration frames and apply zeros 
    and darks to the object frames, and save them in the processed folder
    '''
    try:
        doFirstPass(path)
        return okJSONResponse()
    except ValueError as e:
        return errorJSONResponse(str(e))
    except Exception as e:
        #an unexpected exception
        logger.debug(traceback.format_exc())  #log the traceback
        raise e
Exemplo n.º 11
0
def firstPass(path):
    '''perform the first pass over the folder
    i.e. create calibration frames and apply zeros 
    and darks to the object frames, and save them in the processed folder
    '''
    try:
        doFirstPass(path)
        return okJSONResponse()
    except ValueError as e:
        return errorJSONResponse(str(e))
    except Exception as e:
        #an unexpected exception
        logger.debug(traceback.format_exc()) #log the traceback
        raise e
Exemplo n.º 12
0
def applyFlats(request, path):
    '''apply the given flats to the supplied path'''
    try:
        flats = json.loads(request.POST['flats'])
        for filt, flat in flats.items():
            flats[filt] = Filesystem.getTruePath(flat)
        improc = SecondPassProcessor(path)
        improc.applyFlats(flats)
        return okJSONResponse()
    except ValueError as e:
        return errorJSONResponse(str(e))
    except Exception as e:
        #an unexpected exception
        logger.debug(traceback.format_exc())  #log the traceback
        raise e
Exemplo n.º 13
0
def applyFlats(request,path):
    '''apply the given flats to the supplied path'''
    try:
        flats = json.loads(request.POST['flats'])
        for filt,flat in flats.items():
            flats[filt] = Filesystem.getTruePath(flat)
        improc = SecondPassProcessor(path)
        improc.applyFlats(flats)
        return okJSONResponse()
    except ValueError as e:
        return errorJSONResponse(str(e))
    except Exception as e:
        #an unexpected exception
        logger.debug(traceback.format_exc()) #log the traceback
        raise e
Exemplo n.º 14
0
def secondPass(request,path):
    '''perform the second pass over the folder
    i.e. apply flats and apply world coordinate system
    '''
    try:
        if 'flats' not in request.POST:
            return HttpResponseBadRequest("No flats specified")
        flats = json.loads(request.POST['flats'])
        for filt,flat in flats.items():
            flats[filt] = Filesystem.getTruePath(flat)
        doSecondPass(path,flats)
        return okJSONResponse()
    except ValueError as e:
        return errorJSONResponse(str(e))
    except Exception as e:
        #an unexpected exception
        logger.debug(traceback.format_exc()) #log the traceback
        raise e
Exemplo n.º 15
0
def secondPass(request, path):
    '''perform the second pass over the folder
    i.e. apply flats and apply world coordinate system
    '''
    try:
        if 'flats' not in request.POST:
            return HttpResponseBadRequest("No flats specified")
        flats = json.loads(request.POST['flats'])
        for filt, flat in flats.items():
            flats[filt] = Filesystem.getTruePath(flat)
        doSecondPass(path, flats)
        return okJSONResponse()
    except ValueError as e:
        return errorJSONResponse(str(e))
    except Exception as e:
        #an unexpected exception
        logger.debug(traceback.format_exc())  #log the traceback
        raise e
Exemplo n.º 16
0
def photSelectFolder(request, path):
    '''Allows a client to select a path for performing,
    photometry. The client must supply the paramater 'path',
    which is the virtual path to the folder to perform photometry in,
    and will receive a Json object which contains an object of the following form
        ok: True if the request succeeded
        error: the error message if ok is false, not present if ok is true
        result: the response if ok is true, not present if ok is false, it will be a list
            of objects that do not have coordinates for them, if all objects have coordinates it will
            be an empty list.
    It is up to the client whether to continue forward or not if there are missing coordinates, the client
    can also use the targets API to upload more coordinates.'''
    try:
        mapping, missing = getObjectMapping(path)
        request.session['phot.object_mapping'] = mapping
        request.session['phot.path'] = path
        return okJSONResponse(missing)
    except Exception as e:
        logger.debug(traceback.format_exc())
        return errorJSONResponse(str(e))
Exemplo n.º 17
0
def photSelectFolder(request,path):
    '''Allows a client to select a path for performing,
    photometry. The client must supply the paramater 'path',
    which is the virtual path to the folder to perform photometry in,
    and will receive a Json object which contains an object of the following form
        ok: True if the request succeeded
        error: the error message if ok is false, not present if ok is true
        result: the response if ok is true, not present if ok is false, it will be a list
            of objects that do not have coordinates for them, if all objects have coordinates it will
            be an empty list.
    It is up to the client whether to continue forward or not if there are missing coordinates, the client
    can also use the targets API to upload more coordinates.'''
    try:
       mapping, missing = getObjectMapping(path)
       request.session['phot.object_mapping'] = mapping
       request.session['phot.path'] = path
       return okJSONResponse(missing)
    except Exception as e:
        logger.debug(traceback.format_exc())
        return errorJSONResponse(str(e))
Exemplo n.º 18
0
def thirdPass(request):
    '''web service to perform the photometry'''
    #the mapping object has rather sensitive information in it
    #so we don't want the client to deal with it, so we need to
    #have everything in the session
    path = request.session.get('phot.path')
    mapping = request.session.get('phot.object_mapping')
    if path and mapping:
        #clean up session
        del request.session['phot.path']
        del request.session['phot.object_mapping']
    else:
        return HttpResponseBadRequest("No mapping specified")
    try:
        doThirdPass(path, mapping)
    except Exception as e:
        logger.debug(traceback.format_exc())
        return errorJSONResponse(str(e))
    finally:
        #clean up all the temporary files
        # we need to do this no matter what
        for tempFile, _ in mapping.values():
            os.remove(tempFile)
    return okJSONResponse()
Exemplo n.º 19
0
def thirdPass(request):
    '''web service to perform the photometry'''
    #the mapping object has rather sensitive information in it
    #so we don't want the client to deal with it, so we need to
    #have everything in the session
    path = request.session.get('phot.path')
    mapping = request.session.get('phot.object_mapping')
    if path and mapping:
        #clean up session
        del request.session['phot.path'] 
        del request.session['phot.object_mapping'] 
    else:
        return HttpResponseBadRequest("No mapping specified")
    try:
        doThirdPass(path,mapping)
    except Exception as e:
        logger.debug(traceback.format_exc())
        return errorJSONResponse(str(e))
    finally:
        #clean up all the temporary files
        # we need to do this no matter what
        for tempFile, _ in mapping.values():
            os.remove(tempFile)
    return okJSONResponse()
Exemplo n.º 20
0
def synchronizeTargets(request):
    '''synchronize the targets database with rovor.byu.edu'''
    Target.synchronize()
    return okJSONResponse()
Exemplo n.º 21
0
def renameAll(path):
    '''rename all files in a folder to be .fit instead of .FIT'''
    renamer.renameAll(path)  #rename the files
    return okJSONResponse()
Exemplo n.º 22
0
def renameAll(path):
    '''rename all files in a folder to be .fit instead of .FIT'''
    renamer.renameAll(path) #rename the files
    return okJSONResponse()