Skip to content

Commit

Permalink
Merge pull request #109 from SgmAstro/cordelia
Browse files Browse the repository at this point in the history
fix job dependencies to gold d8 in pipeline
  • Loading branch information
SgmAstro authored Feb 24, 2022
2 parents ea06155 + a994f9c commit c985538
Show file tree
Hide file tree
Showing 25 changed files with 350 additions and 193 deletions.
12 changes: 6 additions & 6 deletions bin/gold_d8_pipeline
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#SBATCH -p cordelia
#SBATCH --mem=20G
#SBATCH --mem=50G
#SBATCH -t 02:00:00
#SBATCH -o gold_d8_pipeline.log
#SBATCH -o /cosma/home/durham/dc-wils7/data/GAMA4/logs/gold_d8_pipeline.log
#SBATCH -A durham
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
Expand All @@ -15,15 +15,15 @@
#

if [ -z ${DRYRUN+x} ]; then
# export DRYRUN=''
export DRYRUN='--dryrun'
export DRYRUN=''
# export DRYRUN='--dryrun'
else
echo 'DRYRUN SET TO BE '$DRYRUN
fi

if [[ -z "${SURVEY}" ]]; then
export SURVEY='desi'
export SURVEYARG='--survey desi'
export SURVEY='gama'
export SURVEYARG='--survey gama'
else
export SURVEYARG='--survey '$SURVEY

Expand Down
2 changes: 1 addition & 1 deletion bin/gold_pipeline
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#SBATCH -p cordelia
#SBATCH --mem=20G
#SBATCH -t 02:00:00
#SBATCH -o gold_pipeline.log
#SBATCH -o /cosma/home/durham/dc-wils7/data/GAMA4/logs/gold_pipeline.log
#SBATCH -A durham
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
Expand Down
17 changes: 8 additions & 9 deletions bin/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import glob
import argparse
import subprocess
import numpy as np

from pathlib import Path
from subprocess import check_output
from findfile import fetch_fields


def run_command(cmd):
print('Command: {}'.format(cmd))

Expand All @@ -29,8 +29,8 @@ def run_command(cmd):

return out

# Sbatch: python3 pipeline.py --survey desi --use_sbatch --log
# Head: python3 pipeline.py --survey desi --reset
# Sbatch: python3 pipeline.py --survey gama --use_sbatch --log --nooverwrite
# Head: python3 pipeline.py --survey desi
parser = argparse.ArgumentParser(description='Run Lumfn pipeline')
parser.add_argument('--use_sbatch', help='Submit via Sbatch', action='store_true')
parser.add_argument('--reset', help='Reset', action='store_true')
Expand Down Expand Up @@ -71,13 +71,12 @@ def run_command(cmd):
print('\n\n>>>>> TRASHING GOLD_DIR AND RANDOMS <<<<<\n\n')

for root in [os.environ['GOLD_DIR'], os.environ['RANDOMS_DIR']]:
for ext in ['fits', 'log']:
cmd = 'rm {}/*.{}'.format(root, ext)
cmd = 'rm -f {}/logs/*.log'.format(root)

print(cmd)

# Split on whitespace.
cmd = cmd.split()
os.system(cmd)

# out = run_command(cmd)
if reset:
os.environ['RESET'] = str(1)
else:
Expand Down Expand Up @@ -211,7 +210,7 @@ def run_command(cmd):

# Requires ddp cat. & random fill factor.
# Note: runs all fields simultaneously.
dependencies = ','.join(rand_ddp_d8_jobids)
dependencies = ','.join(str(rand_ddp_d8_jobids[field]) for field in fields)

