예제 #1
0
def test_script():
    Script('name', 'print(2)')

    try:
        Script('0name', 'print(3)')
    except Exception:
        info_('name not valid')
예제 #2
0
def test_read_labspec():

    ramandir = Path('ramandata')
    scp.info_(ramandir)

    A = scp.read_labspec('Activation.txt', directory=ramandir)
    A.plot()

    A = scp.read_labspec('532nm-191216-Si 200mu.txt', directory=ramandir)
    A.plot()

    A = scp.read_labspec('serie190214-1.txt', directory=ramandir)
    A.plot(colorbar=True)
    A.plot_map(colorbar=True)

    A = scp.read_labspec('SMC1-Initial RT.txt', directory=ramandir)
    A.plot()

    B = scp.read(protocol='labspec', directory=ramandir)

    # this pack all spectra of the subdir directory
    B = scp.read_dir(directory=ramandir / 'subdir')
    B.plot()

    scp.show()
예제 #3
0
def test_script():
    Script("name", "print(2)")

    try:
        Script("0name", "print(3)")
    except Exception:
        info_("name not valid")
예제 #4
0
def test_NNMF():

    w1 = scp.NDDataset([[1, 2, 3], [4, 5, 6]])
    h1 = scp.NDDataset([[1, 2], [3, 4], [5, 6]])

    w2 = scp.NDDataset([[1, 1, 1], [4, 4, 4]])
    h2 = scp.NDDataset([[1, 1], [3, 3], [5, 5]])

    v = scp.dot(w1, h1)

    nnmf = scp.NNMF(v,
                    w2,
                    h2,
                    tol=0.0001,
                    maxtime=60,
                    maxiter=100,
                    verbose=True)

    scp.info_("------")
    scp.info_(nnmf.C)
    scp.info_("------")
    scp.info_(nnmf.St)

    assert_array_almost_equal(nnmf.C.data,
                              np.array([[1.4, 2.1, 2.9], [4.4, 5.2, 6.0]]),
                              decimal=1)
    assert_array_almost_equal(nnmf.St.data,
                              [[0.8, 1.9], [2.9, 3.9], [5.1, 5.9]],
                              decimal=1)
def test_read_carroucell(monkeypatch):

    # Before testing we need to download the data locally if not yet done:
    # because read carrousel is not designed to download itself.
    # Use the read_remote for that:
    NDDataset.read_remote("irdata/carroucell_samp", replace_existing=False)

    nd = NDDataset.read_carroucell("irdata/carroucell_samp", spectra=(1, 2))
    for x in nd:
        info_("  " + x.name + ": " + str(x.shape))
    assert len(nd) == 11
    assert nd[3].shape == (2, 11098)

    nd = NDDataset.read_carroucell("irdata/carroucell_samp", spectra=(1, 1))
    assert isinstance(nd, NDDataset)

    monkeypatch.setattr(spectrochempy.core, "open_dialog", dialog_carroucell)
    monkeypatch.setenv("KEEP_DIALOGS", "True")
    nd = NDDataset.read_carroucell(spectra=(1, 3))
    assert nd[3].shape == (3, 11098)

    nd = NDDataset.read_carroucell(spectra=(2, 3), discardbg=False)
    assert nd[3].shape == (2, 11098)
예제 #6
0
def test_logger(caplog):
    logger = logging.getLogger("SpectroChemPy")
    logger.propagate = True
    caplog.set_level(DEBUG)

    # We can set the level using strings
    set_loglevel("DEBUG")
    assert logger.handlers[0].level == INFO  # DEBUG only on the file
    assert logger.handlers[1].level == DEBUG

    set_loglevel(WARNING)
    assert logger.handlers[0].level == WARNING
    assert logger.handlers[1].level == WARNING

    error_("\n" + "*" * 80 + "\n")
    debug_("debug in WARNING level - should not appear")
    info_("info in WARNING level - should not appear")
    warning_("OK this is a Warning")
    error_("OK This is an Error")

    error_("\n" + "*" * 80 + "\n")

    set_loglevel(INFO)
    assert logger.handlers[0].level == INFO
    assert logger.handlers[1].level == INFO

    debug_("debug in INFO level - should not appear on stdout")
    info_("OK - info in INFO level")
    warning_("OK this is a Warning")
    error_("OK This is an Error")

    error_("\n" + "*" * 80 + "\n")

    set_loglevel("DEBUG")
    assert logger.handlers[0].level == INFO
    assert logger.handlers[1].level == DEBUG

    debug_("OK - debug in DEBUG level")
    info_("OK - info in DEBUG level")
    assert caplog.records[-1].levelname == "INFO"
    assert caplog.records[-1].message.endswith("OK - info in DEBUG level")
    warning_("OK this is a Warning")
    assert caplog.records[-1].levelname == "WARNING"
    assert caplog.records[-1].message.endswith("OK this is a Warning")
    error_("OK This is an Error")
    assert caplog.records[-1].levelname == "ERROR"
    assert caplog.records[-1].message.endswith("OK This is an Error")
