Skip to content

Commit

Permalink
Move projectfile into subpackage refs #219
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfpeterson committed Dec 19, 2019
1 parent 8bebdbd commit 4204e0a
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 45 deletions.
3 changes: 1 addition & 2 deletions pyrs/core/nexus_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import os
from pyrs.core import workspaces
from pyrs.core.instrument_geometry import AnglerCameraDetectorGeometry, HidraSetup
from pyrs.projectfile import HidraConstants
from pyrs.projectfile import HidraConstants, HidraProjectFile, HidraProjectFileMode
from pyrs.utilities import checkdatatypes
from pyrs.utilities.rs_project_file import HidraProjectFile, HidraProjectFileMode


class NeXusConvertingApp(object):
Expand Down
3 changes: 1 addition & 2 deletions pyrs/core/powder_pattern.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from pyrs.core import reduction_manager
from pyrs.utilities import checkdatatypes
from pyrs.core import mask_util
from pyrs.projectfile import HidraProjectFileMode
from pyrs.projectfile import HidraProjectFile, HidraProjectFileMode
from pyrs.utilities import calibration_file_io
from pyrs.utilities.rs_project_file import HidraProjectFile
from matplotlib import pyplot as plt


Expand Down
3 changes: 1 addition & 2 deletions pyrs/core/pyrscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from pyrs.core import instrument_geometry
from pyrs.utilities import file_util
from pyrs.peaks import PeakFitEngineFactory, SupportedPeakProfiles, SupportedBackgroundTypes
from pyrs.projectfile import HidraConstants, HidraProjectFileMode
from pyrs.utilities.rs_project_file import HidraProjectFile
from pyrs.projectfile import HidraConstants, HidraProjectFile, HidraProjectFileMode
from pyrs.core import strain_stress_calculator
from pyrs.core import reduction_manager
from pyrs.core import polefigurecalculator
Expand Down
3 changes: 1 addition & 2 deletions pyrs/core/reduction_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
from pyrs.core import mask_util
from pyrs.core import reduce_hb2b_mtd
from pyrs.core import reduce_hb2b_pyrs
from pyrs.projectfile import HidraConstants, HidraProjectFileMode
from pyrs.projectfile import HidraConstants, HidraProjectFile, HidraProjectFileMode
from pyrs.utilities import calibration_file_io
from pyrs.utilities import checkdatatypes
from pyrs.utilities.rs_project_file import HidraProjectFile


class HB2BReductionManager(object):
Expand Down
17 changes: 8 additions & 9 deletions pyrs/core/workspaces.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Data manager
import numpy
from pyrs.dataobjects import SampleLogs
from pyrs.projectfile import HidraConstants
from pyrs.projectfile import HidraConstants, HidraProjectFile
from pyrs.utilities import checkdatatypes
from pyrs.utilities import rs_project_file


class HidraWorkspace(object):
Expand Down Expand Up @@ -57,7 +56,7 @@ def _load_raw_counts(self, hidra_file):
:param hidra_file:
:return:
"""
checkdatatypes.check_type('HIDRA project file', hidra_file, rs_project_file.HidraProjectFile)
checkdatatypes.check_type('HIDRA project file', hidra_file, HidraProjectFile)

for sub_run_i in self._sample_logs.subruns:
counts_vec_i = hidra_file.read_raw_counts(sub_run_i)
Expand All @@ -72,7 +71,7 @@ def _load_reduced_diffraction_data(self, hidra_file):
:return:
"""
# Check inputs
checkdatatypes.check_type('HIDRA project file', hidra_file, rs_project_file.HidraProjectFile)
checkdatatypes.check_type('HIDRA project file', hidra_file, HidraProjectFile)

# get 2theta value
try:
Expand Down Expand Up @@ -124,7 +123,7 @@ def _load_instrument(self, hidra_file):
:return:
"""
# Check
checkdatatypes.check_type('HIDRA project file', hidra_file, rs_project_file.HidraProjectFile)
checkdatatypes.check_type('HIDRA project file', hidra_file, HidraProjectFile)

# Get values
self._instrument_setup = hidra_file.read_instrument_geometry()
Expand All @@ -136,7 +135,7 @@ def _load_sample_logs(self, hidra_file):
:param hidra_file: HIDRA project file instance
:return:
"""
checkdatatypes.check_type('HIDRA project file', hidra_file, rs_project_file.HidraProjectFile)
checkdatatypes.check_type('HIDRA project file', hidra_file, HidraProjectFile)

