Skip to content

Commit

Permalink
precommit
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffwoollard committed Aug 12, 2024
1 parent ad1d117 commit 1cd0225
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config_files/config_map_to_map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ analysis:
normalize:
do: true
method: median_zscore
output: results/map_to_map_distance_matrix_submission_0.pkl
output: results/map_to_map_distance_matrix_submission_0.pkl
30 changes: 21 additions & 9 deletions src/cryo_challenge/_map_to_map/map_to_map_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ def compute_cost_fsc_chunk(self, maps_gt_flat, maps_user_flat, n_pix):
return cost_matrix, fsc_matrix

@override
def get_distance_matrix(self, maps1, maps2, global_store_of_running_results): # custom method
def get_distance_matrix(
self, maps1, maps2, global_store_of_running_results
): # custom method
maps_gt_flat = maps1
maps_user_flat = maps2
n_pix = self.config["data"]["n_pix"]
Expand Down Expand Up @@ -245,16 +247,26 @@ def __init__(self, config):
super().__init__(config)

@override
def get_distance_matrix(self, maps1, maps2, global_store_of_running_results): # custom method
def get_distance_matrix(
self, maps1, maps2, global_store_of_running_results
): # custom method
# get fsc matrix
fourier_pixel_max = self.config['data']['n_pix'] // 2 # TODO: check for odd psizes if this should be +1
psize = self.config['data']['psize']
fsc_matrix = global_store_of_running_results['fsc']['computed_assets']['fsc_matrix']
units_Angstroms = 2 * psize / (np.arange(1,fourier_pixel_max+1) / fourier_pixel_max)
fourier_pixel_max = (
self.config["data"]["n_pix"] // 2
) # TODO: check for odd psizes if this should be +1
psize = self.config["data"]["psize"]
fsc_matrix = global_store_of_running_results["fsc"]["computed_assets"][
"fsc_matrix"
]
units_Angstroms = (
2 * psize / (np.arange(1, fourier_pixel_max + 1) / fourier_pixel_max)
)

def res_at_fsc_threshold(fscs, threshold=0.5):
res_fsc_half = np.argmin(fscs > threshold, axis=-1)
fraction_nyquist = 0.5*res_fsc_half / fscs.shape[-1]
fraction_nyquist = 0.5 * res_fsc_half / fscs.shape[-1]
return res_fsc_half, fraction_nyquist

res_fsc_half, fraction_nyquist = res_at_fsc_threshold(fsc_matrix)
self.stored_computed_assets = {'fraction_nyquist': fraction_nyquist}
return units_Angstroms[res_fsc_half]
self.stored_computed_assets = {"fraction_nyquist": fraction_nyquist}
return units_Angstroms[res_fsc_half]
9 changes: 6 additions & 3 deletions src/cryo_challenge/_map_to_map/map_to_map_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pandas as pd
import pickle
import torch
import numpy as np

from ..data._validation.output_validators import MapToMapResultsValidator
from .._map_to_map.map_to_map_distance import (
Expand Down Expand Up @@ -79,10 +78,14 @@ def run(config):
print("cost matrix", distance_label)

cost_matrix = map_to_map_distance.get_distance_matrix(
maps_gt_flat, maps_user_flat, global_store_of_running_results=results_dict,
maps_gt_flat,
maps_user_flat,
global_store_of_running_results=results_dict,
)
computed_assets = map_to_map_distance.get_computed_assets(
maps_gt_flat, maps_user_flat, global_store_of_running_results=results_dict,
maps_gt_flat,
maps_user_flat,
global_store_of_running_results=results_dict,
)
computed_assets.update(computed_assets)

Expand Down

0 comments on commit 1cd0225

Please sign in to comment.