Skip to content

Commit

Permalink
Merge pull request #20 from rcpch/18-python-version-upgrade-3.11
Browse files Browse the repository at this point in the history
Python Version upgrade, Dockerisation, GitHub Actions testing, repo tidy.
  • Loading branch information
pacharanero authored Mar 19, 2024
2 parents ae3f64f + 92174de commit eba3d81
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 77 deletions.
Binary file removed .DS_Store
Binary file not shown.
19 changes: 19 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Overview

Please describe the purpose of this PR here.

### Code changes

Please describe the changes you made here.

### Documentation changes (done or required as a result of this PR)

Please describe any changes to documentation here.

### Related Issues

List any issues related to this PR here.

### Mentions

@mentions of the person or team responsible for reviewing proposed changes.
20 changes: 20 additions & 0 deletions .github/workflows/auto-add-issues-to-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Adds new Issues automatically to the dGC Project on GitHub

on:
issues:
types:
- opened
pull_request:
types:
- opened

jobs:
add-to-project:
name: Add issue or PR to project automatically
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
project-url: https://github.com/orgs/rcpch/projects/5 #dGC Project
github-token: ${{ secrets.AUTO_ADD_TO_PROJECT_TOKEN }}

29 changes: 0 additions & 29 deletions .github/workflows/digital-growth-charts.code-workspace

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/run-pytest-on-push-and-all-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Run Pytest on pushes to main branches or PRs to any branch

on:
pull_request:
branches:
- "*"
push:
branches:
- development
- staging
- live

jobs:
deploy:

runs-on: ubuntu-latest
# Runs tests on multiple python versions across the range we support
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4 # latest as at March 2024

- name: Set up Python version ${{ matrix.python-version }}
uses: actions/setup-python@v5 # latest as at March 2024
with:
python-version: ${{ matrix.python-version }}

- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
pip install -r requirements.txt
- name: Run pytest
run: |
pytest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,6 @@ dmypy.json

.vscode
.pytest/cache

# MacOS DS_Store files
.DS_Store
3 changes: 2 additions & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ authors:
orcid: "https://orcid.org/0000-0001-9897-2040"
- family-names: "Baw"
given-names: "Marcus"
orcid: "https://orcid.org/0000-0003-4369-8659"
- family-names: "Cole"
given-names: "Tim"
orcid: "https://orcid.org/0000-0001-5711-8200"
title: "rcpchgrowth"
version: 3.1.17
doi: 10.5281/zenodo.6301089
date-released: 2022-05-14
url: "https://github.com/rcpch/rcpchgrowth-python"
url: "https://github.com/rcpch/rcpchgrowth-python"
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.12-bookworm

COPY requirements.txt .

RUN pip install -r requirements.txt

COPY . .
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# NOTE The below is the Docker Compose specification version NOT the Python version:
version: '3.8'

services:
rcpchgrowth-python:
build: .
volumes:
- .:/app
tty: true # Allocate a pseudo-TTY
stdin_open: true # Keep stdin open
command: |
cd app; pytest
22 changes: 0 additions & 22 deletions rcpchgrowth-projects.code-workspace

This file was deleted.

Binary file removed rcpchgrowth/.DS_Store
Binary file not shown.
15 changes: 11 additions & 4 deletions rcpchgrowth/constants/validation_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
MAXIMUM_HEIGHT_CM = 300
# The smallest baby was report by the BBC on 9/8/2021 (https://www.bbc.co.uk/news/world-asia-58141756.amp)
# to have a length of just 24cm and was born at 25 weeks gestation, discharged at 13 mths of age (chronological)
# from Singapore's National University Hospital
# from Singapore's National University Hospital
# The tallest person for whom there is irrefutable evidence is
# Robert Pershing Wadlow who was 2.72m (8 ft 11.1 in) tall at his death in 1940
# https://en.wikipedia.org/wiki/Robert_Wadlow
Expand All @@ -18,7 +18,7 @@
MAXIMUM_WEIGHT_KG = 500
# The smallest baby was report by the BBC on 9/8/2021 (https://www.bbc.co.uk/news/world-asia-58141756.amp)
# to weigh just 212g and was born at 25 weeks gestation, discharged at 13 mths of age (chronological)
# from Singapore's National University Hospital
# from Singapore's National University Hospital
# The heaviest man according to google is Jon Brower Minnoch (US)
# who had suffered from obesity since childhood. In September 1976,
# he measured 185 cm (6 ft 1 in) tall and weighed 442 kg (974 lb; 69 st 9 lb)
Expand All @@ -41,6 +41,13 @@

