Skip to content

Commit

Permalink
Rework cache (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdstein authored May 17, 2023
1 parent ff50aa6 commit 91f6825
Show file tree
Hide file tree
Showing 21 changed files with 660 additions and 556 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
name: Lint
name: Black

on: [push, pull_request]
on:
push:
pull_request:
merge_group:

jobs:
lint:
black:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: psf/black@stable
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "poetry"
- name: Install dependencies
run: |
pip install --upgrade pip
python -m pip install --upgrade poetry
poetry install
- name: Reformat the code with black
run: |
poetry run black . --check
18 changes: 18 additions & 0 deletions .github/workflows/isort.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Run isort

on:
push:
pull_request:
merge_group:

jobs:
isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: isort
uses: isort/isort-action@v1.0.0
15 changes: 12 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ repos:
exclude: &exclude_pattern '^LIGO_skymaps/'
- id: trailing-whitespace
exclude: *exclude_pattern
- repo: https://github.com/psf/black
rev: 22.6.0
- repo: local
hooks:
- id: black
exclude: *exclude_pattern
name: black
entry: black
language: system
types: [ python ]
- repo: local
hooks:
- id: isort
name: isort (python)
entry: isort
language: system
types: [ python ]
default_language_version:
python: python3.10
23 changes: 10 additions & 13 deletions nuztf/ampel_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
from ampel.ztf.util.ZTFIdMapper import ZTFIdMapper
from astropy.io import fits # type: ignore
from astropy.time import Time # type: ignore
from requests.auth import HTTPBasicAuth
from requests.exceptions import HTTPError

from nuztf import utils
from nuztf.credentials import load_credentials
from requests.auth import HTTPBasicAuth
from nuztf.paths import PREPROCESSED_CACHE_DIR

API_BASEURL = "https://ampel.zeuthen.desy.de"
API_ZTF_ARCHIVE_URL = API_BASEURL + "/api/ztf/archive/v3"
Expand Down Expand Up @@ -680,28 +683,22 @@ def ampel_api_catalog(
return res


def get_preprocessed_results(file_basename: str, logger=None) -> None | list:
def get_preprocessed_results(file_basename: str) -> list:
"""
Access the DESY Cloud to look if there are precomputed results from an AMPEL run there
Access the DESY Cloud to look if there are precomputed results from an AMPEL run
there
"""
if logger is None:
logger = logging.getLogger(__name__)

desy_cloud_token = load_credentials("desy_cloud_token", token_based=True)

filename = file_basename + ".json.gz"
filename = PREPROCESSED_CACHE_DIR.joinpath(f"{file_basename}.json.gz")

res = requests.get(
f"https://syncandshare.desy.de/public.php/webdav/{filename}",
f"https://syncandshare.desy.de/public.php/webdav/{filename.name}",
headers={"X-Requested-With": "XMLHttpRequest"},
auth=(desy_cloud_token, "bla"),
)

if res.status_code != 200:
logger.warning(
"\n\n-------------------- !! -------------------\nSomething went wrong with your query.\nCheck your credentials and make sure Ampel\nhas run correctly at Desy.\n-------------------- !! -------------------\n\n"
)
return None
res.raise_for_status()

with open(f"{filename}", "wb") as f:
f.write(res.content)
Expand Down
Loading

0 comments on commit 91f6825

Please sign in to comment.