-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor project structure #13
base: main
Are you sure you want to change the base?
Conversation
Fix search and replace typo
Fix search and replace typo
Fix import
copick_live/utils/copick_dataset.py
Outdated
) | ||
|
||
copick_dataset = CopickDataset( | ||
copick_config_path=COPICK_TEMPLATE_PATH, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line 291 should be copick_config_path=COPICKLIVE_CONFIG_PATH,
copick_live/utils/copick_dataset.py
Outdated
copick_dataset = None | ||
|
||
|
||
def get_copick_dataset(config_path=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found another bug: the counter_checkpoint_file_path
is not passed correctly. Can we define another function that return this path, similar to returning local_dataset
.
def get_local_dataset(config_path=None):
global local_dataset
if config_path or not local_dataset:
config = configparser.ConfigParser()
if config_path:
config_path = os.path.abspath(config_path)
else:
config_path = os.path.join(os.getcwd(), "config.ini")
if os.path.exists(config_path):
config.read(config_path)
else:
raise FileNotFoundError(f"Config file not found at {config_path}")
LOCAL_FILE_PATH = config.get("local_picks", "PICK_FILE_PATH", fallback=None)
if LOCAL_FILE_PATH:
LOCAL_FILE_PATH = os.path.join(LOCAL_FILE_PATH, "ExperimentRuns/")
COPICK_TEMPLATE_PATH = config.get("copick_template", "COPICK_TEMPLATE_PATH", fallback=None)
if not LOCAL_FILE_PATH or not COPICK_TEMPLATE_PATH:
raise ValueError("Config paths for LocalDataset are not provided and not found in the config file.")
local_dataset = LocalDataset(local_file_path=LOCAL_FILE_PATH, config_path=COPICK_TEMPLATE_PATH)
return local_dataset
def get_counter_file_path(config_path=None):
global COUNTER_FILE_PATH
if config_path or not COUNTER_FILE_PATH:
config = configparser.ConfigParser()
if config_path:
config_path = os.path.abspath(config_path)
else:
config_path = os.path.join(os.getcwd(), "config.ini")
if os.path.exists(config_path):
config.read(config_path)
else:
raise FileNotFoundError(f"Config file not found at {config_path}")
COUNTER_FILE_PATH = config.get("counter_checkpoint", "COUNTER_FILE_PATH", fallback=None)
if not COUNTER_FILE_PATH:
raise ValueError("Config path for COUNTER_FILE_PATH is not provided and not found in the config file.")
return COUNTER_FILE_PATH
copick_live/callbacks/update_res.py
Outdated
blank_fig, | ||
draw_gallery | ||
) | ||
from utils.local_dataset import ( | ||
local_dataset, | ||
from copick_live.utils.local_dataset import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from copick_live.utils.local_dataset import (
get_local_dataset,
get_counter_file_path,
dirs,
dir2id,
)
local_dataset.config_file["user_id"] = input_value | ||
return dict(content=json.dumps(local_dataset.config_file, indent=4), filename=filename) | ||
get_local_dataset().config_file["user_id"] = input_value | ||
return dict(content=json.dumps(get_local_dataset().config_file, indent=4), filename=filename) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace download_txt()
callback function to
@callback(
Output("download-txt", "data"),
Input("btn-download-txt", "n_clicks"),
#State("username", "value"),
prevent_initial_call=True,
)
def download_txt(n_clicks):
counter_checkpoint = get_counter_file_path()
if counter_checkpoint:
with open(counter_checkpoint) as f:
counter = json.load(f)
if counter['repeat'] == 2:
counter['start'] += counter['tasks_per_person']
counter['repeat'] = 0
counter['repeat'] += 1
task_contents = '\n'.join(dirs[counter['start']:counter['start']+counter['tasks_per_person']])
print(task_contents)
task_filename = 'task_recommendation.txt'
with open(counter_checkpoint, 'w') as f:
f.write(json.dumps(counter, indent=4))
return dict(content=task_contents, filename=task_filename)
the comments have been addressed, but this isn't ready to merge due to the project explorer being a wip. i made heavy modifications to how configs work, and i have also updated the code to use copick's api more explicitly (e.g. removing directory traversals in favor of using copick to traverse runs) |
@zhuowenzhao this is my current refactor. I think it is pretty close to done, but I'm running some tests now.