Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload reliability improvements #86

Merged

Conversation

bfhealy
Copy link
Collaborator

@bfhealy bfhealy commented Aug 31, 2022

This PR improves the stability of source uploads using scope_upload_classification.py:

  • All calls to fritz.api() are 'protected' by a try/except loop that catches a JSON error raised by a server response issue. After 10 tries the code will still fail, but this protection helps to keep the loop running in the event of a passing glitch.
  • scope_upload_classification now always calls fritz.save_newsource(). New checks run within save_newsource to enable photometry and period data to be posted even if an object already exists on Fritz. This is useful in the case of an interrupted upload, and also if new ZTF photometry becomes available.
  • Additional checks prevent the upload of duplicate/nan photometry, which previously raised an error.

Copy link
Collaborator

@mcoughlin mcoughlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding a variable at the top of the script to define the number of attempts. Otherwise looks good.

scope/fritz.py Outdated

# post photometry to obj_id; drop flagged data
df_photometry = make_photometry(light_curves, drop_flagged=True)
for attempt in range(10):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make the number of attempts a variable like
MAX_ATTEMPTS = 10
Defined at the top of the script?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! I added this variable for both scripts and replaced all range(10) with range(MAX_ATTEMPTS).

scope/fritz.py Outdated
print(f'Error - Retrying (attempt {attempt+1}).')

# start by checking for existing photometry
for attempt in range(10):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you can reuse it here.

scope/fritz.py Outdated
if response.json()["status"] == "error":
print('Failed to post to Fritz')
return None
for attempt in range(10):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here three!

scope/fritz.py Outdated
@@ -334,7 +354,14 @@ def save_newsource(
"group_ids": group_ids,
"data": {'period': period},
}
response = api("POST", "api/sources/%s/annotations" % obj_id, token, data=data)
for attempt in range(10):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And four ;)

@@ -35,6 +39,12 @@ def upload_classification(
sources = pd.read_csv(file)
columns = sources.columns

if start is not None:
if stop is not None:
sources = sources.loc[start:stop]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be start+1?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the code currently prints the zero-based index of each row in the dataframe, I wanted to stick with that convention for the start argument. I've noted this convention in usage.md and the help info of the scripts.

response = api("GET", f"/api/sources?&ra={ra}&dec={dec}&radius={2/3600}", token)
sleep(0.9)
data = response.json().get("data")
for attempt in range(10):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same variable here.

@bfhealy
Copy link
Collaborator Author

bfhealy commented Sep 1, 2022

Thanks Michael! I just pushed the changes you requested.

@bfhealy
Copy link
Collaborator Author

bfhealy commented Sep 1, 2022

I also just added handling for a ConnectionError, which also should prompt the MAX_ATTEMPTS loop.

@mcoughlin
Copy link
Collaborator

LGTM @bfhealy !

@bfhealy
Copy link
Collaborator Author

bfhealy commented Sep 1, 2022

Thanks, and sorry for the last-minute changes - I added handling for a couple more connection-related errors.

@mcoughlin
Copy link
Collaborator

Which is great. Feel free to merge when ready @bfhealy.

@bfhealy bfhealy merged commit 722f48f into ZwickyTransientFacility:main Sep 1, 2022
@bfhealy bfhealy deleted the upload-stability-improvements branch September 1, 2022 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants