Ejemplo n.º 1
0
def analysis(title, 
             collaboration,
             e_print, 
             journal,
             doi, 
             inspire_url, 
             description, 
             run_condition_name,
             run_condition_description):
    """Create a new analysis and Run Condition.
  
    :param title: Title of the analysis.
    :param collaboration: Choice among: ALICE, ATLAS, CMS, .
    :param e_print: link.
    :param journal: Name of journal.
    :param doi: Arxiv doi?
    :param inspire_url: URL on inspire website.
    :param description: A detailed description of the analysis.
    :param run_condition_name: Name of the run condition.
    :param run_condition_descprition: Detailed description of the run condition.

    :return: JSON object containing data that has been added into DB.
    """
    r_condition_payload = {
        'name': run_condition_name,
        'description': run_condition_description,
        }
    r_condition_url = '{}/'.format(recastapi.ENDPOINTS['RUN_CONDITIONS'])
  
    r_condition_response =  recastapi.post(r_condition_url, r_condition_payload)
    run_condition_id = r_condition_response['id']
    
    owner = recastapi.user.userData()
    owner_id = owner['_items'][0]['id']
    collaboration.upper()

    payload = {
        'owner_id':owner_id,
        'title':title,
        'collaboration':collaboration,
        'e_print':e_print,
        'journal':journal,
        'doi':doi,
        'inspire_URL':inspire_url,
        'description':description,
        'run_condition_id':run_condition_id,
        }
    url = '{}/'.format(recastapi.ENDPOINTS['ANALYSIS'])
    return recastapi.post(url, payload)
Ejemplo n.º 2
0
def basic_response(point_response_id,basic_request_id,result_data, description, replace_existing = True):
    """Adds basic request
    :param point_response_id: ID of the point response
    :param basic_request_id: ID of the basic request
    :param result_data: result data (CLs, logL, etc.)
    :return: JSON object
    """
    payload = {
        'model_id': None,
        'basic_request_id': basic_request_id,
        'point_response_id': point_response_id,
        'description': description
    }
    payload.update(**result_data)

    existing = recastapi.response.read.basic_response(basic_request_id_filter = basic_request_id, description_filter = description)
    if existing and replace_existing:
        existing = existing[0]
        existing_id = existing['id']
        url = '{}/{}'.format(recastapi.ENDPOINTS['BASIC_RESPONSES'],existing_id)
        existing.update(**payload)
        existing = {k:v for k,v in existing.iteritems() if not (k.startswith('_') or k=='id')}
        recastapi.patch(url,existing)
        return recastapi.response.read.basic_response(basic_response_id = existing_id)
    url = '{}/'.format(recastapi.ENDPOINTS['BASIC_RESPONSES'])
    return recastapi.post(url, json=payload)
Ejemplo n.º 3
0
def response_archive(basic_response_id, filename = None):
    basic_response = recastapi.response.read.basic_response(basic_response_id)
    existing = recastapi.response.read.response_archive(basic_response['id'])


    payload = {
        'basic_response_id': basic_response_id,
        'original_file_name': os.path.basename(filename),
    }

    files = {'file': open(filename, 'rb')} if filename else {}

    if existing:
        url = '{}/{}'.format(recastapi.ENDPOINTS['RESPONSE_ARCHIVES'],existing['id'])
        existing.update(**payload)
        existing = {k:v for k,v in existing.iteritems() if not (k.startswith('_') or k=='id')}

        recastapi.patch2(url,data = existing, files = files)
        return


    url = '{}/'.format(recastapi.ENDPOINTS['RESPONSE_ARCHIVES'])
    basic_request_response = recastapi.post(
        url,
        data=payload,
        files=files,
    )
    return basic_request_response