# GESTATION CONSTANTS
MINIMUM_GESTATION_WEEKS = 22
MINIMUM_GESTATION_WEEKS_ERROR = f'It is very unlikely that a gestational age of less than {MINIMUM_GESTATION_WEEKS} weeks is correct'
MINIMUM_GESTATION_WEEKS_ERROR = f"It is very unlikely that a gestational age of less than {MINIMUM_GESTATION_WEEKS} weeks is correct"
MAXIMUM_GESTATION_WEEKS = 44
MAXIMUM_GESTATION_WEEKS_ERROR = f'It is very unlikely that a gestational age of more than {MAXIMUM_GESTATION_WEEKS} weeks is correct'
MAXIMUM_GESTATION_WEEKS_ERROR = f"It is very unlikely that a gestational age of more than {MAXIMUM_GESTATION_WEEKS} weeks is correct"

# PARENTAL HEIGHT CONSTANTS
MINIMUM_PARENTAL_HEIGHT_CM = 50
# the shortest man in the world was 54.6 cm Chandra Bahadur Dangi
# the shortest woman in the world is Jyoti Kishanji Amge at 62.8 cm
# lower limit to paternal and maternal height here therefore set arbitrarily at 50 cm
# (this constant was added from the API server `schemas/request_validation_classes.py`)
Binary file removed rcpchgrowth/data_tables/.DS_Store
Binary file not shown.
41 changes: 21 additions & 20 deletions rcpchgrowth/dynamic_growth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# from scipy.interpolate import UnivariateSpline
# import matplotlib.pyplot as plt
# TODO #21 - do the above lines need to be commented out?

# rcpchgrowth local imports
from rcpchgrowth.constants.reference_constants import FEMALE, MALE, UK_WHO, WEIGHT
Expand All @@ -14,13 +15,13 @@
"""
These functions are experimental
Height, weight, BMI or OFC in terms of SDS / Centile are snapshots in time and tell
us actually very little about growth, which is a dynamic measure. In order to make
us actually very little about growth, which is a dynamic measure. In order to make
predictions, we need to look at change in parameter measured over time (velocity)
which requires 2 measurements over a known time interval, or change in velocity (acceleration/deceleration)
which requires three measurements.
which requires three measurements.
From these measurements predictions can be made about speed of growth, or rate of slowing (catch down)
or acceleration (catch up). The normative data against which to compare the index child are
or acceleration (catch up). The normative data against which to compare the index child are
thrive lines, generated here.
"""
Expand Down Expand Up @@ -134,7 +135,7 @@ def nine_centiles(sex: str):
t=[centile * 0.5 for centile in range(24)]
requested_sd_scores=[-2.67, -2.0, -1.33, -0.67, 0, 0.67, 1.33, 2.0, 2.67]
final_array=[]

