This is a WebApp of the scientific Z-Score App available as
python program on GitHub.
It is based on published DXA reference values for children and adults.
How to use:
- Wait about 20 sec until the page is loaded completely.
- Prepare an Excel file similar to this example file containing all measurements for which z-scores should be computed.
- Units to be used: all weights in kg, except for VAT_mass in g, indices in kg/m^(x) where x is 2 or the fitted exponent, height in cm, age in years (computed as: "days between birthday and measurement"/365.25, not rounded).
- Important: the columns need to have the same names as in the example file. Moreover, different reference values are provided for children and adults (i.e. for different body composition parameters), therefore some z-scores might be empty.
- To compute the z-scores, first select the prepared Excel file.
- Then click on "Upload & Process".
- As soon as you see the preview, you can download the generated file.
Loading ...
import asyncio
import numpy as np
import panel as pn
import pandas as pd
import openpyxl
from panel.io.pyodide import show
from io import StringIO, BytesIO
import os
from scientific_zscore_app import compute_zscores_file
from js import fetch
#### --- code to load and save data files from website ---
# import asyncio
# from js import fetch
# url = "https://raw.githubusercontent.com/FlorianKrach/scientific-LMS-zscore-app/master/data/adults_LMS_FMI_gender0.csv"
# response = await fetch(url)
# text = await response.text()
# filename = "text.csv"
# with open(filename, "w") as f:
# f.write(text)
# df = pd.read_csv(filename, index_col=0)
### ---------------------------------------------
#### --- code to load data files from local directory ---
# import asyncio
# from js import fetch
# from io import StringIO
# url = "data/adults_LMS_FMI_gender0.csv"
# response = await fetch(url)
# text = await response.text()
# df = pd.read_csv(StringIO(text), index_col=0)
### ---------------------------------------------
# TODO: load all data and save in data1
files = ['adults_LMS_appendicular_LMI_gender1.csv',
'adults_LMS_appendicular_LMI_gender0.csv',
'children_LMS_LMI_gender1.csv',
'children_LMS_LMI_gender0.csv',
'children_LMS_fitted_ALMI_gender0.csv',
'children_LMS_fitted_ALMI_gender1.csv',
'adults_LMS_VAT_mass_gender1.csv',
'adults_LMS_VAT_mass_gender0.csv',
'children_LMS_FMI_gender0.csv',
'children_LMS_BMI_gender1.csv',
'children_LMS_BMI_gender0.csv',
'children_LMS_FMI_gender1.csv',
'adults_LMS_LMI_gender1.csv',
'children_LMS_fitted_LMI_gender0.csv',
'children_LMS_fitted_LMI_gender1.csv',
'adults_LMS_LMI_gender0.csv',
'children_LMS_appendicular_LMI_gender0.csv',
'children_LMS_appendicular_LMI_gender1.csv',
'adults_LMS_FM_android_quotient_gynoid_gender1.csv',
'adults_LMS_FM_android_quotient_gynoid_gender0.csv',
'children_LMS_weight_gender1.csv',
'children_LMS_FM_trunk_quotient_limb_gender1.csv',
'adults_LMS_FM_trunk_quotient_limb_gender0.csv',
'adults_LMS_FM_trunk_quotient_limb_gender1.csv',
'children_LMS_FM_trunk_quotient_limb_gender0.csv',
'children_LMS_weight_gender0.csv',
'children_LMS_height_gender1.csv',
'children_LMS_height_gender0.csv',
'children_LMS_percent_FM_gender0.csv',
'children_LMS_percent_FM_gender1.csv',
'children_LMS_fitted_BMI_gender0.csv',
'adults_LMS_FMI_gender0.csv',
'children_LMS_fitted_FMI_gender1.csv',
'children_LMS_fitted_FMI_gender0.csv',
'adults_LMS_FMI_gender1.csv',
'children_LMS_fitted_BMI_gender1.csv']
if not os.path.exists("data1/"):
os.makedirs("data1/")
for filename in files:
url = "data/{}".format(filename)
response = await fetch(url)
text = await response.text()
savefile = "data1/{}".format(filename)
with open(savefile, "w") as f:
f.write(text)
pyscript.write("output", "")
fileInput = pn.widgets.FileInput(accept='.xlsx')
uploadButton = pn.widgets.Button(name='Upload & Process', button_type = 'primary')
Output2 = pn.pane.Str()
filename = "zscores.xlsx"
def process_file(event):
n = 1
Output2.object = ""
if fileInput.value is not None:
f = fileInput.filename
try:
df = pd.read_excel(BytesIO(fileInput.value), header=0,
index_col=None, dtype=float)
df_out = compute_zscores_file(
df, datapath="data1/", age_col="age", gender_col="gender",
height_col="height")
df_out.to_excel(filename, index=False)
pyscript.write("output", "")
Output2.object = "preview:\n\n{}".format(df_out.head(n=10))
except Exception as e:
pyscript.write("output", "error:\n{}".format(e))
Output2.object = ""
else:
pyscript.write("output", "please select a file first ...")
Output2.object = ""
uploadButton.on_click(process_file)
downloadButton = pn.widgets.FileDownload(file=filename)
await show(fileInput, 'fileinput')
await show(uploadButton, 'upload')
await show(downloadButton, 'download')
await show(Output2, 'output2')