Ejemplo n.º 4
0
def analysis(title,
             collaboration,
             doi,
             arxiv_id,
             inspire_id,
             cds_id,
             description,
             run_condition_name,
             run_condition_description):
    """Create a new analysis and Run Condition.

    :param title: Title of the analysis.
    :param collaboration: Choice among: ALICE, ATLAS, CMS, .
    :param doi:  Digital Object Identifier
    :param inspire_id: INSPIRE Record identifier
    :param arxiv_id: link.
    :param description: A detailed description of the analysis.
    :param run_condition_name: Name of the run condition.
    :param run_condition_descprition: Detailed description of the run condition.

    :return: JSON object containing data that has been added into DB.
    """
    run_condition_payload = {
        'name': run_condition_name,
        'description': run_condition_description,
    }
    run_condition_url = '{}/'.format(recastapi.ENDPOINTS['RUN_CONDITIONS'])
    run_condition_response =  recastapi.post(run_condition_url, run_condition_payload)
    run_condition_id = run_condition_response['id']

    owner = recastapi.user.read.this_user()
    owner_id = owner['id']
    collaboration.upper()

    payload = {
        'owner_id':owner_id,
        'title':title,
        'collaboration':collaboration,
        'doi':doi,
        'arxiv_id':arxiv_id,
        'inspire_id':inspire_id,
        'cds_id':cds_id,
        'description':description,
        'run_condition_id':run_condition_id,
        }
    url = '{}/'.format(recastapi.ENDPOINTS['ANALYSIS'])
    return recastapi.post(url, payload)
Ejemplo n.º 5
0
def analysis(title, collaboration, e_print, journal, doi, inspire_url,
             description, run_condition_name, run_condition_description):
    """Create a new analysis and Run Condition.
  
    :param title: Title of the analysis.
    :param collaboration: Choice among: ALICE, ATLAS, CMS, .
    :param e_print: link.
    :param journal: Name of journal.
    :param doi: Arxiv doi?
    :param inspire_url: URL on inspire website.
    :param description: A detailed description of the analysis.
    :param run_condition_name: Name of the run condition.
    :param run_condition_descprition: Detailed description of the run condition.

    :return: JSON object containing data that has been added into DB.
    """
    r_condition_payload = {
        'name': run_condition_name,
        'description': run_condition_description,
    }
    r_condition_url = '{}/'.format(recastapi.ENDPOINTS['RUN_CONDITIONS'])

    r_condition_response = recastapi.post(r_condition_url, r_condition_payload)
    run_condition_id = r_condition_response['id']

    owner = recastapi.user.userData()
    owner_id = owner['_items'][0]['id']
    collaboration.upper()

    payload = {
        'owner_id': owner_id,
        'title': title,
        'collaboration': collaboration,
        'e_print': e_print,
        'journal': journal,
        'doi': doi,
        'inspire_URL': inspire_url,
        'description': description,
        'run_condition_id': run_condition_id,
    }
    url = '{}/'.format(recastapi.ENDPOINTS['ANALYSIS'])
    return recastapi.post(url, payload)
Ejemplo n.º 6
0
def request(analysis_id,
            title,
            description_model,
            reason_for_request,
            additional_information,
            status="Incomplete",
            file_path=None,
            parameter_value=None,
            parameter_title=None):
    """Creates a new request
    
    :param analysis_id: ID of the analysis.
    :param description_model: Detailed description of the model to use.
    :param reason_for_request: Reason for submitting this request.
    :param additional_information: Any other additional information associated to this request.
    :param status: Defaults to Incomplete.
    :param file_path: File to be associated with this request, optional variable.
    :param parameter_value: Value of the scan parameter, optional.
    :param parameter_title: Optional title of the parameter title.
      

    :return: JSON object with data added
    """
    request_uuid = str(uuid.uuid1())
    user = recastapi.user.get.user_data()
    user = user['_items'][0]
    
    payload = {
        'requester_id': user['id'],
        'title': title,
        'reason_for_request': reason_for_request,
        'additional_information': additional_information,
        'analysis_id': analysis_id,
        'zenodo_deposition_id': None,
        'uuid': request_uuid,
        'description_of_model': description_model,
        'status': status,
    }
    print colored(payload, 'green')
    url = '{}/'.format(recastapi.ENDPOINTS['REQUESTS'])
    request_response = recastapi.post(url, data=payload)
    
    if file_path and parameter_value:
        parameter_response = parameter(request_response['id'],
                                       parameter_value,
                                       parameter_title,
                                       file_path)
        request_response['parameter'] = parameter_response

    return request_response
Ejemplo n.º 7
0
def upload_file(parameter_id, filename):
    """Uploads zip file and associates it with a request and basic request.
  
    :param request_id: ID of the request to be associated to this file.
    :param basic_request_id: ID of the basic request to be asso
    :param filename: Path to file to be uploaded.
      

    :return: JSON object    
    """
    recastapi.file_check(filename)
    
    basic_request_response = basic_request(parameter_id)
    basic_request_id = basic_request_response['id']
    
    file_uuid = str(uuid.uuid1())

    #get request ID, so deposition can be retrieved
    point_request_url = '{}/{}'.format(
        recastapi.ENDPOINTS['POINT_REQUESTS'],
        parameter_id)
    point_response = recastapi.get(point_request_url)

    request_id = point_response['scan_request_id']
    
    request_url = '{}/{}'.format(
        recastapi.ENDPOINTS['REQUESTS'],
        request_id
    )
    request_response = recastapi.get(request_url)
    deposition_id = request_response['zenodo_deposition_id']

    payload = {
        'file_name': file_uuid,
        'zenodo_file_id': None,
        'original_file_name': filename,
        'basic_request_id': basic_request_id,
    }
  
    files = {'file': open(filename, 'rb')}
    url = '{}/'.format(recastapi.ENDPOINTS['FILES'])
    file_response = recastapi.post(
        url, 
        data=payload, 
        files=files,
        params = {'deposition_id': deposition_id}
    )
    basic_request_response['metadata'] = file_response
    return basic_request_response
Ejemplo n.º 8
0
def request(analysis_id,
            title,
            description_model,
            reason_for_request,
            additional_information,
            status="Incomplete",
            file_path=None,
            parameter_value=None,
            parameter_title=None):
    """Creates a new request
    
    :param analysis_id: ID of the analysis.
    :param description_model: Detailed description of the model to use.
    :param reason_for_request: Reason for submitting this request.
    :param additional_information: Any other additional information associated to this request.
    :param status: Defaults to Incomplete.
    :param file_path: File to be associated with this request, optional variable.
    :param parameter_value: Value of the scan parameter, optional.
    :param parameter_title: Optional title of the parameter title.
      

    :return: JSON object with data added
    """
    request_uuid = str(uuid.uuid1())
    user = recastapi.user.get.user_data()
    user = user['_items'][0]

    payload = {
        'requester_id': user['id'],
        'title': title,
        'reason_for_request': reason_for_request,
        'additional_information': additional_information,
        'analysis_id': analysis_id,
        'zenodo_deposition_id': None,
        'uuid': request_uuid,
        'description_of_model': description_model,
        'status': status,
    }
    print colored(payload, 'green')
    url = '{}/'.format(recastapi.ENDPOINTS['REQUESTS'])
    request_response = recastapi.post(url, data=payload)

    if file_path and parameter_value:
        parameter_response = parameter(request_response['id'], parameter_value,
                                       parameter_title, file_path)
        request_response['parameter'] = parameter_response

    return request_response
Ejemplo n.º 9
0
def upload_file(filename,
	        point_response_id=None,
		basic_response_id=None):
    """Uploads response file 
    
    Either the basic response or parameter response has to be provided


    :param filename: file to be uploaded
    :param point_response_id: ID of the parameter response
    :param basic_response_id: ID of the basic response

    :return: JSON object
    """
    recastapi.file_check(filename)

    if not point_response_id and not basic_response_id:
        print "*"*60
        print "No point response ID or basic response ID given"
        raise RuntimeError

    if point_response_id and basic_response_id:
        print "*"*60
        print "Point response ID and basic response ID"
        print "Please provide either a point response ID and a basic response ID"
        raise RuntimeError
    
    file_uuid = str(uuid.uuid1()) # how will response provi
    if point_response_id:		
	payload = {
	    'file_name': file_uuid,
	    'original_file_name': filename,
	    'point_response_id': point_response_id
	}
    elif basic_response_id:
	payload = {
	    'file_name': file_uuid,
	    'original_file_name': filename,
	    'basic_response_id': basic_response_id
	}
    else:
	print "*"*60
	print "Either a point response ID or basic response ID needs to be provided"
	raise RuntimeError
	
    files = {'file': open(filename, 'rb')}
    url = '{}/'.format(recastapi.ENDPOINTS['HISTOGRAMS'])
    return recastapi.post(url, data=payload, files=files)