# overwrite the existing sample logs
self._sample_logs = hidra_file.read_sample_logs()
Expand All @@ -146,7 +145,7 @@ def _load_wave_length(self, hidra_file):
:param hidra_file: HIDRA project file instance
:return:
"""
checkdatatypes.check_type('HIDRA project file', hidra_file, rs_project_file.HidraProjectFile)
checkdatatypes.check_type('HIDRA project file', hidra_file, HidraProjectFile)

# reset the wave length (dictionary) from HIDRA project file
self._wave_length_dict = hidra_file.read_wavelengths()
Expand Down Expand Up @@ -258,7 +257,7 @@ def load_hidra_project(self, hidra_file, load_raw_counts, load_reduced_diffracti
:return:
"""
# Check input
checkdatatypes.check_type('HIDRA project file', hidra_file, rs_project_file.HidraProjectFile)
checkdatatypes.check_type('HIDRA project file', hidra_file, HidraProjectFile)
self._project_file_name = hidra_file.name

# create the spectrum map - must exist before loading the counts array
Expand Down Expand Up @@ -645,7 +644,7 @@ def save_reduced_diffraction_data(self, hidra_project):
:param hidra_project: HidraProjectFile instance
:return:
"""
checkdatatypes.check_type('HIDRA project file', hidra_project, rs_project_file.HidraProjectFile)
checkdatatypes.check_type('HIDRA project file', hidra_project, HidraProjectFile)

hidra_project.write_reduced_diffraction_data_set(self._2theta_matrix, self._diff_data_set)

Expand Down
4 changes: 2 additions & 2 deletions pyrs/dataobjects.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# extentable version of dict https://treyhunner.com/2019/04/why-you-shouldnt-inherit-from-list-and-dict-in-python/
from collections import MutableMapping
import numpy as np
from pyrs.projectfile import HidraConstants


def _coerce_to_ndarray(value):
if isinstance(value, np.ndarray):
Expand All @@ -11,7 +11,7 @@ def _coerce_to_ndarray(value):


class SampleLogs(MutableMapping):
SUBRUN_KEY = HidraConstants.SUB_RUNS
SUBRUN_KEY = 'sub-runs' # TODO should be pyrs.projectfile.HidraConstants.SUB_RUNS

def __init__(self, **kwargs):
self._data = dict(kwargs)
Expand Down
14 changes: 7 additions & 7 deletions pyrs/peaks/peak_fit_engine.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# This is the virtual base class as the fitting frame
import numpy as np
from pyrs.core import workspaces
from pyrs.utilities import rs_project_file
from pyrs.core import peak_profile_utility
from pyrs.core.peak_profile_utility import PeakShape
from pyrs.utilities import checkdatatypes
Expand Down Expand Up @@ -175,22 +174,23 @@ def estimate_peak_height(self, peak_range):

return peak_heights, flat_bkgds

def export_to_hydra_project(self, hydra_project_file, peak_tag):
def export_to_hydra_project(self, hidra_project_file, peak_tag):
"""Export fit result from this fitting engine instance to Hidra project file
Parameters
----------
hydra_project_file : pyrs.utilities.rs_project_file.HidraProjectFile
hidra_project_file : ~pyrs.projectfile.HidraProjectFile
peak_tag
Returns
-------
"""
# Check input
checkdatatypes.check_type('Hidra project file', hydra_project_file, rs_project_file.HidraProjectFile)

hydra_project_file.write_peak_fit_result(self._peak_collection_dict[peak_tag])
try:
hidra_project_file.write_peak_fit_result(self._peak_collection_dict[peak_tag])
except AttributeError as e:
print 'Parameter "hidra_project_file" does not appear to be correct type', e
raise RuntimeError('Method requires a HidraProjectFile')

def fit_peaks(self, peak_tag, sub_run_range, peak_function_name, background_function_name, peak_center,
peak_range, max_chi2=1E3, max_peak_shift=2, min_intensity=None):
Expand Down
10 changes: 6 additions & 4 deletions pyrs/projectfile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# flake8: noqa
# pylint: disable=undefined-variable
from .constants import HidraConstants
from .file_mode import HidraProjectFileMode
from __future__ import (absolute_import, division, print_function) # python3 compatibility

__all__ = constants.__all__ + file_mode.__all__
from .constants import *
from .file_mode import *
from .file_object import *

__all__ = constants.__all__ + file_mode.__all__ + file_object.__all__
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pyrs.dataobjects import SampleLogs
from pyrs.projectfile import HidraConstants, HidraProjectFileMode

__all__ = ['DiffractionUnit', 'HidraProjectFile']
__all__ = ['HidraProjectFile']


class DiffractionUnit(Enum):
Expand Down
2 changes: 1 addition & 1 deletion scripts/preparetest/convert_hb2b_peaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""
import numpy
from pyrs.utilities import rs_scan_io
from pyrs.utilities.rs_project_file import HidraProjectFile
from pyrs.projectfile import HidraProjectFile


def main():
Expand Down
4 changes: 2 additions & 2 deletions scripts/preparetest/convert_hzb_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
1. Add PyRS path to python path (refer to pyrsdev.sh)
2. Run this script
"""
import numpy
import os
from pyrs.core.instrument_geometry import HidraSetup
from pyrs.projectfile import HidraConstants, HidraProjectFile, HidraProjectFileMode
from pyrs.utilities import file_util
from pyrs.utilities.rs_project_file import HidraConstants, HidraProjectFile, HidraProjectFileMode
import numpy


