We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
read_opus() shifts the xaxis
Author: @atravert (Arnaud TRAVERT)

Redmine Issue: 75, https://redmine.spectrochempy.fr/issues/75

---

A bug in brukeropusreader module leads to a shift of the xaxis.
It has been corrected on the spectrochempy/brukeropusreader fork (PR FIX wrong setting of wavenumbers axis #1) 
but a change in read_opus() is also needed.



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `spectrochempy/core/readers/readopus.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 #
3 # ======================================================================================================================
4 # Copyright (©) 2015-2020 LCS
5 # Laboratoire Catalyse et Spectrochimie, Caen, France.
6 # CeCILL-B FREE SOFTWARE LICENSE AGREEMENT
7 # See full LICENSE agreement in the root directory
8 # ======================================================================================================================
9 
10 """This module to extend NDDataset with the import methods method.
11 
12 """
13 __all__ = ['read_opus']
14 
15 __dataset_methods__ = __all__
16 
17 # ----------------------------------------------------------------------------------------------------------------------
18 # standard imports
19 # ----------------------------------------------------------------------------------------------------------------------
20 
21 
22 from brukeropusreader import read_file
23 from warnings import warn
24 from datetime import datetime, timezone, timedelta
25 from numpy import linspace
26 
27 # ----------------------------------------------------------------------------------------------------------------------
28 # third party imports
29 # ----------------------------------------------------------------------------------------------------------------------
30 # ----------------------------------------------------------------------------------------------------------------------
31 # local imports
32 # ----------------------------------------------------------------------------------------------------------------------
33 from spectrochempy.core import debug_
34 from spectrochempy.core.dataset.nddataset import NDDataset
35 from spectrochempy.core.dataset.ndcoord import Coord
36 from spectrochempy.utils import readfilename
37 
38 
39 # ======================================================================================================================
40 # Public functions
41 # ======================================================================================================================
42 
43 # .............................................................................
44 def read_opus(dataset=None, **kwargs):
45     """Open Bruker Opus file(s) and group them in a single dataset. Only the spectrum is
46     extracted ("AB" field). Returns an error if dimensions are incompatibles.
47 
48     Parameters
49     ----------
50     filename : `None`, `str`, or list of `str`
51         Filename of the file(s) to load. If `None` : opens a dialog box to select
52          files. If `str` : a single filename. It list of str :
53         a list of filenames.
54     directory : str, optional, default="".
55         From where to read the specified filename. If not specified, read in
56         the defaults datadir.
57 
58     Returns
59     -------
60     dataset : |NDDataset|
61         A dataset corresponding to the (set of) bruker file(s).
62 
63     Examples
64     --------
65     >>> A = NDDataset.read_opus('irdata\\spectrum.0001')
66     >>> print(A)
67     NDDataset: [float64] a.u. (shape: (y:1, x:2568))
68     """
69     debug_("reading bruker opus files")
70 
71     # filename will be given by a keyword parameter except if the first parameters is already
72     # the filename
73     filename = kwargs.get('filename', None)
74 
75     # check if the first parameter is a dataset because we allow not to pass it
76     if not isinstance(dataset, NDDataset):
77         # probably did not specify a dataset
78         # so the first parameters must be the filename
79         if isinstance(dataset, (str, list)) and dataset != '':
80             filename = dataset
81 
82     # check if directory was specified
83     directory = kwargs.get("directory", None)
84     sortbydate = kwargs.get("sortbydate", True)
85 
86     # returns a list of files to read
87     files = readfilename(filename,
88                          directory=directory,
89                          filetypes=['Bruker files (*.*)',
90                                     'all files (*)'],
91                          dictionary=False)
92     # todo: see how to use regular expression in Qt filters
93 
94     if not files:
95         # there is no files, return nothing
96         return None
97 
98     xaxis = None
99     intensities = []
100     names = []
101     acquisitiondates = []
102     timestamps = []
103     for file in files:
104         opus_data = read_file(file)
105         try:
106             opus_data["AB"]
107         except KeyError:  # not an absorbance spectrum
108             warn("opus file {} could not be read".format(file))
109             continue
110 
111         npt = opus_data['AB Data Parameter']['NPT']
112         fxv = opus_data['AB Data Parameter']['FXV']
113         lxv = opus_data['AB Data Parameter']['LXV']
114         xdata = linspace(fxv, lxv, npt)
115 
116         if not xaxis:
117             xaxis = Coord(x=xdata, title='Wavenumbers', units='cm^-1')
118 
119         elif (xdata != xaxis.data).any():
120             raise ValueError("spectra have incompatible dimensions (xaxis)")
121 
122         intensities.append(opus_data["AB"][:npt])
123         names.append(opus_data["Sample"]['SNM'])
124         acqdate = opus_data["AB Data Parameter"]["DAT"]
125         acqtime = opus_data["AB Data Parameter"]["TIM"]
126         GMT_offset_hour = float(acqtime.split('GMT')[1].split(')')[0])
127         date_time = datetime.strptime(acqdate + '_' + acqtime.split()[0],
128                                       '%d/%m/%Y_%H:%M:%S.%f')
129         UTC_date_time = date_time - timedelta(hours=GMT_offset_hour)
130         UTC_date_time = UTC_date_time.replace(tzinfo=timezone.utc)
131         # Transform to timestamp for storage in the Coord object
132         # use datetime.fromtimestamp(d, timezone.utc)) to transform back to datetime
133         timestamp = UTC_date_time.timestamp()
134         acquisitiondates.append(UTC_date_time)
135         timestamps.append(timestamp)
136 
137     # return if none of the files could be read:
138     if not xaxis:
139         return
140 
141     yaxis = Coord(timestamps,
142                   title='Acquisition timestamp (GMT)',
143                   units='s',
144                   labels=(acquisitiondates, names))
145 
146     dataset = NDDataset(intensities)
147     dataset.set_coords(y=yaxis, x=xaxis)
148     dataset.units = 'absorbance'
149     dataset.title = 'Absorbance'
150 
151     # Set origin, description and history
152     dataset.origin = "opus"
153     dataset.description = ('Dataset from opus files. \n')
154 
155     if sortbydate:
156         dataset.sort(dim='y', inplace=True)
157 
158     dataset.history = str(datetime.now()) + ':import from opus files \n'
159 
160     # Set the NDDataset date
161     dataset._date = datetime.now()
162     dataset._modified = dataset.date
163     # debug_("end of reading")
164 
165     return dataset
166
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/spectrochempy/core/readers/readopus.py b/spectrochempy/core/readers/readopus.py
--- a/spectrochempy/core/readers/readopus.py
+++ b/spectrochempy/core/readers/readopus.py
@@ -65,7 +65,10 @@
     >>> A = NDDataset.read_opus('irdata\\spectrum.0001')
     >>> print(A)
     NDDataset: [float64] a.u. (shape: (y:1, x:2568))
+
+
     """
+
     debug_("reading bruker opus files")
 
     # filename will be given by a keyword parameter except if the first parameters is already
@@ -114,7 +117,7 @@
         xdata = linspace(fxv, lxv, npt)
 
         if not xaxis:
-            xaxis = Coord(x=xdata, title='Wavenumbers', units='cm^-1')
+            xaxis = Coord(xdata, title='Wavenumbers', units='cm^-1')
 
         elif (xdata != xaxis.data).any():
             raise ValueError("spectra have incompatible dimensions (xaxis)")
@@ -150,16 +153,13 @@
 
     # Set origin, description and history
     dataset.origin = "opus"
-    dataset.description = ('Dataset from opus files. \n')
+    dataset.description = 'Dataset from opus files. \n'
 
     if sortbydate:
         dataset.sort(dim='y', inplace=True)
 
-    dataset.history = str(datetime.now()) + ':import from opus files \n'
-
-    # Set the NDDataset date
+    dataset.history = str(datetime.now()) + ': import from opus files \n'
     dataset._date = datetime.now()
     dataset._modified = dataset.date
-    # debug_("end of reading")
 
     return dataset

{"golden_diff": "diff --git a/spectrochempy/core/readers/readopus.py b/spectrochempy/core/readers/readopus.py\n--- a/spectrochempy/core/readers/readopus.py\n+++ b/spectrochempy/core/readers/readopus.py\n@@ -65,7 +65,10 @@\n     >>> A = NDDataset.read_opus('irdata\\\\spectrum.0001')\n     >>> print(A)\n     NDDataset: [float64] a.u. (shape: (y:1, x:2568))\n+\n+\n     \"\"\"\n+\n     debug_(\"reading bruker opus files\")\n \n     # filename will be given by a keyword parameter except if the first parameters is already\n@@ -114,7 +117,7 @@\n         xdata = linspace(fxv, lxv, npt)\n \n         if not xaxis:\n-            xaxis = Coord(x=xdata, title='Wavenumbers', units='cm^-1')\n+            xaxis = Coord(xdata, title='Wavenumbers', units='cm^-1')\n \n         elif (xdata != xaxis.data).any():\n             raise ValueError(\"spectra have incompatible dimensions (xaxis)\")\n@@ -150,16 +153,13 @@\n \n     # Set origin, description and history\n     dataset.origin = \"opus\"\n-    dataset.description = ('Dataset from opus files. \\n')\n+    dataset.description = 'Dataset from opus files. \\n'\n \n     if sortbydate:\n         dataset.sort(dim='y', inplace=True)\n \n-    dataset.history = str(datetime.now()) + ':import from opus files \\n'\n-\n-    # Set the NDDataset date\n+    dataset.history = str(datetime.now()) + ': import from opus files \\n'\n     dataset._date = datetime.now()\n     dataset._modified = dataset.date\n-    # debug_(\"end of reading\")\n \n     return dataset\n", "issue": "read_opus() shifts the xaxis\nAuthor: @atravert (Arnaud TRAVERT)\n\nRedmine Issue: 75, https://redmine.spectrochempy.fr/issues/75\n\n---\n\nA bug in brukeropusreader module leads to a shift of the xaxis.\r\nIt has been corrected on the spectrochempy/brukeropusreader fork (PR FIX wrong setting of wavenumbers axis #1) \r\nbut a change in read_opus() is also needed.\n\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# ======================================================================================================================\n# Copyright (\u00a9) 2015-2020 LCS\n# Laboratoire Catalyse et Spectrochimie, Caen, France.\n# CeCILL-B FREE SOFTWARE LICENSE AGREEMENT\n# See full LICENSE agreement in the root directory\n# ======================================================================================================================\n\n\"\"\"This module to extend NDDataset with the import methods method.\n\n\"\"\"\n__all__ = ['read_opus']\n\n__dataset_methods__ = __all__\n\n# ----------------------------------------------------------------------------------------------------------------------\n# standard imports\n# ----------------------------------------------------------------------------------------------------------------------\n\n\nfrom brukeropusreader import read_file\nfrom warnings import warn\nfrom datetime import datetime, timezone, timedelta\nfrom numpy import linspace\n\n# ----------------------------------------------------------------------------------------------------------------------\n# third party imports\n# ----------------------------------------------------------------------------------------------------------------------\n# ----------------------------------------------------------------------------------------------------------------------\n# local imports\n# ----------------------------------------------------------------------------------------------------------------------\nfrom spectrochempy.core import debug_\nfrom spectrochempy.core.dataset.nddataset import NDDataset\nfrom spectrochempy.core.dataset.ndcoord import Coord\nfrom spectrochempy.utils import readfilename\n\n\n# ======================================================================================================================\n# Public functions\n# ======================================================================================================================\n\n# .............................................................................\ndef read_opus(dataset=None, **kwargs):\n    \"\"\"Open Bruker Opus file(s) and group them in a single dataset. Only the spectrum is\n    extracted (\"AB\" field). Returns an error if dimensions are incompatibles.\n\n    Parameters\n    ----------\n    filename : `None`, `str`, or list of `str`\n        Filename of the file(s) to load. If `None` : opens a dialog box to select\n         files. If `str` : a single filename. It list of str :\n        a list of filenames.\n    directory : str, optional, default=\"\".\n        From where to read the specified filename. If not specified, read in\n        the defaults datadir.\n\n    Returns\n    -------\n    dataset : |NDDataset|\n        A dataset corresponding to the (set of) bruker file(s).\n\n    Examples\n    --------\n    >>> A = NDDataset.read_opus('irdata\\\\spectrum.0001')\n    >>> print(A)\n    NDDataset: [float64] a.u. (shape: (y:1, x:2568))\n    \"\"\"\n    debug_(\"reading bruker opus files\")\n\n    # filename will be given by a keyword parameter except if the first parameters is already\n    # the filename\n    filename = kwargs.get('filename', None)\n\n    # check if the first parameter is a dataset because we allow not to pass it\n    if not isinstance(dataset, NDDataset):\n        # probably did not specify a dataset\n        # so the first parameters must be the filename\n        if isinstance(dataset, (str, list)) and dataset != '':\n            filename = dataset\n\n    # check if directory was specified\n    directory = kwargs.get(\"directory\", None)\n    sortbydate = kwargs.get(\"sortbydate\", True)\n\n    # returns a list of files to read\n    files = readfilename(filename,\n                         directory=directory,\n                         filetypes=['Bruker files (*.*)',\n                                    'all files (*)'],\n                         dictionary=False)\n    # todo: see how to use regular expression in Qt filters\n\n    if not files:\n        # there is no files, return nothing\n        return None\n\n    xaxis = None\n    intensities = []\n    names = []\n    acquisitiondates = []\n    timestamps = []\n    for file in files:\n        opus_data = read_file(file)\n        try:\n            opus_data[\"AB\"]\n        except KeyError:  # not an absorbance spectrum\n            warn(\"opus file {} could not be read\".format(file))\n            continue\n\n        npt = opus_data['AB Data Parameter']['NPT']\n        fxv = opus_data['AB Data Parameter']['FXV']\n        lxv = opus_data['AB Data Parameter']['LXV']\n        xdata = linspace(fxv, lxv, npt)\n\n        if not xaxis:\n            xaxis = Coord(x=xdata, title='Wavenumbers', units='cm^-1')\n\n        elif (xdata != xaxis.data).any():\n            raise ValueError(\"spectra have incompatible dimensions (xaxis)\")\n\n        intensities.append(opus_data[\"AB\"][:npt])\n        names.append(opus_data[\"Sample\"]['SNM'])\n        acqdate = opus_data[\"AB Data Parameter\"][\"DAT\"]\n        acqtime = opus_data[\"AB Data Parameter\"][\"TIM\"]\n        GMT_offset_hour = float(acqtime.split('GMT')[1].split(')')[0])\n        date_time = datetime.strptime(acqdate + '_' + acqtime.split()[0],\n                                      '%d/%m/%Y_%H:%M:%S.%f')\n        UTC_date_time = date_time - timedelta(hours=GMT_offset_hour)\n        UTC_date_time = UTC_date_time.replace(tzinfo=timezone.utc)\n        # Transform to timestamp for storage in the Coord object\n        # use datetime.fromtimestamp(d, timezone.utc)) to transform back to datetime\n        timestamp = UTC_date_time.timestamp()\n        acquisitiondates.append(UTC_date_time)\n        timestamps.append(timestamp)\n\n    # return if none of the files could be read:\n    if not xaxis:\n        return\n\n    yaxis = Coord(timestamps,\n                  title='Acquisition timestamp (GMT)',\n                  units='s',\n                  labels=(acquisitiondates, names))\n\n    dataset = NDDataset(intensities)\n    dataset.set_coords(y=yaxis, x=xaxis)\n    dataset.units = 'absorbance'\n    dataset.title = 'Absorbance'\n\n    # Set origin, description and history\n    dataset.origin = \"opus\"\n    dataset.description = ('Dataset from opus files. \\n')\n\n    if sortbydate:\n        dataset.sort(dim='y', inplace=True)\n\n    dataset.history = str(datetime.now()) + ':import from opus files \\n'\n\n    # Set the NDDataset date\n    dataset._date = datetime.now()\n    dataset._modified = dataset.date\n    # debug_(\"end of reading\")\n\n    return dataset\n", "path": "spectrochempy/core/readers/readopus.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# ======================================================================================================================\n# Copyright (\u00a9) 2015-2020 LCS\n# Laboratoire Catalyse et Spectrochimie, Caen, France.\n# CeCILL-B FREE SOFTWARE LICENSE AGREEMENT\n# See full LICENSE agreement in the root directory\n# ======================================================================================================================\n\n\"\"\"This module to extend NDDataset with the import methods method.\n\n\"\"\"\n__all__ = ['read_opus']\n\n__dataset_methods__ = __all__\n\n# ----------------------------------------------------------------------------------------------------------------------\n# standard imports\n# ----------------------------------------------------------------------------------------------------------------------\n\n\nfrom brukeropusreader import read_file\nfrom warnings import warn\nfrom datetime import datetime, timezone, timedelta\nfrom numpy import linspace\n\n# ----------------------------------------------------------------------------------------------------------------------\n# third party imports\n# ----------------------------------------------------------------------------------------------------------------------\n# ----------------------------------------------------------------------------------------------------------------------\n# local imports\n# ----------------------------------------------------------------------------------------------------------------------\nfrom spectrochempy.core import debug_\nfrom spectrochempy.core.dataset.nddataset import NDDataset\nfrom spectrochempy.core.dataset.ndcoord import Coord\nfrom spectrochempy.utils import readfilename\n\n\n# ======================================================================================================================\n# Public functions\n# ======================================================================================================================\n\n# .............................................................................\ndef read_opus(dataset=None, **kwargs):\n    \"\"\"Open Bruker Opus file(s) and group them in a single dataset. Only the spectrum is\n    extracted (\"AB\" field). Returns an error if dimensions are incompatibles.\n\n    Parameters\n    ----------\n    filename : `None`, `str`, or list of `str`\n        Filename of the file(s) to load. If `None` : opens a dialog box to select\n         files. If `str` : a single filename. It list of str :\n        a list of filenames.\n    directory : str, optional, default=\"\".\n        From where to read the specified filename. If not specified, read in\n        the defaults datadir.\n\n    Returns\n    -------\n    dataset : |NDDataset|\n        A dataset corresponding to the (set of) bruker file(s).\n\n    Examples\n    --------\n    >>> A = NDDataset.read_opus('irdata\\\\spectrum.0001')\n    >>> print(A)\n    NDDataset: [float64] a.u. (shape: (y:1, x:2568))\n\n\n    \"\"\"\n\n    debug_(\"reading bruker opus files\")\n\n    # filename will be given by a keyword parameter except if the first parameters is already\n    # the filename\n    filename = kwargs.get('filename', None)\n\n    # check if the first parameter is a dataset because we allow not to pass it\n    if not isinstance(dataset, NDDataset):\n        # probably did not specify a dataset\n        # so the first parameters must be the filename\n        if isinstance(dataset, (str, list)) and dataset != '':\n            filename = dataset\n\n    # check if directory was specified\n    directory = kwargs.get(\"directory\", None)\n    sortbydate = kwargs.get(\"sortbydate\", True)\n\n    # returns a list of files to read\n    files = readfilename(filename,\n                         directory=directory,\n                         filetypes=['Bruker files (*.*)',\n                                    'all files (*)'],\n                         dictionary=False)\n    # todo: see how to use regular expression in Qt filters\n\n    if not files:\n        # there is no files, return nothing\n        return None\n\n    xaxis = None\n    intensities = []\n    names = []\n    acquisitiondates = []\n    timestamps = []\n    for file in files:\n        opus_data = read_file(file)\n        try:\n            opus_data[\"AB\"]\n        except KeyError:  # not an absorbance spectrum\n            warn(\"opus file {} could not be read\".format(file))\n            continue\n\n        npt = opus_data['AB Data Parameter']['NPT']\n        fxv = opus_data['AB Data Parameter']['FXV']\n        lxv = opus_data['AB Data Parameter']['LXV']\n        xdata = linspace(fxv, lxv, npt)\n\n        if not xaxis:\n            xaxis = Coord(xdata, title='Wavenumbers', units='cm^-1')\n\n        elif (xdata != xaxis.data).any():\n            raise ValueError(\"spectra have incompatible dimensions (xaxis)\")\n\n        intensities.append(opus_data[\"AB\"][:npt])\n        names.append(opus_data[\"Sample\"]['SNM'])\n        acqdate = opus_data[\"AB Data Parameter\"][\"DAT\"]\n        acqtime = opus_data[\"AB Data Parameter\"][\"TIM\"]\n        GMT_offset_hour = float(acqtime.split('GMT')[1].split(')')[0])\n        date_time = datetime.strptime(acqdate + '_' + acqtime.split()[0],\n                                      '%d/%m/%Y_%H:%M:%S.%f')\n        UTC_date_time = date_time - timedelta(hours=GMT_offset_hour)\n        UTC_date_time = UTC_date_time.replace(tzinfo=timezone.utc)\n        # Transform to timestamp for storage in the Coord object\n        # use datetime.fromtimestamp(d, timezone.utc)) to transform back to datetime\n        timestamp = UTC_date_time.timestamp()\n        acquisitiondates.append(UTC_date_time)\n        timestamps.append(timestamp)\n\n    # return if none of the files could be read:\n    if not xaxis:\n        return\n\n    yaxis = Coord(timestamps,\n                  title='Acquisition timestamp (GMT)',\n                  units='s',\n                  labels=(acquisitiondates, names))\n\n    dataset = NDDataset(intensities)\n    dataset.set_coords(y=yaxis, x=xaxis)\n    dataset.units = 'absorbance'\n    dataset.title = 'Absorbance'\n\n    # Set origin, description and history\n    dataset.origin = \"opus\"\n    dataset.description = 'Dataset from opus files. \\n'\n\n    if sortbydate:\n        dataset.sort(dim='y', inplace=True)\n\n    dataset.history = str(datetime.now()) + ': import from opus files \\n'\n    dataset._date = datetime.now()\n    dataset._modified = dataset.date\n\n    return dataset\n", "path": "spectrochempy/core/readers/readopus.py"}]}