Skip to content

Commit

Permalink
Add code to rename groups
Browse files Browse the repository at this point in the history
  • Loading branch information
samueljackson92 committed Dec 18, 2024
1 parent cbe659f commit 51692ca
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 62 deletions.
26 changes: 26 additions & 0 deletions mappings/mast/groups.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"abm": {"name": "bolometer", "imas": "bolometer"},
"act": {"name": "charge_exchange", "imas": "charge_exchange"},
"aga": {"name": "gas_injection", "imas": "gas_injection"},
"ahx": {"name": "hard_x_rays", "imas": "hard_x_rays"},
"ait": {"name": "camera_ir", "imas": "camera_ir"},
"alp": {"name": "langmuir_probes", "imas": "langmuir_probes"},
"anb": {"name": "nbi", "imas": "nbi"},
"ane": {"name": "interferometer", "imas": "interferometer"},
"amb": {"name": "magnetics_b", "imas": "magnetics"},
"amc": {"name": "magnetics", "imas": "magnetics"},
"asm": {"name": "magnetics_saddle", "imas": "magnetics"},
"atm": {"name": "thomson_scattering", "imas": "thomson_scattering"},
"ayc": {"name": "thomson_scattering", "imas": "thomson_scattering"},
"aye": {"name": "thomson_scattering_edge", "imas": "thomson_scattering"},
"efm": {"name": "equilibrium", "imas": "equilibrium"},
"rba": {"name": "camera_visible_a", "imas": "camera_visible"},
"rbb": {"name": "camera_visible_b", "imas": "camera_visible"},
"rbc": {"name": "camera_visible_c", "imas": "camera_visible"},
"xdc": {"name": "controllers", "imas": "controllers"},
"xim": {"name": "spectrometer_visible", "imas": "spectrometer_visible"},
"xma": {"name": "magnetics_a", "imas": "magnetics"},
"xmc": {"name": "magnetics_c", "imas": "magnetics"},
"xmo": {"name": "magnetics_mirnov","imas": "magnetics"},
"xsx": {"name": "soft_x_rays", "imas": "soft_x_rays"}
}
26 changes: 26 additions & 0 deletions mappings/mastu/groups.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"abm": {"name": "bolometer", "imas": "bolometer"},
"act": {"name": "charge_exchange", "imas": "charge_exchange"},
"aga": {"name": "gas_injection", "imas": "gas_injection"},
"ahx": {"name": "hard_x_rays", "imas": "hard_x_rays"},
"ait": {"name": "camera_ir", "imas": "camera_ir"},
"alp": {"name": "langmuir_probes", "imas": "langmuir_probes"},
"anb": {"name": "nbi", "imas": "nbi"},
"ane": {"name": "interferometer", "imas": "interferometer"},
"amb": {"name": "magnetics_b", "imas": "magnetics"},
"amc": {"name": "magnetics", "imas": "magnetics"},
"asm": {"name": "magnetics_saddle", "imas": "magnetics"},
"ayc": {"name": "thomson_scattering", "imas": "thomson_scattering"},
"ayd": {"name": "thomson_scattering_divertor", "imas": "thomson_scattering"},
"epm": {"name": "equilibrium", "imas": "equilibrium"},
"epq": {"name": "equilibrium_kinematic", "imas": "equilibrium"},
"rba": {"name": "camera_visible_a", "imas": "camera_visible"},
"rbb": {"name": "camera_visible_b", "imas": "camera_visible"},
"rbc": {"name": "camera_visible_c", "imas": "camera_visible"},
"xdc": {"name": "controllers", "imas": "controllers"},
"xim": {"name": "spectrometer_visible", "imas": "spectrometer_visible"},
"xma": {"name": "magnetics_a", "imas": "magnetics"},
"xmc": {"name": "magnetics_c", "imas": "magnetics"},
"xmo": {"name": "magnetics_mirnov","imas": "magnetics"},
"xsx": {"name": "soft_x_rays", "imas": "soft_x_rays"}
}
19 changes: 16 additions & 3 deletions src/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from src.load import BaseLoader, MissingProfileError
from src.log import logger
from src.pipelines import Pipelines
from src.utils import harmonise_name
from src.utils import harmonise_name, read_json_file
from src.writer import DatasetWriter


Expand All @@ -23,18 +23,31 @@ def __init__(
self.loader = loader
self.include_datasets = include_datasets
self.exclude_datasets = exclude_datasets
self.group_name_mapping = read_json_file(self.pipelines.group_mapping_file)

def create(self, shot: int):
dataset_infos = self.list_datasets(shot)

for dataset_info in dataset_infos:
group_name = dataset_info.name

logger.info(f"Loading dataset {group_name} for shot #{shot}")
dataset = self.load_datasets(shot, group_name)
datasets = self.load_datasets(shot, group_name)

logger.info(f"Processing {group_name} for shot #{shot}")
pipeline = self.pipelines.get(group_name)
dataset = pipeline(dataset)

dataset = pipeline(datasets)

# rename groups
if group_name in self.group_name_mapping:
mapping = self.group_name_mapping[group_name]
imas_name = mapping["imas"]

for dataset in datasets.values():
dataset.attrs["imas"] = imas_name

group_name = mapping["name"]

logger.info(f"Writing {group_name} for shot #{shot}")
file_name = f"{shot}.{self.writer.file_extension}"
Expand Down
Loading

0 comments on commit 51692ca

Please sign in to comment.