magma-multigas


Namemagma-multigas JSON
Version 1.3.0 PyPI version JSON
download
home_pageNone
SummaryMultiGas package for internal use. A collaboration between CVGHM and USGS
upload_time2024-08-08 11:29:18
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords gas volcano multigas usgs cvghm pvmbg
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # magma-multigas
Python package for multigas sensor.

## Installation

---

Make sure you have at least Python 3.10 installed. You can install the package using `pip`
```python
pip install magma-multigas
```

## How to use

---

Import the package first:
```python
from magma_multigas import MultiGas
```

Then lets add all the required files. Please change the files location with your multi gas data. At the moment we are excluding the `span` data files. Will add later in future development.
```python
two_seconds = 'D:\\Projects\\magma-multigas\\input\\TANG_RTU_ChemData_Sec2.dat'
six_hours = 'D:\\Projects\\magma-multigas\\input\\TANG_RTU_Data_6Hr.dat'
one_minute = 'D:\\Projects\\magma-multigas\\input\\TANG_RTU_Wx_Min1.dat'
zero = 'D:\\Projects\\magma-multigas\\input\\TANG_RTU_Zero_Data.dat'
```

Initiate MultiGas module with the code below. This code will correct "NAN" data, and create a new file into your current poject directory. The default location is `<your project directory>/output/normalize` . 
```python
multigas = MultiGas(
    two_seconds=two_seconds,
    six_hours=six_hours,
    one_minute=one_minute,
    zero=zero
)
```

By initiating the module, we can check the output after run the code.
```markdown
💾 New file saved to D:\Projects\magma-multigas\output\normalize\TANG_RTU_ChemData_Sec2.dat
💾 New file saved to D:\Projects\magma-multigas\output\normalize\TANG_RTU_Data_6Hr.dat
💾 New file saved to D:\Projects\magma-multigas\output\normalize\TANG_RTU_Wx_Min1.dat
💾 New file saved to D:\Projects\magma-multigas\output\normalize\TANG_RTU_Zero_Data.dat
```

## Slicing and export for specific time

---

We can filter the data we have by using the code below. At this example we will select data between `start_date = 2024-05-17` and `end_date = 2024-06-18`.
```python
data_filtered = multigas.where_date_between(start_date='2024-05-17', end_date='2024-06-18').save(file_type='excel')
```

We can also save the filtering results. Only `excel`,`xls`,`xlsx` and `csv` are supported.
```python
data_filtered.save(file_type='excel')
```

All files would be saved into `<your project directory>/output/<file_type>`. You can also check the save location after run the `save()` command.
```markdown
✅ Data saved to: D:\Projects\magma-multigas\output\excel\two_seconds_2024-05-17_2024-06-18_TANG_RTU_ChemData_Sec2.xlsx
✅ Data saved to: D:\Projects\magma-multigas\output\excel\six_hours_2024-05-17_2024-06-18_TANG_RTU_Data_6Hr.xlsx
✅ Data saved to: D:\Projects\magma-multigas\output\excel\one_minute_2024-05-17_2024-06-18_TANG_RTU_Wx_Min1.xlsx
✅ Data saved to: D:\Projects\magma-multigas\output\excel\zero_2024-05-17_2024-06-18_TANG_RTU_Zero_Data.xlsx
```

## Selecting Data

---

For now, this package only support 4 type of data.
1. `two_seconds`
2. `six_hours`
3. `one_minute`
4. `zero`

To working on specific dataset, we can do it like this. To choose `two_seconds` data:
```python
two_seconds_data = multigas.two_seconds
```
or:
```python
two_seconds_data = multigas.select('two_seconds').get()
```

Both method will result the same. You can change the `two_seconds` parameter with the available type of data.

## Data Preview

---

After selecting, we can do a quick review by calling `df` parameter:
```python
two_seconds_data.df
```
For anyone not familiar with `df` abbreviation, it's stand for _dataframe_. Just imagine it as an excel with header, but it is in python.

![df-review.png](https://github.com/martanto/magma-multigas/blob/master/images/df-review.png?raw=true)

You can also see the columns name:
```python
two_seconds_data.columns
```
It will show all the columns name:
![columns.png](https://github.com/martanto/magma-multigas/blob/master/images/columns.png?raw=true)

## Filtering
We can do fluent filtering data by using this code below. And it also supports chaining filtering.  
```python
filtered_two_seconds = (two_seconds_data
                        .select_columns(column_names=['H2O','CO2','SO2','H2S','S_total'])
                        .where_date_between(start_date='2024-06-12', end_date='2024-06-18')
                        .where('Status_Flag', '==', 0)
                        .where_values_between(column_name='SO2', start_value=-0.129, end_value=-0.127)
                        .where_values_between(column_name='H2O', start_value=-260, end_value=-228)
                       )
```
We can read the above code as is:
> By using `two_seconds_data`, let's select specific columns, such as: `H2O, CO2, SO2, S_Total` where the `Status_Flag` should have a `0` value. And the `SO2` columns must be between `-0.129` and `-0.127`. In addition `H2O` values would be filtered between `-260` and `-228`.

To see the results, please run the `get()` method:
```python
filtered_two_seconds.get()
```

You can see the example of the results below. Here we only found 1 result based on our query filtering.
![filtering.png](https://github.com/martanto/magma-multigas/blob/master/images/filtering.png?raw=true)

To check and count the results:
```python
filtered_two_seconds.count()
```

## Save Filtering Results

---

We can save it, using `save_as()` method. You can change the `file_type` parameter between `excel`,`xls`,`xlsx`, or `csv`.
```python
filtered_two_seconds.save_as(file_type='excel')
```

You will get the information where your file is saved. By default, it should be in your `output\<file_type>` directory. Here is the example of the output:
```markdown
✅ Data saved to: D:\Projects\magma-multigas\output\excel\two_seconds_2024-06-16_2024-06-16_TANG_RTU_ChemData_Sec2.xlsx
```

## Plot

---

This package provide some basic functionality to plot some data. For the simplicity, we will use `six_hours` data as an example. We will do all the basic things above, from extracting, selecting, and filtering.

#### Selecting Six Hours
```python
six_hours_data = multigas.select('six_hours').get()
```

#### Date Filtering
```python
filtered_six_hours = six_hours_data.where_date_between(start_date='2024-05-17', end_date='2024-06-18')
```

#### Plot Initiating
Using `plot()` method to initiate
```python
plot_six_hours = filtered_six_hours.plot()
```

#### Plot Avg. CO2, H2S, and SO2
This package has some default plotting method. We will use `plot_co2_so2_h2s()` as an example:
```python
plot_six_hours.plot_co2_so2_h2s()
```

You can see the result here:
![plot_example_1.png](https://github.com/martanto/magma-multigas/blob/master/images/plot_example_1.png?raw=true)

From the plot above we can see there ae some anomaly values (below 400 for Av. CO2 Lowpass). We can re-filter it once again to optimize the result. In this case we will select column `Avg_CO2_lowpass` which value greater than or equal to `250`
```python
filtered_six_hours = filtered_six_hours.where('Avg_CO2_lowpass', '>=', 250)
```

Then plot it:
```python
filtered_six_hours.plot().plot_co2_so2_h2s()
```

Result:
![plot_example_2.png](https://github.com/martanto/magma-multigas/blob/master/images/plot_example_2.png?raw=true)

We can also plot as an individual by adding parameter `plot_as_individual=True`
```python
filtered_six_hours.plot().plot_co2_so2_h2s(
    plot_as_individual=True
)
```

And the result:
![plot_example_3.png](https://github.com/martanto/magma-multigas/blob/master/images/plot_example_3.png?raw=true)

###  Plot Specific Column(s)
Select columns to plot:
```python
columns_to_plot = ['Avg_Wind_Speed', 'Avg_Wind_Direction', 'Avg_H2O', 'Avg_CO2_lowpass']
```

Then plot it:
```python
filtered_six_hours.plot(height=2).plot_columns(columns_to_plot)
```

Results:
![plot_example_4.png](https://github.com/martanto/magma-multigas/blob/master/images/plot_example_4.png?raw=true)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "magma-multigas",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "gas, volcano, multigas, usgs, cvghm, pvmbg",
    "author": null,
    "author_email": "Martanto <martanto@live.com>",
    "download_url": "https://files.pythonhosted.org/packages/9c/5f/85c22e091ec050dbf437cfa17533af1d31eef6f1de9dbb4e2b4cc99e5ac6/magma_multigas-1.3.0.tar.gz",
    "platform": null,
    "description": "# magma-multigas\nPython package for multigas sensor.\n\n## Installation\n\n---\n\nMake sure you have at least Python 3.10 installed. You can install the package using `pip`\n```python\npip install magma-multigas\n```\n\n## How to use\n\n---\n\nImport the package first:\n```python\nfrom magma_multigas import MultiGas\n```\n\nThen lets add all the required files. Please change the files location with your multi gas data. At the moment we are excluding the `span` data files. Will add later in future development.\n```python\ntwo_seconds = 'D:\\\\Projects\\\\magma-multigas\\\\input\\\\TANG_RTU_ChemData_Sec2.dat'\nsix_hours = 'D:\\\\Projects\\\\magma-multigas\\\\input\\\\TANG_RTU_Data_6Hr.dat'\none_minute = 'D:\\\\Projects\\\\magma-multigas\\\\input\\\\TANG_RTU_Wx_Min1.dat'\nzero = 'D:\\\\Projects\\\\magma-multigas\\\\input\\\\TANG_RTU_Zero_Data.dat'\n```\n\nInitiate MultiGas module with the code below. This code will correct \"NAN\" data, and create a new file into your current poject directory. The default location is `<your project directory>/output/normalize` . \n```python\nmultigas = MultiGas(\n    two_seconds=two_seconds,\n    six_hours=six_hours,\n    one_minute=one_minute,\n    zero=zero\n)\n```\n\nBy initiating the module, we can check the output after run the code.\n```markdown\n\ud83d\udcbe New file saved to D:\\Projects\\magma-multigas\\output\\normalize\\TANG_RTU_ChemData_Sec2.dat\n\ud83d\udcbe New file saved to D:\\Projects\\magma-multigas\\output\\normalize\\TANG_RTU_Data_6Hr.dat\n\ud83d\udcbe New file saved to D:\\Projects\\magma-multigas\\output\\normalize\\TANG_RTU_Wx_Min1.dat\n\ud83d\udcbe New file saved to D:\\Projects\\magma-multigas\\output\\normalize\\TANG_RTU_Zero_Data.dat\n```\n\n## Slicing and export for specific time\n\n---\n\nWe can filter the data we have by using the code below. At this example we will select data between `start_date = 2024-05-17` and `end_date = 2024-06-18`.\n```python\ndata_filtered = multigas.where_date_between(start_date='2024-05-17', end_date='2024-06-18').save(file_type='excel')\n```\n\nWe can also save the filtering results. Only `excel`,`xls`,`xlsx` and `csv` are supported.\n```python\ndata_filtered.save(file_type='excel')\n```\n\nAll files would be saved into `<your project directory>/output/<file_type>`. You can also check the save location after run the `save()` command.\n```markdown\n\u2705 Data saved to: D:\\Projects\\magma-multigas\\output\\excel\\two_seconds_2024-05-17_2024-06-18_TANG_RTU_ChemData_Sec2.xlsx\n\u2705 Data saved to: D:\\Projects\\magma-multigas\\output\\excel\\six_hours_2024-05-17_2024-06-18_TANG_RTU_Data_6Hr.xlsx\n\u2705 Data saved to: D:\\Projects\\magma-multigas\\output\\excel\\one_minute_2024-05-17_2024-06-18_TANG_RTU_Wx_Min1.xlsx\n\u2705 Data saved to: D:\\Projects\\magma-multigas\\output\\excel\\zero_2024-05-17_2024-06-18_TANG_RTU_Zero_Data.xlsx\n```\n\n## Selecting Data\n\n---\n\nFor now, this package only support 4 type of data.\n1. `two_seconds`\n2. `six_hours`\n3. `one_minute`\n4. `zero`\n\nTo working on specific dataset, we can do it like this. To choose `two_seconds` data:\n```python\ntwo_seconds_data = multigas.two_seconds\n```\nor:\n```python\ntwo_seconds_data = multigas.select('two_seconds').get()\n```\n\nBoth method will result the same. You can change the `two_seconds` parameter with the available type of data.\n\n## Data Preview\n\n---\n\nAfter selecting, we can do a quick review by calling `df` parameter:\n```python\ntwo_seconds_data.df\n```\nFor anyone not familiar with `df` abbreviation, it's stand for _dataframe_. Just imagine it as an excel with header, but it is in python.\n\n![df-review.png](https://github.com/martanto/magma-multigas/blob/master/images/df-review.png?raw=true)\n\nYou can also see the columns name:\n```python\ntwo_seconds_data.columns\n```\nIt will show all the columns name:\n![columns.png](https://github.com/martanto/magma-multigas/blob/master/images/columns.png?raw=true)\n\n## Filtering\nWe can do fluent filtering data by using this code below. And it also supports chaining filtering.  \n```python\nfiltered_two_seconds = (two_seconds_data\n                        .select_columns(column_names=['H2O','CO2','SO2','H2S','S_total'])\n                        .where_date_between(start_date='2024-06-12', end_date='2024-06-18')\n                        .where('Status_Flag', '==', 0)\n                        .where_values_between(column_name='SO2', start_value=-0.129, end_value=-0.127)\n                        .where_values_between(column_name='H2O', start_value=-260, end_value=-228)\n                       )\n```\nWe can read the above code as is:\n> By using `two_seconds_data`, let's select specific columns, such as: `H2O, CO2, SO2, S_Total` where the `Status_Flag` should have a `0` value. And the `SO2` columns must be between `-0.129` and `-0.127`. In addition `H2O` values would be filtered between `-260` and `-228`.\n\nTo see the results, please run the `get()` method:\n```python\nfiltered_two_seconds.get()\n```\n\nYou can see the example of the results below. Here we only found 1 result based on our query filtering.\n![filtering.png](https://github.com/martanto/magma-multigas/blob/master/images/filtering.png?raw=true)\n\nTo check and count the results:\n```python\nfiltered_two_seconds.count()\n```\n\n## Save Filtering Results\n\n---\n\nWe can save it, using `save_as()` method. You can change the `file_type` parameter between `excel`,`xls`,`xlsx`, or `csv`.\n```python\nfiltered_two_seconds.save_as(file_type='excel')\n```\n\nYou will get the information where your file is saved. By default, it should be in your `output\\<file_type>` directory. Here is the example of the output:\n```markdown\n\u2705 Data saved to: D:\\Projects\\magma-multigas\\output\\excel\\two_seconds_2024-06-16_2024-06-16_TANG_RTU_ChemData_Sec2.xlsx\n```\n\n## Plot\n\n---\n\nThis package provide some basic functionality to plot some data. For the simplicity, we will use `six_hours` data as an example. We will do all the basic things above, from extracting, selecting, and filtering.\n\n#### Selecting Six Hours\n```python\nsix_hours_data = multigas.select('six_hours').get()\n```\n\n#### Date Filtering\n```python\nfiltered_six_hours = six_hours_data.where_date_between(start_date='2024-05-17', end_date='2024-06-18')\n```\n\n#### Plot Initiating\nUsing `plot()` method to initiate\n```python\nplot_six_hours = filtered_six_hours.plot()\n```\n\n#### Plot Avg. CO2, H2S, and SO2\nThis package has some default plotting method. We will use `plot_co2_so2_h2s()` as an example:\n```python\nplot_six_hours.plot_co2_so2_h2s()\n```\n\nYou can see the result here:\n![plot_example_1.png](https://github.com/martanto/magma-multigas/blob/master/images/plot_example_1.png?raw=true)\n\nFrom the plot above we can see there ae some anomaly values (below 400 for Av. CO2 Lowpass). We can re-filter it once again to optimize the result. In this case we will select column `Avg_CO2_lowpass` which value greater than or equal to `250`\n```python\nfiltered_six_hours = filtered_six_hours.where('Avg_CO2_lowpass', '>=', 250)\n```\n\nThen plot it:\n```python\nfiltered_six_hours.plot().plot_co2_so2_h2s()\n```\n\nResult:\n![plot_example_2.png](https://github.com/martanto/magma-multigas/blob/master/images/plot_example_2.png?raw=true)\n\nWe can also plot as an individual by adding parameter `plot_as_individual=True`\n```python\nfiltered_six_hours.plot().plot_co2_so2_h2s(\n    plot_as_individual=True\n)\n```\n\nAnd the result:\n![plot_example_3.png](https://github.com/martanto/magma-multigas/blob/master/images/plot_example_3.png?raw=true)\n\n###  Plot Specific Column(s)\nSelect columns to plot:\n```python\ncolumns_to_plot = ['Avg_Wind_Speed', 'Avg_Wind_Direction', 'Avg_H2O', 'Avg_CO2_lowpass']\n```\n\nThen plot it:\n```python\nfiltered_six_hours.plot(height=2).plot_columns(columns_to_plot)\n```\n\nResults:\n![plot_example_4.png](https://github.com/martanto/magma-multigas/blob/master/images/plot_example_4.png?raw=true)\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "MultiGas package for internal use. A collaboration between CVGHM and USGS",
    "version": "1.3.0",
    "project_urls": {
        "Homepage": "https://github.com/martanto/magma-multigas",
        "Issues": "https://github.com/martanto/magma-multigas/issues"
    },
    "split_keywords": [
        "gas",
        " volcano",
        " multigas",
        " usgs",
        " cvghm",
        " pvmbg"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "90ed49b194345fe5c58a4ae8fbadb26304e28a674712af08355c875b5e9cfc2f",
                "md5": "8bf4e9381f18ce50da35154f4f08ebe8",
                "sha256": "c5bb32f409c0a205fe0eb5bfcdbf209108766eead21f7eb0767297004d0c1e5c"
            },
            "downloads": -1,
            "filename": "magma_multigas-1.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8bf4e9381f18ce50da35154f4f08ebe8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 135512,
            "upload_time": "2024-08-08T11:29:16",
            "upload_time_iso_8601": "2024-08-08T11:29:16.867931Z",
            "url": "https://files.pythonhosted.org/packages/90/ed/49b194345fe5c58a4ae8fbadb26304e28a674712af08355c875b5e9cfc2f/magma_multigas-1.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9c5f85c22e091ec050dbf437cfa17533af1d31eef6f1de9dbb4e2b4cc99e5ac6",
                "md5": "93944dbd699a3da81f3a344630b79929",
                "sha256": "3719a6d672d4ba18336d6f269ed11c4cdf902c9f8a6ce95edf852e1f9898dd05"
            },
            "downloads": -1,
            "filename": "magma_multigas-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "93944dbd699a3da81f3a344630b79929",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 132636,
            "upload_time": "2024-08-08T11:29:18",
            "upload_time_iso_8601": "2024-08-08T11:29:18.710143Z",
            "url": "https://files.pythonhosted.org/packages/9c/5f/85c22e091ec050dbf437cfa17533af1d31eef6f1de9dbb4e2b4cc99e5ac6/magma_multigas-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-08 11:29:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "martanto",
    "github_project": "magma-multigas",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "magma-multigas"
}
        
Elapsed time: 3.55806s