Ejemplo n.º 10
0
def basic_request(point_request_id):
    """Adds basic request
    
    
    :param point_request_id: ID of the point request
      
    :return: JSON object
    """
    user = recastapi.user.get.user_data()
    user = user['_items'][0]
    payload = {
        'requester_id': user['id'],
        'point_request_id': point_request_id,
    }
    url = '{}/'.format(recastapi.ENDPOINTS['BASIC_REQUESTS'])
    return recastapi.post(url, data=payload)
Ejemplo n.º 11
0
def basic_request(point_request_id):
    """Adds basic request
    
    
    :param point_request_id: ID of the point request
      
    :return: JSON object
    """
    user = recastapi.user.get.user_data()
    user = user['_items'][0]
    payload = {
        'requester_id': user['id'],
        'point_request_id': point_request_id,
    }
    url = '{}/'.format(recastapi.ENDPOINTS['BASIC_REQUESTS'])
    return recastapi.post(url, data=payload)
Ejemplo n.º 12
0
def user(name, email, orcid_id=None):
    """create a new user.


    :param name: First and last name of the user.
    :param email: Email of the user.
    :param orcid_id: ORCID ID of the user.

    :return: JSON object with added data.
    """
    payload = {
        'name': name,
        'email': email,
        'orcid_id': orcid_id,
    }
    url = '{}/'.format(recastapi.ENDPOINTS['USERS'])
    return recastapi.post(url, payload)
Ejemplo n.º 13
0
def user(name, email, orcid_id=None):
    """create a new user.


    :param name: First and last name of the user.
    :param email: Email of the user.
    :param orcid_id: ORCID ID of the user.

    :return: JSON object with added data.
    """
    payload = {
        'name':name,
        'email':email,
        'orcid_id':orcid_id,
        }
    url = '{}/'.format(recastapi.ENDPOINTS['USERS'])
    return recastapi.post(url, payload)
Ejemplo n.º 14
0
def upload_file(filename, point_response_id=None, basic_response_id=None):
    """Uploads response file 
    
    Either the basic response or parameter response has to be provided


    :param filename: file to be uploaded
    :param point_response_id: ID of the parameter response
    :param basic_response_id: ID of the basic response

    :return: JSON object
    """
    recastapi.file_check(filename)

    if not point_response_id and not basic_response_id:
        print "*" * 60
        print "No point response ID or basic response ID given"
        raise RuntimeError

    if point_response_id and basic_response_id:
        print "*" * 60
        print "Point response ID and basic response ID"
        print "Please provide either a point response ID and a basic response ID"
        raise RuntimeError

    file_uuid = str(uuid.uuid1())  # how will response provi
    if point_response_id:
        payload = {
            'file_name': file_uuid,
            'original_file_name': filename,
            'point_response_id': point_response_id
        }
    elif basic_response_id:
        payload = {
            'file_name': file_uuid,
            'original_file_name': filename,
            'basic_response_id': basic_response_id
        }
    else:
        print "*" * 60
        print "Either a point response ID or basic response ID needs to be provided"
        raise RuntimeError

    files = {'file': open(filename, 'rb')}
    url = '{}/'.format(recastapi.ENDPOINTS['HISTOGRAMS'])
    return recastapi.post(url, data=payload, files=files)
Ejemplo n.º 15
0
def point_request(request_id):
    """Adds point request
    
    :param request_id: ID of the request.
    

    :return: JSON object
    """
    user = recastapi.user.get.user_data()
    user = user['_items'][0]
    payload = {
        "scan_request_id": request_id,
        "requester_id": user['id'],
    }
    
    print colored(payload, 'yellow')
    url = '{}'.format(recastapi.ENDPOINTS['POINT_REQUESTS'])
    return recastapi.post(url, json=payload)
Ejemplo n.º 16
0
def point_request(request_id):
    """Adds point request
    
    :param request_id: ID of the request.
    

    :return: JSON object
    """
    user = recastapi.user.get.user_data()
    user = user['_items'][0]
    payload = {
        "scan_request_id": request_id,
        "requester_id": user['id'],
    }

    print colored(payload, 'yellow')
    url = '{}'.format(recastapi.ENDPOINTS['POINT_REQUESTS'])
    return recastapi.post(url, json=payload)
