def load_responses(exp_type): if exp_type == 'grating': from src.params.grating.datafile_params import DATA_DIR, MICE_NAMES data_locs = [ os.path.join(DATA_DIR, '%s_dir.npy' % c) for c in MICE_NAMES ] data = map(lambda (n, loc): Response(n, loc), zip(MICE_NAMES, data_locs)) elif exp_type == 'natural': from src.params.naturalmovies.datafile_params import DATA_DIR data_locs = [os.path.join(DATA_DIR, '%d.npy' % i) for i in range(11)] data = [Response(str(i), data_locs[i]) for i in range(11)] return data
def handle(event, context): try: event_body = urllib.parse.unquote_plus(event["body"]) event_body = json.loads(event_body) auth = Auth() response = auth.enticate(event_body) return Response.handle(response, 200) except Exception as e: msg = f"Unable to process request: {str(e)}" logging.exception(msg) return Response.handle({"error": msg}, 500)
def handle(event, context): try: event_body = urllib.parse.unquote_plus(event["body"]) event_body = json.loads(event_body) gratitudes = SearchGratitude() create = gratitudes.search(event["requestContext"]["search"], ) return Response.handle(create, 200) except Exception as e: msg = f"Unable to process request: {str(e)}" logging.exception(msg) return Response.handle({"error": msg}, 500)
def test_reponse_created(self): print('running') request = Request(environ, start_response) response = Response(request, '200 OK', 'text/html') self.assertEqual(response.headers, []) self.assertEqual(response.status_code, '200 OK') self.assertEqual(response.content_type, 'text/html') self.assertEqual(response.response_content, [])
async def process_request(self, req): body, ctype = self.load_file(req.path) headers = [('Content-Length', len(body)), ('Content-Type', MIME_TYPE[ctype])] if req.method == 'HEAD': body = None return Response(200, 'OK', headers, body)
def handle(event, context): try: event_body = urllib.parse.unquote_plus(event["body"]) event_body = json.loads(event_body) gratitudes = CreateGratitude() create = gratitudes.create( event["requestContext"]["authorizer"]["claims"]["email"], datetime.now(), event_body[0], ) return Response.handle(create, 200) except Exception as e: msg = f"Unable to process request: {str(e)}" logging.exception(msg) return Response.handle({"error": msg}, 500)
async def send_error(self, exc, client): try: status = exc.status reason = exc.reason body = (exc.body or exc.reason).encode('utf-8') except: status = 400 reason = b'Bad Request' body = b'Bad Request' resp = Response(status, reason, [('Content-Length', len(body))], body) await self.send_response(resp, client)
def test_response(self): results = Response.handle("Foo", 200) self.assertDictEqual( { "statusCode": "200", "body": '"Foo"', "headers": { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*", }, }, results, )
import os # Response tuning properties from src.gaussian_fit import wrapped_double_gaussian from src.gaussian_fit import fit_wrapped_double_gaussian from src.osi import selectivity_index, pref_direction # Reading in the data from src.response import Response # Preprocessing from src.data_manip_utils import smooth_responses locs_dirn = [os.path.join(DATA_DIR, '%s_dir.npy' % c) for c in MICE_NAMES] data_dirn = map(lambda (n, loc): Response(n, loc), zip(MICE_NAMES, locs_dirn)) locs_ori = [os.path.join(DATA_DIR, '%s_ori.npy' % c) for c in MICE_NAMES] data_ori = map(lambda (n, loc): Response(n, loc), zip(MICE_NAMES, locs_ori)) dirs_rad = np.radians(DIRECTIONS) sigma0 = 2 * np.pi / len(DIRECTIONS) # initial tuning curve width for index, (m_dir, m_ori) in enumerate(zip(data_dirn, data_ori)): name = MICE_NAMES[index] print 'Mouse %s' % name # Smooth the responses first. m_dir = smooth_responses(m_dir) m_ori = smooth_responses(m_ori) N = m_dir.data.shape[1]
import numpy as np from matplotlib import pyplot as plt import os from src.response import Response from src.reliability import reliability from src.correlation import signal_correlation, noise_correlation from src.data_manip_utils import smooth_responses exp_type = 'natural' if exp_type == 'grating': from src.params.grating.datafile_params import * from src.params.grating.stimulus_params import * data_locs = [os.path.join(DATA_DIR, '%s_dir.npy' % c) for c in MICE_NAMES] data = map(lambda (n, loc) : Response(n, loc), zip(MICE_NAMES, data_locs)) elif exp_type == 'natural': from src.params.naturalmovies.datafile_params import * from src.params.naturalmovies.stimulus_params import * data_locs = [os.path.join(DATA_DIR, '%d.npy' % i) for i in range(11)] data = [Response(str(i), data_locs[i]) for i in range(11)] for index in range(len(data)): m = data[index] print 'Mouse %s' % m.name # Smoothing responses. Some unnecessarily clunky stuff here as well. # Will do something about that later. data[index] = smooth_responses(m) m = data[index] if exp_type == 'natural':