Skip to content

Commit

Permalink
Merge pull request #114 from neuroscout/example_ridge
Browse files Browse the repository at this point in the history
FIX: Fetch utils, and sorting of uploads
  • Loading branch information
adelavega committed Oct 5, 2023
2 parents dc65808 + 94636af commit c5a388b
Show file tree
Hide file tree
Showing 22 changed files with 399 additions and 674 deletions.
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Expand Up @@ -7,7 +7,7 @@ build:

python:
install:
- requirements: requirements.txt
- requirements: docs/requirements.txt
- method: pip
path: .

Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,4 @@
{
"python.linting.flake8Enabled": true,
"python.linting.enabled": true
}
9 changes: 9 additions & 0 deletions docs/requirements.txt
@@ -0,0 +1,9 @@
pytest>=4.2.0
betamax>=0.8.1
betamax_serializers>=0.2.0
tqdm>=4.30.0
altair>=4.0.0
vega>=2.6.0
pyjwt~=1.7.1
requests>=2.21
sphinx-rtd-theme
6 changes: 4 additions & 2 deletions pyns/api.py
Expand Up @@ -137,10 +137,12 @@ def _authorize(self, email=None, password=None):
self._api_token = rv['access_token']

iat = datetime.utcfromtimestamp(
jwt.decode(self._api_token, verify=False)['iat'])
jwt.decode(self._api_token, verify=False,
options={'verify_signature': False})['iat'])
adj = iat - datetime.now()
self._api_token_exp = datetime.utcfromtimestamp(
jwt.decode(self._api_token, verify=False)['exp']) - adj
jwt.decode(self._api_token, verify=False,
options={'verify_signature': False})['exp']) - adj

def _check_expiry(self):
if self._api_token is not None:
Expand Down
5 changes: 5 additions & 0 deletions pyns/endpoints/analysis.py
Expand Up @@ -529,6 +529,11 @@ def get_uploads(self, id, select='latest', **kwargs):
uploads = self.get(id=id, sub_route='upload')

# Sort by date
# Strip off seconds if they are there
for u in uploads:
if u['uploaded_at'].count(':') > 1:
u['uploaded_at'] = u['uploaded_at'][:-3]

