simudo.util package¶
Submodules¶
simudo.util.attrproxy module¶
simudo.util.base32_token module¶
simudo.util.blackbody module¶
- class simudo.util.blackbody.Blackbody(temperature)[source]¶
Bases:
object- distance_factor¶
- geometric_factor¶
- non_overlapping_energy_ranges(energies, inf=None)[source]¶
Helper method for computing non-overlapping energy ranges.
- Parameters:
energies (dict) – Mapping where keys are arbitrary (typically: names of transitions or optical fields), and values are energy range lower bounds.
inf (optional) – Upper limit on energy. By default, 20 eV.
- Returns:
ranges – Mapping with the same keys as the
energiesargument, and where the values are tuples(lower, upper)such that the lower bound is equal toenergies[k], and the upper bound is the smallest energy that is abovelower. If none exists, thenupperis theinfargument.- Return type:
dict
- photon_flux_integral_on_earth(E0, E1)[source]¶
Assuming an observer at normal incidence on Earth, compute the photon flux coming from a black sun in a given energy range.
- Parameters:
E0 – Lower bound on photon energy.
E1 – Upper bound on photon energy.
- Returns:
photon_flux – Photon flux.
- Return type:
quantity
- property u¶
simudo.util.cartesian_product module¶
simudo.util.latex module¶
simudo.util.logging module¶
- class simudo.util.logging.NameLevelFilter(name_levelno_rules, *args, **kwargs)[source]¶
Bases:
Filter
- class simudo.util.logging.TypicalLoggingSetup(**kwargs)[source]¶
Bases:
SetattrInitMixinClass that sets up logging and filtering in a typical way for Simudo.
- Parameters:
dolfin (bool, optional) – Configure the dolfin log level as well. Note that this imports
dolfin, which takes a while. Only use it if you’re okay with that. (default: True)truncate (bool, optional) – Truncate (delete) the log file contents before starting to write to it. (default: True)
delta_time (bool, optional) – Output both the actual time as well as the time since the logger was created with all logs. (default: False)
collapse_repeated_warnings (bool, optional) – Show each distinct warning once instead of every time it is raised (default: True). See
setup_warnings(). Set the environment variableSIMUDO_ALL_WARNINGS=1to force this off without editing code – useful for the GUI, which launches the runner as a subprocess.
- collapse_repeated_warnings = True¶
- console_formatter¶
- property debug_filename¶
- delta_time = True¶
- dolfin = True¶
- property info_filename¶
- logfile_formatter¶
- setup_warnings()[source]¶
Send warnings to the log, and show each distinct one only once.
Python already shows a given warning once per location; that is the default
DeprecationWarningaction. FEniCS takes it away process-wide:FIAT/check_format_variant.pycallswarnings.simplefilter('always', DeprecationWarning)at module level – not insidecatch_warnings– so that its own notice cannot be missed. Every warning in the process then repeats on every occurrence. In one GUI run that is 53k lines, mostly ffc calling the deprecatednumpy.productonce per generated expression, which overruns the Simulation panel’s 5000-line buffer and pushes out the solver output the user actually wants.Filters cannot fix this reliably:
simplefilterinserts at the front of the list, so anything set here can be overridden by a later call in third-party code.showwarningruns after filtering, so it always gets a say.This restores the standard behaviour rather than suppressing anything: the first occurrence of each
(category, filename, lineno)is reported in full, and only exact repeats are dropped. Warnings go to thepy.warningslogger so they carry timestamps and reach the log file and the GUI panel like everything else.
- stream_console¶
- stream_debug¶
- stream_info¶
- truncate = True¶
simudo.util.name_dict module¶
simudo.util.os module¶
- simudo.util.os.dir_as_prefix(path)[source]¶
Add the final path separator (“/”) if necessary.
For example:
"abc/def" -> "abc/def/" "abc/def/" -> "abc/def/"
- simudo.util.os.outdir_path_helper(path)[source]¶
Calls
mkdirp(), then returnsdir_as_prefix()applied on path.
simudo.util.pint module¶
simudo.util.raise_from module¶
simudo.util.raise_from_py3 module¶
simudo.util.setattr_init_mixin module¶
simudo.util.string_system module¶
simudo.util.todo module¶
simudo.util.with_default_kwargs module¶
- simudo.util.with_default_kwargs.with_default_kwargs()[source]¶
Python doesn’t like it if we pass the same argument by an explicit kwarg and through **kwargs, e.g.,
f(y=3, **{'x': 4, 'y': 5}).This decorator transforms a function so that it receives a default dict of kwargs through its first argument, then remaining kwargs normally (latter taking precedence over the former).
Assuming f was decorated with this wrapper, the call above becomes
f({'x': 4, 'y':5}, y=3).You can (ab)use this function to be lazy and pass all the local variables to a function as kwargs, and still have the option of overriding some of them, e.g.,
f(locals(), y=3).
simudo.util.xcsv module¶
This (standalone) module implements a Pandas CSV reader-writer pair
that allows data types to survive a round-trip (where they wouldn’t
using plain pandas to_csv). It achieves this by saving some column
metadata to JSON, and by prefixing string values with a “:” character
so that they cannot be confused with NaN values (which are also
allowed in string columns, creating unresolvable ambiguity in the
written data).
See to_csv() and read_csv() for more info.
These methods are available as simple functions, so you can do:
>>> to_xcsv(df, "hello.csv")
>>> df2, meta = from_xcsv(df, "hello.csv")
- class simudo.util.xcsv.XCSV[source]¶
Bases:
object- reader_class¶
alias of
XCSVReader
- classmethod to_csv(df, path, json_path=None, to_csv_kwargs={})[source]¶
Basically the same as
pandas.DataFrame.to_csv(), but with proper escaping for strings to prevent them from being accidentally parsed as numbers or nan, and with column dtypes being written to an accompanying json file.If the csv filename is
"a.csv", then the file name containing the metadata will be called"a.csv_meta.json".“XCSV” pronounced “excessive”.
Warning: mixed-type (“object”) columns are assumed to be string columns. So make sure those don’t contain anything other than strings or NaN, or your else your data might not survive the roundtrip test.
What’s definitely safe:
Columns with floats/ints and nans.
Columns with strings and nans.
Columns with booleans (no nans allowed!).
- writer_class¶
alias of
XCSVWriter
- class simudo.util.xcsv.XCSVReader[source]¶
Bases:
XCSVBase- dtypes_dict¶
- meta¶
- string_columns¶
- string_prefix¶
- string_prefix_re¶
- class simudo.util.xcsv.XCSVWriter[source]¶
Bases:
XCSVBase- dtypes_dict¶
- meta¶
- string_columns¶
- property string_prefix¶
- simudo.util.xcsv.read_xcsv(path, json_path=None, read_csv_kwargs={})¶
Opposite of
to_csv().
- simudo.util.xcsv.to_xcsv(df, path, json_path=None, to_csv_kwargs={})¶
Basically the same as
pandas.DataFrame.to_csv(), but with proper escaping for strings to prevent them from being accidentally parsed as numbers or nan, and with column dtypes being written to an accompanying json file.If the csv filename is
"a.csv", then the file name containing the metadata will be called"a.csv_meta.json".“XCSV” pronounced “excessive”.
Warning: mixed-type (“object”) columns are assumed to be string columns. So make sure those don’t contain anything other than strings or NaN, or your else your data might not survive the roundtrip test.
What’s definitely safe:
Columns with floats/ints and nans.
Columns with strings and nans.
Columns with booleans (no nans allowed!).