for index, requested_sd_score in enumerate(requested_sd_scores):
return_ages_array=[]
return_m_array=[]
Expand Down Expand Up @@ -186,7 +187,7 @@ def create_thrive_line(t: list, z1: float, sex: str, target_centile: float = 5.0
cycle_sds=[z1]
return_ages=[t[0]]
z2=0.0

for index in range(len(t)):
observation_value=None
# loop through the list of ages which are ordered and evenly spaced a month apart
Expand All @@ -202,7 +203,7 @@ def create_thrive_line(t: list, z1: float, sex: str, target_centile: float = 5.0
# this is the last item in the list
t2 = t1
z2=z_current

# convert z2 to a measurement and add to the list against t2 in years
observation_value = measurement_from_sds(
reference=UK_WHO,
Expand All @@ -215,18 +216,18 @@ def create_thrive_line(t: list, z1: float, sex: str, target_centile: float = 5.0
cycle_sds.append(z2)
return_ages.append(t2/12)
return_observation_values.append(observation_value)

return {
"zs": cycle_sds,
"ages": return_ages,
"zs": cycle_sds,
"ages": return_ages,
"observation_values": return_observation_values
}

def create_thrive_lines(target_centile: float, sex: str):
# Creates thrive lines for weights in the under 1s
# Each thrive line requires a starting SDS and list of ages against
# Each thrive line requires a starting SDS and list of ages against
# which the lines are plotted.
# The centile_target refers to the velocity centile cut off at which
# The centile_target refers to the velocity centile cut off at which
# the line is drawn.

time_blocks = [i for i in range(12)]
Expand All @@ -235,11 +236,11 @@ def create_thrive_lines(target_centile: float, sex: str):
for index, centile_line in enumerate(centile_lines):
# these are the 9 centile lines
plt.plot(centile_line["ages"], centile_line["observation_values"], linestyle='--' if index % 2==0 else '-' , color="grey", linewidth=0.5)

z=-25
while z <= 25:
thrive_line = create_thrive_line(
t=time_blocks,
t=time_blocks,
z1=z,
sex=sex,
target_centile=target_centile)
Expand Down Expand Up @@ -283,17 +284,17 @@ def create_thrive_lines(target_centile: float, sex: str):
measurements.append(thrive_line['observation_values'][counter])
ages.append(thrive_line['ages'][counter])
counter += 1

# x, y = ages, measurements
# # smoothed_measurements = UnivariateSpline(x,y) smoothed_measurements(x)
# if len(x) > 0 and len(y) > 0:
# plt.plot(x, y, color="green", linestyle='--', dashes=(15,2.5), linewidth=1.0)

# plt.title('Thrive Lines', fontsize=16)
# plt.show()

def return_correlation(t1, t2, time_interval: Literal["weeks", "months"]):
# import the reference - the index of each row and column
# import the reference - the index of each row and column
# relates to the number of weeks or months

cwd = os.path.dirname(__file__) # current location
Expand All @@ -310,20 +311,20 @@ def return_correlation(t1, t2, time_interval: Literal["weeks", "months"]):
with open(final_file_path, mode="r") as json_file:
data=json.load(json_file)
json_file.close()

lowerIndexT1 = math.floor(t1)
upperIndexT1 = lowerIndexT1+1
lowerIndexT2 = math.floor(t2)
upperIndexT2 = lowerIndexT2+1

lowerT1lowerT2 = data[lowerIndexT1][str(lowerIndexT2)]
lowerT1upperT2 = data[lowerIndexT1][str(upperIndexT2)]
upperT1lowerT2 = data[upperIndexT1][str(lowerIndexT2)]
upperT1upperT2 = data[upperIndexT1][str(upperIndexT2)]

correlation = bilinear_interpolation(
x=t1,
y=t2,
x=t1,
y=t2,
points=[
(lowerIndexT1, lowerIndexT2, lowerT1lowerT2),
(lowerIndexT1, upperIndexT2, lowerT1upperT2),
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pytest
python-dateutil
scipy
matplotlib
setuptools
setuptools
10 changes: 10 additions & 0 deletions s/down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -v # Enable verbose mode
set -e # Exit on error

# scripts may need to be made executable on some platforms before they can be run
# chmod +x <filename> is the command to do this on unixy systems

# shuts down the Docker Compose setup but does not destroy containers or images
docker compose down
10 changes: 10 additions & 0 deletions s/rebuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -v # Enable verbose mode
set -e # Exit on error

# scripts may need to be made executable on some platforms before they can be run
# chmod +x <filename> is the command to do this on unixy systems

s/remove-containers-and-images
s/up
10 changes: 10 additions & 0 deletions s/remove-containers-and-images
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -v # Enable verbose mode
set -e # Exit on error

# scripts may need to be made executable on some platforms before they can be run
# chmod +x <filename> is the command to do this on unixy systems

# shuts down the Docker Compose setup AND deletes containers and images (but not volumes)
docker compose down --rmi local # removes the container and local images
Loading

0 comments on commit eba3d81

Please sign in to comment.