Skip to content

MethodSCRIPT

This page documents the MethodSCRIPT (MS) method.

pypalmsens.MethodScript

Create a method script sandbox object.

The MethodSCRIPT Sandbox allows you to write your own MethodSCRIPT and run them on your instrument.

The MethodSCRIPT language allows for programming a human-readable script directly into the potentiostat. The simple script language makes it easy to combine different measurements and other tasks.

For more information see: https://www.palmsens.com/methodscript/

Methods:

  • to_dict

    Return the technique instance as a new key/value dictionary mapping.

  • from_dict

    Structure technique instance from dict.

  • from_method_id

    Create new instance of appropriate technique from method ID.

  • from_file

    Load methodscript from file.

  • to_file

    Save script to file.

  • from_url

    Download script over http.

Attributes:

id class-attribute instance-attribute

id: Literal['ms'] = 'ms'

Unique method identifier.

script class-attribute instance-attribute

script: str = 'e\nwait 100m\nif 1 < 2\n    send_string "Hello world"\nendif\n\n'

Script to run.

For more info on MethodSCRIPT, see: https://www.palmsens.com/methodscript/ for more information.

to_dict

to_dict() -> dict[str, Any]

Return the technique instance as a new key/value dictionary mapping.

Source code in src/pypalmsens/_methods/base.py
45
46
47
def to_dict(self) -> dict[str, Any]:
    """Return the technique instance as a new key/value dictionary mapping."""
    return self.model_dump()

from_dict classmethod

from_dict(obj: dict[str, Any]) -> MethodType

Structure technique instance from dict.

Opposite of .to_dict()

Source code in src/pypalmsens/_methods/base.py
49
50
51
52
53
54
@classmethod
def from_dict(cls, obj: dict[str, Any]) -> MethodType:
    """Structure technique instance from dict.

    Opposite of `.to_dict()`"""
    return cls.model_validate(obj)  # type:ignore

from_method_id classmethod

from_method_id(id: str) -> MethodType

Create new instance of appropriate technique from method ID.

Source code in src/pypalmsens/_methods/base.py
56
57
58
59
60
@classmethod
def from_method_id(cls, id: str) -> MethodType:
    """Create new instance of appropriate technique from method ID."""
    new = cls._registry[id]
    return new()

from_file classmethod

from_file(path: str | Path = 'methodscript.mscr') -> MethodScript

Load methodscript from file.

Parameters:

  • path

    (str | Path, default: 'methodscript.mscr' ) –

    Path to methodscript file.

Returns:

Source code in src/pypalmsens/_methods/techniques.py
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
@classmethod
def from_file(cls, path: str | Path = 'methodscript.mscr') -> MethodScript:
    """Load methodscript from file.

    Parameters
    ----------
    path: str | Path
        Path to methodscript file.

    Returns
    -------
    method: MethodScript
    """
    with Path(path).open('r') as f:
        script = f.read()

    return cls(script=script)

to_file

to_file(path: str | Path = 'methodscript.mscr') -> None

Save script to file.

Parameters:

  • path

    (str | Path, default: 'methodscript.mscr' ) –

    Path to methodscript file.

Source code in src/pypalmsens/_methods/techniques.py
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
def to_file(self, path: str | Path = 'methodscript.mscr') -> None:
    """Save script to file.

    Parameters
    ----------
    path: str | Path
        Path to methodscript file.
    """
    with Path(path).open('w') as f:
        _ = f.write(self.script)

from_url classmethod

from_url(url: str) -> MethodScript

Download script over http.

Parameters:

  • url

    (url) –

    URL to download methodscript file from.

Returns:

Source code in src/pypalmsens/_methods/techniques.py
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
@classmethod
def from_url(cls, url: str) -> MethodScript:
    """Download script over http.

    Parameters
    ----------
    url : url
        URL to download methodscript file from.

    Returns
    -------
    method: MethodScript
    """
    with urllib.request.urlopen(url) as response:
        script = response.read().decode()

    return cls(script=script)