Ejemplo n.º 17
0
def response(request_id, model_id=None):
    """create response.
    
    :param request_id: ID of the request

    :return: JSON object
    """
    # check if there is a response for this request
    scan_response_url = '{}?where=scan_request_id=="{}"'.format(
        recastapi.ENDPOINTS['RESPONSES'], request_id)
    scan_responses = recastapi.get(scan_response_url)

    if not scan_responses['_items']:
        payload = {'scan_request_id': request_id, 'model_id': model_id}

        url = '{}/'.format(recastapi.ENDPOINTS['RESPONSES'])
        return recastapi.post(url, json=payload)
    else:
        return scan_responses['_items'][0]
Ejemplo n.º 18
0
def upload_file(parameter_id, filename):
    """Uploads zip file and associates it with a request and basic request.
  
    :param request_id: ID of the request to be associated to this file.
    :param basic_request_id: ID of the basic request to be asso
    :param filename: Path to file to be uploaded.
      

    :return: JSON object    
    """
    recastapi.file_check(filename)

    basic_request_response = basic_request(parameter_id)
    basic_request_id = basic_request_response['id']

    file_uuid = str(uuid.uuid1())

    #get request ID, so deposition can be retrieved
    point_request_url = '{}/{}'.format(recastapi.ENDPOINTS['POINT_REQUESTS'],
                                       parameter_id)
    point_response = recastapi.get(point_request_url)

    request_id = point_response['scan_request_id']

    request_url = '{}/{}'.format(recastapi.ENDPOINTS['REQUESTS'], request_id)
    request_response = recastapi.get(request_url)
    deposition_id = request_response['zenodo_deposition_id']

    payload = {
        'file_name': file_uuid,
        'zenodo_file_id': None,
        'original_file_name': filename,
        'basic_request_id': basic_request_id,
    }

    files = {'file': open(filename, 'rb')}
    url = '{}/'.format(recastapi.ENDPOINTS['FILES'])
    file_response = recastapi.post(url,
                                   data=payload,
                                   files=files,
                                   params={'deposition_id': deposition_id})
    basic_request_response['metadata'] = file_response
    return basic_request_response
Ejemplo n.º 19
0
def coordinate(parameter_id, coordinate_name, coordinate_value):
    """Adds coordinate given parameter id.
        

    :param parameter_id: analogous to point_request_id.
    :param coordinate_value: value of the coordinate.
    :param coordinate_name: name of the coordinate.

    
    :return: JSON object with added data
    """
    coordinate_payload = {
        'point_request_id': parameter_id,
        'title': coordinate_name,
        'value': float(coordinate_value)
    }

    coordinate_url = '{}/'.format(recastapi.ENDPOINTS['PARAMETER_POINTS'])
    coordinate_response = recastapi.post(coordinate_url,
                                         json=coordinate_payload)
    return coordinate_response
Ejemplo n.º 20
0
def response(request_id, model_id=None):
    """create response.
    
    :param request_id: ID of the request

    :return: JSON object
    """
    # check if there is a response for this request
    scan_response_url = '{}?where=scan_request_id=="{}"'.format(
        recastapi.ENDPOINTS['RESPONSES'], request_id)
    scan_responses = recastapi.get(scan_response_url)

    if not scan_responses['_items']:
        payload = {
            'scan_request_id': request_id,
            'model_id': model_id
        }
        
        url = '{}/'.format(recastapi.ENDPOINTS['RESPONSES'])
        return recastapi.post(url, json=payload)
    else:
        return scan_responses['_items'][0]
Ejemplo n.º 21
0
def scan_response(scan_request_id):
    """Adds scan request
    :param scan_response_id: ID of the scan response
    :param point_request_id: ID of the scan request
    :param result_data: result data (CLs, logL, etc.)
    :return: JSON object
    """
    payload = {
        'model_id': None,
        'scan_request_id': scan_request_id,
    }

    existing = recastapi.response.read.scan_response(scan_request_id = scan_request_id)
    if existing:
        url = '{}/{}'.format(recastapi.ENDPOINTS['SCAN_RESPONSES'],existing['id'])
        existing.update(**payload)
        existing = {k:v for k,v in existing.iteritems() if not (k.startswith('_') or k=='id')}
        recastapi.patch(url,existing)
        scan_response =  recastapi.response.read.scan_response(scan_request_id = scan_request_id)
        return scan_response

    url = '{}/'.format(recastapi.ENDPOINTS['SCAN_RESPONSES'])
    return recastapi.post(url, data=payload)