uploads = sorted(uploads, key=lambda x: datetime.datetime.strptime(
x['uploaded_at'], '%Y-%m-%dT%H:%M'),
reverse=(select == 'latest'))
Expand Down
6 changes: 3 additions & 3 deletions pyns/fetch_utils.py
Expand Up @@ -7,7 +7,7 @@
try:
from bids.variables import SparseRunVariable, BIDSRunVariableCollection
from bids.variables.entities import RunInfo
from bids.layout import BIDSLayout
from bids.layout import BIDSLayout, BIDSLayoutIndexer
except ImportError:
SparseRunVariable = None
BIDSRunVariableCollection = None
Expand Down Expand Up @@ -90,7 +90,7 @@ def fetch_predictors(predictor_names, dataset_name, return_type='df', rescale=Fa
Scale(collection, predictor_names)

if resample:
collection = collection.to_dense().resample('TR')
collection = collection.to_dense('TR')

if return_type == 'df':
collection = collection.to_df()
Expand Down Expand Up @@ -177,7 +177,7 @@ def install_dataset(dataset_dir, preproc_address, no_get=False):
return preproc_dir


def fetch_images(dataset_name, data_dir, no_get=False, datalad_jobs=-1,
def fetch_images(dataset_name, data_dir, no_get=False, datalad_jobs='auto',
preproc_address=None, **kwargs):
""" Fetch preprocessed images from a Neuroscout dataset.
Installs dataset using DataLad if not already installed.
Expand Down
8 changes: 4 additions & 4 deletions tests/cassettes/analysis.json
@@ -1,7 +1,7 @@
{
"http_interactions": [
{
"recorded_at": "2022-07-26T00:02:45",
"recorded_at": "2023-10-05T20:35:16",
"request": {
"body": {
"encoding": "utf-8",
Expand All @@ -15,7 +15,7 @@
"gzip, deflate, br"
],
"Authorization": [
"JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NTkzOTg1NTIsImlhdCI6MTY1ODc5Mzc1MiwibmJmIjoxNjU4NzkzNzUyLCJpZGVudGl0eSI6MX0.55A1Lj_YkR1rnvtVxXnDkHuyMbY8I5xRYvD38Rh9NXY"
"JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2OTcxNDI5MDMsImlhdCI6MTY5NjUzODEwMywibmJmIjoxNjk2NTM4MTAzLCJpZGVudGl0eSI6MX0.hHABEu1rQp90CjzyOR4_lNzu9NFmGMYqo8tTE3tnlDA"
],
"Connection": [
"keep-alive"
Expand All @@ -35,7 +35,7 @@
},
"response": {
"body": {
"base64_string": "H4sIAAAAAAAAA31Sy2rDMBC89zP2rIDj0rTxLTQNFJoeEh8KIRjFXhM1siT0CDXG/96V3ZT0kPrkHWlmZ3bVQWmRe6wK7iGDNEnTSfI4SWd5kmQJMKi45w59ISrI5lSiK60wXmgFmQpSMjhydxyOQT+5QyCO1OUJCai5dMig0RVKyDp4VSb4+LMJxN5N9wy24fCJJYE7sKJK4jcFwnPuTqQoRY3QM3jnDVJpWo/OF1xx2TrhqNXWo3HE7uBZK2+587EigWVomvYK6yBvTdTwUe8Nz9HSYITB+mLwI/pwBrE8wp6u5ZYrV2vb8Bh4UO5Zd1t79bJeXMtf0v1L+mNoOY4b+tieBidqcXs36tZU1LkodVDEShgYblGNCxwXZixWovxJBPALaBsTTtN58rCPoDjTw4DM20BLtGHIn97P6Mx57kMkLzeLVU4KLhwa4S/PaGwTHFq6gl+8MRKLoezvvgEbyNMlcQIAAA==",
"base64_string": "H4sIAAAAAAAAA31Sy2rDMBC89zP2rIDtkEJ8C00DhaaHxIdCCEaR10SNJQs9Qo3xv3dlN6U9pD55R5rZmV31ICxyj1XJPeSQJdl8liazZFFkST4HBhX33KEvZQX5kkp0wkrjZash16FpGJy5O4/HIJSxijhNKy5IQM0bhwxUW2EDeQ8v2gQff3aB2If0yGAfTh8oCDyAlVUSvxQIL7i7kGIja4SBwRtXSKXpPDpfcs2bzklHrfYejSN2D0+t9pY7HysSWAelul9YD0VnooaPeq94jZZGIwy2N4Pv0YcziOIMR7pWWK5d3VrFY+BReWD9fe3N83b1W/6W7l/SH0PradwwxPY0OFnL+7vR96air6VogyZWwsBwi3pa4LQwY7GS4jsRwA/Q2pgwzZbJ4hhBeaWHAbm3gZZow5g/mz/SmfPch0he71abghRcOCnpb89oahMcWrqCn1yZBsuxHB6+AGVJPhBxAgAA",
"encoding": "utf-8",
"string": ""
},
Expand All @@ -53,7 +53,7 @@
"application/json"
],
"Date": [
"Tue, 26 Jul 2022 00:02:45 GMT"
"Thu, 05 Oct 2023 20:35:16 GMT"
],
"Server": [
"nginx/1.21.6"
Expand Down
30 changes: 15 additions & 15 deletions tests/cassettes/analysis_object.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions tests/cassettes/auth.json
@@ -1,7 +1,7 @@
{
"http_interactions": [
{
"recorded_at": "2022-07-26T00:02:32",
"recorded_at": "2023-10-05T20:35:03",
"request": {
"body": {
"encoding": "utf-8",
Expand Down Expand Up @@ -32,7 +32,7 @@
},
"response": {
"body": {
"base64_string": "H4sIAAAAAAAAAxWM0Q6CIAAA3/sMP8BJZavenDaDEpepg15cEktArWWZ0vr36PG2u/tYZ8Z41xXPm+Kttbb4iBxOPBELtMvBQex9VJUh+zPMNARYoJVtpJpvjSQ3U5wqHadXgFPYwaauLj5cRCkFccDcSDMQibcoG9RAeRuwzOZYK411Nprx/RTmr0tYO/xoGuLYruuBvSyoSsCj7Z/5QNpAbV9jVNIldIeE9sFsmVQrTKj1nfwA8qMS37wAAAA=",
"base64_string": "H4sIAAAAAAAAAxWM0Q6CIAAA3/sMP6BpacveSEyhwFXotBdXxiaIWakraf179njb3X2Mc1Hwts27puI3Y2XwAZs8BSISeJtYe7HzcHkJij+jWCOLCuxOR0nxcJSkP4tY8aYQOQSSFtWqvHpoQVjmUBnrCPovMrzEpcY1ks2bympGGbEJA3oc309B0l8DZfLj2KTmtAzB2u+t5/7ump7UQ3Swc0V179JNHZDs0Sw75s+7m4LA+E5+szv14bwAAAA=",
"encoding": "utf-8",
"string": ""
},
Expand All @@ -50,7 +50,7 @@
"application/json"
],
"Date": [
"Tue, 26 Jul 2022 00:02:32 GMT"
"Thu, 05 Oct 2023 20:35:03 GMT"
],
"Server": [
"nginx/1.21.6"
Expand Down
34 changes: 17 additions & 17 deletions tests/cassettes/dataset.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions tests/cassettes/get_analysis.json
@@ -1,7 +1,7 @@
{
"http_interactions": [
{
"recorded_at": "2022-07-26T00:02:45",
"recorded_at": "2023-10-05T20:35:17",
"request": {
"body": {
"encoding": "utf-8",
Expand All @@ -15,7 +15,7 @@
"gzip, deflate, br"
],
"Authorization": [
"JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NTkzOTg1NTIsImlhdCI6MTY1ODc5Mzc1MiwibmJmIjoxNjU4NzkzNzUyLCJpZGVudGl0eSI6MX0.55A1Lj_YkR1rnvtVxXnDkHuyMbY8I5xRYvD38Rh9NXY"
"JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2OTcxNDI5MDMsImlhdCI6MTY5NjUzODEwMywibmJmIjoxNjk2NTM4MTAzLCJpZGVudGl0eSI6MX0.hHABEu1rQp90CjzyOR4_lNzu9NFmGMYqo8tTE3tnlDA"
],
"Connection": [
"keep-alive"
Expand All @@ -25,11 +25,11 @@
]
},
"method": "GET",
"uri": "https://neuroscout.org/api/analyses/o8sbu"
"uri": "https://neuroscout.org/api/analyses/cmprm"
},
"response": {
"body": {
"base64_string": "H4sIAAAAAAAAA31Sy2rDMBC89zP2rIDj0rTxLTQNFJoeEh8KIRjFXhM1siT0CDXG/96V3ZT0kPrkHWlmZ3bVQWmRe6wK7iGDNEnTSfI4SWd5kmQJMKi45w59ISrI5lSiK60wXmgFmQpSMjhydxyOQT+5QyCO1OUJCai5dMig0RVKyDp4VSb4+LMJxN5N9wy24fCJJYE7sKJK4jcFwnPuTqQoRY3QM3jnDVJpWo/OF1xx2TrhqNXWo3HE7uBZK2+587EigWVomvYK6yBvTdTwUe8Nz9HSYITB+mLwI/pwBrE8wp6u5ZYrV2vb8Bh4UO5Zd1t79bJeXMtf0v1L+mNoOY4b+tieBidqcXs36tZU1LkodVDEShgYblGNCxwXZixWovxJBPALaBsTTtN58rCPoDjTw4DM20BLtGHIn97P6Mx57kMkLzeLVU4KLhwa4S/PaGwTHFq6gl+8MRKLoezvvgEbyNMlcQIAAA==",
"base64_string": "H4sIAAAAAAAAA31Sy2rDMBC89zP2rIDtkEJ8C00DhaaHxIdCCEaR10SNJQs9Qo3xv3dlN6U9pD55R5rZmV31ICxyj1XJPeSQJdl8liazZFFkST4HBhX33KEvZQX5kkp0wkrjZash16FpGJy5O4/HIJSxijhNKy5IQM0bhwxUW2EDeQ8v2gQff3aB2If0yGAfTh8oCDyAlVUSvxQIL7i7kGIja4SBwRtXSKXpPDpfcs2bzklHrfYejSN2D0+t9pY7HysSWAelul9YD0VnooaPeq94jZZGIwy2N4Pv0YcziOIMR7pWWK5d3VrFY+BReWD9fe3N83b1W/6W7l/SH0PradwwxPY0OFnL+7vR96air6VogyZWwsBwi3pa4LQwY7GS4jsRwA/Q2pgwzZbJ4hhBeaWHAbm3gZZow5g/mz/SmfPch0he71abghRcOCnpb89oahMcWrqCn1yZBsuxHB6+AGVJPhBxAgAA",
"encoding": "utf-8",
"string": ""
},
Expand All @@ -47,7 +47,7 @@
"application/json"
],
"Date": [
"Tue, 26 Jul 2022 00:02:45 GMT"
"Thu, 05 Oct 2023 20:35:17 GMT"
],
"Server": [
"nginx/1.21.6"
Expand All @@ -66,11 +66,11 @@
"code": 200,
"message": "OK"
},
"url": "https://neuroscout.org/api/analyses/o8sbu"
"url": "https://neuroscout.org/api/analyses/cmprm"
}
},
{
"recorded_at": "2022-07-26T00:02:46",
"recorded_at": "2023-10-05T20:35:17",
"request": {
"body": {
"encoding": "utf-8",
Expand All @@ -84,7 +84,7 @@
"gzip, deflate, br"
],
"Authorization": [
"JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NTkzOTg1NTIsImlhdCI6MTY1ODc5Mzc1MiwibmJmIjoxNjU4NzkzNzUyLCJpZGVudGl0eSI6MX0.55A1Lj_YkR1rnvtVxXnDkHuyMbY8I5xRYvD38Rh9NXY"
"JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2OTcxNDI5MDMsImlhdCI6MTY5NjUzODEwMywibmJmIjoxNjk2NTM4MTAzLCJpZGVudGl0eSI6MX0.hHABEu1rQp90CjzyOR4_lNzu9NFmGMYqo8tTE3tnlDA"
],
"Connection": [
"keep-alive"
Expand Down Expand Up @@ -116,7 +116,7 @@
"application/json"
],
"Date": [
"Tue, 26 Jul 2022 00:02:46 GMT"
"Thu, 05 Oct 2023 20:35:17 GMT"
],
"Server": [
"nginx/1.21.6"
Expand All @@ -139,7 +139,7 @@
}
},
{
"recorded_at": "2022-07-26T00:02:46",
"recorded_at": "2023-10-05T20:35:17",
"request": {
"body": {
"encoding": "utf-8",
Expand All @@ -153,7 +153,7 @@
"gzip, deflate, br"
],
"Authorization": [
"JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NTkzOTg1NTIsImlhdCI6MTY1ODc5Mzc1MiwibmJmIjoxNjU4NzkzNzUyLCJpZGVudGl0eSI6MX0.55A1Lj_YkR1rnvtVxXnDkHuyMbY8I5xRYvD38Rh9NXY"
"JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2OTcxNDI5MDMsImlhdCI6MTY5NjUzODEwMywibmJmIjoxNjk2NTM4MTAzLCJpZGVudGl0eSI6MX0.hHABEu1rQp90CjzyOR4_lNzu9NFmGMYqo8tTE3tnlDA"
],
"Connection": [
"keep-alive"
Expand Down Expand Up @@ -185,7 +185,7 @@
"application/json"
],
"Date": [
"Tue, 26 Jul 2022 00:02:46 GMT"
"Thu, 05 Oct 2023 20:35:17 GMT"
],
"Server": [
"nginx/1.21.6"
Expand Down

0 comments on commit c5a388b

Please sign in to comment.