| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,23 +13,23 @@ Using the parsers module, we can load file data into simple and easy-to-work-wit | |||
| 13 | 13 | Our goal will be to extract the data, and the parameters listed in the header, from this file and | |
| 14 | 14 | load it into our program. | |
| 15 | 15 | ||
| 16 | - 2) To get the data table, we will use the ``loadData`` function. The default behavior of this | ||
| 16 | + 2) To get the data table, we will use the ``load_data`` function. The default behavior of this | ||
| 17 | 17 | function is to find and extract a data table from a file. | |
| 18 | 18 | ||
| 19 | 19 | .. code-block:: python | |
| 20 | 20 | ||
| 21 | - from diffpy.utils.parsers.loaddata import loadData | ||
| 22 | - data_table = loadData('<PATH to data.txt>') | ||
| 21 | + from diffpy.utils.parsers import load_data | ||
| 22 | + data_table = load_data('<PATH to data.txt>') | ||
| 23 | 23 | ||
| 24 | 24 | While this will work with most datasets, on our ``data.txt`` file, we got a ``ValueError``. The reason for this is | |
| 25 | 25 | due to the comments ``$ Phase Transition Near This Temperature Range`` and ``--> Note Significant Jump in Rw <--`` | |
| 26 | 26 | embedded within the dataset. To fix this, try using the ``comments`` parameter. | |
| 27 | 27 | ||
| 28 | 28 | .. code-block:: python | |
| 29 | 29 | ||
| 30 | - data_table = loadData('<PATH to data.txt>', comments=['$', '-->']) | ||
| 30 | + data_table = load_data('<PATH to data.txt>', comments=['$', '-->']) | ||
| 31 | 31 | ||
| 32 | - This parameter tells ``loadData`` that any lines beginning with ``$`` and ``-->`` are just comments and | ||
| 32 | + This parameter tells ``load_data`` that any lines beginning with ``$`` and ``-->`` are just comments and | ||
| 33 | 33 | more entries in our data table may follow. | |
| 34 | 34 | ||
| 35 | 35 | Here are a few other parameters to test out: | |
@@ -39,30 +39,30 @@ Here are a few other parameters to test out: | |||
| 39 | 39 | ||
| 40 | 40 | .. code-block:: python | |
| 41 | 41 | ||
| 42 | - loadData('<PATH to data.txt>', comments=['$', '-->'], delimiter=',') | ||
| 42 | + load_data('<PATH to data.txt>', comments=['$', '-->'], delimiter=',') | ||
| 43 | 43 | ||
| 44 | 44 | returns an empty list. | |
| 45 | 45 | * ``minrows=50``: Only look for data tables with at least 50 rows. Since our data table has much less than that many | |
| 46 | 46 | rows, running | |
| 47 | 47 | ||
| 48 | 48 | .. code-block:: python | |
| 49 | 49 | ||
| 50 | - loadData('<PATH to data.txt>', comments=['$', '-->'], minrows=50) | ||
| 50 | + load_data('<PATH to data.txt>', comments=['$', '-->'], minrows=50) | ||
| 51 | 51 | ||
| 52 | 52 | returns an empty list. | |
| 53 | 53 | * ``usecols=[0, 3]``: Only return the 0th and 3rd columns (zero-indexed) of the data table. For ``data.txt``, this | |
| 54 | 54 | corresponds to the temperature and rw columns. | |
| 55 | 55 | ||
| 56 | 56 | .. code-block:: python | |
| 57 | 57 | ||
| 58 | - loadData('<PATH to data.txt>', comments=['$', '-->'], usecols=[0, 3]) | ||
| 58 | + load_data('<PATH to data.txt>', comments=['$', '-->'], usecols=[0, 3]) | ||
| 59 | 59 | ||
| 60 | - 3) Next, to get the header information, we can again use ``loadData``, | ||
| 60 | + 3) Next, to get the header information, we can again use ``load_data``, | ||
| 61 | 61 | but this time with the ``headers`` parameter enabled. | |
| 62 | 62 | ||
| 63 | 63 | .. code-block:: python | |
| 64 | 64 | ||
| 65 | - hdata = loadData('<PATH to data.txt>', comments=['$', '-->'], headers=True) | ||
| 65 | + hdata = load_data('<PATH to data.txt>', comments=['$', '-->'], headers=True) | ||
| 66 | 66 | ||
| 67 | 67 | 4) Rather than working with separate ``data_table`` and ``hdata`` objects, it may be easier to combine them into a single | |
| 68 | 68 | dictionary. We can do so using the ``serialize_data`` function. | |
@@ -116,8 +116,8 @@ The returned value, ``parsed_file_data``, is the dictionary we just added to ``s | |||
| 116 | 116 | ||
| 117 | 117 | .. code-block:: python | |
| 118 | 118 | ||
| 119 | - data_table = loadData('<PATH to moredata.txt>') | ||
| 120 | - hdata = loadData('<PATH to moredata.txt>', headers=True) | ||
| 119 | + data_table = load_data('<PATH to moredata.txt>') | ||
| 120 | + hdata = load_data('<PATH to moredata.txt>', headers=True) | ||
| 121 | 121 | serialize_data('<PATH to moredata.txt>', hdata, data_table, serial_file='<PATH to serialdata.json>') | |
| 122 | 122 | ||
| 123 | 123 | The serial file ``serialfile.json`` should now contain two entries: ``data.txt`` and ``moredata.txt``. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,9 +16,9 @@ given enough datapoints. | |||
| 16 | 16 | ||
| 17 | 17 | .. code-block:: python | |
| 18 | 18 | ||
| 19 | - from diffpy.utils.parsers.loaddata import loadData | ||
| 20 | - nickel_datatable = loadData('<PATH to Nickel.gr>') | ||
| 21 | - nitarget_datatable = loadData('<PATH to NiTarget.gr>') | ||
| 19 | + from diffpy.utils.parsers import load_data | ||
| 20 | + nickel_datatable = load_data('<PATH to Nickel.gr>') | ||
| 21 | + nitarget_datatable = load_data('<PATH to NiTarget.gr>') | ||
| 22 | 22 | ||
| 23 | 23 | Each data table has two columns: first is the grid and second is the function value. | |
| 24 | 24 | To extract the columns, we can utilize the serialize function ... | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ Parsers Utility | |||
| 5 | 5 | ||
| 6 | 6 | The ``diffpy.utils.parsers`` module allows users to easily and robustly load file data into a Python project. | |
| 7 | 7 | ||
| 8 | - - ``loaddata.loadData()``: Find and load a data table/block from a text file. This seems to work for most datafiles | ||
| 8 | + - ``loaddata.load_data()``: Find and load a data table/block from a text file. This seems to work for most datafiles | ||
| 9 | 9 | including those generated by diffpy programs. Running only ``numpy.loadtxt`` will result in errors | |
| 10 | 10 | for most these files as there is often excess data or parameters stored above the data block. | |
| 11 | 11 | Users can instead choose to load all the parameters of the form ``<param_name> = <param_value>`` into a dictionary | |
@@ -17,7 +17,7 @@ The ``diffpy.utils.parsers`` module allows users to easily and robustly load fil | |||
| 17 | 17 | - ``serialization.deserialize_data()``: Load data from a serial file format into a Python dictionary. Currently, the only supported | |
| 18 | 18 | serial format is ``.json``. | |
| 19 | 19 | ||
| 20 | - - ``serialization.serialize_data()``: Serialize the data generated by ``loadData()`` into a serial file format. Currently, the only | ||
| 20 | + - ``serialization.serialize_data()``: Serialize the data generated by ``load_data()`` into a serial file format. Currently, the only | ||
| 21 | 21 | supported serial format is ``.json``. | |
| 22 | 22 | ||
| 23 | 23 | For a more in-depth tutorial for how to use these parser utilities, click :ref:`here <Parsers Example>`. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,23 @@ | |||
| 1 | + **Added:** | ||
| 2 | + | ||
| 3 | + * <news item> | ||
| 4 | + | ||
| 5 | + **Changed:** | ||
| 6 | + | ||
| 7 | + * load_data now takes a Path or a string for the file-path | ||
| 8 | + | ||
| 9 | + **Deprecated:** | ||
| 10 | + | ||
| 11 | + * diffpy.utils.parsers.loaddata.loadData replaced by diffpy.utils.parsers.load_data | ||
| 12 | + | ||
| 13 | + **Removed:** | ||
| 14 | + | ||
| 15 | + * <news item> | ||
| 16 | + | ||
| 17 | + **Fixed:** | ||
| 18 | + | ||
| 19 | + * <news item> | ||
| 20 | + | ||
| 21 | + **Security:** | ||
| 22 | + | ||
| 23 | + * <news item> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ def deprecated(message, *, category=DeprecationWarning, stacklevel=1): | |||
| 20 | 20 | ||
| 21 | 21 | .. code-block:: python | |
| 22 | 22 | ||
| 23 | - from diffpy._deprecations import deprecated | ||
| 23 | + from diffpy.utils._deprecator import deprecated | ||
| 24 | 24 | import warnings | |
| 25 | 25 | ||
| 26 | 26 | @deprecated("old_function is deprecated; use new_function instead") | |
@@ -39,7 +39,6 @@ def new_function(x, y): | |||
| 39 | 39 | .. code-block:: python | |
| 40 | 40 | ||
| 41 | 41 | from diffpy._deprecations import deprecated | |
| 42 | - import warnings | ||
| 43 | 42 | ||
| 44 | 43 | warnings.simplefilter("always", DeprecationWarning) | |
| 45 | 44 | ||
@@ -83,7 +82,9 @@ def wrapper(*args, **kwargs): | |||
| 83 | 82 | return decorator | |
| 84 | 83 | ||
| 85 | 84 | ||
| 86 | - def deprecation_message(base, old_name, new_name, removal_version): | ||
| 85 | + def deprecation_message( | ||
| 86 | + base, old_name, new_name, removal_version, new_base=None | ||
| 87 | + ): | ||
| 87 | 88 | """Generate a deprecation message. | |
| 88 | 89 | ||
| 89 | 90 | Parameters | |
@@ -102,7 +103,17 @@ def deprecation_message(base, old_name, new_name, removal_version): | |||
| 102 | 103 | str | |
| 103 | 104 | A formatted deprecation message. | |
| 104 | 105 | """ | |
| 106 | + if new_base is None: | ||
| 107 | + new_base = base | ||
| 105 | 108 | return ( | |
| 106 | 109 | f"'{base}.{old_name}' is deprecated and will be removed in " | |
| 107 | - f"version {removal_version}. Please use '{base}.{new_name}' instead." | ||
| 110 | + f"version {removal_version}. Please use '{new_base}.{new_name}' " | ||
| 111 | + f"instead." | ||
| 108 | 112 | ) | |
| 113 | + | ||
| 114 | + | ||
| 115 | + _DEPRECATION_DOCSTRING_TEMPLATE = ( | ||
| 116 | + "This function has been deprecated and will be " | ||
| 117 | + "removed in version {removal_version}. Please use" | ||
| 118 | + "{new_base}.{new_name} instead." | ||
| 119 | + ) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,10 +6,18 @@ | |||
| 6 | 6 | # (c) 2010 The Trustees of Columbia University | |
| 7 | 7 | # in the City of New York. All rights reserved. | |
| 8 | 8 | # | |
| 9 | - # File coded by: Chris Farrow | ||
| 9 | + # File coded by: Simon Billinge | ||
| 10 | 10 | # | |
| 11 | 11 | # See AUTHORS.txt for a list of people who contributed. | |
| 12 | 12 | # See LICENSE_DANSE.txt for license information. | |
| 13 | 13 | # | |
| 14 | 14 | ############################################################################## | |
| 15 | 15 | """Various utilities related to data parsing and manipulation.""" | |
| 16 | + | ||
| 17 | + # this allows load_data to be imported from diffpy.utils.parsers | ||
| 18 | + # it is needed during deprecation of the old loadData structure | ||
| 19 | + # when we remove loadData we can move all the parser functionality | ||
| 20 | + # a parsers.py module (like tools.py) and remove this if we want | ||
| 21 | + from .loaddata import load_data | ||
| 22 | + | ||
| 23 | + __all__ = ["load_data"] | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments