Closed MichaelMedford closed 5 years ago
Hi Michael,
It's been a long time I did not use NightSummary. Something may have changed. I'll look at it today.
There are two issues arising.
First is when the author name has a space in it, such as "Richard Deka". The split() command adds an extra element into each of these rows, making the total number of columns in that particular row one more than the columns used to initiate the dataframe.
Second is when there is a missing fileroot in the summary. The split() skips over the fileroot column for that row, making the total number of columns in that particular row one less than the columns used to initiate the dataframe.
I came up with the following hack that works, although it is not at all generalized:
def download_night_summary(night, ztfops_auth = None):
"""
Parameters
----------
night: [string]
Format: YYYYMMDD like for instance 20180429
ztfops_auth: [string, string] -optional-
Provide directly the [username, password] of the ztfops page.
"""
import requests
from pandas import DataFrame
# = Password and username
if ztfops_auth is None:
from .io import _load_id_
ztfops_auth = _load_id_("ztfops", askit=True)
summary = requests.get(_NIGHT_SUMMARY_URL+"%s/exp.%s.tbl"%(night,night),
auth=ztfops_auth).content.decode('utf-8').splitlines()
columns = [l.replace(" ","") for l in summary[0].split('|') if len(l.replace(" ",""))>0]
# data = [l.split() for l in summary[1:] if not l.startswith('|') and len(l)>1]
# Hacky Loop
data = []
for i, line in enumerate(summary):
# Same continue condition as in the list comprehension
if line.startswith('|') and len(line)>1: continue
# PI cannot have a space in the name, this is the one I keep seeing
line = line.replace('Richard Deka', 'RichardDeka')
d = line.split()
# Fileroot cannot be dropped from file. This assumes that a missing column
# is always due to a missing fileroot.
if len(d) < len(columns):
d = d[:-2] + ['None'] + d[-2:]
data.append(d)
dataf = DataFrame(data=data, columns=[l if l!= "fil" else "fid" for l in columns])
dataf["fid"][dataf["fid"]=="4"] = "3"
return dataf
Thanks for looking closely into it. I'm at a conference right now so I haven't had the time to find a solution, but want you made looks great. I'll be back into it asap.
I have come up with a solution and ran a pull request title Night summaries to daraframes through indexer. Please check it out and let me know what you think.
Thanks for doing this Michael
Running the example for night summary provided on the Readme still works. However running later dates of the night summary returns a list with an index out of range.
results in
I also know that this is not an authentication issue because I have repeated the attempt using
and ended up with the same results.