def parameter(request_id, coordinate_value=None, coordinate_title=None, filename=None): """Add a parameter point to a request. :param request_id: ID of the request to be associated to this parameter point. :param coordinate_value: Value of the scan coordinate. :param parameter_title: Optional title of the scan title. :param filename: Optional file path to file to associate to this parameter point. :return: JSON object with data added """ if filename: recastapi.file_check(filename) parameter_response = point_request(request_id) if coordinate_value: coordinate_response = coordinate(parameter_response['id'], coordinate_title, coordinate_value) parameter_response['coordinate'] = coordinate_response if filename: file_response = upload_file(parameter_response['id'], filename) parameter_response['file'] = file_response return parameter_response
def upload_file_by_index(request_id, parameter_index, filename): """ Uploads zip file given the parameter index :param request_id: ID of the request :param parameter_index: index of the parameter :param filename: file to upload. Must be zip format :return: JSON object """ recastapi.file_check(filename) #get parameter id parameter_url = '{}?where=scan_request_id=="{}"'.format( recastapi.ENDPOINTS['POINT_REQUESTS'], request_id) parameters = recastapi.get(parameter_url) if parameter_index > len(parameters['_items']) - 1: print "*" * 60 print "Parameter index out of bounds" print "The request has ", len(parameters['_items']), " parameters" raise RuntimeError parameter_id = parameter_index['_items'][parameter_index]['id'] return upload_file(parameter_id=parameter_id, filename=filename)
def upload_file_by_index(request_id, parameter_index, filename): """ Uploads zip file given the parameter index :param request_id: ID of the request :param parameter_index: index of the parameter :param filename: file to upload. Must be zip format :return: JSON object """ recastapi.file_check(filename) #get parameter id parameter_url = '{}?where=scan_request_id=="{}"'.format( recastapi.ENDPOINTS['POINT_REQUESTS'], request_id) parameters = recastapi.get(parameter_url) if parameter_index > len(parameters['_items'])-1: print "*"*60 print "Parameter index out of bounds" print "The request has ", len(parameters['_items']), " parameters" raise RuntimeError parameter_id = parameter_index['_items'][parameter_index]['id'] return upload_file(parameter_id=parameter_id, filename=filename)
def parameter(request_id, coordinate_value=None, coordinate_title=None, filename=None): """Add a parameter point to a request. :param request_id: ID of the request to be associated to this parameter point. :param coordinate_value: Value of the scan coordinate. :param parameter_title: Optional title of the scan title. :param filename: Optional file path to file to associate to this parameter point. :return: JSON object with data added """ if filename: recastapi.file_check(filename) parameter_response = point_request(request_id) if coordinate_value: coordinate_response = coordinate(parameter_response['id'], coordinate_title, coordinate_value) parameter_response['coordinate'] = coordinate_response if filename: file_response = upload_file(parameter_response['id'], filename) parameter_response['file'] = file_response return parameter_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 """ recastapi.file_check(filename) f = open(yaml_file) data_map = yaml.load(f) f.close() try: payload = { 'lower_1sig_expected_CLs': float(data_map['lower_1sig_expected_CLs']), 'lower_2sig_expected_CLs': float(data_map['lower_2sig_expected_CLs']), 'expected_CLs': float(data_map['expected_CLs']), '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']), 'point_response_id': int(point_response_id), 'basic_request_id': int(basic_request_id) } except Exception, e: print "*"*60 print "YAML file not correctly formatted: ", e print "-"*60 raise RuntimeError
def parameter_response(yaml_file, scan_response_id, point_request_id, filename): """ adds and associates parameter to response and request :param yaml_file: file containing parameter response data :param scan_response_id: ID of the response :param point_request_id: ID of the point request :param filename: filename associtated to the parameter. Must be *.zip :return: JSON object """ recastapi.file_check(filename) f = open(yaml_file) data_map = yaml.load(f) f.close() try: payload = { 'lower_1sig_expected_CLs': float(data_map['lower_1sig_expected_CLs']), 'lower_2sig_expected_CLs': float(data_map['lower_2sig_expected_CLs']), 'expected_CLs': float(data_map['expected_CLs']), '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
def basic_response_by_index(yaml_file, request_id, parameter_index, basic_index, filename): """ Add basic response given the request id, parameter index, and basic index :param yaml_file: file containing basic response data :param request_id: associate request id :param parameter_index: index of the parameter :param basic_index: index of the basic response :param filename: file associated to the basic response :return: JSON object """ recastapi.file_check(filename) # Find the point_response_id point_request_url = '{}?where=scan_request_id=="{}"'.format( recastapi.ENDPOINTS['POINT_REQUESTS'], request_id) point_requests = recastapi.get(point_request_url) if parameter_index > len(point_requests['_items'])-1: print "*"*60 print "Parameter index out of bounds" print "The request has ", len(point_requests['_items']), " elements" raise RuntimeError point_request_id = point_requests['_items'][parameter_index]['id'] # Find the point response point_response_url = '{}?where=point_request_id=="{}"'.format( recastapi.ENDPOINTS['POINT_RESPONSES'], point_request_id) point_responses = recastapi.get(point_response_url) if len(point_responses['_items']) < 1: print "*"*60 print "No Parameter response found!" print "Please add a Parameter response before a Basic response" raise RuntimeError point_response_id = point_responses['_items'][0]['id'] #Find the basic request basic_request_url = '{}?where=point_request_id=="{}"'.format( recastapi.ENDPOINTS['BASIC_REQUESTS'], point_request_id) basic_requests = recastapi.get(basic_request_url) if basic_index > len(basic_requests['_items'])-1: print "*"*60 print "Basic index out of bounds" print "The parameter has ", len(basic_requests['_items']), " basic elements" raise RuntimeError basic_request_id = basic_requests['_items'][basic_index]['id'] return basic_response(yaml_file, point_response_id, basic_request_id, filename)
def basic_response_by_index(yaml_file, request_id, parameter_index, basic_index, filename): """ Add basic response given the request id, parameter index, and basic index :param yaml_file: file containing basic response data :param request_id: associate request id :param parameter_index: index of the parameter :param basic_index: index of the basic response :param filename: file associated to the basic response :return: JSON object """ recastapi.file_check(filename) # Find the point_response_id point_request_url = '{}?where=scan_request_id=="{}"'.format( recastapi.ENDPOINTS['POINT_REQUESTS'], request_id) point_requests = recastapi.get(point_request_url) if parameter_index > len(point_requests['_items']) - 1: print "*" * 60 print "Parameter index out of bounds" print "The request has ", len(point_requests['_items']), " elements" raise RuntimeError point_request_id = point_requests['_items'][parameter_index]['id'] # Find the point response point_response_url = '{}?where=point_request_id=="{}"'.format( recastapi.ENDPOINTS['POINT_RESPONSES'], point_request_id) point_responses = recastapi.get(point_response_url) if len(point_responses['_items']) < 1: print "*" * 60 print "No Parameter response found!" print "Please add a Parameter response before a Basic response" raise RuntimeError point_response_id = point_responses['_items'][0]['id'] #Find the basic request basic_request_url = '{}?where=point_request_id=="{}"'.format( recastapi.ENDPOINTS['BASIC_REQUESTS'], point_request_id) basic_requests = recastapi.get(basic_request_url) if basic_index > len(basic_requests['_items']) - 1: print "*" * 60 print "Basic index out of bounds" print "The parameter has ", len( basic_requests['_items']), " basic elements" raise RuntimeError basic_request_id = basic_requests['_items'][basic_index]['id'] return basic_response(yaml_file, point_response_id, basic_request_id, filename)
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
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)
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)
def parameter_response(yaml_file, scan_response_id, point_request_id, filename): """ adds and associates parameter to response and request :param yaml_file: file containing parameter response data :param scan_response_id: ID of the response :param point_request_id: ID of the point request :param filename: filename associtated to the parameter. Must be *.zip :return: JSON object """ recastapi.file_check(filename) f = open(yaml_file) data_map = yaml.load(f) f.close() try: payload = { 'lower_1sig_expected_CLs': float(data_map['lower_1sig_expected_CLs']), 'lower_2sig_expected_CLs': float(data_map['lower_2sig_expected_CLs']), 'expected_CLs': float(data_map['expected_CLs']), '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
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
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 """ recastapi.file_check(filename) f = open(yaml_file) data_map = yaml.load(f) f.close() try: payload = { 'lower_1sig_expected_CLs': float(data_map['lower_1sig_expected_CLs']), 'lower_2sig_expected_CLs': float(data_map['lower_2sig_expected_CLs']), 'expected_CLs': float(data_map['expected_CLs']), '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']), 'point_response_id': int(point_response_id), 'basic_request_id': int(basic_request_id) } except Exception, e: print "*" * 60 print "YAML file not correctly formatted: ", e print "-" * 60 raise RuntimeError
def parameter_response_by_index(yaml_file, request_id, parameter_index, filename): """Adds Point response/Parameter response given the request id and parameter index index with reference from 0 :param yaml_file: file containing the data of the response :param request_id: request id :param parameter_index: index of the parameter :param filename: filename associated to the parameter :return: JSON object """ recastapi.file_check(filename) # Query scan responses check if the response has already been created scan_response_url = '{}?where=scan_request_id=="{}"'.format( recastapi.ENDPOINTS['RESPONSES'], request_id) scan_responses = recastapi.get(scan_response_url) if len(scan_responses['_items']) == 0: # make new scan response if none is associated to the request scan_responses = response(request_id) scan_response_id = scan_responses['id'] else: scan_response_id = scan_responses['_items'][0]['id'] # get the point request id # Query the point request for a given request_id get the index in the list point_request_url = '{}?where=scan_request_id=="{}"'.format( recastapi.ENDPOINTS['POINT_REQUESTS'], request_id) point_requests = recastapi.get(point_request_url) if parameter_index > len(point_requests['_items'])-1: print "*"*60 print "Parameter index out of bounds" print "The request has ", len(point_requests['_items']), "elements" raise RuntimeError point_request_id = point_requests['_items'][parameter_index]['id'] return parameter_response(yaml_file, scan_response_id, point_request_id, filename)
def parameter_response_by_index(yaml_file, request_id, parameter_index, filename): """Adds Point response/Parameter response given the request id and parameter index index with reference from 0 :param yaml_file: file containing the data of the response :param request_id: request id :param parameter_index: index of the parameter :param filename: filename associated to the parameter :return: JSON object """ recastapi.file_check(filename) # Query scan responses check if the response has already been created scan_response_url = '{}?where=scan_request_id=="{}"'.format( recastapi.ENDPOINTS['RESPONSES'], request_id) scan_responses = recastapi.get(scan_response_url) if len(scan_responses['_items']) == 0: # make new scan response if none is associated to the request scan_responses = response(request_id) scan_response_id = scan_responses['id'] else: scan_response_id = scan_responses['_items'][0]['id'] # get the point request id # Query the point request for a given request_id get the index in the list point_request_url = '{}?where=scan_request_id=="{}"'.format( recastapi.ENDPOINTS['POINT_REQUESTS'], request_id) point_requests = recastapi.get(point_request_url) if parameter_index > len(point_requests['_items']) - 1: print "*" * 60 print "Parameter index out of bounds" print "The request has ", len(point_requests['_items']), "elements" raise RuntimeError point_request_id = point_requests['_items'][parameter_index]['id'] return parameter_response(yaml_file, scan_response_id, point_request_id, filename)