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

Update setup and ci #5

Merged
merged 9 commits into from
Apr 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ruff/black: automatic changes
mhuen committed Apr 11, 2024
commit 96215be11c50fee07003b437a66e59082e277634
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -15,4 +15,3 @@ tmp/*
!logs/.gitkeep
!checkpoints/.gitkeep
!configs/user/.gitkeep

6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -17,17 +17,15 @@ IceCube DNN reconstruction
# Create data transformation model:
# We must first create a transformation model that will take care of data normalization and transformation
python create_trafo_model.py /PATH/TO/MY/YAML/CONFIG/FILE

# Train model:
# This step can be run with as many config files and settings as you wish.
# The settings and number of training iterations is automatically logged and will be exported together
# with the final model.
python train_model.py /PATH/TO/MY/YAML/CONFIG/FILE

# Export model:
# Once the model is trained, we can export it, so that it can be used to reconstruct IceCube events with the provided I3Module
python export_model.py /PATH/TO/MY/YAML/CONFIG/FILE -s /PATH/TO/CONFIG/FILE/USED/TO/CREATE/TRAINING/DATA -o OUTPUT/Directory

# More documentation can be found here: https://icecube.wisc.edu/~mhuennefeld/docs/dnn_reco/html/


44 changes: 27 additions & 17 deletions dnn_reco/count_number_of_events.py
Original file line number Diff line number Diff line change
@@ -18,17 +18,18 @@
def count_num_events(data):
input_data, config = data
try:
with pd.HDFStore(input_data, mode='r') as f:
time_offset = f[config['data_handler_time_offset_name']]['value']
with pd.HDFStore(input_data, mode="r") as f:
time_offset = f[config["data_handler_time_offset_name"]]["value"]
return len(time_offset)
except KeyError:
return 0


@click.command()
@click.argument('config_files', type=click.Path(exists=True), nargs=-1)
@click.option('--n_jobs', '-j',
default=1, help='Number of jobs to run in parallel.')
@click.argument("config_files", type=click.Path(exists=True), nargs=-1)
@click.option(
"--n_jobs", "-j", default=1, help="Number of jobs to run in parallel."
)
def main(config_files, n_jobs):
"""Script to count number of events.

@@ -44,12 +45,16 @@ def main(config_files, n_jobs):
setup_manager = SetupManager(config_files)
config = setup_manager.get_config()

names = ['test_data_file', 'validation_data_file',
'training_data_file', 'trafo_data_file']
names = [
"test_data_file",
"validation_data_file",
"training_data_file",
"trafo_data_file",
]
num_events_list = []
for name in names:
# get files
print('Creating file list for {!r}'.format(name))
print("Creating file list for {!r}".format(name))
input_data = config[name]
if isinstance(input_data, list):
input_data = set(input_data)
@@ -60,25 +65,30 @@ def main(config_files, n_jobs):
file_list = glob.glob(input_data)
file_list = set(file_list)

print('Starting counting')
print("Starting counting")
pool = Pool(processes=n_jobs)
num_files = len(file_list)
num_events = 0
with tqdm(total=num_files) as pbar:
for i, n in tqdm(enumerate(pool.imap_unordered(
count_num_events, [(f, config) for f in file_list]))):
for i, n in tqdm(
enumerate(
pool.imap_unordered(
count_num_events, [(f, config) for f in file_list]
)
)
):
pbar.update()
num_events += n

num_events_list.append(num_events)
print('Found {!r} events for {!r}\n'.format(num_events, name))
print("Found {!r} events for {!r}\n".format(num_events, name))

print('\n===============================')
print('= Completed Counting Events: =')
print('===============================')
print("\n===============================")
print("= Completed Counting Events: =")
print("===============================")
for num_events, name in zip(num_events_list, names):
print('Found {!r} events for {!r}'.format(num_events, name))
print("Found {!r} events for {!r}".format(num_events, name))


if __name__ == '__main__':
if __name__ == "__main__":
main()
85 changes: 44 additions & 41 deletions dnn_reco/create_trafo_model.py
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@


@click.command()
@click.argument('config_files', type=click.Path(exists=True), nargs=-1)
@click.argument("config_files", type=click.Path(exists=True), nargs=-1)
def main(config_files):
"""Script to generate trafo model.

@@ -31,66 +31,69 @@ def main(config_files):

# Create Data Handler object
data_handler = DataHandler(config)
data_handler.setup_with_test_data(config['trafo_data_file'])
data_handler.setup_with_test_data(config["trafo_data_file"])

settings_trafo = {
'input_data': config['trafo_data_file'],
'batch_size': config['batch_size'],
'sample_randomly': True,
'pick_random_files_forever': False,
'file_capacity': 1,
'batch_capacity': 2,
'num_jobs': config['trafo_num_jobs'],
'num_add_files': 1,
'num_repetitions': 1,
'num_splits': config['data_handler_num_splits'],
'init_values': config['DOM_init_values'],
'nan_fill_value': config['data_handler_nan_fill_value'],
}
"input_data": config["trafo_data_file"],
"batch_size": config["batch_size"],
"sample_randomly": True,
"pick_random_files_forever": False,
"file_capacity": 1,
"batch_capacity": 2,
"num_jobs": config["trafo_num_jobs"],
"num_add_files": 1,
"num_repetitions": 1,
"num_splits": config["data_handler_num_splits"],
"init_values": config["DOM_init_values"],
"nan_fill_value": config["data_handler_nan_fill_value"],
}
trafo_data_generator = data_handler.get_batch_generator(**settings_trafo)

# create TrafoModel
data_transformer = DataTransformer(
data_handler=data_handler,
treat_doms_equally=config['trafo_treat_doms_equally'],
normalize_dom_data=config['trafo_normalize_dom_data'],
normalize_label_data=config['trafo_normalize_label_data'],
normalize_misc_data=config['trafo_normalize_misc_data'],
log_dom_bins=config['trafo_log_dom_bins'],
log_label_bins=config['trafo_log_label_bins'],
log_misc_bins=config['trafo_log_misc_bins'],
norm_constant=config['trafo_norm_constant'])
data_handler=data_handler,
treat_doms_equally=config["trafo_treat_doms_equally"],
normalize_dom_data=config["trafo_normalize_dom_data"],
normalize_label_data=config["trafo_normalize_label_data"],
normalize_misc_data=config["trafo_normalize_misc_data"],
log_dom_bins=config["trafo_log_dom_bins"],
log_label_bins=config["trafo_log_label_bins"],
log_misc_bins=config["trafo_log_misc_bins"],
norm_constant=config["trafo_norm_constant"],
)

data_transformer.create_trafo_model_iteratively(
data_iterator=trafo_data_generator,
num_batches=config['trafo_num_batches'])
data_iterator=trafo_data_generator,
num_batches=config["trafo_num_batches"],
)

# save trafo model to file
base_name = os.path.basename(config['trafo_model_path'])
if '.' in base_name:
file_ending = base_name.split('.')[-1]
base_name = base_name.replace('.' + file_ending, '')
base_name = os.path.basename(config["trafo_model_path"])
if "." in base_name:
file_ending = base_name.split(".")[-1]
base_name = base_name.replace("." + file_ending, "")

directory = os.path.dirname(config['trafo_model_path'])
directory = os.path.dirname(config["trafo_model_path"])
if not os.path.isdir(directory):
os.makedirs(directory)
misc.print_warning('Creating directory: {}'.format(directory))
misc.print_warning("Creating directory: {}".format(directory))

trafo_config_file = os.path.join(directory,
'config_trafo__{}.yaml'.format(base_name))
trafo_config_file = os.path.join(
directory, "config_trafo__{}.yaml".format(base_name)
)

with open(trafo_config_file, 'w') as yaml_file:
with open(trafo_config_file, "w") as yaml_file:
yaml.dump(config, yaml_file, default_flow_style=False)
data_transformer.save_trafo_model(config['trafo_model_path'])
data_transformer.save_trafo_model(config["trafo_model_path"])

# kill multiprocessing queues and workers
data_handler.kill()

print('\n=======================================')
print('= Successfully saved trafo model to: =')
print('=======================================')
print('{!r}\n'.format(config['trafo_model_path']))
print("\n=======================================")
print("= Successfully saved trafo model to: =")
print("=======================================")
print("{!r}\n".format(config["trafo_model_path"]))


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading