semvec/pypi-packages huggingface dataset:
xrd-xy-parser 0.0.4
parse xy format file of X-ray diffraction
Requires Python: >=3.10

# xrd-xy-parser

xrd-xy-parser is parser of xy file from X-ray diffraction.<br>
Python ver >= 3.10


## installation

```sh
pip install xrd-xy-parser
```
or
```sh
pip3 install xrd-xy-parser
```
 
## how to use
```python
from xrd_xy_parser import xy

if __name__ == "__main__":

    try:
        header, body, footer = xy.readstr("examples/example.xy")
        print("header:{}\n" "body:{}\n" "footer:{}\n".format(header, body, footer))
        '''
        header:
        <301.15K> 
        Wavelength = 1.54059 

        body:
        array([[30.  ,  1.  ],
        [30.01,  1.  ],
        [30.02,  3.  ],
        ...,
        [49.97,  3.  ],
        [49.98,  1.  ],
        [49.99,  0.  ]])

        footer:
        ""
        '''
    except xy.ParseError as e:
        print(e)
```
getting 2θ,Intensity column
```python
    # 2θ column
    print(body[:,0]) # array([30.  , 30.01, 30.02, ..., 49.97, 49.98, 49.99])

    # Intensity column
    print(body[:,1]) # array([1., 1., 3., ..., 3., 1., 0.])
```
or read2xy 
```python
    try:
        xy = read2xy("examples/example.xy")
        print(xy)
        # x:array([30.  , 30.01, 30.02, ..., 49.97, 49.98,])
        # y:array([1., 1., 3., ..., 3., 1., 0.])
    except xy.ParseError as e:
        print(e)
    
```
## function

### `xy.read(str)`
### `xy.read(Pathlib.Path)`
### `xy.read(TextIOBase)`
read xy data from `str` ,`Path` or `TextIOBase`,return tuple (header, body, footer).


### `xy.read2xy(str)`
### `xy.read2xy(Pathlib.Path)`
### `xy.read2xy(TextIOBase)`
read xy data from `str` ,`Path` or `TextIOBase`,return xrdXY object.

## class
### `xrdXY`
#### attribute
* x: np.ndarray
* y: np.ndarray


## xy file structure

xy file is not explicitly specified.<br>
xy file consists from `header`,`body`,`footer` parts.<br>
`header` includes some infomation,
`body` is float list.
`footer` is empty or consists from `\s` ,`\t` ,`\r\n`,`\n`.

```xy
<301.15K> \\header
Wavelength = 1.54059 \\header
26.78	11598.00 \\body
26.8	10786.00
26.82	5768.00
26.84	1149.00
26.86	255.00
26.88	74.00
26.9	52.00
26.92	30.00
26.94	19.00 \\body
\\ footer
```
np2mcpl 0.1.0
Package to convert a Monte Carlo particle in the form of a numpy-array to a MCPL-file.
Requires Python: >=3.8

# np2mcpl
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

np2mcpl is a low-key tool to help write mcpl-files directly from numpy-arrays.

## Build/Install/Use
1. Make sure you have installed the MCPL-library (and NumPy)
2. Build the python/c module: ```python setup.py build```
3. Add the build directory to PYTHONPATH _or_ run: ```python setup.py install```
4. In your python script: ```import np2mcpl```
5. Create a numpy array and save it. E.g. : ```np2mcpl.save("output",M)```

