Welcome to base_bah’s documentation!

base_bah contains basic functions used in Python software from the Büro für Angewandte Hydrologie, Berlin. This package needs no other “heavy” packages, like numpy or pandas.

Contents:

Installing base_bah

base_bah should work on Python 3.6 (or later) on Windows, Linux or OS X.

The following command will build and install base_bah:

python setup.py install

Installing binary wheels with pip

Binary wheel distributions of base_bah are hosted on Pypi <https://bitbucket.org/BAH_Berlin/base_bah>_.

pip install base_bah

base_bah reference documentation.

Read

Functions

Read ArcEGMO configuration files and output

pegel_dbf(arcegmo_ste, hyd_stat)

Read the pegel.dbf, creates a relation between fgw and gauge in a dictionary.

pegel_RegType(arcegmo_ste, hyd_stat, fgw, ...)

Read the pegel.dbf, returns the position of a FGW in the file

arcegmo_ste(path_to_root, filename[, ...])

Read the arc_egmo.ste into a dictionary.

config(control[, read_what, proj_conf])

Read other configuration files from arc_egmo.

configurationFile([folder, filex])

Read the configuration file for MOO.

path_met_hyd_data(inp)

Return the further path for MET and HYD input data.

complete_config(path_to_root, filename[, ...])

Read more or less the whole configuration.

arcegmo_qc(control, config[, results_file])

Read the simulation results in excel mode.

arcegmo_qt(arcegmo_ste, config[, model])

Read the observation time series in excel mode.

sim_obs(qc, qt, relation[, starttime, ...])

Return simulation and observation time series with the same starting and ending times.

cf_name(basefolder, filename[, spec, critical])

Find the correct file name or directory name in the folder ignoring the case.

Classes

Parse the ArcEGMO configuration tree

Ae_config2(basefolder, ae_filename[, guide, ...])

Class that provides functionality to read the ArcEGMO confilguration file hierarchy.

Write

save_res_beo(obj, name)

saves the results or simulation dictionaries

load_res_beo(name)

loads the results or simulation dictionaries

configure_configfile(arcegmo_ste[, keyword, ...])

Configures arc_EGMO configuration files with new parameter values, parameters are given for specific sections in the file

y_TX_file(threadnumber, obj_fun)

writes the y_TX.txt file containing the objective function values and backup filename

write_logfile(threadnumber, obj_fun, path, ...)

writes the log file for each thread

overwrite_ae(arcegmo, config_, model)

ov3rride an arc_egmo.ste file to set another BERECHNUNGS_VARIANTE

arc_egmo_conf(compare, path_and_file[, ...])

writes a dictionary back into a configuration file, uses a template of the file

Format

Functions to format strings.

arcEGMOheader(selection_idx[, date])

compile an time header for ArcEGMO and format string

len2(variable)

assures that month or day are returned as %mm and are string

make_shape_two(item[, date, length, filler])

returns a string with a given length.

arcegmoDateFromDatetime(dtobj[, offset])

generates an arcEGMO time entry for hourly data.

update_progress(progress)

prints a nice status bar and updates it, if called again.

add_quotes_to_datecolumn(path, file)

Add back the quotes around the date columns like "01.01.2018 00:15" to ArcEGMO files.

strip_path(string)

strip leading and tailing slash and backslash from pathsegment

get_ending_number(string, where)

returns a number from the beginning or ending of a string

FTP

Class to handle downloads from a FTP-Server

MyFTP(FZ_serverD)

Class to download from FTP servers.

Download

Functions for downloading from the interwebs.

folder_ACC([local_folder, server, ...])

Download all files found in the given FTP-folder into a folder with a foldername derived from the ACC file in DWD forecast folder

folder([local_folder, server, ...])

Download all files found in the given FTP-folder

link(urlLink, filename[, timeout])

Download a file given the link.

https(urlLink[, filename, timeout, headers])

downloads a link to a file from a https site..

get_station_filename2(fo_list, station, mode)

Create the file name for a DWD weather station with 2 parameter.

get_url_content(url[, log_dict, parameter, ...])

get the folder contents --> get html file

Output

Functions to handle command line outputs

update_progress(progress)

prints a nice status bar and updates it, if called again.

PKL

Functions to create and read (gzip compressed) pickle files

save_obj_compressed(name, obj[, ending])

Saves a struct or list into a prickle binary file.

load_obj_compressed(name[, ending])

Loads a prickle binary file.

save_obj(name, obj[, ending])

Save a struct or list into a prickle binary file.

load_obj(name[, ending])

Load a prickle binary file.

Utilities

Functions

Random stuff

modify_and_import(module_name, package, ...)

Load and modify the source of a module.

Classification

Classification of dates

month_conv(month)

Return the month as int, for names or abbreviations.

ae_timestr_from_sec(sec)

Look up the time scale.

pandas_periode_from_sec(sec)

Return the pandas period string for value in seconds

pandas_periode_to_sec(inp)

Return the time in seconds for a pandas period string

Other classifications

code_lookup

Date

Functions for dates

roundTime([dt, roundTo])

Round a datetime object to any time laps in seconds

add_timedelta_sweeptimes(sweep_times, lag)

Add a lagtime to a list of dates.

months_between(date1, date2)

Return the number of months between date1 and date2

last_day_of_month(date)

Return the number of days in the month

from_to(tstart, tend, tdelta[, xformat])

Return a list of timesteps from <tstart> to <tend> of length <tdelta>

json_serial(obj)

JSON serializer for objects not serializable by default json code extended from here: https://stackoverflow.com/questions/11875770/how-to-overcome-datetime-datetime-not-json-serializable-in-python

DateTimeEncoder(*[, skipkeys, ensure_ascii, ...])

Class for JSON encodings of datetimes.

time_mhd(inp)

Return the timestep as string for the given int in seconds

doy(Y[, M, D])

Given year, month, day return day of year Astronomical Algorithms, Jean Meeus, 2d ed, 1998, chap 7

ymd(Y, N)

Given year = Y and day of year = N, return year, month, day Astronomical Algorithms, Jean Meeus, 2d ed, 1998, chap 7

woy(time_curr[, year])

Given a datetime or a list with doy and year, lookup the week of the year

full_steps_timediff(d1, d2)

Calculate the timesteps in weeks, months and days between 2 dates.

calc_period(ss, se)

Return two list with months (seasons) such that ss is the beginning of the first season and se the end of the first season.

is_leap_year(year)

If year is a leap year return True else return False

License

Software

base_bah is licensed under the GNU General Public License, Version 3.0 or later.

Copyright (C) 2018-2020 Ruben Müller, Büro für Angewandte Hydrologie, Berlin

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.

Documentation

This documentation is licensed under the GNU Free Documentation License, Version 1.3 or later.

Copyright (C) 2018-2020 Ruben Müller, Büro für Angewandte Hydrologie, Berlin

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”.