예제 #7
0
def test_logger(caplog):
    logger = logging.getLogger('SpectroChemPy')
    logger.propagate = True
    caplog.set_level(logging.DEBUG)

    # We can set the level using strings
    set_loglevel("DEBUG")
    assert logger.level == logging.DEBUG

    set_loglevel(WARNING)
    assert logger.level == logging.WARNING

    error_('\n' + '*' * 80 + '\n')
    debug_('debug in WARNING level - should not appear')
    info_('info in WARNING level - should not appear')
    warning_('OK this is a Warning')
    error_('OK This is an Error')

    error_('\n' + '*' * 80 + '\n')

    set_loglevel(INFO)
    assert logger.level == logging.INFO

    debug_('debug in INFO level - should not appear')
    info_('OK - info in INFO level')
    warning_('OK this is a Warning')
    error_('OK This is an Error')

    error_('\n' + '*' * 80 + '\n')

    set_loglevel('DEBUG')
    assert logger.level == logging.DEBUG

    debug_('OK - debug in DEBUG level')
    info_('OK - info in DEBUG level')
    assert caplog.records[-1].levelname == 'INFO'
    assert caplog.records[-1].message == 'OK - info in DEBUG level'
    warning_('OK this is a Warning')
    assert caplog.records[-1].levelname == 'WARNING'
    assert caplog.records[-1].message == 'OK this is a Warning'
    error_('OK This is an Error')
    assert caplog.records[-1].levelname == 'ERROR'
    assert caplog.records[-1].message == 'OK This is an Error'
예제 #8
0
except Exception:
    pass

# %% [markdown]
# ## API Configuration
#
# Many options of the API can be set up

# %%
scp.set_loglevel(scp.INFO)

# %% [markdown]
# In the above cell, we have set the **log** level to display ``info`` messages, such as this one:

# %%
scp.info_('this is an info message!')
scp.debug_('this is a debug message!')

# %% [markdown]
# Only the info message is displayed, as expected.
#
# If we change it to ``DEBUG``, we should get the two messages

# %%
scp.set_loglevel(scp.DEBUG)

scp.info_('this is an info message!')
scp.debug_('this is a debug message!')

# %% [markdown]
# Let's now come back to a standard level of message for the rest of the Tutorial.
예제 #9
0
# %% [markdown]
# And  finally, the next instructions reset the loglevel to `WARNING` level (default), and print it.
# As seen below, no message `changed default log_level to ...` is delivered

# %%
scp.set_loglevel("WARNING")  # reset to default
print(f"New loglevel: {scp.get_loglevel()}")

# %% [markdown]
# It is also possible to issue such messages in scripts. In the cell below, we set the loglevel to `INFO` and try to
# print two types of messages:

# %%
scp.set_loglevel("INFO")
scp.info_("this is an info message!")
scp.debug_("this is a debug message!")

# %% [markdown]
# As expected, only the info message was displayed.
#
# If we change the loglevel to ``DEBUG``, then the two messages will be printed:

# %%
scp.set_loglevel(scp.DEBUG)
scp.info_("this is an info message!")
scp.debug_("this is a debug message!")

# %% [markdown]
# Finally, we come back to the standard level of message for the rest of the Tutorial -- in this case neither `DEBUG`
# nor `INFO` messages will be printed.