def parse_hzb_tiff(tiff_file_name):
Expand Down
3 changes: 1 addition & 2 deletions scripts/preparetest/convert_strain_stress_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# System (library) test for classes and methods that will be used to calculate strain and stress
import os
import sys
from pyrs.projectfile import HidraProjectFileMode
from pyrs.utilities.rs_project_file import HidraProjectFile
from pyrs.projectfile import HidraProjectFile, HidraProjectFileMode


def contain_strain_stress_main():
Expand Down
3 changes: 1 addition & 2 deletions scripts/pyrs_calibration.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import numpy
import time
from pyrs.projectfile import HidraProjectFileMode
from pyrs.projectfile import HidraProjectFile, HidraProjectFileMode
from pyrs.utilities import calibration_file_io
from pyrs.utilities.rs_project_file import HidraProjectFile
from pyrs.calibration import peakfit_calibration

# DEFAULT VALUES FOR DATA PROCESSING
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_calibration_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import time
import os
import json
from pyrs.projectfile import HidraProjectFileMode
from pyrs.projectfile import HidraProjectFile, HidraProjectFileMode
from pyrs.utilities import calibration_file_io
from pyrs.utilities.rs_project_file import HidraProjectFile
try:
from pyrs.calibration import peakfit_calibration
except ImportError as e:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_peak_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pyrs.core.peak_profile_utility import PeakShape, BackgroundFunction
from pyrs.core.summary_generator import SummaryGenerator
from pyrs.dataobjects import SampleLogs
from pyrs.utilities.rs_project_file import HidraProjectFile
from pyrs.projectfile import HidraProjectFile
from pyrs.peaks import PeakFitEngineFactory
import h5py
from pyrs.core import peak_profile_utility
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_project_file_rw.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pyrs.core import workspaces
from pyrs.utilities.rs_project_file import HidraProjectFile
from pyrs.projectfile import HidraProjectFile
from pyrs.core.instrument_geometry import HidraSetup
import os
import pytest
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_reduction.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyrs.utilities.rs_project_file import HidraProjectFile
from pyrs.projectfile import HidraProjectFile
from pyrs.utilities import calibration_file_io
from pyrs.core import workspaces
import pytest
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_hidra_project_file.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""
Test for reading and writing components to HiDRA project file
"""
from pyrs.projectfile import HidraConstants, HidraProjectFileMode
from pyrs.utilities.rs_project_file import HidraProjectFile
from pyrs.projectfile import HidraConstants, HidraProjectFile, HidraProjectFileMode
import os
import numpy as np
import datetime
Expand Down

0 comments on commit 4204e0a

Please sign in to comment.