## Notes and limitations
- np2mcpl takes as input a 2D NumPy array with 10 or 13 columns, where the columns are assumed to be:
```
PDG-code  x y z   ux uy uz   t e_kin weight    [ px py pz ]
```
 where the PDG-code denotes which kind of particle it is, e.g. 2112 for neutrons, 22 for photon, ... as documented here: [Particle Numbering Scheme](https://pdg.lbl.gov/2023/mcdata/mc_particle_id_contents.html)
- The vector ux,uy,uz must have unit length. The optional vector px,py,pz is the polarisation vector associated with the Monte Carlo-particle.
- Units follow the MCPL-standard. I.e. x,y,z in cm, e_kin in MeV, t in ms.
- The input array is expected to be made of floating point numbers (including the PDG-code) in either double or single precision. If the numpy array is in single precision, this will be reflected in the mcpl-file.
optunizer 0.1.17
Optuna extension for JSON and YAML configuration files
Requires Python: >=3.6

# optunizer
Optuna extension for JSON and YAML configuration files

## Installation
```sh
pip install optunizer
```
* with PostresSQL connector
```sh
pip install optunizer[psycopg]
```

## Running
0. Suppose you have some script/program (e.g. `main.py`) with config in YAML/JSON file (e.g. `config.yaml`) that returns some output (e.g. `metrics.json`)
* main.py
```python
import json
import yaml
config_file = 'config.yaml'
with open(config_file) as f:
  params = yaml.safe_load(f)
metric = params['param1'] + params['param2']
metrics = {'metric': metric}
metrics_file = 'metrics.json'
with open(metrics_file, 'w') as f:
  json.dump(metrics, f)
```

* config.yaml
```yaml
param1: 2
param2: 0.5
param3: c
```

* metrics.json
```json
{
  "metric": 0.3
}
```
1. Make optunizer config file, e.g. `optunizer.yaml`

```yaml
attrs:  # track all fields in files
  config.yaml: true
  metrics.json: true
  optunizer_sysinfo.json: true
class: optunizer.optimizer.Optimizer
load_if_exists: true
export_csv: optunizer_results.csv
export_metrics: optunizer_metrics.json
export_sysinfo: optunizer_sysinfo.json
study: optunizer_test
objectives:  # Specify objectives, e.g. fields in metrics.json file
  metric@metrics.json: minimize
params:  # Specify params, e.g. fields in config.yaml file
  param1@config.yaml:
    method: suggest_int
    method_kwargs:
      high: 3
      low: 0
  param2@config.yaml:
    method: suggest_float
    method_kwargs:
      high: 1.0
      low: 0.01
      log: true
  param3@config.yaml:
    method: suggest_categorical
    method_kwargs:
      choices: [a, b, c]
pruner: PatientPruner
pruner_kwargs:  # Specify pruner, e.g. PatientPruner with NopPruner subpruner
  min_delta: 0
  patience: 0
  wrapped_pruner: NopPruner
  wrapped_pruner_kwargs: {}
sampler: PartialFixedSampler
sampler_kwargs:   # Specify sampler, e.g. PartialFixedSampler with GridSampler subsampler
  base_sampler: RandomSampler
  base_sampler_kwargs: {}
  # base_sampler: GridSampler
  # base_sampler_kwargs:
  #   search_space:
  #     param1@config.yaml: [0, 1, 2]
  #     param2@config.yaml: [0.01, 0.5]
  fixed_params:
    param3@config.yaml: a
subprocess_kwargs:  # Specify your command
  args:
  - python
  - main.py
  - config.yaml
```

2. Run optunizer
```sh
OPTUNA_CONFIG=optunizer.yaml python -m optunizer
```
or
```sh
python -m optunizer optunizer.yaml
```

3. Run optunizer streamlit viz
```sh
pip install optunizer[viz]
python -m optunizer app
```

4. There are several useful environment variables, that could be set in command line, `.env` or `.env.secret` files
```sh
OPTUNA_CONFIG=optunizer.yaml
OPTUNA_CONFIG_APP=app.yaml
OPTUNA_SHARED=.env
OPTUNA_SECRET=.env.secret
OPTUNA_URL=postgresql+psycopg2://USER:PASSWORD@IP:PORT/DB  # see https://docs.sqlalchemy.org/en/14/core/engines.html
OPTUNA_STUDY=STUDY_NAME
OPTUNA_TRIALS=3
OPTUNA_TIMEOUT=3600
OPTUNA_LOAD_IF_EXISTS=1
OPTUNA_EXPORT_CSV=CSV_FILE_NAME
OPTUNA_EXPORT_METRICS=METRICS_FILE_NAME
OPTUNA_EXPORT_SYSINFO=SYSINFO_FILE_NAME
```