Skip to content

Commit

Permalink
Merge pull request #147 from lephare-photoz/issue/115/test_suite
Browse files Browse the repository at this point in the history
Port over test_suite.sh
  • Loading branch information
raphaelshirley authored May 17, 2024
2 parents 25e3ce7 + ac00039 commit 9faf282
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 2 deletions.
8 changes: 6 additions & 2 deletions examples/color.py → docs/historical_examples/color.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from sys import *
from matplotlib.pyplot import *
# ruff: noqa
# These historical examples are not maintained or covered by tests or linting!

from math import *
from sys import *

import numpy as np
from matplotlib.backends.backend_pdf import PdfPages
from matplotlib.pyplot import *


############################
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# ruff: noqa
# These historical examples are not maintained or covered by tests or linting!

from sys import *

from matplotlib.pyplot import *
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# ruff: noqa
# These historical examples are not maintained or covered by tests or linting!

from sys import *

from matplotlib.pyplot import *
Expand Down
3 changes: 3 additions & 0 deletions examples/spec.py → docs/historical_examples/spec.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# ruff: noqa
# These historical examples are not maintained or covered by tests or linting!

# Plot (file or window) the observed magnitudes
# of the objects, along with best-fit templates,
# reading the info form .zsp and .pdz output
Expand Down
48 changes: 48 additions & 0 deletions docs/historical_examples/test_suite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

# Set the number of threads for OpenMP
export OMP_NUM_THREADS='30'

# Set the LEPHAREDIR and LEPHAREWORK variables
export LEPHAREDIR=$(python -c "import lephare as lp; print(f'{lp.LEPHAREDIR}')" | tail -n 1) # use tail to ignore the on-import print statement
export LEPHAREWORK=$(python -c "import lephare as lp; print(f'{lp.dm.LEPHAREWORK}')" | tail -n 1) # use tail to ignore the on-import print statement

# Set catalog and config file names
CAT_IN="$LEPHAREDIR/examples/COSMOS.in"
CAT_OUT="zphot_short.out"
CONFIG_FILE="$LEPHAREDIR/examples/COSMOS.para"

# For debugging:
# echo "LEPHAREDIR:" $LEPHAREDIR
# echo "LEPHAREWORK:" $LEPHAREWORK
# echo "CONFIG_FILE:" $CONFIG_FILE

# Get the data
echo "Downloading to $CAT_IN..."
curl -s -o $CAT_IN https://raw.githubusercontent.com/lephare-photoz/lephare-data/main/examples/COSMOS.in

# Run commands
echo "Running filter..."
filter -c $CONFIG_FILE

echo "Running sedtolib and mag_gal for stars..."
sedtolib -c $CONFIG_FILE -t S --STAR_SED $LEPHAREDIR/examples/STAR_MOD_ALL.list --LIB_ASCII YES
mag_gal -c $CONFIG_FILE -t S --LIB_ASCII YES --STAR_LIB_OUT ALLSTAR_COSMOS

echo "Running sedtolib and mag_gal for QSOs..."
sedtolib -c $CONFIG_FILE -t Q --QSO_SED $LEPHAREDIR/sed/QSO/SALVATO09/AGN_MOD.list
mag_gal -c $CONFIG_FILE -t Q --MOD_EXTINC 0,1000 --EB_V 0.,0.1,0.2,0.3 --EXTINC_LAW SB_calzetti.dat --LIB_ASCII NO --Z_STEP 0.04,0,6 --LIB_ASCII YES

echo "Running sedtolib and mag_gal for galaxies..."
sedtolib -c $CONFIG_FILE -t G --GAL_SED $LEPHAREDIR/examples/COSMOS_MOD.list --GAL_LIB LIB_VISTA
mag_gal -c $CONFIG_FILE -t G --GAL_LIB_IN LIB_VISTA --GAL_LIB_OUT VISTA_COSMOS_FREE --MOD_EXTINC 18,26,26,33,26,33,26,33 --EXTINC_LAW SMC_prevot.dat,SB_calzetti.dat,SB_calzetti_bump1.dat,SB_calzetti_bump2.dat --EM_LINES EMP_UV --EM_DISPERSION 0.5,0.75,1.,1.5,2. --Z_STEP 0.04,0,6 --LIB_ASCII YES

echo "Running zphota..."
zphota -c $CONFIG_FILE --CAT_IN $CAT_IN --CAT_OUT $CAT_OUT --ZPHOTLIB VISTA_COSMOS_FREE,ALLSTAR_COSMOS,QSO_COSMOS --ADD_EMLINES 0,100 --AUTO_ADAPT YES --Z_STEP 0.04,0,6 --CAT_LINES 1,100 --SPEC_OUT YES --PARA_OUT $LEPHAREDIR/examples/output.para --VERBOSE NO --ZFIX NO --PDZ_OUT $LEPHAREWORK/zphota/

echo "Generating figures and specs..."
python $LEPHAREDIR/examples/figuresLPZ.py $CAT_OUT
python $LEPHAREDIR/examples/spec.py *.spec -d pdf -o $LEPHAREWORK/zphota/spec

echo "Moving output files..."
mv $CAT_OUT Id*.spec figuresLPZ.pdf $LEPHAREWORK/zphota/
81 changes: 81 additions & 0 deletions docs/notebooks/Command_line_demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Command line demo\n",
"\n",
"In this very simple notebook we download the files required to run lephare and demonstrate the command line example script.\n",
"\n",
"This is not the reccomended way to run lephare but provides access to the legacy running commands."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import lephare as lp"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Download the data required in the example config file."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"config = lp.string_dict_to_keymap(lp.default_cosmos_config)\n",
"lp.data_retrieval.get_auxiliary_data(\n",
" keymap=config, additional_files=[\"examples/COSMOS.in\", \"examples/output.para\", \"examples/COSMOS.para\"]\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script. This will take around ten minutes."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!bash ../historical_examples/test_suite.sh"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit 9faf282

Please sign in to comment.