|
10 | 10 |
|
11 | 11 | from murfey.server.api.auth import MurfeySessionIDInstrument as MurfeySessionID |
12 | 12 | from murfey.server.api.auth import validate_instrument_token |
13 | | -from murfey.server.gain import Camera, prepare_eer_gain, prepare_gain |
| 13 | +from murfey.server.api.file_io_shared import GainReference |
| 14 | +from murfey.server.api.file_io_shared import process_gain as _process_gain |
14 | 15 | from murfey.server.murfey_db import murfey_db |
15 | 16 | from murfey.util import sanitise, secure_path |
16 | 17 | from murfey.util.config import get_machine_config |
17 | 18 | from murfey.util.db import Session, SessionProcessingParameters |
18 | 19 | from murfey.util.eer import num_frames |
19 | 20 |
|
20 | | -logger = getLogger("murfey.server.api.file_manip") |
| 21 | +logger = getLogger("murfey.server.api.file_io_instrument") |
| 22 | + |
21 | 23 |
|
22 | 24 | router = APIRouter( |
23 | | - prefix="/file_manipulation", |
| 25 | + prefix="/file_io/instrument", |
24 | 26 | dependencies=[Depends(validate_instrument_token)], |
25 | | - tags=["File Manipulation"], |
| 27 | + tags=["File I/O: Instrument"], |
26 | 28 | ) |
27 | 29 |
|
28 | 30 |
|
@@ -107,85 +109,12 @@ def make_rsyncer_destination(session_id: int, destination: Dest, db=murfey_db): |
107 | 109 | return destination |
108 | 110 |
|
109 | 111 |
|
110 | | -class GainReference(BaseModel): |
111 | | - gain_ref: Path |
112 | | - rescale: bool = True |
113 | | - eer: bool = False |
114 | | - tag: str = "" |
115 | | - |
116 | | - |
117 | 112 | @router.post("/sessions/{session_id}/process_gain") |
118 | 113 | async def process_gain( |
119 | 114 | session_id: MurfeySessionID, gain_reference_params: GainReference, db=murfey_db |
120 | 115 | ): |
121 | | - murfey_session = db.exec(select(Session).where(Session.id == session_id)).one() |
122 | | - visit_name = murfey_session.visit |
123 | | - instrument_name = murfey_session.instrument_name |
124 | | - machine_config = get_machine_config(instrument_name=instrument_name)[ |
125 | | - instrument_name |
126 | | - ] |
127 | | - camera = getattr(Camera, machine_config.camera) |
128 | | - if gain_reference_params.eer: |
129 | | - executables = machine_config.external_executables_eer |
130 | | - else: |
131 | | - executables = machine_config.external_executables |
132 | | - env = machine_config.external_environment |
133 | | - safe_path_name = secure_filename(gain_reference_params.gain_ref.name) |
134 | | - filepath = ( |
135 | | - Path(machine_config.rsync_basepath) |
136 | | - / str(datetime.now().year) |
137 | | - / secure_filename(visit_name) |
138 | | - / machine_config.gain_directory_name |
139 | | - ) |
140 | | - |
141 | | - # Check under previous year if the folder doesn't exist |
142 | | - if not filepath.exists(): |
143 | | - filepath_prev = filepath |
144 | | - filepath = ( |
145 | | - Path(machine_config.rsync_basepath) |
146 | | - / str(datetime.now().year - 1) |
147 | | - / secure_filename(visit_name) |
148 | | - / machine_config.gain_directory_name |
149 | | - ) |
150 | | - # If it's not in the previous year, it's a genuine error |
151 | | - if not filepath.exists(): |
152 | | - log_message = ( |
153 | | - "Unable to find gain reference directory under " |
154 | | - f"{str(filepath_prev)!r} or {str(filepath)}" |
155 | | - ) |
156 | | - logger.error(log_message) |
157 | | - raise FileNotFoundError(log_message) |
158 | | - |
159 | | - if gain_reference_params.eer: |
160 | | - new_gain_ref, new_gain_ref_superres = await prepare_eer_gain( |
161 | | - filepath / safe_path_name, |
162 | | - executables, |
163 | | - env, |
164 | | - tag=gain_reference_params.tag, |
165 | | - ) |
166 | | - else: |
167 | | - new_gain_ref, new_gain_ref_superres = await prepare_gain( |
168 | | - camera, |
169 | | - filepath / safe_path_name, |
170 | | - executables, |
171 | | - env, |
172 | | - rescale=gain_reference_params.rescale, |
173 | | - tag=gain_reference_params.tag, |
174 | | - ) |
175 | | - if new_gain_ref and new_gain_ref_superres: |
176 | | - return { |
177 | | - "gain_ref": new_gain_ref.relative_to(Path(machine_config.rsync_basepath)), |
178 | | - "gain_ref_superres": new_gain_ref_superres.relative_to( |
179 | | - Path(machine_config.rsync_basepath) |
180 | | - ), |
181 | | - } |
182 | | - elif new_gain_ref: |
183 | | - return { |
184 | | - "gain_ref": new_gain_ref.relative_to(Path(machine_config.rsync_basepath)), |
185 | | - "gain_ref_superres": None, |
186 | | - } |
187 | | - else: |
188 | | - return {"gain_ref": str(filepath / safe_path_name), "gain_ref_superres": None} |
| 116 | + result = await _process_gain(session_id, gain_reference_params, db) |
| 117 | + return result |
189 | 118 |
|
190 | 119 |
|
191 | 120 | class FractionationParameters(BaseModel): |
|
0 commit comments