Skip to content

Commit 1d5775b

Browse files
committed
Merge branch 'feature/path_setup' into develop #84
2 parents 69ddda5 + 00702e6 commit 1d5775b

2 files changed

Lines changed: 40 additions & 38 deletions

File tree

Metallicity_Stack_Commons/__init__.py

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
all_line_name = ['OII_3726', 'OII_3729'] + line_name[1:]
2323
wavelength_dict = dict(zip(all_line_name, all_lambda0))
2424

25-
fitspath_reagen = '/Users/reagenleimbach/Desktop/Zcalbase_gal/'
26-
27-
fitspath_caroline = 'C:/Users/carol/Google Drive/'
28-
29-
fitspath_chun = '/Users/cly/GoogleDrive/Research/'
25+
fitspath_dict = {
26+
'reagenleimbach': '/Users/reagenleimbach/GoogleDrive/Research/',
27+
'carol': 'C:/Users/carol/Google Drive/',
28+
'cly': '/Users/cly/GoogleDrive/Research/',
29+
'travis': '/home/travis/',
30+
'runner': '/home/runner/'
31+
}
3032

3133
scalefact = 1e-17
3234

@@ -59,35 +61,31 @@ def exclude_outliers(objno):
5961
return flag
6062

6163

62-
def dir_date(org_name, path_init='', year=False):
64+
def dir_date(folder_name, path_init='', year=False):
6365
"""
6466
Purpose:
65-
This function finds and returns the path to a directory named after the
66-
current date (MMDDYYYY). If the directory doesn't exist yet, it creates
67-
a new directory named after the current date in the provided org_name
68-
directory.
67+
This function finds and returns the path to a directory named after the
68+
current date (MMDDYYYY). If the directory doesn't exist yet, it creates
69+
a new directory named after the current date in the provided folder_name
70+
directory.
6971
7072
From https://github.com/rafia37/Evolution-of-Galaxies/blob/master/general.py
71-
Usage:
72-
fitspath = dir_date(org_name, path_init='', year=True)
73-
74-
Params:
75-
org_name --> a string of the directory that the date subdirectory will be in.
7673
77-
Returns:
78-
fitspath --> the path to the date directory.
74+
:param folder_name: str containing directory for date subdirectory will be in
75+
:param path_init: root path. Default: empty string
76+
:param year: Indicate whether to include year in date folder. Default: False
7977
80-
Outputs:
81-
"Path already exists" --> prints this message if the current date directory already exists.
82-
fitspath --> prints the path to the directory.
78+
:return: fitspath: Full path to the date directory
8379
80+
Usage:
81+
fitspath = dir_date(folder_name, path_init='', year=True)
8482
"""
8583

8684
today = date.today()
8785

88-
list_path = [path_init, org_name, "%02i%02i" % (today.month, today.day), '']
86+
list_path = [path_init, folder_name, "%02i%02i" % (today.month, today.day), '']
8987
if year:
90-
list_path[-2] += "%02i" % today.year
88+
list_path[-2] = "%i" % today.year + list_path[-2]
9189

9290
fitspath = os.path.join(*list_path)
9391
try:
@@ -103,13 +101,9 @@ def get_user(username=None):
103101
if isinstance(username, type(None)):
104102
username = getpass.getuser()
105103

106-
if username == 'reagenleimbach':
107-
fitspath = fitspath_reagen
108-
109-
if username == 'carol':
110-
fitspath = fitspath_caroline
111-
112-
if username == 'cly':
113-
fitspath = fitspath_chun
104+
if username in fitspath_dict.keys():
105+
fitspath = fitspath_dict[username]
106+
else:
107+
raise ValueError("Incorrect username input")
114108

115109
return fitspath

tests/test_commons.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,44 @@
11
from Metallicity_Stack_Commons import column_names, dir_date, exclude_outliers
2-
from Metallicity_Stack_Commons import get_user, fitspath_reagen, fitspath_caroline
2+
from Metallicity_Stack_Commons import get_user, fitspath_dict
33

44
from os.path import exists
55
from os import rmdir
66

77
import numpy as np
8+
import getpass
9+
10+
import pytest
811

912

1013
def test_dir_date():
1114
mmdd = dir_date('', '')
12-
mmddyyyy = dir_date('', '', year=True)
15+
yyyymmdd = dir_date('', '', year=True)
1316

1417
assert exists(mmdd)
15-
assert exists(mmddyyyy)
18+
assert exists(yyyymmdd)
1619

1720
# Check path existence
1821
mmdd = dir_date('', '')
1922

2023
if exists(mmdd):
2124
rmdir(mmdd)
2225

23-
if exists(mmddyyyy):
24-
rmdir(mmddyyyy)
26+
if exists(yyyymmdd):
27+
rmdir(yyyymmdd)
2528

2629
assert len(mmdd) == 5
27-
assert len(mmddyyyy) == 9
30+
assert len(yyyymmdd) == 9
2831

2932

3033
def test_get_user():
3134

32-
assert get_user('reagenleimbach') == fitspath_reagen
33-
assert get_user('carol') == fitspath_caroline
35+
for username in ['reagenleimbach', 'carol']:
36+
assert get_user(username=username) == fitspath_dict[username]
37+
38+
with pytest.raises(ValueError):
39+
get_user(username='test')
40+
41+
assert get_user() == fitspath_dict[getpass.getuser()]
3442

3543

3644
def test_exclude_outliers():

0 commit comments

Comments
 (0)