Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhandberg committed Apr 21, 2021
2 parents 7c794f7 + 2a820ba commit 3fe40bf
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
master-v0.4.8
master-v0.4.9
4 changes: 4 additions & 0 deletions flows/load_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ def load_image(FILENAME):
image.photfilter = {
'B Bes': 'B',
'V Bes': 'V',
'R Bes': 'R',
'g SDSS': 'gp',
'r SDSS': 'rp',
'i SDSS': 'ip',
'i int': 'ip', # Interference filter
'u SDSS': 'up',
'z SDSS': 'zp'
}.get(hdr['FILTER'].replace('_', ' '), hdr['FILTER'])
Expand All @@ -142,9 +144,11 @@ def load_image(FILENAME):
if len(filters_used) == 1:
image.photfilter = {
'V_Bes 530_80': 'V',
'R_Bes 650_130': 'R',
"g'_SDSS 480_145": 'gp',
"r'_SDSS 618_148": 'rp',
"i'_SDSS 771_171": 'ip',
'i_int 797_157': 'ip', # Interference filter
"z'_SDSS 832_LP": 'zp'
}.get(filters_used[0].replace(' ', ' '), filters_used[0])
else:
Expand Down
6 changes: 3 additions & 3 deletions flows/ztf.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ def download_ztf_photometry(targetid):
# Create Astropy table, cut out the needed columns
# and rename columns to something better for what we are doing:
tab = Table(data=jsn)
tab = tab[['fid', 'mjd', 'magpsf_corr', 'sigmapsf_corr']]
tab = tab[['fid', 'mjd', 'magpsf', 'sigmapsf']]
tab.rename_column('fid', 'photfilter')
tab.rename_column('mjd', 'time')
tab.rename_column('magpsf_corr', 'mag')
tab.rename_column('sigmapsf_corr', 'mag_err')
tab.rename_column('magpsf', 'mag')
tab.rename_column('sigmapsf', 'mag_err')

# Remove bad values of time and magnitude:
tab['time'] = np.asarray(tab['time'], dtype='float64')
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pytest
flake8
flake8-tabs !=2.3.0,!=2.3.1
flake8-builtins
flake8-logging-format
numpy >= 1.16
Expand Down
15 changes: 10 additions & 5 deletions run_download_ztf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ def main():

# Check that output directory exists:
if not os.path.isdir(output_dir):
parser.error("Output directory does not exist: '%s'" % output_dir) # noqa: G002
parser.error(f"Output directory does not exist: '{output_dir}'") # noqa: G004

# Use API to get list of targets to process:
if args.target is None:
targets = api.get_targets()
else:
targets = [api.get_target(args.target)]

# Colors used for the different filters in plots:
# I know purple is in the wrong end of the scale, but not much I can do
colors = {'gp': 'tab:green', 'rp': 'tab:red', 'ip': 'tab:purple'}

# Loop through targets:
for tgt in targets:
logger.debug("Target: %s", tgt)
Expand All @@ -67,12 +71,12 @@ def main():
# Download ZTF photometry as Astropy Table:
tab = ztf.download_ztf_photometry(tgt['targetid'])
logger.debug("ZTF Photometry:\n%s", tab)
if tab is None:
if tab is None or len(tab) == 0:
continue

# Write table to file:
target_name = tab.meta['target_name']
tab.write(os.path.join(output_dir, '{0:s}-ztf.ecsv'.format(target_name)),
tab.write(os.path.join(output_dir, f'{target_name:s}-ztf.ecsv'),
format='ascii.ecsv', delimiter=',')

# Find time of maxmimum and 14 days from that:
Expand All @@ -85,16 +89,17 @@ def main():
ax.axvline(maximum_mjd, ls='--', c='k', lw=0.5, label='Maximum')
ax.axvline(fortnight_mjd, ls='--', c='0.5', lw=0.5, label='+14 days')
for fid in np.unique(tab['photfilter']):
col = colors[fid]
band = tab[tab['photfilter'] == fid]
ax.errorbar(band['time'], band['mag'], band['mag_err'],
ls='-', lw=0.5, marker='.', label=fid)
color=col, ls='-', lw=0.5, marker='.', label=fid)

ax.invert_yaxis()
ax.set_title(target_name)
ax.set_xlabel('Time (MJD)')
ax.set_ylabel('Magnitude')
ax.legend()
fig.savefig(os.path.join(output_dir, '{0:s}-ztf.png'.format(target_name)), format='png', bbox_inches='tight')
fig.savefig(os.path.join(output_dir, f'{target_name:s}-ztf.png'), format='png', bbox_inches='tight')
plt.close(fig)

#--------------------------------------------------------------------------------------------------
Expand Down
13 changes: 11 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
exclude = .git,__pycache__,notes
max-line-length = 99

enable-extensions=G
# Enable flake8-logging-format:
enable-extensions = G

# Configuration of flake8-tabs:
use-flake8-tabs = True
blank-lines-indent = never
indent-tabs-def = 1
indent-style = tab

ignore =
E117, # over-indented (set when using tabs)
Expand All @@ -18,11 +25,13 @@ ignore =
E305, # expected 2 blank lines after class or function definition, found 1
E501, # line too long
E701, # multiple statements on one line (colon)
W191, # indentation contains tabs
W503, # Line break occurred before a binary operator
ET128, # (flake8-tabs) unexpected number of tabs and spaces at start of XXX

[tool:pytest]
addopts = --strict-markers --durations=10
testpaths = tests
xfail_strict = True

#[coverage:run]
#branch = True
Expand Down

0 comments on commit 3fe40bf

Please sign in to comment.