Skip to content

Commit

Permalink
modified grid helper in plotter
Browse files Browse the repository at this point in the history
  • Loading branch information
bingli621 committed Nov 9, 2024
1 parent 2c0bbf7 commit c605478
Show file tree
Hide file tree
Showing 104 changed files with 55 additions and 456 deletions.
Binary file modified .DS_Store
Binary file not shown.
16 changes: 13 additions & 3 deletions src/tavi/convert_spice_to_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
def convert_spice_to_nexus(
path_to_spice_folder: str,
path_to_nexus_folder: Optional[str] = None,
path_to_instrument_json: Optional[str] = None,
path_to_sample_json: Optional[str] = None,
):
"""convert datafiles in spice folder into nexus entries
Expand All @@ -15,7 +17,11 @@ def convert_spice_to_nexus(
will be creatred in the same parent folder as the SPICE data,
using the defalut folder name IPTSxxxxx_INSTRU_exp0000"""

scan_dict = NexusEntry.from_spice(path_to_spice_folder)
scan_dict = NexusEntry.from_spice(
path_to_spice_folder,
path_to_instrument_json=path_to_instrument_json,
path_to_sample_json=path_to_sample_json,
)
scan0001 = next(iter(scan_dict.values()))
nexus_folder_name = scan0001["attrs"]["dataset_name"]

Expand All @@ -31,7 +37,11 @@ def convert_spice_to_nexus(


if __name__ == "__main__":
path_to_instrument_json = "./src/tavi/instrument/instrument_params/cg4c.json"
path_to_spice_folder = "./test_data/exp424"
path_to_spice_folder = "./test_data/exp815" # empty runs in exp815
# path_to_spice_folder = "./test_data/exp815" # empty runs in exp815
# path_to_spice_folder = "./test_data/exp813"
convert_spice_to_nexus(path_to_spice_folder)
convert_spice_to_nexus(
path_to_spice_folder,
path_to_instrument_json=path_to_instrument_json,
)
11 changes: 10 additions & 1 deletion src/tavi/data/nxdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def __init__(self, ds, **kwargs):

match kwargs:
case {"type": "NX_CHAR"}:
dataset = str(ds)
dataset = np.array(ds) if isinstance(ds, list) else str(ds)

case {"type": "NX_INT"} | {"type": "NX_FLOAT"}:
dataset = _recast_type(ds, kwargs["type"])
case {"type": "NX_DATE_TIME"}:
Expand Down Expand Up @@ -159,6 +160,9 @@ def spice_scan_to_nxdict(

spicelogs = _create_spicelogs(path_to_scan_file)
metadata = spicelogs["metadata"]
# ---------------------------------------- user ----------------------------------------
nxuser = NXentry(NX_class="NXuser")
nxuser.add_dataset("name", NXdataset(ds=metadata["users"].split(","), type="NX_CHAR"))

# ---------------------------------------- source ----------------------------------------

Expand All @@ -168,6 +172,10 @@ def spice_scan_to_nxdict(
NX_class="NXsource",
EX_required="true",
)
# TODO
if "source" in instrument_config_params:
pass

# ------------------------------------- monochromator ----------------------------------------

nxmono = NXentry(
Expand Down Expand Up @@ -345,6 +353,7 @@ def spice_scan_to_nxdict(
instrument=nxinstrument,
monitor=nxmonitor,
sample=nxsample,
user=nxuser,
NX_class="NXentry",
EX_required="true",
)
Expand Down
7 changes: 6 additions & 1 deletion src/tavi/data/nxentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ def format_dataset(value):
attr_type = attr.get("type")
match attr_type:
case "NX_CHAR":
dv = dv.encode("utf-8")
if isinstance(dv, list | np.ndarray):
dv = np.array([v.encode("utf-8") for v in dv])
elif isinstance(dv, str):
dv = dv.encode("utf-8")
else:
raise ValueError(f"Unrecogonized type for dataset={dv}")
case "NX_FLOAT":
dv = np.array(dv).astype("float")
case "NX_INT":
Expand Down
255 changes: 0 additions & 255 deletions src/tavi/data/scan_group_backup.py

This file was deleted.

6 changes: 5 additions & 1 deletion src/tavi/instrument/resolution/ellipsoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ def plot_ellipses(self):
p.add_reso(ellipse_co, c="k", linestyle="solid")
p.add_reso(ellipse_inco, c="k", linestyle="dashed")

ax = fig.add_subplot(int(f"23{i+1}"), axes_class=Axes, grid_helper=p.grid_helper)
ax = fig.add_subplot(
int(f"23{i+1}"),
axes_class=Axes,
grid_helper=p.grid_helper(ellipse_co.angle),
)
p.plot(ax)

fig.tight_layout(pad=2)
12 changes: 7 additions & 5 deletions src/tavi/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ def __init__(self) -> None:
self.LOG_Y = False
self.LOG_Z = False

self.grid_helper = None

def add_contour(self, contour_data: ScanData2D, **kwargs):

for key, val in kwargs.items():
Expand All @@ -130,14 +128,18 @@ def add_reso(self, reso_data: ResoEllipse, **kwargs):
for key, val in kwargs.items():
reso_data.fmt.update({key: val})
self.reso_data.append(reso_data)
self.grid_helper = GridHelperCurveLinear(

@staticmethod
def grid_helper(angle: float):
grid_helper = GridHelperCurveLinear(
(
partial(tr, angle=reso_data.angle),
partial(inv_tr, angle=reso_data.angle),
partial(tr, angle=angle),
partial(inv_tr, angle=angle),
),
grid_locator1=MaxNLocator(integer=True, steps=[1]),
grid_locator2=MaxNLocator(integer=True, steps=[1]),
)
return grid_helper

def plot(self, ax):
for contour in self.contour_data:
Expand Down
Loading

0 comments on commit c605478

Please sign in to comment.