# possibly missing RESET=$RESET
#cmd = 'serialorparallel -p $USESBATCH -e DRYRUN=$DRYRUN,NOOVERWRITE=$NOOVERWRITE,SURVEY=$SURVEY -d {dependencies} -s gold_d8_pipeline -c $CODE_ROOT'
Expand Down
4 changes: 2 additions & 2 deletions bin/rand_d8_pipeline
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#SBATCH -p cordelia
#SBATCH --mem=20G
#SBATCH --mem=50G
#SBATCH -t 04:00:00
#SBATCH -o rand_d8_pipeline.log
#SBATCH -o /cosma/home/durham/dc-wils7/data/GAMA4/randoms/logs/rand_d8_pipeline.log
#SBATCH -A durham
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
Expand Down
4 changes: 2 additions & 2 deletions bin/rand_ddp1_d8_pipeline
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#SBATCH -p cordelia
#SBATCH --mem=20G
#SBATCH --mem=50G
#SBATCH -t 04:00:00
#SBATCH -o rand_ddp1_d8_pipeline.log
#SBATCH -o /cosma/home/durham/dc-wils7/data/GAMA4/randoms/logs/rand_ddp1_d8_pipeline.log
#SBATCH -A durham
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
Expand Down
4 changes: 2 additions & 2 deletions bin/rand_ddp1_pipeline
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#SBATCH -p cordelia
#SBATCH --mem=20G
#SBATCH --mem=50G
#SBATCH -t 04:00:00
#SBATCH -o rand_ddp1_pipeline.log
#SBATCH -o /cosma/home/durham/dc-wils7/data/GAMA4/randoms/logs/rand_ddp1_pipeline.log
#SBATCH -A durham
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
Expand Down
4 changes: 2 additions & 2 deletions bin/rand_pipeline
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#SBATCH -p cordelia
#SBATCH --mem=20G
#SBATCH --mem=50G
#SBATCH -t 04:00:00
#SBATCH -o rand_pipeline.log
#SBATCH -o /cosma/home/durham/dc-wils7/data/GAMA4/randoms/logs/rand_pipeline.log
#SBATCH -A durham
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
Expand Down
6 changes: 2 additions & 4 deletions bound_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from astropy.table import Table
from multiprocessing import Pool
from runtime import calc_runtime
from findfile import findfile
from findfile import findfile, overwrite_check