Ejemplo n.º 22
0
def coordinate(parameter_id,
                   coordinate_name,
                   coordinate_value):
    """Adds coordinate given parameter id.
        

    :param parameter_id: analogous to point_request_id.
    :param coordinate_value: value of the coordinate.
    :param coordinate_name: name of the coordinate.

    
    :return: JSON object with added data
    """
    coordinate_payload = {
        'point_request_id': parameter_id,
        'title': coordinate_name,
        'value': float(coordinate_value)        
    }
    
    coordinate_url = '{}/'.format(recastapi.ENDPOINTS['PARAMETER_POINTS'])
    coordinate_response = recastapi.post(coordinate_url,
                                         json=coordinate_payload)
    return coordinate_response
Ejemplo n.º 23
0
def create(analysis_id,
           subscription_type,
           description, 
           requirements,
           notifications=[],
           authoritative=False):     
    """Creates a subscription.
    

    :param analysis: ID of the analysis
    :param subscription_type: provider or observer
    :param description: description of subscription
    :param requirements: requirements
    :param notification: recast_requests or recast_responses or new subscribers
    :param authoritative: True or False
    
    :return: JSON object
    """
    
    assert subscription_type in ['provider', 'observer']
    for notif in notifications:
        assert notif in ['recast_requests', 'recast_responses', 'new_subscribers']
        
        
    user = recastapi.user.userData()
    payload = {
        'subscription_type': subscription_type,
        'description': description,
        'requirements': requirements,
        'notification': ','.join(notifications),
        'authoritative': authoritative,
        'subscriber_id': user['_items'][0]['id'],
        'analysis_id': analysis_id,
    }
    url = '{}/'.format(recastapi.ENDPOINTS['SUBSCRIPTIONS'])
    return recastapi.post(url, payload)
Ejemplo n.º 24
0
	    'upper_1sig_expected_CLs': float(data_map['upper_1sig_expected_CLs']),
	    'upper_2sig_expected_CLs': float(data_map['upper_2sig_expected_CLs']),
	    'observed_CLs': float(data_map['observed_CLs']),
            'log_likelihood_at_reference': float(data_map['log_likelihood_at_reference']),
            'scan_response_id': int(scan_response_id),
            'point_request_id': int(point_request_id)
	}
    except Exception, e:
	print "*"*60
	print "YAML file not correctly formatted: ", e
	print "-"*60
	raise RuntimeError
    
    print payload
    url = '{}/'.format(recastapi.ENDPOINTS['POINT_RESPONSES'])
    response = recastapi.post(url, json=payload)
    
    if filename:
	response['metadata'] = upload_file(filename, point_response_id=response['id'])
        	
    return response
	
def basic_response(yaml_file, point_response_id, basic_request_id, filename):
    """" Adds and associtate basic response to parameter response
    
    :param yaml_file: file containing data of the basic response
    :param point_response_id: parameter response ID
    :param basic_request_id: index of the basic request
    :param filename: file associated to basic response

    :return: JSON object
Ejemplo n.º 25
0
            'log_likelihood_at_reference':
            float(data_map['log_likelihood_at_reference']),
            'scan_response_id':
            int(scan_response_id),
            'point_request_id':
            int(point_request_id)
        }
    except Exception, e:
        print "*" * 60
        print "YAML file not correctly formatted: ", e
        print "-" * 60
        raise RuntimeError

    print payload
    url = '{}/'.format(recastapi.ENDPOINTS['POINT_RESPONSES'])
    response = recastapi.post(url, json=payload)

    if filename:
        response['metadata'] = upload_file(filename,
                                           point_response_id=response['id'])

    return response


def basic_response(yaml_file, point_response_id, basic_request_id, filename):
    """" Adds and associtate basic response to parameter response
    
    :param yaml_file: file containing data of the basic response
    :param point_response_id: parameter response ID
    :param basic_request_id: index of the basic request
    :param filename: file associated to basic response