Skip to content

Commit

Permalink
Merge pull request #4 from dbarrous/update-devcontainer-and-stub-code
Browse files Browse the repository at this point in the history
Update .devcontainer config and Stub Code for Pipeline
  • Loading branch information
dbarrous authored Sep 27, 2024
2 parents da2c24e + 53d1c20 commit 5718bbe
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 53 deletions.
106 changes: 62 additions & 44 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,73 @@
// https://github.com/microsoft/vscode-dev-containers/tree/v0.183.0/containers/python-3
{
"name": "Ubuntu 20.04 Python 3",
// Repo where this image's Dockerfile is maintained: https://github.com/HERMES-SOC/docker-lambda-base
"image": "public.ecr.aws/w5r9l1c8/swsoc-docker-lambda-base:latest",
"initializeCommand": "docker logout public.ecr.aws && docker pull public.ecr.aws/w5r9l1c8/swsoc-docker-lambda-base:latest",
// Set *default* container specific settings.json values on container create.
"settings": {
"python.pythonPath": "/usr/bin/python3",
"python.languageServer": "Pylance",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.blackPath": "/usr/local/bin/black",
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"100"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.linting.lintOnSave": true,
"python.linting.flake8Enabled": true,
"editor.formatOnSave": true,
"python.linting.banditPath": "/usr/local/bin/bandit",
"python.linting.flake8Path": "/usr/local/bin/flake8",
"python.linting.mypyPath": "/usr/local/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/bin/pydocstyle",
"python.linting.pylintPath": "/usr/bin/pylint",
"terminal.integrated.defaultProfile.linux": "bash (login)",
"terminal.integrated.profiles.linux": {
"bash (login)": {
"path": "bash"
}
}
// Repo where this image's Dockerfile is maintained: https://github.com/PADRESat/sdc_aws_base_docker_image
"image": "public.ecr.aws/w5r9l1c8/dev-padre-swsoc-docker-lambda-base:latest",
"initializeCommand": "docker logout public.ecr.aws && docker pull public.ecr.aws/w5r9l1c8/dev-padre-swsoc-docker-lambda-base:latest",
// If you want to run the production version of the container, comment out the image and initializeCommand lines above and uncomment the line below.
// "image": "public.ecr.aws/w5r9l1c8/padre-swsoc-docker-lambda-base:latest",
// "initializeCommand": "docker logout public.ecr.aws && docker pull public.ecr.aws/w5r9l1c8/swsoc-docker-lambda-base:latest",
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.pythonPath": "/usr/bin/python3",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.languageServer": "Pylance",

//PyLint Settings
"pylint.enabled": true,
"pylint.path": ["/usr/bin/pylint"],
"pylint.lintOnChange": true,

// Black Settings
"python.editor.defaultFormatter": "ms-python.black-formatter",
"python.editor.formatOnSave": true,
"black-formatter.path": ["/usr/local/bin/black"],
"black-formatter.args": [
"--line-length",
"100"
],

// Flake8 Settings
"flake8.path": ["/usr/local/bin/flake8"],
"flake8.lintOnChange": true,

// Terminal Settings
"terminal.integrated.defaultProfile.linux": "bash (login)",
"terminal.integrated.profiles.linux": {
"bash (login)": {
"path": "bash"
}
}
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.pylint",
"ms-python.black-formatter",
"ms-python.flake8",
"marklarah.pre-commit-vscode",
"ms-toolsai.jupyter",
"ms-toolsai.jupyter-renderers",
"ms-toolsai.jupyter-keymap",
"jithurjacob.nbpreviewer"
],
}
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"marklarah.pre-commit-vscode",
"ms-toolsai.jupyter",
"ms-toolsai.jupyter-renderers",
"ms-toolsai.jupyter-keymap",
"jithurjacob.nbpreviewer"
],

// Mount to a volume if you'd like to persist data to your disk
// "mounts": ["source=<add your /path/on/host here>, target=/workspaces/hermes_core, type=bind"],
"mounts": [
"source=${localEnv:HOME}/.bash_profile,target=/home/vscode/.bashrc,type=bind,consistency=cached"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
//"postCreateCommand": "bash -i -c 'pip3 install --user .[all]'",
"postCreateCommand": "sudo pip3 uninstall padre_sharp -y",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
43 changes: 35 additions & 8 deletions padre_sharp/calibration/calibration.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""
A module for all things calibration.
"""

from pathlib import Path
import random

from astropy.time import Time

from swxsoc.util import util
from padre_sharp import log

__all__ = [
Expand Down Expand Up @@ -34,7 +36,7 @@ def process_file(data_filename: Path) -> list:
log.info(f"Processing file {data_filename}.")
output_files = []

# calibrated_file = calibrate_file(data_filename)
calibrated_file = calibrate_file(data_filename)
output_files.append(calibrated_file)
# data_plot_files = plot_file(data_filename)
# calib_plot_files = plot_file(calibrated_file)
Expand Down Expand Up @@ -74,15 +76,40 @@ def calibrate_file(data_filename: Path, output_level=2) -> Path:
)
)

calib_file = get_calibration_file(data_filename)
if calib_file is None:
raise ValueError("Calibration file for {} not found.".format(data_filename))
else:
calib_data = read_calibration_file(calib_file)
file_metadata = util.parse_science_filename(data_filename)

# example log messages
# Temporary directory
tmp_dir = Path("/tmp")

return None
if file_metadata is None:
log.error(f"Could not parse filename {data_filename}.")
return None

if file_metadata["level"] == "l0":
new_filename = tmp_dir / util.create_science_filename(
instrument=file_metadata["instrument"],
time=file_metadata["time"],
version=f"0.0.{file_metadata['version']}",
level="l1",
)
with open(new_filename, "w"):
pass

elif file_metadata["level"] == "l1":
new_filename = tmp_dir / util.create_science_filename(
instrument=file_metadata["instrument"],
time=file_metadata["time"],
version=file_metadata["version"],
level="ql",
)

with open(new_filename, "w"):
pass
else:
log.error(f"Could not calibrate file {data_filename}.")
raise ValueError(f"Cannot find calibration for file {data_filename}.")

return new_filename


def get_calibration_file(time: Time) -> Path:
Expand Down
2 changes: 1 addition & 1 deletion padre_sharp/tests/test_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def test_calibrate_file():
calib.calibrate_file("datafile_with_no_calib.cdf")
assert (
str(excinfo.value)
== "Calibration file for datafile_with_no_calib.cdf not found."
== "File datafile_with_no_calib.cdf not recognized. Not a valid mission name."
)


Expand Down
1 change: 1 addition & 0 deletions padre_sharp/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
This code is based on that provided by SunPy see
licenses/SUNPY.rst
"""

import os
import shutil
import configparser
Expand Down
1 change: 1 addition & 0 deletions padre_sharp/util/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
This code is based on that provided by SunPy see
licenses/SUNPY.rst
"""

import warnings

__all__ = [
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ classifiers = [
dependencies = [
'astropy',
'sunpy',
'swxsoc @ git+https://github.com/swxsoc/swxsoc.git@main',
]

[project.optional-dependencies]
Expand Down

0 comments on commit 5718bbe

Please sign in to comment.