'''
Script to calculate the maximum distance [Mpc/h] of each random from the boundary.
Expand Down Expand Up @@ -48,9 +48,7 @@
opath = findfile(ftype='randoms_bd', dryrun=dryrun, field=field, survey=survey, prefix=prefix)

if args.nooverwrite:
if os.path.isfile(opath):
print('{} found on disk and overwrite forbidden (--nooverwrite).'.format(opath))
exit(0)
overwrite_check(opath)

# Output is sorted by fillfactor.py;
body = Table.read(fpath)
Expand Down
57 changes: 51 additions & 6 deletions boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,23 @@
from desi_randoms import desi_randoms
from findfile import fetch_fields, findfile, overwrite_check
from gama_limits import gama_limits, gama_field

from scipy.spatial.transform import Rotation as R
from ros_tools import roscen

np.random.seed(314)

def rotate2rosette(ros_ra, ros_dec, pos):
pos = np.array(pos, copy=True)

rot = R.from_rotvec(-np.radians(90. - ros_dec) * np.array([1, 0, 0]))
res = rot.apply(pos)

rot = R.from_rotvec(np.radians(ros_ra - 90.) * np.array([0, 0, 1]))

resres = rot.apply(res)

return resres

parser = argparse.ArgumentParser(description='Calculate a set of boundary points')
parser.add_argument('-f', '--field', type=str, help='select GAMA field [G9, G12, G15] or DESI rosette [R1...]', required=True)
parser.add_argument('-d', '--dryrun', help='Dryrun.', action='store_true')
Expand Down Expand Up @@ -50,6 +63,9 @@
## opath = os.environ['RANDOMS_DIR'] + '/{}_{}_{:d}.fits'.format(prefix, field, realz)
opath = findfile(ftype='randoms', dryrun=dryrun, field=field, survey=survey, prefix=prefix, realz=realz)

if args.nooverwrite:
overwrite_check(opath)

## ras and decs.
if survey == 'gama':
area = 60.
Expand Down Expand Up @@ -102,12 +118,41 @@
randoms.rename_column('BOUND_Z', 'Z')

elif survey == 'desi':
if 'NERSC_HOST' in os.environ.keys():
raise NotImplementedError()
# No requirement on NERSC HOST for boundary.
inner = 0.5 # deg.
outer = 1.5 # deg.
# HACK?
area = np.pi * (outer**2. - inner**2.)

ras = np.arange(0., 360., 1.e-3)
idecs = (90. - inner) * np.ones_like(ras)
odecs = (90. - outer) * np.ones_like(ras)

np.random.shuffle(ras)

randoms = np.c_[ras, idecs]
randoms = np.vstack((randoms, np.c_[ras, odecs]))

randoms = Table(randoms, names=['BOUND_RA', 'BOUND_DEC'])
randoms['Z'] = 0.2

chis = np.ones_like(randoms['Z'])
chis *= cosmo.comoving_distance(0.2).value # Mpc/h

xyz = cartesian(randoms['BOUND_RA'], randoms['BOUND_DEC'], randoms['Z'], rotate=False)

rr = int(field[1:])
rr = roscen[rr]

ros_xyz = rotate2rosette(rr[0], rr[1], xyz)

ras = np.degrees(np.arctan2(ros_xyz[:,1], ros_xyz[:,0]))

thetas = np.degrees(np.arccos(ros_xyz[:,2] / chis))
decs = 90. - thetas

else:
print(f'As you are not running on nersc, the output of this script is assumed to be present at {opath} for dryrun: {dryrun}.')
exit(0)
randoms = Table(np.c_[ras, decs], names=['BOUND_RA', 'BOUND_DEC'])
randoms['Z'] = np.random.uniform(zmin, zmax, len(randoms))

else:
raise NotImplementedError(f'No implementation for survey: {survey}')
Expand Down
10 changes: 5 additions & 5 deletions cartesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def cartesian(ras, decs, zs, rotate=False):
mean_phi = np.median(phi)
mean_theta = np.median(theta)

chis = cosmo.comoving_distance(zs).value # Mpc/h
chis = cosmo.comoving_distance(zs).value # Mpc/h

zs = chis * np.cos(theta)
ys = chis * np.sin(theta) * np.sin(phi)
xs = chis * np.sin(theta) * np.cos(phi)
zs = chis * np.cos(theta)
ys = chis * np.sin(theta) * np.sin(phi)
xs = chis * np.sin(theta) * np.cos(phi)

pos = np.c_[xs, ys, zs]
pos = np.c_[xs, ys, zs]

if rotate:
pos = rotate(ras, decs, pos)
Expand Down
26 changes: 17 additions & 9 deletions ddp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,32 @@
tmr_DDP2 = [-20.6, -19.3]
tmr_DDP3 = [-19.6, -17.8]


root = os.environ['GOLD_DIR'] + '/ddrp_limits/'

_bright_curve = fitsio.read(root + '/ddrp_limit_3.fits') # 7 (12.0 QCOLOR 0.131)
_faint_curve = fitsio.read(root + '/ddrp_limit_17.fits') # 27 (19.8 QCOLOR 1.067)
def initialise_ddplimits(survey, Mcol='M0P0_QALL'):
assert Mcol == 'M0P0_QALL', 'Hard coded limit numbers and curves'

_bright_curve = fitsio.read(root + f'/{survey}/ddrp_limit_3.fits') # 7 (12.0 QCOLOR 0.131)
_faint_curve = fitsio.read(root + f'/{survey}/ddrp_limit_17.fits') # 27 (19.8 QCOLOR 1.067)

# TODO: extend the curve limits and put bounds_error back on.
bright_curve = interp1d(_bright_curve['M0P0_QALL'], _bright_curve['Z'], kind='linear', copy=True, bounds_error=False, fill_value=0.0, assume_sorted=False)
bright_curve_r = interp1d(_bright_curve['Z'], _bright_curve['M0P0_QALL'], kind='linear', copy=True, bounds_error=False, fill_value=0.0, assume_sorted=False)
# TODO: extend the curve limits and put bounds_error back on.
bright_curve = interp1d(_bright_curve[Mcol], _bright_curve['Z'], kind='linear', copy=True, bounds_error=False, fill_value=0.0, assume_sorted=False)
bright_curve_r = interp1d(_bright_curve['Z'], _bright_curve['M0P0_QALL'], kind='linear', copy=True, bounds_error=False, fill_value=0.0, assume_sorted=False)

faint_curve = interp1d(_faint_curve['M0P0_QALL'], _faint_curve['Z'], kind='linear', copy=True, bounds_error=False, fill_value=1.0, assume_sorted=False)
faint_curve_r = interp1d(_faint_curve['Z'], _faint_curve['M0P0_QALL'], kind='linear', copy=True, bounds_error=False, fill_value=1.0, assume_sorted=False)
faint_curve = interp1d(_faint_curve[Mcol], _faint_curve['Z'], kind='linear', copy=True, bounds_error=False, fill_value=1.0, assume_sorted=False)
faint_curve_r = interp1d(_faint_curve['Z'], _faint_curve['M0P0_QALL'], kind='linear', copy=True, bounds_error=False, fill_value=1.0, assume_sorted=False)

def get_ddps(Area, M_0P0s, zs):
return bright_curve, bright_curve_r, faint_curve, faint_curve_r

def get_ddps(Area, M_0P0s, zs, survey):
result = np.zeros(len(zs) * 3, dtype=int).reshape(len(zs), 3)
resultz = np.zeros(len(zs) * 3, dtype=int).reshape(len(zs), 3)
resultz = np.zeros(len(zs) * 3, dtype=int).reshape(len(zs), 3)

zlims = {}

bright_curve, bright_curve_r, faint_curve, faint_curve_r = initialise_ddplimits(survey=survey)

for i, lims in enumerate([tmr_DDP1, tmr_DDP2, tmr_DDP3]):
in_ddp = (M_0P0s >= lims[0]) & (M_0P0s <= lims[1])

Expand Down
24 changes: 14 additions & 10 deletions ddp_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
from data.ke_params import *
from survey import survey_specifics

parser = argparse.ArgumentParser(description='Gen kE cat.')

parser = argparse.ArgumentParser(description='Gen kE DDP limit curves')
parser.add_argument('--nooverwrite', help='Do not overwrite outputs if on disk', action='store_true')
parser.add_argument('-s', '--survey', help='Select survey', default='gama')

args = parser.parse_args()
survey = args.survey.lower()
args = parser.parse_args()
survey = args.survey.lower()

kcorr_r = GAMA_KCorrection(band='R')
kcorr_RG = GAMA_KCorrection_color()
Expand All @@ -28,13 +29,10 @@
gmrs_0p0 = np.array([0.158, 0.298, 0.419, 0.553, 0.708, 0.796, 0.960])

# bright and faint limits.
limits = survey_specifics(survey)
rlims = [limits['rmax'], limits['rlim']]

zs = np.arange(0.01, 0.6, 0.01)
mus = cosmo.distmod(zs)
limits = survey_specifics(survey)
rlims = [limits['rmax'], limits['rlim']]

root = os.environ['GOLD_DIR'] + '/ddrp_limits/'
root = os.environ['GOLD_DIR'] + f'/ddrp_limits/{survey}'

if not os.path.isdir(root):
print('Creating {}'.format(root))
Expand All @@ -43,6 +41,8 @@

count = 0

zs = mus = None

for rlim in rlims:
print('----------------------------------')

Expand All @@ -59,6 +59,10 @@

continue

if (zs is None) | (mus is None):
zs = np.arange(0.01, 0.6, 0.01)
mus = cosmo.distmod(zs)

gmr_0P1 = gmr_0P1 * np.ones_like(zs)
gmr_0P0 = kcorr_RG.rest_gmr_nonnative(gmr_0P1)

Expand All @@ -67,7 +71,7 @@
Mrs_0P0 = abs_mag(rs, mus, ks, es)

dat = Table(np.c_[zs, ks, es, Mrs_0P0], names=['Z', 'K', 'E', 'M0P0_{}'.format(all_type)])
dat.meta = {'RLIM': rlim, 'ALL': aall, 'GMR_0P1': gmr_0P1[0], 'GMR_0P0': gmr_0P0[0]}
dat.meta = {'RLIM': rlim, 'ALL': aall, 'GMR_0P1': gmr_0P1[0], 'GMR_0P0': gmr_0P0[0], 'SURVEY': survey}

dat.write(opath, format='fits', overwrite=True)

Expand Down
Loading

0 comments on commit c985538

Please sign in to comment.