repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
39
1.84M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Auth.connect
def connect(self): """|coro| Connect to ubisoft, automatically called when needed""" if time.time() < self._login_cooldown: raise FailedToConnect("login on cooldown") resp = yield from self.session.post("https://connect.ubi.com/ubiservices/v2/profiles/sessions", headers = { "Content-Type": "application/json", "Ubi-AppId": self.appid, "Authorization": "Basic " + self.token }, data=json.dumps({"rememberMe": True})) data = yield from resp.json() if "ticket" in data: self.key = data.get("ticket") self.sessionid = data.get("sessionId") self.uncertain_spaceid = data.get("spaceId") else: raise FailedToConnect
python
def connect(self): if time.time() < self._login_cooldown: raise FailedToConnect("login on cooldown") resp = yield from self.session.post("https://connect.ubi.com/ubiservices/v2/profiles/sessions", headers = { "Content-Type": "application/json", "Ubi-AppId": self.appid, "Authorization": "Basic " + self.token }, data=json.dumps({"rememberMe": True})) data = yield from resp.json() if "ticket" in data: self.key = data.get("ticket") self.sessionid = data.get("sessionId") self.uncertain_spaceid = data.get("spaceId") else: raise FailedToConnect
[ "def", "connect", "(", "self", ")", ":", "if", "time", ".", "time", "(", ")", "<", "self", ".", "_login_cooldown", ":", "raise", "FailedToConnect", "(", "\"login on cooldown\"", ")", "resp", "=", "yield", "from", "self", ".", "session", ".", "post", "(", "\"https://connect.ubi.com/ubiservices/v2/profiles/sessions\"", ",", "headers", "=", "{", "\"Content-Type\"", ":", "\"application/json\"", ",", "\"Ubi-AppId\"", ":", "self", ".", "appid", ",", "\"Authorization\"", ":", "\"Basic \"", "+", "self", ".", "token", "}", ",", "data", "=", "json", ".", "dumps", "(", "{", "\"rememberMe\"", ":", "True", "}", ")", ")", "data", "=", "yield", "from", "resp", ".", "json", "(", ")", "if", "\"ticket\"", "in", "data", ":", "self", ".", "key", "=", "data", ".", "get", "(", "\"ticket\"", ")", "self", ".", "sessionid", "=", "data", ".", "get", "(", "\"sessionId\"", ")", "self", ".", "uncertain_spaceid", "=", "data", ".", "get", "(", "\"spaceId\"", ")", "else", ":", "raise", "FailedToConnect" ]
|coro| Connect to ubisoft, automatically called when needed
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L378-L398
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Auth.get_players
def get_players(self, name=None, platform=None, uid=None): """|coro| get a list of players matching the term on that platform, exactly one of uid and name must be given, platform must be given, this list almost always has only 1 element, so it's easier to use get_player Parameters ---------- name : str the name of the player you're searching for platform : str the name of the platform you're searching on (See :class:`Platforms`) uid : str the uid of the player you're searching for Returns ------- list[:class:`Player`] list of found players""" if name is None and uid is None: raise TypeError("name and uid are both None, exactly one must be given") if name is not None and uid is not None: raise TypeError("cannot search by uid and name at the same time, please give one or the other") if platform is None: raise TypeError("platform cannot be None") if "platform" not in self.cache: self.cache[platform] = {} if name: cache_key = "NAME:%s" % name else: cache_key = "UID:%s" % uid if cache_key in self.cache[platform]: if self.cachetime > 0 and self.cache[platform][cache_key][0] < time.time(): del self.cache[platform][cache_key] else: return self.cache[platform][cache_key][1] if name: data = yield from self.get("https://public-ubiservices.ubi.com/v2/profiles?nameOnPlatform=%s&platformType=%s" % (parse.quote(name), parse.quote(platform))) else: data = yield from self.get("https://public-ubiservices.ubi.com/v2/users/%s/profiles?platformType=%s" % (uid, parse.quote(platform))) if "profiles" in data: results = [Player(self, x) for x in data["profiles"] if x.get("platformType", "") == platform] if len(results) == 0: raise InvalidRequest("No results") if self.cachetime != 0: self.cache[platform][cache_key] = [time.time() + self.cachetime, results] return results else: raise InvalidRequest("Missing key profiles in returned JSON object %s" % str(data))
python
def get_players(self, name=None, platform=None, uid=None): if name is None and uid is None: raise TypeError("name and uid are both None, exactly one must be given") if name is not None and uid is not None: raise TypeError("cannot search by uid and name at the same time, please give one or the other") if platform is None: raise TypeError("platform cannot be None") if "platform" not in self.cache: self.cache[platform] = {} if name: cache_key = "NAME:%s" % name else: cache_key = "UID:%s" % uid if cache_key in self.cache[platform]: if self.cachetime > 0 and self.cache[platform][cache_key][0] < time.time(): del self.cache[platform][cache_key] else: return self.cache[platform][cache_key][1] if name: data = yield from self.get("https://public-ubiservices.ubi.com/v2/profiles?nameOnPlatform=%s&platformType=%s" % (parse.quote(name), parse.quote(platform))) else: data = yield from self.get("https://public-ubiservices.ubi.com/v2/users/%s/profiles?platformType=%s" % (uid, parse.quote(platform))) if "profiles" in data: results = [Player(self, x) for x in data["profiles"] if x.get("platformType", "") == platform] if len(results) == 0: raise InvalidRequest("No results") if self.cachetime != 0: self.cache[platform][cache_key] = [time.time() + self.cachetime, results] return results else: raise InvalidRequest("Missing key profiles in returned JSON object %s" % str(data))
[ "def", "get_players", "(", "self", ",", "name", "=", "None", ",", "platform", "=", "None", ",", "uid", "=", "None", ")", ":", "if", "name", "is", "None", "and", "uid", "is", "None", ":", "raise", "TypeError", "(", "\"name and uid are both None, exactly one must be given\"", ")", "if", "name", "is", "not", "None", "and", "uid", "is", "not", "None", ":", "raise", "TypeError", "(", "\"cannot search by uid and name at the same time, please give one or the other\"", ")", "if", "platform", "is", "None", ":", "raise", "TypeError", "(", "\"platform cannot be None\"", ")", "if", "\"platform\"", "not", "in", "self", ".", "cache", ":", "self", ".", "cache", "[", "platform", "]", "=", "{", "}", "if", "name", ":", "cache_key", "=", "\"NAME:%s\"", "%", "name", "else", ":", "cache_key", "=", "\"UID:%s\"", "%", "uid", "if", "cache_key", "in", "self", ".", "cache", "[", "platform", "]", ":", "if", "self", ".", "cachetime", ">", "0", "and", "self", ".", "cache", "[", "platform", "]", "[", "cache_key", "]", "[", "0", "]", "<", "time", ".", "time", "(", ")", ":", "del", "self", ".", "cache", "[", "platform", "]", "[", "cache_key", "]", "else", ":", "return", "self", ".", "cache", "[", "platform", "]", "[", "cache_key", "]", "[", "1", "]", "if", "name", ":", "data", "=", "yield", "from", "self", ".", "get", "(", "\"https://public-ubiservices.ubi.com/v2/profiles?nameOnPlatform=%s&platformType=%s\"", "%", "(", "parse", ".", "quote", "(", "name", ")", ",", "parse", ".", "quote", "(", "platform", ")", ")", ")", "else", ":", "data", "=", "yield", "from", "self", ".", "get", "(", "\"https://public-ubiservices.ubi.com/v2/users/%s/profiles?platformType=%s\"", "%", "(", "uid", ",", "parse", ".", "quote", "(", "platform", ")", ")", ")", "if", "\"profiles\"", "in", "data", ":", "results", "=", "[", "Player", "(", "self", ",", "x", ")", "for", "x", "in", "data", "[", "\"profiles\"", "]", "if", "x", ".", "get", "(", "\"platformType\"", ",", "\"\"", ")", "==", "platform", "]", "if", "len", "(", "results", ")", "==", "0", ":", "raise", "InvalidRequest", "(", "\"No results\"", ")", "if", "self", ".", "cachetime", "!=", "0", ":", "self", ".", "cache", "[", "platform", "]", "[", "cache_key", "]", "=", "[", "time", ".", "time", "(", ")", "+", "self", ".", "cachetime", ",", "results", "]", "return", "results", "else", ":", "raise", "InvalidRequest", "(", "\"Missing key profiles in returned JSON object %s\"", "%", "str", "(", "data", ")", ")" ]
|coro| get a list of players matching the term on that platform, exactly one of uid and name must be given, platform must be given, this list almost always has only 1 element, so it's easier to use get_player Parameters ---------- name : str the name of the player you're searching for platform : str the name of the platform you're searching on (See :class:`Platforms`) uid : str the uid of the player you're searching for Returns ------- list[:class:`Player`] list of found players
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L460-L515
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Auth.get_player
def get_player(self, name=None, platform=None, uid=None): """|coro| Calls get_players and returns the first element, exactly one of uid and name must be given, platform must be given Parameters ---------- name : str the name of the player you're searching for platform : str the name of the platform you're searching on (See :class:`Platforms`) uid : str the uid of the player you're searching for Returns ------- :class:`Player` player found""" results = yield from self.get_players(name=name, platform=platform, uid=uid) return results[0]
python
def get_player(self, name=None, platform=None, uid=None): results = yield from self.get_players(name=name, platform=platform, uid=uid) return results[0]
[ "def", "get_player", "(", "self", ",", "name", "=", "None", ",", "platform", "=", "None", ",", "uid", "=", "None", ")", ":", "results", "=", "yield", "from", "self", ".", "get_players", "(", "name", "=", "name", ",", "platform", "=", "platform", ",", "uid", "=", "uid", ")", "return", "results", "[", "0", "]" ]
|coro| Calls get_players and returns the first element, exactly one of uid and name must be given, platform must be given Parameters ---------- name : str the name of the player you're searching for platform : str the name of the platform you're searching on (See :class:`Platforms`) uid : str the uid of the player you're searching for Returns ------- :class:`Player` player found
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L518-L539
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Auth.get_operator_definitions
def get_operator_definitions(self): """|coro| Retrieves a list of information about operators - their badge, unique statistic, etc. Returns ------- dict operators""" if self._op_definitions is not None: return self._op_definitions resp = yield from self.session.get("https://game-rainbow6.ubi.com/assets/data/operators.24b865895.json") data = yield from resp.json() self._op_definitions = data return data
python
def get_operator_definitions(self): if self._op_definitions is not None: return self._op_definitions resp = yield from self.session.get("https://game-rainbow6.ubi.com/assets/data/operators.24b865895.json") data = yield from resp.json() self._op_definitions = data return data
[ "def", "get_operator_definitions", "(", "self", ")", ":", "if", "self", ".", "_op_definitions", "is", "not", "None", ":", "return", "self", ".", "_op_definitions", "resp", "=", "yield", "from", "self", ".", "session", ".", "get", "(", "\"https://game-rainbow6.ubi.com/assets/data/operators.24b865895.json\"", ")", "data", "=", "yield", "from", "resp", ".", "json", "(", ")", "self", ".", "_op_definitions", "=", "data", "return", "data" ]
|coro| Retrieves a list of information about operators - their badge, unique statistic, etc. Returns ------- dict operators
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L542-L558
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Auth.get_operator_index
def get_operator_index(self, name): """|coro| Gets the operators index from the operator definitions dict Returns ------- str the operator index""" opdefs = yield from self.get_operator_definitions() name = name.lower() if name not in opdefs: return None return opdefs[name]["index"]
python
def get_operator_index(self, name): opdefs = yield from self.get_operator_definitions() name = name.lower() if name not in opdefs: return None return opdefs[name]["index"]
[ "def", "get_operator_index", "(", "self", ",", "name", ")", ":", "opdefs", "=", "yield", "from", "self", ".", "get_operator_definitions", "(", ")", "name", "=", "name", ".", "lower", "(", ")", "if", "name", "not", "in", "opdefs", ":", "return", "None", "return", "opdefs", "[", "name", "]", "[", "\"index\"", "]" ]
|coro| Gets the operators index from the operator definitions dict Returns ------- str the operator index
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L561-L576
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Auth.get_operator_statistic
def get_operator_statistic(self, name): """|coro| Gets the operator unique statistic from the operator definitions dict Returns ------- str the name of the operator unique statistic""" opdefs = yield from self.get_operator_definitions() name = name.lower() if name not in opdefs: return None # some operators (e.g. Kaid and Nomad) don't have a unique statistic sectoin for some reason... if "uniqueStatistic" not in opdefs[name] or "pvp" not in opdefs[name]["uniqueStatistic"]: return None return opdefs[name]["uniqueStatistic"]["pvp"]["statisticId"]
python
def get_operator_statistic(self, name): opdefs = yield from self.get_operator_definitions() name = name.lower() if name not in opdefs: return None if "uniqueStatistic" not in opdefs[name] or "pvp" not in opdefs[name]["uniqueStatistic"]: return None return opdefs[name]["uniqueStatistic"]["pvp"]["statisticId"]
[ "def", "get_operator_statistic", "(", "self", ",", "name", ")", ":", "opdefs", "=", "yield", "from", "self", ".", "get_operator_definitions", "(", ")", "name", "=", "name", ".", "lower", "(", ")", "if", "name", "not", "in", "opdefs", ":", "return", "None", "# some operators (e.g. Kaid and Nomad) don't have a unique statistic sectoin for some reason...", "if", "\"uniqueStatistic\"", "not", "in", "opdefs", "[", "name", "]", "or", "\"pvp\"", "not", "in", "opdefs", "[", "name", "]", "[", "\"uniqueStatistic\"", "]", ":", "return", "None", "return", "opdefs", "[", "name", "]", "[", "\"uniqueStatistic\"", "]", "[", "\"pvp\"", "]", "[", "\"statisticId\"", "]" ]
|coro| Gets the operator unique statistic from the operator definitions dict Returns ------- str the name of the operator unique statistic
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L579-L598
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Auth.get_operator_badge
def get_operator_badge(self, name): """|coro| Gets the operator badge URL Returns ------- str the operators badge URL""" opdefs = yield from self.get_operator_definitions() name = name.lower() if name not in opdefs: return None badge = opdefs[name]["badge"] if not badge.startswith("http"): badge = "https://game-rainbow6.ubi.com/" + badge return badge
python
def get_operator_badge(self, name): opdefs = yield from self.get_operator_definitions() name = name.lower() if name not in opdefs: return None badge = opdefs[name]["badge"] if not badge.startswith("http"): badge = "https://game-rainbow6.ubi.com/" + badge return badge
[ "def", "get_operator_badge", "(", "self", ",", "name", ")", ":", "opdefs", "=", "yield", "from", "self", ".", "get_operator_definitions", "(", ")", "name", "=", "name", ".", "lower", "(", ")", "if", "name", "not", "in", "opdefs", ":", "return", "None", "badge", "=", "opdefs", "[", "name", "]", "[", "\"badge\"", "]", "if", "not", "badge", ".", "startswith", "(", "\"http\"", ")", ":", "badge", "=", "\"https://game-rainbow6.ubi.com/\"", "+", "badge", "return", "badge" ]
|coro| Gets the operator badge URL Returns ------- str the operators badge URL
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L601-L621
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Auth.get_definitions
def get_definitions(self): """|coro| Retrieves the list of api definitions, downloading it from Ubisoft if it hasn't been fetched all ready Primarily for internal use, but could contain useful information. Returns ------- dict definitions""" if self._definitions is not None: return self._definitions resp = yield from self.session.get("https://ubistatic-a.akamaihd.net/0058/prod/assets/data/statistics.definitions.eb165e13.json") data = yield from resp.json() self._definitions = data return data
python
def get_definitions(self): if self._definitions is not None: return self._definitions resp = yield from self.session.get("https://ubistatic-a.akamaihd.net/0058/prod/assets/data/statistics.definitions.eb165e13.json") data = yield from resp.json() self._definitions = data return data
[ "def", "get_definitions", "(", "self", ")", ":", "if", "self", ".", "_definitions", "is", "not", "None", ":", "return", "self", ".", "_definitions", "resp", "=", "yield", "from", "self", ".", "session", ".", "get", "(", "\"https://ubistatic-a.akamaihd.net/0058/prod/assets/data/statistics.definitions.eb165e13.json\"", ")", "data", "=", "yield", "from", "resp", ".", "json", "(", ")", "self", ".", "_definitions", "=", "data", "return", "data" ]
|coro| Retrieves the list of api definitions, downloading it from Ubisoft if it hasn't been fetched all ready Primarily for internal use, but could contain useful information. Returns ------- dict definitions
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L625-L642
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Auth.get_object_index
def get_object_index(self, key): """|coro| Mainly for internal use with get_operator, returns the "location" index for the key in the definitions Returns ------- str the object's location index""" defns = yield from self.get_definitions() for x in defns: if key in x and "objectIndex" in defns[x]: return defns[x]["objectIndex"] return None
python
def get_object_index(self, key): defns = yield from self.get_definitions() for x in defns: if key in x and "objectIndex" in defns[x]: return defns[x]["objectIndex"] return None
[ "def", "get_object_index", "(", "self", ",", "key", ")", ":", "defns", "=", "yield", "from", "self", ".", "get_definitions", "(", ")", "for", "x", "in", "defns", ":", "if", "key", "in", "x", "and", "\"objectIndex\"", "in", "defns", "[", "x", "]", ":", "return", "defns", "[", "x", "]", "[", "\"objectIndex\"", "]", "return", "None" ]
|coro| Mainly for internal use with get_operator, returns the "location" index for the key in the definitions Returns ------- str the object's location index
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L645-L661
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Rank.get_charm_url
def get_charm_url(self): """Get charm URL for the bracket this rank is in Returns ------- :class:`str` the URL for the charm """ if self.rank_id <= 4: return self.RANK_CHARMS[0] if self.rank_id <= 8: return self.RANK_CHARMS[1] if self.rank_id <= 12: return self.RANK_CHARMS[2] if self.rank_id <= 16: return self.RANK_CHARMS[3] if self.rank_id <= 19: return self.RANK_CHARMS[4] return self.RANK_CHARMS[5]
python
def get_charm_url(self): if self.rank_id <= 4: return self.RANK_CHARMS[0] if self.rank_id <= 8: return self.RANK_CHARMS[1] if self.rank_id <= 12: return self.RANK_CHARMS[2] if self.rank_id <= 16: return self.RANK_CHARMS[3] if self.rank_id <= 19: return self.RANK_CHARMS[4] return self.RANK_CHARMS[5]
[ "def", "get_charm_url", "(", "self", ")", ":", "if", "self", ".", "rank_id", "<=", "4", ":", "return", "self", ".", "RANK_CHARMS", "[", "0", "]", "if", "self", ".", "rank_id", "<=", "8", ":", "return", "self", ".", "RANK_CHARMS", "[", "1", "]", "if", "self", ".", "rank_id", "<=", "12", ":", "return", "self", ".", "RANK_CHARMS", "[", "2", "]", "if", "self", ".", "rank_id", "<=", "16", ":", "return", "self", ".", "RANK_CHARMS", "[", "3", "]", "if", "self", ".", "rank_id", "<=", "19", ":", "return", "self", ".", "RANK_CHARMS", "[", "4", "]", "return", "self", ".", "RANK_CHARMS", "[", "5", "]" ]
Get charm URL for the bracket this rank is in Returns ------- :class:`str` the URL for the charm
[ "Get", "charm", "URL", "for", "the", "bracket", "this", "rank", "is", "in" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L808-L822
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Player.load_level
def load_level(self): """|coro| Load the players XP and level""" data = yield from self.auth.get("https://public-ubiservices.ubi.com/v1/spaces/%s/sandboxes/%s/r6playerprofile/playerprofile/progressions?profile_ids=%s" % (self.spaceid, self.platform_url, self.id)) if "player_profiles" in data and len(data["player_profiles"]) > 0: self.xp = data["player_profiles"][0].get("xp", 0) self.level = data["player_profiles"][0].get("level", 0) else: raise InvalidRequest("Missing key player_profiles in returned JSON object %s" % str(data))
python
def load_level(self): data = yield from self.auth.get("https://public-ubiservices.ubi.com/v1/spaces/%s/sandboxes/%s/r6playerprofile/playerprofile/progressions?profile_ids=%s" % (self.spaceid, self.platform_url, self.id)) if "player_profiles" in data and len(data["player_profiles"]) > 0: self.xp = data["player_profiles"][0].get("xp", 0) self.level = data["player_profiles"][0].get("level", 0) else: raise InvalidRequest("Missing key player_profiles in returned JSON object %s" % str(data))
[ "def", "load_level", "(", "self", ")", ":", "data", "=", "yield", "from", "self", ".", "auth", ".", "get", "(", "\"https://public-ubiservices.ubi.com/v1/spaces/%s/sandboxes/%s/r6playerprofile/playerprofile/progressions?profile_ids=%s\"", "%", "(", "self", ".", "spaceid", ",", "self", ".", "platform_url", ",", "self", ".", "id", ")", ")", "if", "\"player_profiles\"", "in", "data", "and", "len", "(", "data", "[", "\"player_profiles\"", "]", ")", ">", "0", ":", "self", ".", "xp", "=", "data", "[", "\"player_profiles\"", "]", "[", "0", "]", ".", "get", "(", "\"xp\"", ",", "0", ")", "self", ".", "level", "=", "data", "[", "\"player_profiles\"", "]", "[", "0", "]", ".", "get", "(", "\"level\"", ",", "0", ")", "else", ":", "raise", "InvalidRequest", "(", "\"Missing key player_profiles in returned JSON object %s\"", "%", "str", "(", "data", ")", ")" ]
|coro| Load the players XP and level
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L1093-L1103
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Player.load_rank
def load_rank(self, region, season=-1): """|coro| Loads the players rank for this region and season Parameters ---------- region : str the name of the region you want to get the rank for season : Optional[int] the season you want to get the rank for (defaults to -1, latest season) Returns ------- :class:`Rank` the players rank for this region and season""" data = yield from self.auth.get("https://public-ubiservices.ubi.com/v1/spaces/%s/sandboxes/%s/r6karma/players?board_id=pvp_ranked&profile_ids=%s&region_id=%s&season_id=%s" % (self.spaceid, self.platform_url, self.id, region, season)) if "players" in data and self.id in data["players"]: regionkey = "%s:%s" % (region, season) self.ranks[regionkey] = Rank(data["players"][self.id]) return self.ranks[regionkey] else: raise InvalidRequest("Missing players key in returned JSON object %s" % str(data))
python
def load_rank(self, region, season=-1): data = yield from self.auth.get("https://public-ubiservices.ubi.com/v1/spaces/%s/sandboxes/%s/r6karma/players?board_id=pvp_ranked&profile_ids=%s&region_id=%s&season_id=%s" % (self.spaceid, self.platform_url, self.id, region, season)) if "players" in data and self.id in data["players"]: regionkey = "%s:%s" % (region, season) self.ranks[regionkey] = Rank(data["players"][self.id]) return self.ranks[regionkey] else: raise InvalidRequest("Missing players key in returned JSON object %s" % str(data))
[ "def", "load_rank", "(", "self", ",", "region", ",", "season", "=", "-", "1", ")", ":", "data", "=", "yield", "from", "self", ".", "auth", ".", "get", "(", "\"https://public-ubiservices.ubi.com/v1/spaces/%s/sandboxes/%s/r6karma/players?board_id=pvp_ranked&profile_ids=%s&region_id=%s&season_id=%s\"", "%", "(", "self", ".", "spaceid", ",", "self", ".", "platform_url", ",", "self", ".", "id", ",", "region", ",", "season", ")", ")", "if", "\"players\"", "in", "data", "and", "self", ".", "id", "in", "data", "[", "\"players\"", "]", ":", "regionkey", "=", "\"%s:%s\"", "%", "(", "region", ",", "season", ")", "self", ".", "ranks", "[", "regionkey", "]", "=", "Rank", "(", "data", "[", "\"players\"", "]", "[", "self", ".", "id", "]", ")", "return", "self", ".", "ranks", "[", "regionkey", "]", "else", ":", "raise", "InvalidRequest", "(", "\"Missing players key in returned JSON object %s\"", "%", "str", "(", "data", ")", ")" ]
|coro| Loads the players rank for this region and season Parameters ---------- region : str the name of the region you want to get the rank for season : Optional[int] the season you want to get the rank for (defaults to -1, latest season) Returns ------- :class:`Rank` the players rank for this region and season
[ "|coro|", "Loads", "the", "players", "rank", "for", "this", "region", "and", "season" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L1114-L1136
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Player.get_rank
def get_rank(self, region, season=-1): """|coro| Checks the players rank for this region, only loading it if it hasn't already been found Parameters ---------- region : str the name of the region you want to get the rank for season : Optional[int] the season you want to get the rank for (defaults to -1, latest season) Returns ------- :class:`Rank` the players rank for this region and season""" cache_key = "%s:%s" % (region, season) if cache_key in self.ranks: return self.ranks[cache_key] result = yield from self.load_rank(region, season) return result
python
def get_rank(self, region, season=-1): cache_key = "%s:%s" % (region, season) if cache_key in self.ranks: return self.ranks[cache_key] result = yield from self.load_rank(region, season) return result
[ "def", "get_rank", "(", "self", ",", "region", ",", "season", "=", "-", "1", ")", ":", "cache_key", "=", "\"%s:%s\"", "%", "(", "region", ",", "season", ")", "if", "cache_key", "in", "self", ".", "ranks", ":", "return", "self", ".", "ranks", "[", "cache_key", "]", "result", "=", "yield", "from", "self", ".", "load_rank", "(", "region", ",", "season", ")", "return", "result" ]
|coro| Checks the players rank for this region, only loading it if it hasn't already been found Parameters ---------- region : str the name of the region you want to get the rank for season : Optional[int] the season you want to get the rank for (defaults to -1, latest season) Returns ------- :class:`Rank` the players rank for this region and season
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L1139-L1160
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Player.load_all_operators
def load_all_operators(self): """|coro| Loads the player stats for all operators Returns ------- dict[:class:`Operator`] the dictionary of all operators found""" statistics = "operatorpvp_kills,operatorpvp_death,operatorpvp_roundwon,operatorpvp_roundlost,operatorpvp_meleekills,operatorpvp_totalxp,operatorpvp_headshot,operatorpvp_timeplayed,operatorpvp_dbno" for operator in OperatorStatisticNames: operator_key = yield from self.auth.get_operator_statistic(operator) if operator_key: statistics += "," + operator_key data = yield from self.auth.get("https://public-ubiservices.ubi.com/v1/spaces/%s/sandboxes/%s/playerstats2/statistics?populations=%s&statistics=%s" % (self.spaceid, self.platform_url, self.id, statistics)) if "results" not in data or not self.id in data["results"]: raise InvalidRequest("Missing results key in returned JSON object %s" % str(data)) data = data["results"][self.id] for operator in OperatorStatisticNames: location = yield from self.auth.get_operator_index(operator.lower()) op_data = {x.split(":")[0].split("_")[1]: data[x] for x in data if x is not None and location in x} operator_key = yield from self.auth.get_operator_statistic(operator) if operator_key: op_data["__statistic_name"] = operator_key.split("_")[1] self.operators[operator.lower()] = Operator(operator.lower(), op_data) return self.operators
python
def load_all_operators(self): statistics = "operatorpvp_kills,operatorpvp_death,operatorpvp_roundwon,operatorpvp_roundlost,operatorpvp_meleekills,operatorpvp_totalxp,operatorpvp_headshot,operatorpvp_timeplayed,operatorpvp_dbno" for operator in OperatorStatisticNames: operator_key = yield from self.auth.get_operator_statistic(operator) if operator_key: statistics += "," + operator_key data = yield from self.auth.get("https://public-ubiservices.ubi.com/v1/spaces/%s/sandboxes/%s/playerstats2/statistics?populations=%s&statistics=%s" % (self.spaceid, self.platform_url, self.id, statistics)) if "results" not in data or not self.id in data["results"]: raise InvalidRequest("Missing results key in returned JSON object %s" % str(data)) data = data["results"][self.id] for operator in OperatorStatisticNames: location = yield from self.auth.get_operator_index(operator.lower()) op_data = {x.split(":")[0].split("_")[1]: data[x] for x in data if x is not None and location in x} operator_key = yield from self.auth.get_operator_statistic(operator) if operator_key: op_data["__statistic_name"] = operator_key.split("_")[1] self.operators[operator.lower()] = Operator(operator.lower(), op_data) return self.operators
[ "def", "load_all_operators", "(", "self", ")", ":", "statistics", "=", "\"operatorpvp_kills,operatorpvp_death,operatorpvp_roundwon,operatorpvp_roundlost,operatorpvp_meleekills,operatorpvp_totalxp,operatorpvp_headshot,operatorpvp_timeplayed,operatorpvp_dbno\"", "for", "operator", "in", "OperatorStatisticNames", ":", "operator_key", "=", "yield", "from", "self", ".", "auth", ".", "get_operator_statistic", "(", "operator", ")", "if", "operator_key", ":", "statistics", "+=", "\",\"", "+", "operator_key", "data", "=", "yield", "from", "self", ".", "auth", ".", "get", "(", "\"https://public-ubiservices.ubi.com/v1/spaces/%s/sandboxes/%s/playerstats2/statistics?populations=%s&statistics=%s\"", "%", "(", "self", ".", "spaceid", ",", "self", ".", "platform_url", ",", "self", ".", "id", ",", "statistics", ")", ")", "if", "\"results\"", "not", "in", "data", "or", "not", "self", ".", "id", "in", "data", "[", "\"results\"", "]", ":", "raise", "InvalidRequest", "(", "\"Missing results key in returned JSON object %s\"", "%", "str", "(", "data", ")", ")", "data", "=", "data", "[", "\"results\"", "]", "[", "self", ".", "id", "]", "for", "operator", "in", "OperatorStatisticNames", ":", "location", "=", "yield", "from", "self", ".", "auth", ".", "get_operator_index", "(", "operator", ".", "lower", "(", ")", ")", "op_data", "=", "{", "x", ".", "split", "(", "\":\"", ")", "[", "0", "]", ".", "split", "(", "\"_\"", ")", "[", "1", "]", ":", "data", "[", "x", "]", "for", "x", "in", "data", "if", "x", "is", "not", "None", "and", "location", "in", "x", "}", "operator_key", "=", "yield", "from", "self", ".", "auth", ".", "get_operator_statistic", "(", "operator", ")", "if", "operator_key", ":", "op_data", "[", "\"__statistic_name\"", "]", "=", "operator_key", ".", "split", "(", "\"_\"", ")", "[", "1", "]", "self", ".", "operators", "[", "operator", ".", "lower", "(", ")", "]", "=", "Operator", "(", "operator", ".", "lower", "(", ")", ",", "op_data", ")", "return", "self", ".", "operators" ]
|coro| Loads the player stats for all operators Returns ------- dict[:class:`Operator`] the dictionary of all operators found
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L1163-L1195
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Player.get_all_operators
def get_all_operators(self): """|coro| Checks the player stats for all operators, loading them all again if any aren't found This is significantly more efficient than calling get_operator for every operator name. Returns ------- dict[:class:`Operator`] the dictionary of all operators found""" if len(self.operators) >= len(OperatorStatisticNames): return self.operators result = yield from self.load_all_operators() return result
python
def get_all_operators(self): if len(self.operators) >= len(OperatorStatisticNames): return self.operators result = yield from self.load_all_operators() return result
[ "def", "get_all_operators", "(", "self", ")", ":", "if", "len", "(", "self", ".", "operators", ")", ">=", "len", "(", "OperatorStatisticNames", ")", ":", "return", "self", ".", "operators", "result", "=", "yield", "from", "self", ".", "load_all_operators", "(", ")", "return", "result" ]
|coro| Checks the player stats for all operators, loading them all again if any aren't found This is significantly more efficient than calling get_operator for every operator name. Returns ------- dict[:class:`Operator`] the dictionary of all operators found
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L1198-L1212
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Player.load_operator
def load_operator(self, operator): """|coro| Loads the players stats for the operator Parameters ---------- operator : str the name of the operator Returns ------- :class:`Operator` the operator object found""" location = yield from self.auth.get_operator_index(operator) if location is None: raise ValueError("invalid operator %s" % operator) operator_key = yield from self.auth.get_operator_statistic(operator) if operator_key is not None: operator_key = "," + operator_key else: operator_key = "" data = yield from self.auth.get("https://public-ubiservices.ubi.com/v1/spaces/%s/sandboxes/%s/playerstats2/statistics?populations=%s&statistics=operatorpvp_kills,operatorpvp_death,operatorpvp_roundwon,operatorpvp_roundlost,operatorpvp_meleekills,operatorpvp_totalxp,operatorpvp_headshot,operatorpvp_timeplayed,operatorpvp_dbno%s" % (self.spaceid, self.platform_url, self.id, operator_key)) if not "results" in data or not self.id in data["results"]: raise InvalidRequest("Missing results key in returned JSON object %s" % str(data)) data = data["results"][self.id] data = {x.split(":")[0].split("_")[1]: data[x] for x in data if x is not None and location in x} if operator_key: data["__statistic_name"] = operator_key.split("_")[1] #if len(data) < 5: # raise InvalidRequest("invalid number of results for operator in JSON object %s" % data) oper = Operator(operator, data) self.operators[operator] = oper return oper
python
def load_operator(self, operator): location = yield from self.auth.get_operator_index(operator) if location is None: raise ValueError("invalid operator %s" % operator) operator_key = yield from self.auth.get_operator_statistic(operator) if operator_key is not None: operator_key = "," + operator_key else: operator_key = "" data = yield from self.auth.get("https://public-ubiservices.ubi.com/v1/spaces/%s/sandboxes/%s/playerstats2/statistics?populations=%s&statistics=operatorpvp_kills,operatorpvp_death,operatorpvp_roundwon,operatorpvp_roundlost,operatorpvp_meleekills,operatorpvp_totalxp,operatorpvp_headshot,operatorpvp_timeplayed,operatorpvp_dbno%s" % (self.spaceid, self.platform_url, self.id, operator_key)) if not "results" in data or not self.id in data["results"]: raise InvalidRequest("Missing results key in returned JSON object %s" % str(data)) data = data["results"][self.id] data = {x.split(":")[0].split("_")[1]: data[x] for x in data if x is not None and location in x} if operator_key: data["__statistic_name"] = operator_key.split("_")[1] oper = Operator(operator, data) self.operators[operator] = oper return oper
[ "def", "load_operator", "(", "self", ",", "operator", ")", ":", "location", "=", "yield", "from", "self", ".", "auth", ".", "get_operator_index", "(", "operator", ")", "if", "location", "is", "None", ":", "raise", "ValueError", "(", "\"invalid operator %s\"", "%", "operator", ")", "operator_key", "=", "yield", "from", "self", ".", "auth", ".", "get_operator_statistic", "(", "operator", ")", "if", "operator_key", "is", "not", "None", ":", "operator_key", "=", "\",\"", "+", "operator_key", "else", ":", "operator_key", "=", "\"\"", "data", "=", "yield", "from", "self", ".", "auth", ".", "get", "(", "\"https://public-ubiservices.ubi.com/v1/spaces/%s/sandboxes/%s/playerstats2/statistics?populations=%s&statistics=operatorpvp_kills,operatorpvp_death,operatorpvp_roundwon,operatorpvp_roundlost,operatorpvp_meleekills,operatorpvp_totalxp,operatorpvp_headshot,operatorpvp_timeplayed,operatorpvp_dbno%s\"", "%", "(", "self", ".", "spaceid", ",", "self", ".", "platform_url", ",", "self", ".", "id", ",", "operator_key", ")", ")", "if", "not", "\"results\"", "in", "data", "or", "not", "self", ".", "id", "in", "data", "[", "\"results\"", "]", ":", "raise", "InvalidRequest", "(", "\"Missing results key in returned JSON object %s\"", "%", "str", "(", "data", ")", ")", "data", "=", "data", "[", "\"results\"", "]", "[", "self", ".", "id", "]", "data", "=", "{", "x", ".", "split", "(", "\":\"", ")", "[", "0", "]", ".", "split", "(", "\"_\"", ")", "[", "1", "]", ":", "data", "[", "x", "]", "for", "x", "in", "data", "if", "x", "is", "not", "None", "and", "location", "in", "x", "}", "if", "operator_key", ":", "data", "[", "\"__statistic_name\"", "]", "=", "operator_key", ".", "split", "(", "\"_\"", ")", "[", "1", "]", "#if len(data) < 5:", "# raise InvalidRequest(\"invalid number of results for operator in JSON object %s\" % data)", "oper", "=", "Operator", "(", "operator", ",", "data", ")", "self", ".", "operators", "[", "operator", "]", "=", "oper", "return", "oper" ]
|coro| Loads the players stats for the operator Parameters ---------- operator : str the name of the operator Returns ------- :class:`Operator` the operator object found
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L1215-L1256
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Player.get_operator
def get_operator(self, operator): """|coro| Checks the players stats for this operator, only loading them if they haven't already been found Parameters ---------- operator : str the name of the operator Returns ------- :class:`Operator` the operator object found""" if operator in self.operators: return self.operators[operator] result = yield from self.load_operator(operator) return result
python
def get_operator(self, operator): if operator in self.operators: return self.operators[operator] result = yield from self.load_operator(operator) return result
[ "def", "get_operator", "(", "self", ",", "operator", ")", ":", "if", "operator", "in", "self", ".", "operators", ":", "return", "self", ".", "operators", "[", "operator", "]", "result", "=", "yield", "from", "self", ".", "load_operator", "(", "operator", ")", "return", "result" ]
|coro| Checks the players stats for this operator, only loading them if they haven't already been found Parameters ---------- operator : str the name of the operator Returns ------- :class:`Operator` the operator object found
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L1259-L1277
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Player.load_weapons
def load_weapons(self): """|coro| Load the players weapon stats Returns ------- list[:class:`Weapon`] list of all the weapon objects found""" data = yield from self.auth.get("https://public-ubiservices.ubi.com/v1/spaces/%s/sandboxes/%s/playerstats2/statistics?populations=%s&statistics=weapontypepvp_kills,weapontypepvp_headshot,weapontypepvp_bulletfired,weapontypepvp_bullethit" % (self.spaceid, self.platform_url, self.id)) if not "results" in data or not self.id in data["results"]: raise InvalidRequest("Missing key results in returned JSON object %s" % str(data)) data = data["results"][self.id] self.weapons = [Weapon(i) for i in range(7)] for x in data: spl = x.split(":") category = spl[0].split("_")[1] try: weapontype = int(spl[1]) - 1 weapon = self.weapons[weapontype] if category == "kills": weapon.kills = data[x] elif category == "headshot": weapon.headshots = data[x] elif category == "bulletfired": weapon.shots = data[x] elif category == "bullethit": weapon.hits = data[x] except (ValueError, TypeError, IndexError): pass return self.weapons
python
def load_weapons(self): data = yield from self.auth.get("https://public-ubiservices.ubi.com/v1/spaces/%s/sandboxes/%s/playerstats2/statistics?populations=%s&statistics=weapontypepvp_kills,weapontypepvp_headshot,weapontypepvp_bulletfired,weapontypepvp_bullethit" % (self.spaceid, self.platform_url, self.id)) if not "results" in data or not self.id in data["results"]: raise InvalidRequest("Missing key results in returned JSON object %s" % str(data)) data = data["results"][self.id] self.weapons = [Weapon(i) for i in range(7)] for x in data: spl = x.split(":") category = spl[0].split("_")[1] try: weapontype = int(spl[1]) - 1 weapon = self.weapons[weapontype] if category == "kills": weapon.kills = data[x] elif category == "headshot": weapon.headshots = data[x] elif category == "bulletfired": weapon.shots = data[x] elif category == "bullethit": weapon.hits = data[x] except (ValueError, TypeError, IndexError): pass return self.weapons
[ "def", "load_weapons", "(", "self", ")", ":", "data", "=", "yield", "from", "self", ".", "auth", ".", "get", "(", "\"https://public-ubiservices.ubi.com/v1/spaces/%s/sandboxes/%s/playerstats2/statistics?populations=%s&statistics=weapontypepvp_kills,weapontypepvp_headshot,weapontypepvp_bulletfired,weapontypepvp_bullethit\"", "%", "(", "self", ".", "spaceid", ",", "self", ".", "platform_url", ",", "self", ".", "id", ")", ")", "if", "not", "\"results\"", "in", "data", "or", "not", "self", ".", "id", "in", "data", "[", "\"results\"", "]", ":", "raise", "InvalidRequest", "(", "\"Missing key results in returned JSON object %s\"", "%", "str", "(", "data", ")", ")", "data", "=", "data", "[", "\"results\"", "]", "[", "self", ".", "id", "]", "self", ".", "weapons", "=", "[", "Weapon", "(", "i", ")", "for", "i", "in", "range", "(", "7", ")", "]", "for", "x", "in", "data", ":", "spl", "=", "x", ".", "split", "(", "\":\"", ")", "category", "=", "spl", "[", "0", "]", ".", "split", "(", "\"_\"", ")", "[", "1", "]", "try", ":", "weapontype", "=", "int", "(", "spl", "[", "1", "]", ")", "-", "1", "weapon", "=", "self", ".", "weapons", "[", "weapontype", "]", "if", "category", "==", "\"kills\"", ":", "weapon", ".", "kills", "=", "data", "[", "x", "]", "elif", "category", "==", "\"headshot\"", ":", "weapon", ".", "headshots", "=", "data", "[", "x", "]", "elif", "category", "==", "\"bulletfired\"", ":", "weapon", ".", "shots", "=", "data", "[", "x", "]", "elif", "category", "==", "\"bullethit\"", ":", "weapon", ".", "hits", "=", "data", "[", "x", "]", "except", "(", "ValueError", ",", "TypeError", ",", "IndexError", ")", ":", "pass", "return", "self", ".", "weapons" ]
|coro| Load the players weapon stats Returns ------- list[:class:`Weapon`] list of all the weapon objects found
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L1280-L1310
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Player.load_gamemodes
def load_gamemodes(self): """|coro| Loads the players gamemode stats Returns ------- dict dict of all the gamemodes found (gamemode_name: :class:`Gamemode`)""" stats = yield from self._fetch_statistics("secureareapvp_matchwon", "secureareapvp_matchlost", "secureareapvp_matchplayed", "secureareapvp_bestscore", "rescuehostagepvp_matchwon", "rescuehostagepvp_matchlost", "rescuehostagepvp_matchplayed", "rescuehostagepvp_bestscore", "plantbombpvp_matchwon", "plantbombpvp_matchlost", "plantbombpvp_matchplayed", "plantbombpvp_bestscore", "generalpvp_servershacked", "generalpvp_serverdefender", "generalpvp_serveraggression", "generalpvp_hostagerescue", "generalpvp_hostagedefense") self.gamemodes = {x: Gamemode(x) for x in GamemodeNames} for name in self.gamemodes: statname, gamemode = name + "pvp_", self.gamemodes[name] gamemode.best_score = stats.get(statname + "bestscore", 0) gamemode.lost = stats.get(statname + "matchlost", 0) gamemode.won = stats.get(statname + "matchwon", 0) gamemode.played = stats.get(statname + "matchplayed", 0) if name == "securearea": gamemode.areas_secured = stats.get("generalpvp_servershacked", 0) gamemode.areas_defended = stats.get("generalpvp_serverdefender", 0) gamemode.areas_contested = stats.get("generalpvp_serveraggression", 0) elif name == "rescuehostage": gamemode.hostages_rescued = stats.get("generalpvp_hostagerescue", 0) gamemode.hostages_defended = stats.get("generalpvp_hostagedefense", 0) return self.gamemodes
python
def load_gamemodes(self): stats = yield from self._fetch_statistics("secureareapvp_matchwon", "secureareapvp_matchlost", "secureareapvp_matchplayed", "secureareapvp_bestscore", "rescuehostagepvp_matchwon", "rescuehostagepvp_matchlost", "rescuehostagepvp_matchplayed", "rescuehostagepvp_bestscore", "plantbombpvp_matchwon", "plantbombpvp_matchlost", "plantbombpvp_matchplayed", "plantbombpvp_bestscore", "generalpvp_servershacked", "generalpvp_serverdefender", "generalpvp_serveraggression", "generalpvp_hostagerescue", "generalpvp_hostagedefense") self.gamemodes = {x: Gamemode(x) for x in GamemodeNames} for name in self.gamemodes: statname, gamemode = name + "pvp_", self.gamemodes[name] gamemode.best_score = stats.get(statname + "bestscore", 0) gamemode.lost = stats.get(statname + "matchlost", 0) gamemode.won = stats.get(statname + "matchwon", 0) gamemode.played = stats.get(statname + "matchplayed", 0) if name == "securearea": gamemode.areas_secured = stats.get("generalpvp_servershacked", 0) gamemode.areas_defended = stats.get("generalpvp_serverdefender", 0) gamemode.areas_contested = stats.get("generalpvp_serveraggression", 0) elif name == "rescuehostage": gamemode.hostages_rescued = stats.get("generalpvp_hostagerescue", 0) gamemode.hostages_defended = stats.get("generalpvp_hostagedefense", 0) return self.gamemodes
[ "def", "load_gamemodes", "(", "self", ")", ":", "stats", "=", "yield", "from", "self", ".", "_fetch_statistics", "(", "\"secureareapvp_matchwon\"", ",", "\"secureareapvp_matchlost\"", ",", "\"secureareapvp_matchplayed\"", ",", "\"secureareapvp_bestscore\"", ",", "\"rescuehostagepvp_matchwon\"", ",", "\"rescuehostagepvp_matchlost\"", ",", "\"rescuehostagepvp_matchplayed\"", ",", "\"rescuehostagepvp_bestscore\"", ",", "\"plantbombpvp_matchwon\"", ",", "\"plantbombpvp_matchlost\"", ",", "\"plantbombpvp_matchplayed\"", ",", "\"plantbombpvp_bestscore\"", ",", "\"generalpvp_servershacked\"", ",", "\"generalpvp_serverdefender\"", ",", "\"generalpvp_serveraggression\"", ",", "\"generalpvp_hostagerescue\"", ",", "\"generalpvp_hostagedefense\"", ")", "self", ".", "gamemodes", "=", "{", "x", ":", "Gamemode", "(", "x", ")", "for", "x", "in", "GamemodeNames", "}", "for", "name", "in", "self", ".", "gamemodes", ":", "statname", ",", "gamemode", "=", "name", "+", "\"pvp_\"", ",", "self", ".", "gamemodes", "[", "name", "]", "gamemode", ".", "best_score", "=", "stats", ".", "get", "(", "statname", "+", "\"bestscore\"", ",", "0", ")", "gamemode", ".", "lost", "=", "stats", ".", "get", "(", "statname", "+", "\"matchlost\"", ",", "0", ")", "gamemode", ".", "won", "=", "stats", ".", "get", "(", "statname", "+", "\"matchwon\"", ",", "0", ")", "gamemode", ".", "played", "=", "stats", ".", "get", "(", "statname", "+", "\"matchplayed\"", ",", "0", ")", "if", "name", "==", "\"securearea\"", ":", "gamemode", ".", "areas_secured", "=", "stats", ".", "get", "(", "\"generalpvp_servershacked\"", ",", "0", ")", "gamemode", ".", "areas_defended", "=", "stats", ".", "get", "(", "\"generalpvp_serverdefender\"", ",", "0", ")", "gamemode", ".", "areas_contested", "=", "stats", ".", "get", "(", "\"generalpvp_serveraggression\"", ",", "0", ")", "elif", "name", "==", "\"rescuehostage\"", ":", "gamemode", ".", "hostages_rescued", "=", "stats", ".", "get", "(", "\"generalpvp_hostagerescue\"", ",", "0", ")", "gamemode", ".", "hostages_defended", "=", "stats", ".", "get", "(", "\"generalpvp_hostagedefense\"", ",", "0", ")", "return", "self", ".", "gamemodes" ]
|coro| Loads the players gamemode stats Returns ------- dict dict of all the gamemodes found (gamemode_name: :class:`Gamemode`)
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L1327-L1363
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Player.load_general
def load_general(self): """|coro| Loads the players general stats""" stats = yield from self._fetch_statistics("generalpvp_timeplayed", "generalpvp_matchplayed", "generalpvp_matchwon", "generalpvp_matchlost", "generalpvp_kills", "generalpvp_death", "generalpvp_bullethit", "generalpvp_bulletfired", "generalpvp_killassists", "generalpvp_revive", "generalpvp_headshot", "generalpvp_penetrationkills", "generalpvp_meleekills", "generalpvp_dbnoassists", "generalpvp_suicide", "generalpvp_barricadedeployed", "generalpvp_reinforcementdeploy", "generalpvp_totalxp", "generalpvp_rappelbreach", "generalpvp_distancetravelled", "generalpvp_revivedenied", "generalpvp_dbno", "generalpvp_gadgetdestroy", "generalpvp_blindkills") statname = "generalpvp_" self.deaths = stats.get(statname + "death", 0) self.penetration_kills = stats.get(statname + "penetrationkills", 0) self.matches_won = stats.get(statname + "matchwon", 0) self.bullets_hit = stats.get(statname + "bullethit", 0) self.melee_kills = stats.get(statname + "meleekills", 0) self.bullets_fired = stats.get(statname + "bulletfired", 0) self.matches_played = stats.get(statname + "matchplayed", 0) self.kill_assists = stats.get(statname + "killassists", 0) self.time_played = stats.get(statname + "timeplayed", 0) self.revives = stats.get(statname + "revive", 0) self.kills = stats.get(statname + "kills", 0) self.headshots = stats.get(statname + "headshot", 0) self.matches_lost = stats.get(statname + "matchlost", 0) self.dbno_assists = stats.get(statname + "dbnoassists", 0) self.suicides = stats.get(statname + "suicide", 0) self.barricades_deployed = stats.get(statname + "barricadedeployed", 0) self.reinforcements_deployed = stats.get(statname + "reinforcementdeploy", 0) self.total_xp = stats.get(statname + "totalxp", 0) self.rappel_breaches = stats.get(statname + "rappelbreach", 0) self.distance_travelled = stats.get(statname + "distancetravelled", 0) self.revives_denied = stats.get(statname + "revivedenied", 0) self.dbnos = stats.get(statname + "dbno", 0) self.gadgets_destroyed = stats.get(statname + "gadgetdestroy", 0) self.blind_kills = stats.get(statname + "blindkills")
python
def load_general(self): stats = yield from self._fetch_statistics("generalpvp_timeplayed", "generalpvp_matchplayed", "generalpvp_matchwon", "generalpvp_matchlost", "generalpvp_kills", "generalpvp_death", "generalpvp_bullethit", "generalpvp_bulletfired", "generalpvp_killassists", "generalpvp_revive", "generalpvp_headshot", "generalpvp_penetrationkills", "generalpvp_meleekills", "generalpvp_dbnoassists", "generalpvp_suicide", "generalpvp_barricadedeployed", "generalpvp_reinforcementdeploy", "generalpvp_totalxp", "generalpvp_rappelbreach", "generalpvp_distancetravelled", "generalpvp_revivedenied", "generalpvp_dbno", "generalpvp_gadgetdestroy", "generalpvp_blindkills") statname = "generalpvp_" self.deaths = stats.get(statname + "death", 0) self.penetration_kills = stats.get(statname + "penetrationkills", 0) self.matches_won = stats.get(statname + "matchwon", 0) self.bullets_hit = stats.get(statname + "bullethit", 0) self.melee_kills = stats.get(statname + "meleekills", 0) self.bullets_fired = stats.get(statname + "bulletfired", 0) self.matches_played = stats.get(statname + "matchplayed", 0) self.kill_assists = stats.get(statname + "killassists", 0) self.time_played = stats.get(statname + "timeplayed", 0) self.revives = stats.get(statname + "revive", 0) self.kills = stats.get(statname + "kills", 0) self.headshots = stats.get(statname + "headshot", 0) self.matches_lost = stats.get(statname + "matchlost", 0) self.dbno_assists = stats.get(statname + "dbnoassists", 0) self.suicides = stats.get(statname + "suicide", 0) self.barricades_deployed = stats.get(statname + "barricadedeployed", 0) self.reinforcements_deployed = stats.get(statname + "reinforcementdeploy", 0) self.total_xp = stats.get(statname + "totalxp", 0) self.rappel_breaches = stats.get(statname + "rappelbreach", 0) self.distance_travelled = stats.get(statname + "distancetravelled", 0) self.revives_denied = stats.get(statname + "revivedenied", 0) self.dbnos = stats.get(statname + "dbno", 0) self.gadgets_destroyed = stats.get(statname + "gadgetdestroy", 0) self.blind_kills = stats.get(statname + "blindkills")
[ "def", "load_general", "(", "self", ")", ":", "stats", "=", "yield", "from", "self", ".", "_fetch_statistics", "(", "\"generalpvp_timeplayed\"", ",", "\"generalpvp_matchplayed\"", ",", "\"generalpvp_matchwon\"", ",", "\"generalpvp_matchlost\"", ",", "\"generalpvp_kills\"", ",", "\"generalpvp_death\"", ",", "\"generalpvp_bullethit\"", ",", "\"generalpvp_bulletfired\"", ",", "\"generalpvp_killassists\"", ",", "\"generalpvp_revive\"", ",", "\"generalpvp_headshot\"", ",", "\"generalpvp_penetrationkills\"", ",", "\"generalpvp_meleekills\"", ",", "\"generalpvp_dbnoassists\"", ",", "\"generalpvp_suicide\"", ",", "\"generalpvp_barricadedeployed\"", ",", "\"generalpvp_reinforcementdeploy\"", ",", "\"generalpvp_totalxp\"", ",", "\"generalpvp_rappelbreach\"", ",", "\"generalpvp_distancetravelled\"", ",", "\"generalpvp_revivedenied\"", ",", "\"generalpvp_dbno\"", ",", "\"generalpvp_gadgetdestroy\"", ",", "\"generalpvp_blindkills\"", ")", "statname", "=", "\"generalpvp_\"", "self", ".", "deaths", "=", "stats", ".", "get", "(", "statname", "+", "\"death\"", ",", "0", ")", "self", ".", "penetration_kills", "=", "stats", ".", "get", "(", "statname", "+", "\"penetrationkills\"", ",", "0", ")", "self", ".", "matches_won", "=", "stats", ".", "get", "(", "statname", "+", "\"matchwon\"", ",", "0", ")", "self", ".", "bullets_hit", "=", "stats", ".", "get", "(", "statname", "+", "\"bullethit\"", ",", "0", ")", "self", ".", "melee_kills", "=", "stats", ".", "get", "(", "statname", "+", "\"meleekills\"", ",", "0", ")", "self", ".", "bullets_fired", "=", "stats", ".", "get", "(", "statname", "+", "\"bulletfired\"", ",", "0", ")", "self", ".", "matches_played", "=", "stats", ".", "get", "(", "statname", "+", "\"matchplayed\"", ",", "0", ")", "self", ".", "kill_assists", "=", "stats", ".", "get", "(", "statname", "+", "\"killassists\"", ",", "0", ")", "self", ".", "time_played", "=", "stats", ".", "get", "(", "statname", "+", "\"timeplayed\"", ",", "0", ")", "self", ".", "revives", "=", "stats", ".", "get", "(", "statname", "+", "\"revive\"", ",", "0", ")", "self", ".", "kills", "=", "stats", ".", "get", "(", "statname", "+", "\"kills\"", ",", "0", ")", "self", ".", "headshots", "=", "stats", ".", "get", "(", "statname", "+", "\"headshot\"", ",", "0", ")", "self", ".", "matches_lost", "=", "stats", ".", "get", "(", "statname", "+", "\"matchlost\"", ",", "0", ")", "self", ".", "dbno_assists", "=", "stats", ".", "get", "(", "statname", "+", "\"dbnoassists\"", ",", "0", ")", "self", ".", "suicides", "=", "stats", ".", "get", "(", "statname", "+", "\"suicide\"", ",", "0", ")", "self", ".", "barricades_deployed", "=", "stats", ".", "get", "(", "statname", "+", "\"barricadedeployed\"", ",", "0", ")", "self", ".", "reinforcements_deployed", "=", "stats", ".", "get", "(", "statname", "+", "\"reinforcementdeploy\"", ",", "0", ")", "self", ".", "total_xp", "=", "stats", ".", "get", "(", "statname", "+", "\"totalxp\"", ",", "0", ")", "self", ".", "rappel_breaches", "=", "stats", ".", "get", "(", "statname", "+", "\"rappelbreach\"", ",", "0", ")", "self", ".", "distance_travelled", "=", "stats", ".", "get", "(", "statname", "+", "\"distancetravelled\"", ",", "0", ")", "self", ".", "revives_denied", "=", "stats", ".", "get", "(", "statname", "+", "\"revivedenied\"", ",", "0", ")", "self", ".", "dbnos", "=", "stats", ".", "get", "(", "statname", "+", "\"dbno\"", ",", "0", ")", "self", ".", "gadgets_destroyed", "=", "stats", ".", "get", "(", "statname", "+", "\"gadgetdestroy\"", ",", "0", ")", "self", ".", "blind_kills", "=", "stats", ".", "get", "(", "statname", "+", "\"blindkills\"", ")" ]
|coro| Loads the players general stats
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L1380-L1418
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Player.load_queues
def load_queues(self): """|coro| Loads the players game queues""" stats = yield from self._fetch_statistics("casualpvp_matchwon", "casualpvp_matchlost", "casualpvp_timeplayed", "casualpvp_matchplayed", "casualpvp_kills", "casualpvp_death", "rankedpvp_matchwon", "rankedpvp_matchlost", "rankedpvp_timeplayed", "rankedpvp_matchplayed", "rankedpvp_kills", "rankedpvp_death") self.ranked = GameQueue("ranked") self.casual = GameQueue("casual") for gq in (self.ranked, self.casual): statname = gq.name + "pvp_" gq.won = stats.get(statname + "matchwon", 0) gq.lost = stats.get(statname + "matchlost", 0) gq.time_played = stats.get(statname + "timeplayed", 0) gq.played = stats.get(statname + "matchplayed", 0) gq.kills = stats.get(statname + "kills", 0) gq.deaths = stats.get(statname + "death", 0)
python
def load_queues(self): stats = yield from self._fetch_statistics("casualpvp_matchwon", "casualpvp_matchlost", "casualpvp_timeplayed", "casualpvp_matchplayed", "casualpvp_kills", "casualpvp_death", "rankedpvp_matchwon", "rankedpvp_matchlost", "rankedpvp_timeplayed", "rankedpvp_matchplayed", "rankedpvp_kills", "rankedpvp_death") self.ranked = GameQueue("ranked") self.casual = GameQueue("casual") for gq in (self.ranked, self.casual): statname = gq.name + "pvp_" gq.won = stats.get(statname + "matchwon", 0) gq.lost = stats.get(statname + "matchlost", 0) gq.time_played = stats.get(statname + "timeplayed", 0) gq.played = stats.get(statname + "matchplayed", 0) gq.kills = stats.get(statname + "kills", 0) gq.deaths = stats.get(statname + "death", 0)
[ "def", "load_queues", "(", "self", ")", ":", "stats", "=", "yield", "from", "self", ".", "_fetch_statistics", "(", "\"casualpvp_matchwon\"", ",", "\"casualpvp_matchlost\"", ",", "\"casualpvp_timeplayed\"", ",", "\"casualpvp_matchplayed\"", ",", "\"casualpvp_kills\"", ",", "\"casualpvp_death\"", ",", "\"rankedpvp_matchwon\"", ",", "\"rankedpvp_matchlost\"", ",", "\"rankedpvp_timeplayed\"", ",", "\"rankedpvp_matchplayed\"", ",", "\"rankedpvp_kills\"", ",", "\"rankedpvp_death\"", ")", "self", ".", "ranked", "=", "GameQueue", "(", "\"ranked\"", ")", "self", ".", "casual", "=", "GameQueue", "(", "\"casual\"", ")", "for", "gq", "in", "(", "self", ".", "ranked", ",", "self", ".", "casual", ")", ":", "statname", "=", "gq", ".", "name", "+", "\"pvp_\"", "gq", ".", "won", "=", "stats", ".", "get", "(", "statname", "+", "\"matchwon\"", ",", "0", ")", "gq", ".", "lost", "=", "stats", ".", "get", "(", "statname", "+", "\"matchlost\"", ",", "0", ")", "gq", ".", "time_played", "=", "stats", ".", "get", "(", "statname", "+", "\"timeplayed\"", ",", "0", ")", "gq", ".", "played", "=", "stats", ".", "get", "(", "statname", "+", "\"matchplayed\"", ",", "0", ")", "gq", ".", "kills", "=", "stats", ".", "get", "(", "statname", "+", "\"kills\"", ",", "0", ")", "gq", ".", "deaths", "=", "stats", ".", "get", "(", "statname", "+", "\"death\"", ",", "0", ")" ]
|coro| Loads the players game queues
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L1430-L1451
billy-yoyo/RainbowSixSiege-Python-API
r6sapi/r6sapi.py
Player.load_terrohunt
def load_terrohunt(self): """|coro| Loads the player's general stats for terrorist hunt""" stats = yield from self._fetch_statistics("generalpve_dbnoassists", "generalpve_death", "generalpve_revive", "generalpve_matchwon", "generalpve_suicide", "generalpve_servershacked", "generalpve_serverdefender", "generalpve_barricadedeployed", "generalpve_reinforcementdeploy", "generalpve_kills", "generalpve_hostagedefense", "generalpve_bulletfired", "generalpve_matchlost", "generalpve_killassists", "generalpve_totalxp", "generalpve_hostagerescue", "generalpve_penetrationkills", "generalpve_meleekills", "generalpve_rappelbreach", "generalpve_distancetravelled", "generalpve_matchplayed", "generalpve_serveraggression", "generalpve_timeplayed", "generalpve_revivedenied", "generalpve_dbno", "generalpve_bullethit", "generalpve_blindkills", "generalpve_headshot", "generalpve_gadgetdestroy", "generalpve_accuracy") self.terrorist_hunt = GameQueue("terrohunt") statname = "generalpve_" self.terrorist_hunt.deaths = stats.get(statname + "death", 0) self.terrorist_hunt.penetration_kills = stats.get(statname + "penetrationkills", 0) self.terrorist_hunt.matches_won = stats.get(statname + "matchwon", 0) self.terrorist_hunt.bullets_hit = stats.get(statname + "bullethit", 0) self.terrorist_hunt.melee_kills = stats.get(statname + "meleekills", 0) self.terrorist_hunt.bullets_fired = stats.get(statname + "bulletfired", 0) self.terrorist_hunt.matches_played = stats.get(statname + "matchplayed", 0) self.terrorist_hunt.kill_assists = stats.get(statname + "killassists", 0) self.terrorist_hunt.time_played = stats.get(statname + "timeplayed", 0) self.terrorist_hunt.revives = stats.get(statname + "revive", 0) self.terrorist_hunt.kills = stats.get(statname + "kills", 0) self.terrorist_hunt.headshots = stats.get(statname + "headshot", 0) self.terrorist_hunt.matches_lost = stats.get(statname + "matchlost", 0) self.terrorist_hunt.dbno_assists = stats.get(statname + "dbnoassists", 0) self.terrorist_hunt.suicides = stats.get(statname + "suicide", 0) self.terrorist_hunt.barricades_deployed = stats.get(statname + "barricadedeployed", 0) self.terrorist_hunt.reinforcements_deployed = stats.get(statname + "reinforcementdeploy", 0) self.terrorist_hunt.total_xp = stats.get(statname + "totalxp", 0) self.terrorist_hunt.rappel_breaches = stats.get(statname + "rappelbreach", 0) self.terrorist_hunt.distance_travelled = stats.get(statname + "distancetravelled", 0) self.terrorist_hunt.revives_denied = stats.get(statname + "revivedenied", 0) self.terrorist_hunt.dbnos = stats.get(statname + "dbno", 0) self.terrorist_hunt.gadgets_destroyed = stats.get(statname + "gadgetdestroy", 0) self.terrorist_hunt.areas_secured = stats.get(statname + "servershacked", 0) self.terrorist_hunt.areas_defended = stats.get(statname + "serverdefender", 0) self.terrorist_hunt.areas_contested = stats.get(statname + "serveraggression", 0) self.terrorist_hunt.hostages_rescued = stats.get(statname + "hostagerescue", 0) self.terrorist_hunt.hostages_defended = stats.get(statname + "hostagedefense", 0) self.terrorist_hunt.blind_kills = stats.get(statname + "blindkills", 0) return self.terrorist_hunt
python
def load_terrohunt(self): stats = yield from self._fetch_statistics("generalpve_dbnoassists", "generalpve_death", "generalpve_revive", "generalpve_matchwon", "generalpve_suicide", "generalpve_servershacked", "generalpve_serverdefender", "generalpve_barricadedeployed", "generalpve_reinforcementdeploy", "generalpve_kills", "generalpve_hostagedefense", "generalpve_bulletfired", "generalpve_matchlost", "generalpve_killassists", "generalpve_totalxp", "generalpve_hostagerescue", "generalpve_penetrationkills", "generalpve_meleekills", "generalpve_rappelbreach", "generalpve_distancetravelled", "generalpve_matchplayed", "generalpve_serveraggression", "generalpve_timeplayed", "generalpve_revivedenied", "generalpve_dbno", "generalpve_bullethit", "generalpve_blindkills", "generalpve_headshot", "generalpve_gadgetdestroy", "generalpve_accuracy") self.terrorist_hunt = GameQueue("terrohunt") statname = "generalpve_" self.terrorist_hunt.deaths = stats.get(statname + "death", 0) self.terrorist_hunt.penetration_kills = stats.get(statname + "penetrationkills", 0) self.terrorist_hunt.matches_won = stats.get(statname + "matchwon", 0) self.terrorist_hunt.bullets_hit = stats.get(statname + "bullethit", 0) self.terrorist_hunt.melee_kills = stats.get(statname + "meleekills", 0) self.terrorist_hunt.bullets_fired = stats.get(statname + "bulletfired", 0) self.terrorist_hunt.matches_played = stats.get(statname + "matchplayed", 0) self.terrorist_hunt.kill_assists = stats.get(statname + "killassists", 0) self.terrorist_hunt.time_played = stats.get(statname + "timeplayed", 0) self.terrorist_hunt.revives = stats.get(statname + "revive", 0) self.terrorist_hunt.kills = stats.get(statname + "kills", 0) self.terrorist_hunt.headshots = stats.get(statname + "headshot", 0) self.terrorist_hunt.matches_lost = stats.get(statname + "matchlost", 0) self.terrorist_hunt.dbno_assists = stats.get(statname + "dbnoassists", 0) self.terrorist_hunt.suicides = stats.get(statname + "suicide", 0) self.terrorist_hunt.barricades_deployed = stats.get(statname + "barricadedeployed", 0) self.terrorist_hunt.reinforcements_deployed = stats.get(statname + "reinforcementdeploy", 0) self.terrorist_hunt.total_xp = stats.get(statname + "totalxp", 0) self.terrorist_hunt.rappel_breaches = stats.get(statname + "rappelbreach", 0) self.terrorist_hunt.distance_travelled = stats.get(statname + "distancetravelled", 0) self.terrorist_hunt.revives_denied = stats.get(statname + "revivedenied", 0) self.terrorist_hunt.dbnos = stats.get(statname + "dbno", 0) self.terrorist_hunt.gadgets_destroyed = stats.get(statname + "gadgetdestroy", 0) self.terrorist_hunt.areas_secured = stats.get(statname + "servershacked", 0) self.terrorist_hunt.areas_defended = stats.get(statname + "serverdefender", 0) self.terrorist_hunt.areas_contested = stats.get(statname + "serveraggression", 0) self.terrorist_hunt.hostages_rescued = stats.get(statname + "hostagerescue", 0) self.terrorist_hunt.hostages_defended = stats.get(statname + "hostagedefense", 0) self.terrorist_hunt.blind_kills = stats.get(statname + "blindkills", 0) return self.terrorist_hunt
[ "def", "load_terrohunt", "(", "self", ")", ":", "stats", "=", "yield", "from", "self", ".", "_fetch_statistics", "(", "\"generalpve_dbnoassists\"", ",", "\"generalpve_death\"", ",", "\"generalpve_revive\"", ",", "\"generalpve_matchwon\"", ",", "\"generalpve_suicide\"", ",", "\"generalpve_servershacked\"", ",", "\"generalpve_serverdefender\"", ",", "\"generalpve_barricadedeployed\"", ",", "\"generalpve_reinforcementdeploy\"", ",", "\"generalpve_kills\"", ",", "\"generalpve_hostagedefense\"", ",", "\"generalpve_bulletfired\"", ",", "\"generalpve_matchlost\"", ",", "\"generalpve_killassists\"", ",", "\"generalpve_totalxp\"", ",", "\"generalpve_hostagerescue\"", ",", "\"generalpve_penetrationkills\"", ",", "\"generalpve_meleekills\"", ",", "\"generalpve_rappelbreach\"", ",", "\"generalpve_distancetravelled\"", ",", "\"generalpve_matchplayed\"", ",", "\"generalpve_serveraggression\"", ",", "\"generalpve_timeplayed\"", ",", "\"generalpve_revivedenied\"", ",", "\"generalpve_dbno\"", ",", "\"generalpve_bullethit\"", ",", "\"generalpve_blindkills\"", ",", "\"generalpve_headshot\"", ",", "\"generalpve_gadgetdestroy\"", ",", "\"generalpve_accuracy\"", ")", "self", ".", "terrorist_hunt", "=", "GameQueue", "(", "\"terrohunt\"", ")", "statname", "=", "\"generalpve_\"", "self", ".", "terrorist_hunt", ".", "deaths", "=", "stats", ".", "get", "(", "statname", "+", "\"death\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "penetration_kills", "=", "stats", ".", "get", "(", "statname", "+", "\"penetrationkills\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "matches_won", "=", "stats", ".", "get", "(", "statname", "+", "\"matchwon\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "bullets_hit", "=", "stats", ".", "get", "(", "statname", "+", "\"bullethit\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "melee_kills", "=", "stats", ".", "get", "(", "statname", "+", "\"meleekills\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "bullets_fired", "=", "stats", ".", "get", "(", "statname", "+", "\"bulletfired\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "matches_played", "=", "stats", ".", "get", "(", "statname", "+", "\"matchplayed\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "kill_assists", "=", "stats", ".", "get", "(", "statname", "+", "\"killassists\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "time_played", "=", "stats", ".", "get", "(", "statname", "+", "\"timeplayed\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "revives", "=", "stats", ".", "get", "(", "statname", "+", "\"revive\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "kills", "=", "stats", ".", "get", "(", "statname", "+", "\"kills\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "headshots", "=", "stats", ".", "get", "(", "statname", "+", "\"headshot\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "matches_lost", "=", "stats", ".", "get", "(", "statname", "+", "\"matchlost\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "dbno_assists", "=", "stats", ".", "get", "(", "statname", "+", "\"dbnoassists\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "suicides", "=", "stats", ".", "get", "(", "statname", "+", "\"suicide\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "barricades_deployed", "=", "stats", ".", "get", "(", "statname", "+", "\"barricadedeployed\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "reinforcements_deployed", "=", "stats", ".", "get", "(", "statname", "+", "\"reinforcementdeploy\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "total_xp", "=", "stats", ".", "get", "(", "statname", "+", "\"totalxp\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "rappel_breaches", "=", "stats", ".", "get", "(", "statname", "+", "\"rappelbreach\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "distance_travelled", "=", "stats", ".", "get", "(", "statname", "+", "\"distancetravelled\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "revives_denied", "=", "stats", ".", "get", "(", "statname", "+", "\"revivedenied\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "dbnos", "=", "stats", ".", "get", "(", "statname", "+", "\"dbno\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "gadgets_destroyed", "=", "stats", ".", "get", "(", "statname", "+", "\"gadgetdestroy\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "areas_secured", "=", "stats", ".", "get", "(", "statname", "+", "\"servershacked\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "areas_defended", "=", "stats", ".", "get", "(", "statname", "+", "\"serverdefender\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "areas_contested", "=", "stats", ".", "get", "(", "statname", "+", "\"serveraggression\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "hostages_rescued", "=", "stats", ".", "get", "(", "statname", "+", "\"hostagerescue\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "hostages_defended", "=", "stats", ".", "get", "(", "statname", "+", "\"hostagedefense\"", ",", "0", ")", "self", ".", "terrorist_hunt", ".", "blind_kills", "=", "stats", ".", "get", "(", "statname", "+", "\"blindkills\"", ",", "0", ")", "return", "self", ".", "terrorist_hunt" ]
|coro| Loads the player's general stats for terrorist hunt
[ "|coro|" ]
train
https://github.com/billy-yoyo/RainbowSixSiege-Python-API/blob/9860fdfd9a78aabd977eaa71b0a4ab4ed69e94d0/r6sapi/r6sapi.py#L1463-L1511
jepcastelein/marketo-rest-python
marketorestpython/client.py
MarketoClient.execute
def execute(self, method, *args, **kargs): result = None ''' max 10 rechecks ''' for i in range(0, 10): try: method_map = { 'get_lead_by_id': self.get_lead_by_id, 'get_multiple_leads_by_filter_type': self.get_multiple_leads_by_filter_type, 'get_multiple_leads_by_list_id': self.get_multiple_leads_by_list_id, 'get_multiple_leads_by_list_id_yield': self.get_multiple_leads_by_list_id_yield, 'get_multiple_leads_by_program_id': self.get_multiple_leads_by_program_id, 'get_multiple_leads_by_program_id_yield': self.get_multiple_leads_by_program_id_yield, 'change_lead_program_status': self.change_lead_program_status, 'create_update_leads': self.create_update_leads, 'associate_lead': self.associate_lead, 'push_lead': self.push_lead, 'merge_lead': self.merge_lead, 'get_lead_partitions': self.get_lead_partitions, 'create_list': self.create_list, 'update_list': self.update_list, 'delete_list': self.delete_list, 'get_list_by_id': self.get_list_by_id, 'get_list_by_name': self.get_list_by_name, 'get_multiple_lists': self.get_multiple_lists, 'browse_lists': self.browse_lists, 'add_leads_to_list': self.add_leads_to_list, 'remove_leads_from_list': self.remove_leads_from_list, 'member_of_list': self.member_of_list, 'get_campaign_by_id': self.get_campaign_by_id, 'get_multiple_campaigns': self.get_multiple_campaigns, 'schedule_campaign': self.schedule_campaign, 'request_campaign': self.request_campaign, 'import_lead': self.import_lead, 'get_import_lead_status': self.get_import_lead_status, 'get_import_failure_file': self.get_import_failure_file, 'get_import_warning_file': self.get_import_warning_file, 'describe': self.describe, 'get_activity_types': self.get_activity_types, 'get_paging_token': self.get_paging_token, 'get_lead_activities': self.get_lead_activities, 'get_lead_activities_yield': self.get_lead_activities_yield, 'get_lead_changes': self.get_lead_changes, 'get_lead_changes_yield': self.get_lead_changes_yield, 'add_custom_activities': self.add_custom_activities, 'get_daily_usage': self.get_daily_usage, 'get_last_7_days_usage': self.get_last_7_days_usage, 'get_daily_errors': self.get_daily_errors, 'get_last_7_days_errors': self.get_last_7_days_errors, 'delete_lead': self.delete_lead, 'get_deleted_leads': self.get_deleted_leads, 'update_leads_partition': self.update_leads_partition, 'create_folder': self.create_folder, 'get_folder_by_id': self.get_folder_by_id, 'get_folder_by_name': self.get_folder_by_name, 'get_folder_contents': self.get_folder_contents, 'update_folder': self.update_folder, 'delete_folder': self.delete_folder, 'browse_folders': self.browse_folders, 'create_token': self.create_token, 'get_tokens': self.get_tokens, 'delete_tokens': self.delete_tokens, 'create_email_template': self.create_email_template, 'get_email_template_by_id': self.get_email_template_by_id, 'get_email_template_by_name': self.get_email_template_by_name, 'update_email_template': self.update_email_template, 'delete_email_template': self.delete_email_template, 'get_email_templates': self.get_email_templates, 'get_email_templates_yield': self.get_email_templates_yield, 'get_email_template_content': self.get_email_template_content, 'update_email_template_content': self.update_email_template_content, 'approve_email_template': self.approve_email_template, 'unapprove_email_template': self.unapprove_email_template, 'discard_email_template_draft': self.discard_email_template_draft, 'clone_email_template': self.clone_email_template, 'create_email': self.create_email, 'get_email_by_id': self.get_email_by_id, 'get_email_by_name': self.get_email_by_name, 'delete_email': self.delete_email, 'update_email': self.update_email, 'get_emails': self.get_emails, 'get_emails_yield': self.get_emails_yield, 'get_email_content': self.get_email_content, 'update_email_content': self.update_email_content, 'update_email_content_in_editable_section': self.update_email_content_in_editable_section, 'get_email_dynamic_content': self.get_email_dynamic_content, 'update_email_dynamic_content': self.update_email_dynamic_content, 'approve_email': self.approve_email, 'unapprove_email': self.unapprove_email, 'discard_email_draft': self.discard_email_draft, 'clone_email': self.clone_email, 'send_sample_email': self.send_sample_email, 'get_email_full_content': self.get_email_full_content, 'create_landing_page': self.create_landing_page, 'get_landing_page_by_id': self.get_landing_page_by_id, 'get_landing_page_by_name': self.get_landing_page_by_name, 'delete_landing_page': self.delete_landing_page, 'update_landing_page': self.update_landing_page, 'get_landing_pages': self.get_landing_pages, 'get_landing_pages_yield': self.get_landing_pages_yield, 'get_landing_page_content': self.get_landing_page_content, 'create_landing_page_content_section': self.create_landing_page_content_section, 'update_landing_page_content_section': self.update_landing_page_content_section, 'delete_landing_page_content_section': self.delete_landing_page_content_section, 'get_landing_page_dynamic_content': self.get_landing_page_dynamic_content, 'update_landing_page_dynamic_content': self.update_landing_page_dynamic_content, 'approve_landing_page': self.approve_landing_page, 'unapprove_landing_page': self.unapprove_landing_page, 'discard_landing_page_draft': self.discard_landing_page_draft, 'clone_landing_page': self.clone_landing_page, 'create_form': self.create_form, 'get_form_by_id': self.get_form_by_id, 'get_form_by_name': self.get_form_by_name, 'delete_form': self.delete_form, 'update_form': self.update_form, 'get_forms': self.get_forms, 'get_forms_yield': self.get_forms_yield, 'get_form_fields': self.get_form_fields, 'create_form_field': self.create_form_field, 'update_form_field': self.update_form_field, 'delete_form_field': self.delete_form_field, 'approve_form': self.approve_form, 'unapprove_form': self.unapprove_form, 'discard_form_draft': self.discard_form_draft, 'clone_form': self.clone_form, 'create_file': self.create_file, 'get_file_by_id': self.get_file_by_id, 'get_file_by_name': self.get_file_by_name, 'list_files': self.list_files, 'get_files_yield': self.get_files_yield, 'update_file_content': self.update_file_content, 'create_snippet': self.create_snippet, 'get_snippet_by_id': self.get_snippet_by_id, 'delete_snippet': self.delete_snippet, 'update_snippet': self.update_snippet, 'get_snippets': self.get_snippets, 'get_snippets_yield': self.get_snippets_yield, 'get_snippet_content': self.get_snippet_content, 'update_snippet_content': self.update_snippet_content, 'approve_snippet': self.approve_snippet, 'unapprove_snippet': self.unapprove_snippet, 'discard_snippet_draft': self.discard_snippet_draft, 'clone_snippet': self.clone_snippet, 'update_snippet_dynamic_content': self.update_snippet_dynamic_content, 'get_snippet_dynamic_content': self.get_snippet_dynamic_content, 'get_segmentations': self.get_segmentations, 'get_segments': self.get_segments, 'create_landing_page_template': self.create_landing_page_template, 'get_landing_page_template_by_id': self.get_landing_page_template_by_id, 'get_landing_page_template_by_name': self.get_landing_page_template_by_name, 'get_landing_page_templates': self.get_landing_page_templates, 'get_landing_page_templates_yield': self.get_landing_page_templates_yield, 'get_landing_page_template_content': self.get_landing_page_template_content, 'update_landing_page_template_content': self.update_landing_page_template_content, 'update_landing_page_template': self.update_landing_page_template, 'delete_landing_page_template': self.delete_landing_page_template, 'approve_landing_page_template': self.approve_landing_page_template, 'unapprove_landing_page_template': self.unapprove_landing_page_template, 'discard_landing_page_template_draft': self.discard_landing_page_template_draft, 'clone_landing_page_template': self.clone_landing_page_template, 'create_program': self.create_program, 'get_program_by_id': self.get_program_by_id, 'get_program_by_name': self.get_program_by_name, 'get_program_by_tag_type': self.get_program_by_tag_type, 'update_program': self.update_program, 'delete_program': self.delete_program, 'browse_programs': self.browse_programs, 'get_programs_yield': self.get_programs_yield, 'clone_program': self.clone_program, 'approve_program': self.approve_program, 'unapprove_program': self.unapprove_program, 'get_channels': self.get_channels, 'get_channel_by_name': self.get_channel_by_name, 'get_tags': self.get_tags, 'get_tag_by_name': self.get_tag_by_name, 'get_list_of_custom_objects': self.get_list_of_custom_objects, 'describe_custom_object': self.describe_custom_object, 'create_update_custom_objects': self.create_update_custom_objects, 'delete_custom_objects': self.delete_custom_objects, 'get_custom_objects': self.get_custom_objects, 'describe_opportunity': self.describe_opportunity, 'create_update_opportunities': self.create_update_opportunities, 'delete_opportunities': self.delete_opportunities, 'get_opportunities': self.get_opportunities, 'describe_opportunity_role': self.describe_opportunity_role, 'create_update_opportunities_roles': self.create_update_opportunities_roles, 'delete_opportunity_roles': self.delete_opportunity_roles, 'get_opportunity_roles': self.get_opportunity_roles, 'describe_company': self.describe_company, 'create_update_companies': self.create_update_companies, 'delete_companies': self.delete_companies, 'get_companies': self.get_companies, 'describe_sales_person': self.describe_sales_person, 'create_update_sales_persons': self.create_update_sales_persons, 'delete_sales_persons': self.delete_sales_persons, 'get_sales_persons': self.get_sales_persons, 'get_custom_activity_types': self.get_custom_activity_types, 'describe_custom_activity_type': self.describe_custom_activity_type, 'create_custom_activity_type': self.create_custom_activity_type, 'update_custom_activity_type': self.update_custom_activity_type, 'approve_custom_activity_type': self.approve_custom_activity_type, 'create_custom_activity_type_attribute': self.create_custom_activity_type_attribute, 'discard_custom_activity_type_draft': self.discard_custom_activity_type_draft, 'delete_custom_activity_type': self.delete_custom_activity_type, 'update_custom_activity_type_attribute': self.update_custom_activity_type_attribute, 'delete_custom_activity_type_attribute': self.delete_custom_activity_type_attribute, 'get_leads_export_jobs_list': self.get_leads_export_jobs_list, 'get_activities_export_jobs_list': self.get_activities_export_jobs_list, 'create_leads_export_job': self.create_leads_export_job, 'create_activities_export_job': self.create_activities_export_job, 'enqueue_leads_export_job': self.enqueue_leads_export_job, 'enqueue_activities_export_job': self.enqueue_activities_export_job, 'cancel_leads_export_job': self.cancel_leads_export_job, 'cancel_activities_export_job': self.cancel_activities_export_job, 'get_leads_export_job_status': self.get_leads_export_job_status, 'get_activities_export_job_status': self.get_activities_export_job_status, 'get_leads_export_job_file': self.get_leads_export_job_file, 'get_activities_export_job_file': self.get_activities_export_job_file } result = method_map[method](*args, **kargs) except MarketoException as e: ''' 601 -> auth token not valid 602 -> auth token expired ''' if e.code in ['601', '602']: self.authenticate() continue else: raise Exception({'message': e.message, 'code': e.code}) break return result
python
def execute(self, method, *args, **kargs): result = None for i in range(0, 10): try: method_map = { 'get_lead_by_id': self.get_lead_by_id, 'get_multiple_leads_by_filter_type': self.get_multiple_leads_by_filter_type, 'get_multiple_leads_by_list_id': self.get_multiple_leads_by_list_id, 'get_multiple_leads_by_list_id_yield': self.get_multiple_leads_by_list_id_yield, 'get_multiple_leads_by_program_id': self.get_multiple_leads_by_program_id, 'get_multiple_leads_by_program_id_yield': self.get_multiple_leads_by_program_id_yield, 'change_lead_program_status': self.change_lead_program_status, 'create_update_leads': self.create_update_leads, 'associate_lead': self.associate_lead, 'push_lead': self.push_lead, 'merge_lead': self.merge_lead, 'get_lead_partitions': self.get_lead_partitions, 'create_list': self.create_list, 'update_list': self.update_list, 'delete_list': self.delete_list, 'get_list_by_id': self.get_list_by_id, 'get_list_by_name': self.get_list_by_name, 'get_multiple_lists': self.get_multiple_lists, 'browse_lists': self.browse_lists, 'add_leads_to_list': self.add_leads_to_list, 'remove_leads_from_list': self.remove_leads_from_list, 'member_of_list': self.member_of_list, 'get_campaign_by_id': self.get_campaign_by_id, 'get_multiple_campaigns': self.get_multiple_campaigns, 'schedule_campaign': self.schedule_campaign, 'request_campaign': self.request_campaign, 'import_lead': self.import_lead, 'get_import_lead_status': self.get_import_lead_status, 'get_import_failure_file': self.get_import_failure_file, 'get_import_warning_file': self.get_import_warning_file, 'describe': self.describe, 'get_activity_types': self.get_activity_types, 'get_paging_token': self.get_paging_token, 'get_lead_activities': self.get_lead_activities, 'get_lead_activities_yield': self.get_lead_activities_yield, 'get_lead_changes': self.get_lead_changes, 'get_lead_changes_yield': self.get_lead_changes_yield, 'add_custom_activities': self.add_custom_activities, 'get_daily_usage': self.get_daily_usage, 'get_last_7_days_usage': self.get_last_7_days_usage, 'get_daily_errors': self.get_daily_errors, 'get_last_7_days_errors': self.get_last_7_days_errors, 'delete_lead': self.delete_lead, 'get_deleted_leads': self.get_deleted_leads, 'update_leads_partition': self.update_leads_partition, 'create_folder': self.create_folder, 'get_folder_by_id': self.get_folder_by_id, 'get_folder_by_name': self.get_folder_by_name, 'get_folder_contents': self.get_folder_contents, 'update_folder': self.update_folder, 'delete_folder': self.delete_folder, 'browse_folders': self.browse_folders, 'create_token': self.create_token, 'get_tokens': self.get_tokens, 'delete_tokens': self.delete_tokens, 'create_email_template': self.create_email_template, 'get_email_template_by_id': self.get_email_template_by_id, 'get_email_template_by_name': self.get_email_template_by_name, 'update_email_template': self.update_email_template, 'delete_email_template': self.delete_email_template, 'get_email_templates': self.get_email_templates, 'get_email_templates_yield': self.get_email_templates_yield, 'get_email_template_content': self.get_email_template_content, 'update_email_template_content': self.update_email_template_content, 'approve_email_template': self.approve_email_template, 'unapprove_email_template': self.unapprove_email_template, 'discard_email_template_draft': self.discard_email_template_draft, 'clone_email_template': self.clone_email_template, 'create_email': self.create_email, 'get_email_by_id': self.get_email_by_id, 'get_email_by_name': self.get_email_by_name, 'delete_email': self.delete_email, 'update_email': self.update_email, 'get_emails': self.get_emails, 'get_emails_yield': self.get_emails_yield, 'get_email_content': self.get_email_content, 'update_email_content': self.update_email_content, 'update_email_content_in_editable_section': self.update_email_content_in_editable_section, 'get_email_dynamic_content': self.get_email_dynamic_content, 'update_email_dynamic_content': self.update_email_dynamic_content, 'approve_email': self.approve_email, 'unapprove_email': self.unapprove_email, 'discard_email_draft': self.discard_email_draft, 'clone_email': self.clone_email, 'send_sample_email': self.send_sample_email, 'get_email_full_content': self.get_email_full_content, 'create_landing_page': self.create_landing_page, 'get_landing_page_by_id': self.get_landing_page_by_id, 'get_landing_page_by_name': self.get_landing_page_by_name, 'delete_landing_page': self.delete_landing_page, 'update_landing_page': self.update_landing_page, 'get_landing_pages': self.get_landing_pages, 'get_landing_pages_yield': self.get_landing_pages_yield, 'get_landing_page_content': self.get_landing_page_content, 'create_landing_page_content_section': self.create_landing_page_content_section, 'update_landing_page_content_section': self.update_landing_page_content_section, 'delete_landing_page_content_section': self.delete_landing_page_content_section, 'get_landing_page_dynamic_content': self.get_landing_page_dynamic_content, 'update_landing_page_dynamic_content': self.update_landing_page_dynamic_content, 'approve_landing_page': self.approve_landing_page, 'unapprove_landing_page': self.unapprove_landing_page, 'discard_landing_page_draft': self.discard_landing_page_draft, 'clone_landing_page': self.clone_landing_page, 'create_form': self.create_form, 'get_form_by_id': self.get_form_by_id, 'get_form_by_name': self.get_form_by_name, 'delete_form': self.delete_form, 'update_form': self.update_form, 'get_forms': self.get_forms, 'get_forms_yield': self.get_forms_yield, 'get_form_fields': self.get_form_fields, 'create_form_field': self.create_form_field, 'update_form_field': self.update_form_field, 'delete_form_field': self.delete_form_field, 'approve_form': self.approve_form, 'unapprove_form': self.unapprove_form, 'discard_form_draft': self.discard_form_draft, 'clone_form': self.clone_form, 'create_file': self.create_file, 'get_file_by_id': self.get_file_by_id, 'get_file_by_name': self.get_file_by_name, 'list_files': self.list_files, 'get_files_yield': self.get_files_yield, 'update_file_content': self.update_file_content, 'create_snippet': self.create_snippet, 'get_snippet_by_id': self.get_snippet_by_id, 'delete_snippet': self.delete_snippet, 'update_snippet': self.update_snippet, 'get_snippets': self.get_snippets, 'get_snippets_yield': self.get_snippets_yield, 'get_snippet_content': self.get_snippet_content, 'update_snippet_content': self.update_snippet_content, 'approve_snippet': self.approve_snippet, 'unapprove_snippet': self.unapprove_snippet, 'discard_snippet_draft': self.discard_snippet_draft, 'clone_snippet': self.clone_snippet, 'update_snippet_dynamic_content': self.update_snippet_dynamic_content, 'get_snippet_dynamic_content': self.get_snippet_dynamic_content, 'get_segmentations': self.get_segmentations, 'get_segments': self.get_segments, 'create_landing_page_template': self.create_landing_page_template, 'get_landing_page_template_by_id': self.get_landing_page_template_by_id, 'get_landing_page_template_by_name': self.get_landing_page_template_by_name, 'get_landing_page_templates': self.get_landing_page_templates, 'get_landing_page_templates_yield': self.get_landing_page_templates_yield, 'get_landing_page_template_content': self.get_landing_page_template_content, 'update_landing_page_template_content': self.update_landing_page_template_content, 'update_landing_page_template': self.update_landing_page_template, 'delete_landing_page_template': self.delete_landing_page_template, 'approve_landing_page_template': self.approve_landing_page_template, 'unapprove_landing_page_template': self.unapprove_landing_page_template, 'discard_landing_page_template_draft': self.discard_landing_page_template_draft, 'clone_landing_page_template': self.clone_landing_page_template, 'create_program': self.create_program, 'get_program_by_id': self.get_program_by_id, 'get_program_by_name': self.get_program_by_name, 'get_program_by_tag_type': self.get_program_by_tag_type, 'update_program': self.update_program, 'delete_program': self.delete_program, 'browse_programs': self.browse_programs, 'get_programs_yield': self.get_programs_yield, 'clone_program': self.clone_program, 'approve_program': self.approve_program, 'unapprove_program': self.unapprove_program, 'get_channels': self.get_channels, 'get_channel_by_name': self.get_channel_by_name, 'get_tags': self.get_tags, 'get_tag_by_name': self.get_tag_by_name, 'get_list_of_custom_objects': self.get_list_of_custom_objects, 'describe_custom_object': self.describe_custom_object, 'create_update_custom_objects': self.create_update_custom_objects, 'delete_custom_objects': self.delete_custom_objects, 'get_custom_objects': self.get_custom_objects, 'describe_opportunity': self.describe_opportunity, 'create_update_opportunities': self.create_update_opportunities, 'delete_opportunities': self.delete_opportunities, 'get_opportunities': self.get_opportunities, 'describe_opportunity_role': self.describe_opportunity_role, 'create_update_opportunities_roles': self.create_update_opportunities_roles, 'delete_opportunity_roles': self.delete_opportunity_roles, 'get_opportunity_roles': self.get_opportunity_roles, 'describe_company': self.describe_company, 'create_update_companies': self.create_update_companies, 'delete_companies': self.delete_companies, 'get_companies': self.get_companies, 'describe_sales_person': self.describe_sales_person, 'create_update_sales_persons': self.create_update_sales_persons, 'delete_sales_persons': self.delete_sales_persons, 'get_sales_persons': self.get_sales_persons, 'get_custom_activity_types': self.get_custom_activity_types, 'describe_custom_activity_type': self.describe_custom_activity_type, 'create_custom_activity_type': self.create_custom_activity_type, 'update_custom_activity_type': self.update_custom_activity_type, 'approve_custom_activity_type': self.approve_custom_activity_type, 'create_custom_activity_type_attribute': self.create_custom_activity_type_attribute, 'discard_custom_activity_type_draft': self.discard_custom_activity_type_draft, 'delete_custom_activity_type': self.delete_custom_activity_type, 'update_custom_activity_type_attribute': self.update_custom_activity_type_attribute, 'delete_custom_activity_type_attribute': self.delete_custom_activity_type_attribute, 'get_leads_export_jobs_list': self.get_leads_export_jobs_list, 'get_activities_export_jobs_list': self.get_activities_export_jobs_list, 'create_leads_export_job': self.create_leads_export_job, 'create_activities_export_job': self.create_activities_export_job, 'enqueue_leads_export_job': self.enqueue_leads_export_job, 'enqueue_activities_export_job': self.enqueue_activities_export_job, 'cancel_leads_export_job': self.cancel_leads_export_job, 'cancel_activities_export_job': self.cancel_activities_export_job, 'get_leads_export_job_status': self.get_leads_export_job_status, 'get_activities_export_job_status': self.get_activities_export_job_status, 'get_leads_export_job_file': self.get_leads_export_job_file, 'get_activities_export_job_file': self.get_activities_export_job_file } result = method_map[method](*args, **kargs) except MarketoException as e: if e.code in ['601', '602']: self.authenticate() continue else: raise Exception({'message': e.message, 'code': e.code}) break return result
[ "def", "execute", "(", "self", ",", "method", ",", "*", "args", ",", "*", "*", "kargs", ")", ":", "result", "=", "None", "for", "i", "in", "range", "(", "0", ",", "10", ")", ":", "try", ":", "method_map", "=", "{", "'get_lead_by_id'", ":", "self", ".", "get_lead_by_id", ",", "'get_multiple_leads_by_filter_type'", ":", "self", ".", "get_multiple_leads_by_filter_type", ",", "'get_multiple_leads_by_list_id'", ":", "self", ".", "get_multiple_leads_by_list_id", ",", "'get_multiple_leads_by_list_id_yield'", ":", "self", ".", "get_multiple_leads_by_list_id_yield", ",", "'get_multiple_leads_by_program_id'", ":", "self", ".", "get_multiple_leads_by_program_id", ",", "'get_multiple_leads_by_program_id_yield'", ":", "self", ".", "get_multiple_leads_by_program_id_yield", ",", "'change_lead_program_status'", ":", "self", ".", "change_lead_program_status", ",", "'create_update_leads'", ":", "self", ".", "create_update_leads", ",", "'associate_lead'", ":", "self", ".", "associate_lead", ",", "'push_lead'", ":", "self", ".", "push_lead", ",", "'merge_lead'", ":", "self", ".", "merge_lead", ",", "'get_lead_partitions'", ":", "self", ".", "get_lead_partitions", ",", "'create_list'", ":", "self", ".", "create_list", ",", "'update_list'", ":", "self", ".", "update_list", ",", "'delete_list'", ":", "self", ".", "delete_list", ",", "'get_list_by_id'", ":", "self", ".", "get_list_by_id", ",", "'get_list_by_name'", ":", "self", ".", "get_list_by_name", ",", "'get_multiple_lists'", ":", "self", ".", "get_multiple_lists", ",", "'browse_lists'", ":", "self", ".", "browse_lists", ",", "'add_leads_to_list'", ":", "self", ".", "add_leads_to_list", ",", "'remove_leads_from_list'", ":", "self", ".", "remove_leads_from_list", ",", "'member_of_list'", ":", "self", ".", "member_of_list", ",", "'get_campaign_by_id'", ":", "self", ".", "get_campaign_by_id", ",", "'get_multiple_campaigns'", ":", "self", ".", "get_multiple_campaigns", ",", "'schedule_campaign'", ":", "self", ".", "schedule_campaign", ",", "'request_campaign'", ":", "self", ".", "request_campaign", ",", "'import_lead'", ":", "self", ".", "import_lead", ",", "'get_import_lead_status'", ":", "self", ".", "get_import_lead_status", ",", "'get_import_failure_file'", ":", "self", ".", "get_import_failure_file", ",", "'get_import_warning_file'", ":", "self", ".", "get_import_warning_file", ",", "'describe'", ":", "self", ".", "describe", ",", "'get_activity_types'", ":", "self", ".", "get_activity_types", ",", "'get_paging_token'", ":", "self", ".", "get_paging_token", ",", "'get_lead_activities'", ":", "self", ".", "get_lead_activities", ",", "'get_lead_activities_yield'", ":", "self", ".", "get_lead_activities_yield", ",", "'get_lead_changes'", ":", "self", ".", "get_lead_changes", ",", "'get_lead_changes_yield'", ":", "self", ".", "get_lead_changes_yield", ",", "'add_custom_activities'", ":", "self", ".", "add_custom_activities", ",", "'get_daily_usage'", ":", "self", ".", "get_daily_usage", ",", "'get_last_7_days_usage'", ":", "self", ".", "get_last_7_days_usage", ",", "'get_daily_errors'", ":", "self", ".", "get_daily_errors", ",", "'get_last_7_days_errors'", ":", "self", ".", "get_last_7_days_errors", ",", "'delete_lead'", ":", "self", ".", "delete_lead", ",", "'get_deleted_leads'", ":", "self", ".", "get_deleted_leads", ",", "'update_leads_partition'", ":", "self", ".", "update_leads_partition", ",", "'create_folder'", ":", "self", ".", "create_folder", ",", "'get_folder_by_id'", ":", "self", ".", "get_folder_by_id", ",", "'get_folder_by_name'", ":", "self", ".", "get_folder_by_name", ",", "'get_folder_contents'", ":", "self", ".", "get_folder_contents", ",", "'update_folder'", ":", "self", ".", "update_folder", ",", "'delete_folder'", ":", "self", ".", "delete_folder", ",", "'browse_folders'", ":", "self", ".", "browse_folders", ",", "'create_token'", ":", "self", ".", "create_token", ",", "'get_tokens'", ":", "self", ".", "get_tokens", ",", "'delete_tokens'", ":", "self", ".", "delete_tokens", ",", "'create_email_template'", ":", "self", ".", "create_email_template", ",", "'get_email_template_by_id'", ":", "self", ".", "get_email_template_by_id", ",", "'get_email_template_by_name'", ":", "self", ".", "get_email_template_by_name", ",", "'update_email_template'", ":", "self", ".", "update_email_template", ",", "'delete_email_template'", ":", "self", ".", "delete_email_template", ",", "'get_email_templates'", ":", "self", ".", "get_email_templates", ",", "'get_email_templates_yield'", ":", "self", ".", "get_email_templates_yield", ",", "'get_email_template_content'", ":", "self", ".", "get_email_template_content", ",", "'update_email_template_content'", ":", "self", ".", "update_email_template_content", ",", "'approve_email_template'", ":", "self", ".", "approve_email_template", ",", "'unapprove_email_template'", ":", "self", ".", "unapprove_email_template", ",", "'discard_email_template_draft'", ":", "self", ".", "discard_email_template_draft", ",", "'clone_email_template'", ":", "self", ".", "clone_email_template", ",", "'create_email'", ":", "self", ".", "create_email", ",", "'get_email_by_id'", ":", "self", ".", "get_email_by_id", ",", "'get_email_by_name'", ":", "self", ".", "get_email_by_name", ",", "'delete_email'", ":", "self", ".", "delete_email", ",", "'update_email'", ":", "self", ".", "update_email", ",", "'get_emails'", ":", "self", ".", "get_emails", ",", "'get_emails_yield'", ":", "self", ".", "get_emails_yield", ",", "'get_email_content'", ":", "self", ".", "get_email_content", ",", "'update_email_content'", ":", "self", ".", "update_email_content", ",", "'update_email_content_in_editable_section'", ":", "self", ".", "update_email_content_in_editable_section", ",", "'get_email_dynamic_content'", ":", "self", ".", "get_email_dynamic_content", ",", "'update_email_dynamic_content'", ":", "self", ".", "update_email_dynamic_content", ",", "'approve_email'", ":", "self", ".", "approve_email", ",", "'unapprove_email'", ":", "self", ".", "unapprove_email", ",", "'discard_email_draft'", ":", "self", ".", "discard_email_draft", ",", "'clone_email'", ":", "self", ".", "clone_email", ",", "'send_sample_email'", ":", "self", ".", "send_sample_email", ",", "'get_email_full_content'", ":", "self", ".", "get_email_full_content", ",", "'create_landing_page'", ":", "self", ".", "create_landing_page", ",", "'get_landing_page_by_id'", ":", "self", ".", "get_landing_page_by_id", ",", "'get_landing_page_by_name'", ":", "self", ".", "get_landing_page_by_name", ",", "'delete_landing_page'", ":", "self", ".", "delete_landing_page", ",", "'update_landing_page'", ":", "self", ".", "update_landing_page", ",", "'get_landing_pages'", ":", "self", ".", "get_landing_pages", ",", "'get_landing_pages_yield'", ":", "self", ".", "get_landing_pages_yield", ",", "'get_landing_page_content'", ":", "self", ".", "get_landing_page_content", ",", "'create_landing_page_content_section'", ":", "self", ".", "create_landing_page_content_section", ",", "'update_landing_page_content_section'", ":", "self", ".", "update_landing_page_content_section", ",", "'delete_landing_page_content_section'", ":", "self", ".", "delete_landing_page_content_section", ",", "'get_landing_page_dynamic_content'", ":", "self", ".", "get_landing_page_dynamic_content", ",", "'update_landing_page_dynamic_content'", ":", "self", ".", "update_landing_page_dynamic_content", ",", "'approve_landing_page'", ":", "self", ".", "approve_landing_page", ",", "'unapprove_landing_page'", ":", "self", ".", "unapprove_landing_page", ",", "'discard_landing_page_draft'", ":", "self", ".", "discard_landing_page_draft", ",", "'clone_landing_page'", ":", "self", ".", "clone_landing_page", ",", "'create_form'", ":", "self", ".", "create_form", ",", "'get_form_by_id'", ":", "self", ".", "get_form_by_id", ",", "'get_form_by_name'", ":", "self", ".", "get_form_by_name", ",", "'delete_form'", ":", "self", ".", "delete_form", ",", "'update_form'", ":", "self", ".", "update_form", ",", "'get_forms'", ":", "self", ".", "get_forms", ",", "'get_forms_yield'", ":", "self", ".", "get_forms_yield", ",", "'get_form_fields'", ":", "self", ".", "get_form_fields", ",", "'create_form_field'", ":", "self", ".", "create_form_field", ",", "'update_form_field'", ":", "self", ".", "update_form_field", ",", "'delete_form_field'", ":", "self", ".", "delete_form_field", ",", "'approve_form'", ":", "self", ".", "approve_form", ",", "'unapprove_form'", ":", "self", ".", "unapprove_form", ",", "'discard_form_draft'", ":", "self", ".", "discard_form_draft", ",", "'clone_form'", ":", "self", ".", "clone_form", ",", "'create_file'", ":", "self", ".", "create_file", ",", "'get_file_by_id'", ":", "self", ".", "get_file_by_id", ",", "'get_file_by_name'", ":", "self", ".", "get_file_by_name", ",", "'list_files'", ":", "self", ".", "list_files", ",", "'get_files_yield'", ":", "self", ".", "get_files_yield", ",", "'update_file_content'", ":", "self", ".", "update_file_content", ",", "'create_snippet'", ":", "self", ".", "create_snippet", ",", "'get_snippet_by_id'", ":", "self", ".", "get_snippet_by_id", ",", "'delete_snippet'", ":", "self", ".", "delete_snippet", ",", "'update_snippet'", ":", "self", ".", "update_snippet", ",", "'get_snippets'", ":", "self", ".", "get_snippets", ",", "'get_snippets_yield'", ":", "self", ".", "get_snippets_yield", ",", "'get_snippet_content'", ":", "self", ".", "get_snippet_content", ",", "'update_snippet_content'", ":", "self", ".", "update_snippet_content", ",", "'approve_snippet'", ":", "self", ".", "approve_snippet", ",", "'unapprove_snippet'", ":", "self", ".", "unapprove_snippet", ",", "'discard_snippet_draft'", ":", "self", ".", "discard_snippet_draft", ",", "'clone_snippet'", ":", "self", ".", "clone_snippet", ",", "'update_snippet_dynamic_content'", ":", "self", ".", "update_snippet_dynamic_content", ",", "'get_snippet_dynamic_content'", ":", "self", ".", "get_snippet_dynamic_content", ",", "'get_segmentations'", ":", "self", ".", "get_segmentations", ",", "'get_segments'", ":", "self", ".", "get_segments", ",", "'create_landing_page_template'", ":", "self", ".", "create_landing_page_template", ",", "'get_landing_page_template_by_id'", ":", "self", ".", "get_landing_page_template_by_id", ",", "'get_landing_page_template_by_name'", ":", "self", ".", "get_landing_page_template_by_name", ",", "'get_landing_page_templates'", ":", "self", ".", "get_landing_page_templates", ",", "'get_landing_page_templates_yield'", ":", "self", ".", "get_landing_page_templates_yield", ",", "'get_landing_page_template_content'", ":", "self", ".", "get_landing_page_template_content", ",", "'update_landing_page_template_content'", ":", "self", ".", "update_landing_page_template_content", ",", "'update_landing_page_template'", ":", "self", ".", "update_landing_page_template", ",", "'delete_landing_page_template'", ":", "self", ".", "delete_landing_page_template", ",", "'approve_landing_page_template'", ":", "self", ".", "approve_landing_page_template", ",", "'unapprove_landing_page_template'", ":", "self", ".", "unapprove_landing_page_template", ",", "'discard_landing_page_template_draft'", ":", "self", ".", "discard_landing_page_template_draft", ",", "'clone_landing_page_template'", ":", "self", ".", "clone_landing_page_template", ",", "'create_program'", ":", "self", ".", "create_program", ",", "'get_program_by_id'", ":", "self", ".", "get_program_by_id", ",", "'get_program_by_name'", ":", "self", ".", "get_program_by_name", ",", "'get_program_by_tag_type'", ":", "self", ".", "get_program_by_tag_type", ",", "'update_program'", ":", "self", ".", "update_program", ",", "'delete_program'", ":", "self", ".", "delete_program", ",", "'browse_programs'", ":", "self", ".", "browse_programs", ",", "'get_programs_yield'", ":", "self", ".", "get_programs_yield", ",", "'clone_program'", ":", "self", ".", "clone_program", ",", "'approve_program'", ":", "self", ".", "approve_program", ",", "'unapprove_program'", ":", "self", ".", "unapprove_program", ",", "'get_channels'", ":", "self", ".", "get_channels", ",", "'get_channel_by_name'", ":", "self", ".", "get_channel_by_name", ",", "'get_tags'", ":", "self", ".", "get_tags", ",", "'get_tag_by_name'", ":", "self", ".", "get_tag_by_name", ",", "'get_list_of_custom_objects'", ":", "self", ".", "get_list_of_custom_objects", ",", "'describe_custom_object'", ":", "self", ".", "describe_custom_object", ",", "'create_update_custom_objects'", ":", "self", ".", "create_update_custom_objects", ",", "'delete_custom_objects'", ":", "self", ".", "delete_custom_objects", ",", "'get_custom_objects'", ":", "self", ".", "get_custom_objects", ",", "'describe_opportunity'", ":", "self", ".", "describe_opportunity", ",", "'create_update_opportunities'", ":", "self", ".", "create_update_opportunities", ",", "'delete_opportunities'", ":", "self", ".", "delete_opportunities", ",", "'get_opportunities'", ":", "self", ".", "get_opportunities", ",", "'describe_opportunity_role'", ":", "self", ".", "describe_opportunity_role", ",", "'create_update_opportunities_roles'", ":", "self", ".", "create_update_opportunities_roles", ",", "'delete_opportunity_roles'", ":", "self", ".", "delete_opportunity_roles", ",", "'get_opportunity_roles'", ":", "self", ".", "get_opportunity_roles", ",", "'describe_company'", ":", "self", ".", "describe_company", ",", "'create_update_companies'", ":", "self", ".", "create_update_companies", ",", "'delete_companies'", ":", "self", ".", "delete_companies", ",", "'get_companies'", ":", "self", ".", "get_companies", ",", "'describe_sales_person'", ":", "self", ".", "describe_sales_person", ",", "'create_update_sales_persons'", ":", "self", ".", "create_update_sales_persons", ",", "'delete_sales_persons'", ":", "self", ".", "delete_sales_persons", ",", "'get_sales_persons'", ":", "self", ".", "get_sales_persons", ",", "'get_custom_activity_types'", ":", "self", ".", "get_custom_activity_types", ",", "'describe_custom_activity_type'", ":", "self", ".", "describe_custom_activity_type", ",", "'create_custom_activity_type'", ":", "self", ".", "create_custom_activity_type", ",", "'update_custom_activity_type'", ":", "self", ".", "update_custom_activity_type", ",", "'approve_custom_activity_type'", ":", "self", ".", "approve_custom_activity_type", ",", "'create_custom_activity_type_attribute'", ":", "self", ".", "create_custom_activity_type_attribute", ",", "'discard_custom_activity_type_draft'", ":", "self", ".", "discard_custom_activity_type_draft", ",", "'delete_custom_activity_type'", ":", "self", ".", "delete_custom_activity_type", ",", "'update_custom_activity_type_attribute'", ":", "self", ".", "update_custom_activity_type_attribute", ",", "'delete_custom_activity_type_attribute'", ":", "self", ".", "delete_custom_activity_type_attribute", ",", "'get_leads_export_jobs_list'", ":", "self", ".", "get_leads_export_jobs_list", ",", "'get_activities_export_jobs_list'", ":", "self", ".", "get_activities_export_jobs_list", ",", "'create_leads_export_job'", ":", "self", ".", "create_leads_export_job", ",", "'create_activities_export_job'", ":", "self", ".", "create_activities_export_job", ",", "'enqueue_leads_export_job'", ":", "self", ".", "enqueue_leads_export_job", ",", "'enqueue_activities_export_job'", ":", "self", ".", "enqueue_activities_export_job", ",", "'cancel_leads_export_job'", ":", "self", ".", "cancel_leads_export_job", ",", "'cancel_activities_export_job'", ":", "self", ".", "cancel_activities_export_job", ",", "'get_leads_export_job_status'", ":", "self", ".", "get_leads_export_job_status", ",", "'get_activities_export_job_status'", ":", "self", ".", "get_activities_export_job_status", ",", "'get_leads_export_job_file'", ":", "self", ".", "get_leads_export_job_file", ",", "'get_activities_export_job_file'", ":", "self", ".", "get_activities_export_job_file", "}", "result", "=", "method_map", "[", "method", "]", "(", "*", "args", ",", "*", "*", "kargs", ")", "except", "MarketoException", "as", "e", ":", "'''\n 601 -> auth token not valid\n 602 -> auth token expired\n '''", "if", "e", ".", "code", "in", "[", "'601'", ",", "'602'", "]", ":", "self", ".", "authenticate", "(", ")", "continue", "else", ":", "raise", "Exception", "(", "{", "'message'", ":", "e", ".", "message", ",", "'code'", ":", "e", ".", "code", "}", ")", "break", "return", "result" ]
max 10 rechecks
[ "max", "10", "rechecks" ]
train
https://github.com/jepcastelein/marketo-rest-python/blob/af9592b7f6dea8166dca1a0223ebc1066c25ca93/marketorestpython/client.py#L46-L280
NaturalHistoryMuseum/pylibdmtx
pylibdmtx/wrapper.py
load_libdmtx
def load_libdmtx(): """Loads the libdmtx shared library. Populates the globals LIBDMTX and EXTERNAL_DEPENDENCIES. """ global LIBDMTX global EXTERNAL_DEPENDENCIES if not LIBDMTX: LIBDMTX = dmtx_library.load() EXTERNAL_DEPENDENCIES = [LIBDMTX] return LIBDMTX
python
def load_libdmtx(): global LIBDMTX global EXTERNAL_DEPENDENCIES if not LIBDMTX: LIBDMTX = dmtx_library.load() EXTERNAL_DEPENDENCIES = [LIBDMTX] return LIBDMTX
[ "def", "load_libdmtx", "(", ")", ":", "global", "LIBDMTX", "global", "EXTERNAL_DEPENDENCIES", "if", "not", "LIBDMTX", ":", "LIBDMTX", "=", "dmtx_library", ".", "load", "(", ")", "EXTERNAL_DEPENDENCIES", "=", "[", "LIBDMTX", "]", "return", "LIBDMTX" ]
Loads the libdmtx shared library. Populates the globals LIBDMTX and EXTERNAL_DEPENDENCIES.
[ "Loads", "the", "libdmtx", "shared", "library", "." ]
train
https://github.com/NaturalHistoryMuseum/pylibdmtx/blob/a425ec36050500af4875bf94eda02feb26ea62ad/pylibdmtx/wrapper.py#L32-L43
NaturalHistoryMuseum/pylibdmtx
pylibdmtx/wrapper.py
libdmtx_function
def libdmtx_function(fname, restype, *args): """Returns a foreign function exported by `libdmtx`. Args: fname (:obj:`str`): Name of the exported function as string. restype (:obj:): Return type - one of the `ctypes` primitive C data types. *args: Arguments - a sequence of `ctypes` primitive C data types. Returns: cddl.CFunctionType: A wrapper around the function. """ prototype = CFUNCTYPE(restype, *args) return prototype((fname, load_libdmtx()))
python
def libdmtx_function(fname, restype, *args): prototype = CFUNCTYPE(restype, *args) return prototype((fname, load_libdmtx()))
[ "def", "libdmtx_function", "(", "fname", ",", "restype", ",", "*", "args", ")", ":", "prototype", "=", "CFUNCTYPE", "(", "restype", ",", "*", "args", ")", "return", "prototype", "(", "(", "fname", ",", "load_libdmtx", "(", ")", ")", ")" ]
Returns a foreign function exported by `libdmtx`. Args: fname (:obj:`str`): Name of the exported function as string. restype (:obj:): Return type - one of the `ctypes` primitive C data types. *args: Arguments - a sequence of `ctypes` primitive C data types. Returns: cddl.CFunctionType: A wrapper around the function.
[ "Returns", "a", "foreign", "function", "exported", "by", "libdmtx", "." ]
train
https://github.com/NaturalHistoryMuseum/pylibdmtx/blob/a425ec36050500af4875bf94eda02feb26ea62ad/pylibdmtx/wrapper.py#L46-L59
NaturalHistoryMuseum/pylibdmtx
pylibdmtx/dmtx_library.py
load
def load(): """Loads the libdmtx shared library. """ if 'Windows' == platform.system(): # Possible scenarios here # 1. Run from source, DLLs are in pylibdmtx directory # cdll.LoadLibrary() imports DLLs in repo root directory # 2. Wheel install into CPython installation # cdll.LoadLibrary() imports DLLs in package directory # 3. Wheel install into virtualenv # cdll.LoadLibrary() imports DLLs in package directory # 4. Frozen # cdll.LoadLibrary() imports DLLs alongside executable fname = _windows_fname() try: libdmtx = cdll.LoadLibrary(fname) except OSError: libdmtx = cdll.LoadLibrary( str(Path(__file__).parent.joinpath(fname)) ) else: # Assume a shared library on the path path = find_library('dmtx') if not path: raise ImportError('Unable to find dmtx shared library') libdmtx = cdll.LoadLibrary(path) return libdmtx
python
def load(): if 'Windows' == platform.system(): fname = _windows_fname() try: libdmtx = cdll.LoadLibrary(fname) except OSError: libdmtx = cdll.LoadLibrary( str(Path(__file__).parent.joinpath(fname)) ) else: path = find_library('dmtx') if not path: raise ImportError('Unable to find dmtx shared library') libdmtx = cdll.LoadLibrary(path) return libdmtx
[ "def", "load", "(", ")", ":", "if", "'Windows'", "==", "platform", ".", "system", "(", ")", ":", "# Possible scenarios here", "# 1. Run from source, DLLs are in pylibdmtx directory", "# cdll.LoadLibrary() imports DLLs in repo root directory", "# 2. Wheel install into CPython installation", "# cdll.LoadLibrary() imports DLLs in package directory", "# 3. Wheel install into virtualenv", "# cdll.LoadLibrary() imports DLLs in package directory", "# 4. Frozen", "# cdll.LoadLibrary() imports DLLs alongside executable", "fname", "=", "_windows_fname", "(", ")", "try", ":", "libdmtx", "=", "cdll", ".", "LoadLibrary", "(", "fname", ")", "except", "OSError", ":", "libdmtx", "=", "cdll", ".", "LoadLibrary", "(", "str", "(", "Path", "(", "__file__", ")", ".", "parent", ".", "joinpath", "(", "fname", ")", ")", ")", "else", ":", "# Assume a shared library on the path", "path", "=", "find_library", "(", "'dmtx'", ")", "if", "not", "path", ":", "raise", "ImportError", "(", "'Unable to find dmtx shared library'", ")", "libdmtx", "=", "cdll", ".", "LoadLibrary", "(", "path", ")", "return", "libdmtx" ]
Loads the libdmtx shared library.
[ "Loads", "the", "libdmtx", "shared", "library", "." ]
train
https://github.com/NaturalHistoryMuseum/pylibdmtx/blob/a425ec36050500af4875bf94eda02feb26ea62ad/pylibdmtx/dmtx_library.py#L22-L50
NaturalHistoryMuseum/pylibdmtx
pylibdmtx/pylibdmtx.py
_image
def _image(pixels, width, height, pack): """A context manager for `DmtxImage`, created and destroyed by `dmtxImageCreate` and `dmtxImageDestroy`. Args: pixels (:obj:): width (int): height (int): pack (int): Yields: DmtxImage: The created image Raises: PyLibDMTXError: If the image could not be created. """ image = dmtxImageCreate(pixels, width, height, pack) if not image: raise PyLibDMTXError('Could not create image') else: try: yield image finally: dmtxImageDestroy(byref(image))
python
def _image(pixels, width, height, pack): image = dmtxImageCreate(pixels, width, height, pack) if not image: raise PyLibDMTXError('Could not create image') else: try: yield image finally: dmtxImageDestroy(byref(image))
[ "def", "_image", "(", "pixels", ",", "width", ",", "height", ",", "pack", ")", ":", "image", "=", "dmtxImageCreate", "(", "pixels", ",", "width", ",", "height", ",", "pack", ")", "if", "not", "image", ":", "raise", "PyLibDMTXError", "(", "'Could not create image'", ")", "else", ":", "try", ":", "yield", "image", "finally", ":", "dmtxImageDestroy", "(", "byref", "(", "image", ")", ")" ]
A context manager for `DmtxImage`, created and destroyed by `dmtxImageCreate` and `dmtxImageDestroy`. Args: pixels (:obj:): width (int): height (int): pack (int): Yields: DmtxImage: The created image Raises: PyLibDMTXError: If the image could not be created.
[ "A", "context", "manager", "for", "DmtxImage", "created", "and", "destroyed", "by", "dmtxImageCreate", "and", "dmtxImageDestroy", "." ]
train
https://github.com/NaturalHistoryMuseum/pylibdmtx/blob/a425ec36050500af4875bf94eda02feb26ea62ad/pylibdmtx/pylibdmtx.py#L57-L80
NaturalHistoryMuseum/pylibdmtx
pylibdmtx/pylibdmtx.py
_decoder
def _decoder(image, shrink): """A context manager for `DmtxDecode`, created and destroyed by `dmtxDecodeCreate` and `dmtxDecodeDestroy`. Args: image (POINTER(DmtxImage)): shrink (int): Yields: POINTER(DmtxDecode): The created decoder Raises: PyLibDMTXError: If the decoder could not be created. """ decoder = dmtxDecodeCreate(image, shrink) if not decoder: raise PyLibDMTXError('Could not create decoder') else: try: yield decoder finally: dmtxDecodeDestroy(byref(decoder))
python
def _decoder(image, shrink): decoder = dmtxDecodeCreate(image, shrink) if not decoder: raise PyLibDMTXError('Could not create decoder') else: try: yield decoder finally: dmtxDecodeDestroy(byref(decoder))
[ "def", "_decoder", "(", "image", ",", "shrink", ")", ":", "decoder", "=", "dmtxDecodeCreate", "(", "image", ",", "shrink", ")", "if", "not", "decoder", ":", "raise", "PyLibDMTXError", "(", "'Could not create decoder'", ")", "else", ":", "try", ":", "yield", "decoder", "finally", ":", "dmtxDecodeDestroy", "(", "byref", "(", "decoder", ")", ")" ]
A context manager for `DmtxDecode`, created and destroyed by `dmtxDecodeCreate` and `dmtxDecodeDestroy`. Args: image (POINTER(DmtxImage)): shrink (int): Yields: POINTER(DmtxDecode): The created decoder Raises: PyLibDMTXError: If the decoder could not be created.
[ "A", "context", "manager", "for", "DmtxDecode", "created", "and", "destroyed", "by", "dmtxDecodeCreate", "and", "dmtxDecodeDestroy", "." ]
train
https://github.com/NaturalHistoryMuseum/pylibdmtx/blob/a425ec36050500af4875bf94eda02feb26ea62ad/pylibdmtx/pylibdmtx.py#L84-L105
NaturalHistoryMuseum/pylibdmtx
pylibdmtx/pylibdmtx.py
_region
def _region(decoder, timeout): """A context manager for `DmtxRegion`, created and destroyed by `dmtxRegionFindNext` and `dmtxRegionDestroy`. Args: decoder (POINTER(DmtxDecode)): timeout (int or None): Yields: DmtxRegion: The next region or None, if all regions have been found. """ region = dmtxRegionFindNext(decoder, timeout) try: yield region finally: if region: dmtxRegionDestroy(byref(region))
python
def _region(decoder, timeout): region = dmtxRegionFindNext(decoder, timeout) try: yield region finally: if region: dmtxRegionDestroy(byref(region))
[ "def", "_region", "(", "decoder", ",", "timeout", ")", ":", "region", "=", "dmtxRegionFindNext", "(", "decoder", ",", "timeout", ")", "try", ":", "yield", "region", "finally", ":", "if", "region", ":", "dmtxRegionDestroy", "(", "byref", "(", "region", ")", ")" ]
A context manager for `DmtxRegion`, created and destroyed by `dmtxRegionFindNext` and `dmtxRegionDestroy`. Args: decoder (POINTER(DmtxDecode)): timeout (int or None): Yields: DmtxRegion: The next region or None, if all regions have been found.
[ "A", "context", "manager", "for", "DmtxRegion", "created", "and", "destroyed", "by", "dmtxRegionFindNext", "and", "dmtxRegionDestroy", "." ]
train
https://github.com/NaturalHistoryMuseum/pylibdmtx/blob/a425ec36050500af4875bf94eda02feb26ea62ad/pylibdmtx/pylibdmtx.py#L109-L125
NaturalHistoryMuseum/pylibdmtx
pylibdmtx/pylibdmtx.py
_decoded_matrix_region
def _decoded_matrix_region(decoder, region, corrections): """A context manager for `DmtxMessage`, created and destoyed by `dmtxDecodeMatrixRegion` and `dmtxMessageDestroy`. Args: decoder (POINTER(DmtxDecode)): region (POINTER(DmtxRegion)): corrections (int): Yields: DmtxMessage: The message. """ message = dmtxDecodeMatrixRegion(decoder, region, corrections) try: yield message finally: if message: dmtxMessageDestroy(byref(message))
python
def _decoded_matrix_region(decoder, region, corrections): message = dmtxDecodeMatrixRegion(decoder, region, corrections) try: yield message finally: if message: dmtxMessageDestroy(byref(message))
[ "def", "_decoded_matrix_region", "(", "decoder", ",", "region", ",", "corrections", ")", ":", "message", "=", "dmtxDecodeMatrixRegion", "(", "decoder", ",", "region", ",", "corrections", ")", "try", ":", "yield", "message", "finally", ":", "if", "message", ":", "dmtxMessageDestroy", "(", "byref", "(", "message", ")", ")" ]
A context manager for `DmtxMessage`, created and destoyed by `dmtxDecodeMatrixRegion` and `dmtxMessageDestroy`. Args: decoder (POINTER(DmtxDecode)): region (POINTER(DmtxRegion)): corrections (int): Yields: DmtxMessage: The message.
[ "A", "context", "manager", "for", "DmtxMessage", "created", "and", "destoyed", "by", "dmtxDecodeMatrixRegion", "and", "dmtxMessageDestroy", "." ]
train
https://github.com/NaturalHistoryMuseum/pylibdmtx/blob/a425ec36050500af4875bf94eda02feb26ea62ad/pylibdmtx/pylibdmtx.py#L129-L146
NaturalHistoryMuseum/pylibdmtx
pylibdmtx/pylibdmtx.py
_decode_region
def _decode_region(decoder, region, corrections, shrink): """Decodes and returns the value in a region. Args: region (DmtxRegion): Yields: Decoded or None: The decoded value. """ with _decoded_matrix_region(decoder, region, corrections) as msg: if msg: # Coordinates p00 = DmtxVector2() p11 = DmtxVector2(1.0, 1.0) dmtxMatrix3VMultiplyBy( p00, region.contents.fit2raw ) dmtxMatrix3VMultiplyBy(p11, region.contents.fit2raw) x0 = int((shrink * p00.X) + 0.5) y0 = int((shrink * p00.Y) + 0.5) x1 = int((shrink * p11.X) + 0.5) y1 = int((shrink * p11.Y) + 0.5) return Decoded( string_at(msg.contents.output), Rect(x0, y0, x1 - x0, y1 - y0) ) else: return None
python
def _decode_region(decoder, region, corrections, shrink): with _decoded_matrix_region(decoder, region, corrections) as msg: if msg: p00 = DmtxVector2() p11 = DmtxVector2(1.0, 1.0) dmtxMatrix3VMultiplyBy( p00, region.contents.fit2raw ) dmtxMatrix3VMultiplyBy(p11, region.contents.fit2raw) x0 = int((shrink * p00.X) + 0.5) y0 = int((shrink * p00.Y) + 0.5) x1 = int((shrink * p11.X) + 0.5) y1 = int((shrink * p11.Y) + 0.5) return Decoded( string_at(msg.contents.output), Rect(x0, y0, x1 - x0, y1 - y0) ) else: return None
[ "def", "_decode_region", "(", "decoder", ",", "region", ",", "corrections", ",", "shrink", ")", ":", "with", "_decoded_matrix_region", "(", "decoder", ",", "region", ",", "corrections", ")", "as", "msg", ":", "if", "msg", ":", "# Coordinates", "p00", "=", "DmtxVector2", "(", ")", "p11", "=", "DmtxVector2", "(", "1.0", ",", "1.0", ")", "dmtxMatrix3VMultiplyBy", "(", "p00", ",", "region", ".", "contents", ".", "fit2raw", ")", "dmtxMatrix3VMultiplyBy", "(", "p11", ",", "region", ".", "contents", ".", "fit2raw", ")", "x0", "=", "int", "(", "(", "shrink", "*", "p00", ".", "X", ")", "+", "0.5", ")", "y0", "=", "int", "(", "(", "shrink", "*", "p00", ".", "Y", ")", "+", "0.5", ")", "x1", "=", "int", "(", "(", "shrink", "*", "p11", ".", "X", ")", "+", "0.5", ")", "y1", "=", "int", "(", "(", "shrink", "*", "p11", ".", "Y", ")", "+", "0.5", ")", "return", "Decoded", "(", "string_at", "(", "msg", ".", "contents", ".", "output", ")", ",", "Rect", "(", "x0", ",", "y0", ",", "x1", "-", "x0", ",", "y1", "-", "y0", ")", ")", "else", ":", "return", "None" ]
Decodes and returns the value in a region. Args: region (DmtxRegion): Yields: Decoded or None: The decoded value.
[ "Decodes", "and", "returns", "the", "value", "in", "a", "region", "." ]
train
https://github.com/NaturalHistoryMuseum/pylibdmtx/blob/a425ec36050500af4875bf94eda02feb26ea62ad/pylibdmtx/pylibdmtx.py#L149-L177
NaturalHistoryMuseum/pylibdmtx
pylibdmtx/pylibdmtx.py
_pixel_data
def _pixel_data(image): """Returns (pixels, width, height, bpp) Returns: :obj: `tuple` (pixels, width, height, bpp) """ # Test for PIL.Image and numpy.ndarray without requiring that cv2 or PIL # are installed. if 'PIL.' in str(type(image)): pixels = image.tobytes() width, height = image.size elif 'numpy.ndarray' in str(type(image)): if 'uint8' != str(image.dtype): image = image.astype('uint8') try: pixels = image.tobytes() except AttributeError: # `numpy.ndarray.tobytes()` introduced in `numpy` 1.9.0 - use the # older `tostring` method. pixels = image.tostring() height, width = image.shape[:2] else: # image should be a tuple (pixels, width, height) pixels, width, height = image # Check dimensions if 0 != len(pixels) % (width * height): raise PyLibDMTXError( ( 'Inconsistent dimensions: image data of {0} bytes is not ' 'divisible by (width x height = {1})' ).format(len(pixels), (width * height)) ) # Compute bits-per-pixel bpp = 8 * len(pixels) // (width * height) if bpp not in _PACK_ORDER: raise PyLibDMTXError( 'Unsupported bits-per-pixel: [{0}] Should be one of {1}'.format( bpp, sorted(_PACK_ORDER.keys()) ) ) return pixels, width, height, bpp
python
def _pixel_data(image): if 'PIL.' in str(type(image)): pixels = image.tobytes() width, height = image.size elif 'numpy.ndarray' in str(type(image)): if 'uint8' != str(image.dtype): image = image.astype('uint8') try: pixels = image.tobytes() except AttributeError: pixels = image.tostring() height, width = image.shape[:2] else: pixels, width, height = image if 0 != len(pixels) % (width * height): raise PyLibDMTXError( ( 'Inconsistent dimensions: image data of {0} bytes is not ' 'divisible by (width x height = {1})' ).format(len(pixels), (width * height)) ) bpp = 8 * len(pixels) // (width * height) if bpp not in _PACK_ORDER: raise PyLibDMTXError( 'Unsupported bits-per-pixel: [{0}] Should be one of {1}'.format( bpp, sorted(_PACK_ORDER.keys()) ) ) return pixels, width, height, bpp
[ "def", "_pixel_data", "(", "image", ")", ":", "# Test for PIL.Image and numpy.ndarray without requiring that cv2 or PIL", "# are installed.", "if", "'PIL.'", "in", "str", "(", "type", "(", "image", ")", ")", ":", "pixels", "=", "image", ".", "tobytes", "(", ")", "width", ",", "height", "=", "image", ".", "size", "elif", "'numpy.ndarray'", "in", "str", "(", "type", "(", "image", ")", ")", ":", "if", "'uint8'", "!=", "str", "(", "image", ".", "dtype", ")", ":", "image", "=", "image", ".", "astype", "(", "'uint8'", ")", "try", ":", "pixels", "=", "image", ".", "tobytes", "(", ")", "except", "AttributeError", ":", "# `numpy.ndarray.tobytes()` introduced in `numpy` 1.9.0 - use the", "# older `tostring` method.", "pixels", "=", "image", ".", "tostring", "(", ")", "height", ",", "width", "=", "image", ".", "shape", "[", ":", "2", "]", "else", ":", "# image should be a tuple (pixels, width, height)", "pixels", ",", "width", ",", "height", "=", "image", "# Check dimensions", "if", "0", "!=", "len", "(", "pixels", ")", "%", "(", "width", "*", "height", ")", ":", "raise", "PyLibDMTXError", "(", "(", "'Inconsistent dimensions: image data of {0} bytes is not '", "'divisible by (width x height = {1})'", ")", ".", "format", "(", "len", "(", "pixels", ")", ",", "(", "width", "*", "height", ")", ")", ")", "# Compute bits-per-pixel", "bpp", "=", "8", "*", "len", "(", "pixels", ")", "//", "(", "width", "*", "height", ")", "if", "bpp", "not", "in", "_PACK_ORDER", ":", "raise", "PyLibDMTXError", "(", "'Unsupported bits-per-pixel: [{0}] Should be one of {1}'", ".", "format", "(", "bpp", ",", "sorted", "(", "_PACK_ORDER", ".", "keys", "(", ")", ")", ")", ")", "return", "pixels", ",", "width", ",", "height", ",", "bpp" ]
Returns (pixels, width, height, bpp) Returns: :obj: `tuple` (pixels, width, height, bpp)
[ "Returns", "(", "pixels", "width", "height", "bpp", ")" ]
train
https://github.com/NaturalHistoryMuseum/pylibdmtx/blob/a425ec36050500af4875bf94eda02feb26ea62ad/pylibdmtx/pylibdmtx.py#L180-L223
NaturalHistoryMuseum/pylibdmtx
pylibdmtx/pylibdmtx.py
decode
def decode(image, timeout=None, gap_size=None, shrink=1, shape=None, deviation=None, threshold=None, min_edge=None, max_edge=None, corrections=None, max_count=None): """Decodes datamatrix barcodes in `image`. Args: image: `numpy.ndarray`, `PIL.Image` or tuple (pixels, width, height) timeout (int): milliseconds gap_size (int): shrink (int): shape (int): deviation (int): threshold (int): min_edge (int): max_edge (int): corrections (int): max_count (int): stop after reading this many barcodes. `None` to read as many as possible. Returns: :obj:`list` of :obj:`Decoded`: The values decoded from barcodes. """ dmtx_timeout = None if timeout: now = dmtxTimeNow() dmtx_timeout = dmtxTimeAdd(now, timeout) if max_count is not None and max_count < 1: raise ValueError('Invalid max_count [{0}]'.format(max_count)) pixels, width, height, bpp = _pixel_data(image) results = [] with _image( cast(pixels, c_ubyte_p), width, height, _PACK_ORDER[bpp] ) as img: with _decoder(img, shrink) as decoder: properties = [ (DmtxProperty.DmtxPropScanGap, gap_size), (DmtxProperty.DmtxPropSymbolSize, shape), (DmtxProperty.DmtxPropSquareDevn, deviation), (DmtxProperty.DmtxPropEdgeThresh, threshold), (DmtxProperty.DmtxPropEdgeMin, min_edge), (DmtxProperty.DmtxPropEdgeMax, max_edge) ] # Set only those properties with a non-None value for prop, value in ((p, v) for p, v in properties if v is not None): dmtxDecodeSetProp(decoder, prop, value) if not corrections: corrections = DmtxUndefined while True: with _region(decoder, dmtx_timeout) as region: # Finished file or ran out of time before finding another # region if not region: break else: # Decoded res = _decode_region( decoder, region, corrections, shrink ) if res: results.append(res) # Stop if we've reached maximum count if max_count and len(results) == max_count: break return results
python
def decode(image, timeout=None, gap_size=None, shrink=1, shape=None, deviation=None, threshold=None, min_edge=None, max_edge=None, corrections=None, max_count=None): dmtx_timeout = None if timeout: now = dmtxTimeNow() dmtx_timeout = dmtxTimeAdd(now, timeout) if max_count is not None and max_count < 1: raise ValueError('Invalid max_count [{0}]'.format(max_count)) pixels, width, height, bpp = _pixel_data(image) results = [] with _image( cast(pixels, c_ubyte_p), width, height, _PACK_ORDER[bpp] ) as img: with _decoder(img, shrink) as decoder: properties = [ (DmtxProperty.DmtxPropScanGap, gap_size), (DmtxProperty.DmtxPropSymbolSize, shape), (DmtxProperty.DmtxPropSquareDevn, deviation), (DmtxProperty.DmtxPropEdgeThresh, threshold), (DmtxProperty.DmtxPropEdgeMin, min_edge), (DmtxProperty.DmtxPropEdgeMax, max_edge) ] for prop, value in ((p, v) for p, v in properties if v is not None): dmtxDecodeSetProp(decoder, prop, value) if not corrections: corrections = DmtxUndefined while True: with _region(decoder, dmtx_timeout) as region: if not region: break else: res = _decode_region( decoder, region, corrections, shrink ) if res: results.append(res) if max_count and len(results) == max_count: break return results
[ "def", "decode", "(", "image", ",", "timeout", "=", "None", ",", "gap_size", "=", "None", ",", "shrink", "=", "1", ",", "shape", "=", "None", ",", "deviation", "=", "None", ",", "threshold", "=", "None", ",", "min_edge", "=", "None", ",", "max_edge", "=", "None", ",", "corrections", "=", "None", ",", "max_count", "=", "None", ")", ":", "dmtx_timeout", "=", "None", "if", "timeout", ":", "now", "=", "dmtxTimeNow", "(", ")", "dmtx_timeout", "=", "dmtxTimeAdd", "(", "now", ",", "timeout", ")", "if", "max_count", "is", "not", "None", "and", "max_count", "<", "1", ":", "raise", "ValueError", "(", "'Invalid max_count [{0}]'", ".", "format", "(", "max_count", ")", ")", "pixels", ",", "width", ",", "height", ",", "bpp", "=", "_pixel_data", "(", "image", ")", "results", "=", "[", "]", "with", "_image", "(", "cast", "(", "pixels", ",", "c_ubyte_p", ")", ",", "width", ",", "height", ",", "_PACK_ORDER", "[", "bpp", "]", ")", "as", "img", ":", "with", "_decoder", "(", "img", ",", "shrink", ")", "as", "decoder", ":", "properties", "=", "[", "(", "DmtxProperty", ".", "DmtxPropScanGap", ",", "gap_size", ")", ",", "(", "DmtxProperty", ".", "DmtxPropSymbolSize", ",", "shape", ")", ",", "(", "DmtxProperty", ".", "DmtxPropSquareDevn", ",", "deviation", ")", ",", "(", "DmtxProperty", ".", "DmtxPropEdgeThresh", ",", "threshold", ")", ",", "(", "DmtxProperty", ".", "DmtxPropEdgeMin", ",", "min_edge", ")", ",", "(", "DmtxProperty", ".", "DmtxPropEdgeMax", ",", "max_edge", ")", "]", "# Set only those properties with a non-None value", "for", "prop", ",", "value", "in", "(", "(", "p", ",", "v", ")", "for", "p", ",", "v", "in", "properties", "if", "v", "is", "not", "None", ")", ":", "dmtxDecodeSetProp", "(", "decoder", ",", "prop", ",", "value", ")", "if", "not", "corrections", ":", "corrections", "=", "DmtxUndefined", "while", "True", ":", "with", "_region", "(", "decoder", ",", "dmtx_timeout", ")", "as", "region", ":", "# Finished file or ran out of time before finding another", "# region", "if", "not", "region", ":", "break", "else", ":", "# Decoded", "res", "=", "_decode_region", "(", "decoder", ",", "region", ",", "corrections", ",", "shrink", ")", "if", "res", ":", "results", ".", "append", "(", "res", ")", "# Stop if we've reached maximum count", "if", "max_count", "and", "len", "(", "results", ")", "==", "max_count", ":", "break", "return", "results" ]
Decodes datamatrix barcodes in `image`. Args: image: `numpy.ndarray`, `PIL.Image` or tuple (pixels, width, height) timeout (int): milliseconds gap_size (int): shrink (int): shape (int): deviation (int): threshold (int): min_edge (int): max_edge (int): corrections (int): max_count (int): stop after reading this many barcodes. `None` to read as many as possible. Returns: :obj:`list` of :obj:`Decoded`: The values decoded from barcodes.
[ "Decodes", "datamatrix", "barcodes", "in", "image", "." ]
train
https://github.com/NaturalHistoryMuseum/pylibdmtx/blob/a425ec36050500af4875bf94eda02feb26ea62ad/pylibdmtx/pylibdmtx.py#L226-L297
NaturalHistoryMuseum/pylibdmtx
pylibdmtx/pylibdmtx.py
encode
def encode(data, scheme=None, size=None): """ Encodes `data` in a DataMatrix image. For now bpp is the libdmtx default which is 24 Args: data: bytes instance scheme: encoding scheme - one of `ENCODING_SCHEME_NAMES`, or `None`. If `None`, defaults to 'Ascii'. size: image dimensions - one of `ENCODING_SIZE_NAMES`, or `None`. If `None`, defaults to 'ShapeAuto'. Returns: Encoded: with properties `(width, height, bpp, pixels)`. You can use that result to build a PIL image: Image.frombytes('RGB', (width, height), pixels) """ size = size if size else 'ShapeAuto' size_name = '{0}{1}'.format(ENCODING_SIZE_PREFIX, size) if not hasattr(DmtxSymbolSize, size_name): raise PyLibDMTXError( 'Invalid size [{0}]: should be one of {1}'.format( size, ENCODING_SIZE_NAMES ) ) size = getattr(DmtxSymbolSize, size_name) scheme = scheme if scheme else 'Ascii' scheme_name = '{0}{1}'.format( ENCODING_SCHEME_PREFIX, scheme.capitalize() ) if not hasattr(DmtxScheme, scheme_name): raise PyLibDMTXError( 'Invalid scheme [{0}]: should be one of {1}'.format( scheme, ENCODING_SCHEME_NAMES ) ) scheme = getattr(DmtxScheme, scheme_name) with _encoder() as encoder: dmtxEncodeSetProp(encoder, DmtxProperty.DmtxPropScheme, scheme) dmtxEncodeSetProp(encoder, DmtxProperty.DmtxPropSizeRequest, size) if dmtxEncodeDataMatrix(encoder, len(data), cast(data, c_ubyte_p)) == 0: raise PyLibDMTXError( 'Could not encode data, possibly because the image is not ' 'large enough to contain the data' ) w, h, bpp = map( partial(dmtxImageGetProp, encoder[0].image), ( DmtxProperty.DmtxPropWidth, DmtxProperty.DmtxPropHeight, DmtxProperty.DmtxPropBitsPerPixel ) ) size = w * h * bpp // 8 pixels = cast( encoder[0].image[0].pxl, ctypes.POINTER(ctypes.c_ubyte * size) ) return Encoded( width=w, height=h, bpp=bpp, pixels=ctypes.string_at(pixels, size) )
python
def encode(data, scheme=None, size=None): size = size if size else 'ShapeAuto' size_name = '{0}{1}'.format(ENCODING_SIZE_PREFIX, size) if not hasattr(DmtxSymbolSize, size_name): raise PyLibDMTXError( 'Invalid size [{0}]: should be one of {1}'.format( size, ENCODING_SIZE_NAMES ) ) size = getattr(DmtxSymbolSize, size_name) scheme = scheme if scheme else 'Ascii' scheme_name = '{0}{1}'.format( ENCODING_SCHEME_PREFIX, scheme.capitalize() ) if not hasattr(DmtxScheme, scheme_name): raise PyLibDMTXError( 'Invalid scheme [{0}]: should be one of {1}'.format( scheme, ENCODING_SCHEME_NAMES ) ) scheme = getattr(DmtxScheme, scheme_name) with _encoder() as encoder: dmtxEncodeSetProp(encoder, DmtxProperty.DmtxPropScheme, scheme) dmtxEncodeSetProp(encoder, DmtxProperty.DmtxPropSizeRequest, size) if dmtxEncodeDataMatrix(encoder, len(data), cast(data, c_ubyte_p)) == 0: raise PyLibDMTXError( 'Could not encode data, possibly because the image is not ' 'large enough to contain the data' ) w, h, bpp = map( partial(dmtxImageGetProp, encoder[0].image), ( DmtxProperty.DmtxPropWidth, DmtxProperty.DmtxPropHeight, DmtxProperty.DmtxPropBitsPerPixel ) ) size = w * h * bpp // 8 pixels = cast( encoder[0].image[0].pxl, ctypes.POINTER(ctypes.c_ubyte * size) ) return Encoded( width=w, height=h, bpp=bpp, pixels=ctypes.string_at(pixels, size) )
[ "def", "encode", "(", "data", ",", "scheme", "=", "None", ",", "size", "=", "None", ")", ":", "size", "=", "size", "if", "size", "else", "'ShapeAuto'", "size_name", "=", "'{0}{1}'", ".", "format", "(", "ENCODING_SIZE_PREFIX", ",", "size", ")", "if", "not", "hasattr", "(", "DmtxSymbolSize", ",", "size_name", ")", ":", "raise", "PyLibDMTXError", "(", "'Invalid size [{0}]: should be one of {1}'", ".", "format", "(", "size", ",", "ENCODING_SIZE_NAMES", ")", ")", "size", "=", "getattr", "(", "DmtxSymbolSize", ",", "size_name", ")", "scheme", "=", "scheme", "if", "scheme", "else", "'Ascii'", "scheme_name", "=", "'{0}{1}'", ".", "format", "(", "ENCODING_SCHEME_PREFIX", ",", "scheme", ".", "capitalize", "(", ")", ")", "if", "not", "hasattr", "(", "DmtxScheme", ",", "scheme_name", ")", ":", "raise", "PyLibDMTXError", "(", "'Invalid scheme [{0}]: should be one of {1}'", ".", "format", "(", "scheme", ",", "ENCODING_SCHEME_NAMES", ")", ")", "scheme", "=", "getattr", "(", "DmtxScheme", ",", "scheme_name", ")", "with", "_encoder", "(", ")", "as", "encoder", ":", "dmtxEncodeSetProp", "(", "encoder", ",", "DmtxProperty", ".", "DmtxPropScheme", ",", "scheme", ")", "dmtxEncodeSetProp", "(", "encoder", ",", "DmtxProperty", ".", "DmtxPropSizeRequest", ",", "size", ")", "if", "dmtxEncodeDataMatrix", "(", "encoder", ",", "len", "(", "data", ")", ",", "cast", "(", "data", ",", "c_ubyte_p", ")", ")", "==", "0", ":", "raise", "PyLibDMTXError", "(", "'Could not encode data, possibly because the image is not '", "'large enough to contain the data'", ")", "w", ",", "h", ",", "bpp", "=", "map", "(", "partial", "(", "dmtxImageGetProp", ",", "encoder", "[", "0", "]", ".", "image", ")", ",", "(", "DmtxProperty", ".", "DmtxPropWidth", ",", "DmtxProperty", ".", "DmtxPropHeight", ",", "DmtxProperty", ".", "DmtxPropBitsPerPixel", ")", ")", "size", "=", "w", "*", "h", "*", "bpp", "//", "8", "pixels", "=", "cast", "(", "encoder", "[", "0", "]", ".", "image", "[", "0", "]", ".", "pxl", ",", "ctypes", ".", "POINTER", "(", "ctypes", ".", "c_ubyte", "*", "size", ")", ")", "return", "Encoded", "(", "width", "=", "w", ",", "height", "=", "h", ",", "bpp", "=", "bpp", ",", "pixels", "=", "ctypes", ".", "string_at", "(", "pixels", ",", "size", ")", ")" ]
Encodes `data` in a DataMatrix image. For now bpp is the libdmtx default which is 24 Args: data: bytes instance scheme: encoding scheme - one of `ENCODING_SCHEME_NAMES`, or `None`. If `None`, defaults to 'Ascii'. size: image dimensions - one of `ENCODING_SIZE_NAMES`, or `None`. If `None`, defaults to 'ShapeAuto'. Returns: Encoded: with properties `(width, height, bpp, pixels)`. You can use that result to build a PIL image: Image.frombytes('RGB', (width, height), pixels)
[ "Encodes", "data", "in", "a", "DataMatrix", "image", "." ]
train
https://github.com/NaturalHistoryMuseum/pylibdmtx/blob/a425ec36050500af4875bf94eda02feb26ea62ad/pylibdmtx/pylibdmtx.py#L312-L378
GeoPyTool/GeoPyTool
geopytool/Stereo.py
Stereo.lines
def lines(self, Width=1, Color='k'): ''' read the Excel, then draw the wulf net and Plot points, job done~ ''' self.axes.clear() # self.axes.set_xlim(-90, 450) self.axes.set_ylim(0, 90) titles = list('NWSE') titles = ['N', '330', '300', 'W', '240', '210', 'S', '150', '120', 'E', '60', '30'] self.n = len(titles) self.angles = np.arange(90, 90 + 360, 360.0 / self.n) self.angles = np.array([90., 120., 150., 180., 210., 240., 270., 300., 330., 360., 30., 60.]) self.axes.set_thetagrids(self.angles, labels=titles, fontsize=14) raw = self._df Data = [] Labels = [] if (int(self.type_slider.value()) == 0): list1 = [self.eqan(x) for x in range(15, 90, 15)] else: list1 = [self.eqar(x) for x in range(15, 90, 15)] list2 = [str(x) for x in range(15, 90, 15)] self.axes.set_rgrids(list1, list2) for i in range(len(raw)): Data.append([raw.at[i, 'Dip'], raw.at[i, 'Dip-Angle'], raw.at[i, 'Color'], raw.at[i, 'Width'], raw.at[i, 'Alpha'], raw.at[i, 'Label']]) Dip = raw.at[i, 'Dip'] Dip_Angle = raw.at[i, 'Dip-Angle'] Label = raw.at[i, 'Label'] if (Label not in Labels): Labels.append(Label) else: Label = '' Width = 1 Color = 'red' Alpha = 0.8 Marker = 'o' Size = 50 Setting = [Width, Color, Alpha, Marker, Size] Width = raw.at[i, 'Width'] Color = raw.at[i, 'Color'] Alpha = raw.at[i, 'Alpha'] Marker = raw.at[i, 'Marker'] Size = raw.at[i, 'Size'] if (Color not in Setting or Color != ''): Width = raw.at[i, 'Width'] Color = raw.at[i, 'Color'] Alpha = raw.at[i, 'Alpha'] Marker = raw.at[i, 'Marker'] Size = raw.at[i, 'Size'] Setting = [Width, Color, Alpha, Marker, Size] r = np.arange(Dip - 90, Dip + 91, 1) BearR = [np.radians(-A + 90) for A in r] if (int(self.type_slider.value()) == 0): Line = (self.eqan(self.getangular(Dip_Angle, Dip, r))) else: Line = (self.eqar(self.getangular(Dip_Angle, Dip, r))) self.axes.plot(BearR, Line, color=Color, linewidth=Width, alpha=Alpha, label=Label) # self.axes.thetagrids(range(360 + 90, 0 + 90, -30), [str(x) for x in range(0, 360, 30)]) if (self.legend_cb.isChecked()): self.axes.legend(bbox_to_anchor=(1.5, 1), loc=2, borderaxespad=0, prop=fontprop)
python
def lines(self, Width=1, Color='k'): self.axes.clear() self.axes.set_ylim(0, 90) titles = list('NWSE') titles = ['N', '330', '300', 'W', '240', '210', 'S', '150', '120', 'E', '60', '30'] self.n = len(titles) self.angles = np.arange(90, 90 + 360, 360.0 / self.n) self.angles = np.array([90., 120., 150., 180., 210., 240., 270., 300., 330., 360., 30., 60.]) self.axes.set_thetagrids(self.angles, labels=titles, fontsize=14) raw = self._df Data = [] Labels = [] if (int(self.type_slider.value()) == 0): list1 = [self.eqan(x) for x in range(15, 90, 15)] else: list1 = [self.eqar(x) for x in range(15, 90, 15)] list2 = [str(x) for x in range(15, 90, 15)] self.axes.set_rgrids(list1, list2) for i in range(len(raw)): Data.append([raw.at[i, 'Dip'], raw.at[i, 'Dip-Angle'], raw.at[i, 'Color'], raw.at[i, 'Width'], raw.at[i, 'Alpha'], raw.at[i, 'Label']]) Dip = raw.at[i, 'Dip'] Dip_Angle = raw.at[i, 'Dip-Angle'] Label = raw.at[i, 'Label'] if (Label not in Labels): Labels.append(Label) else: Label = '' Width = 1 Color = 'red' Alpha = 0.8 Marker = 'o' Size = 50 Setting = [Width, Color, Alpha, Marker, Size] Width = raw.at[i, 'Width'] Color = raw.at[i, 'Color'] Alpha = raw.at[i, 'Alpha'] Marker = raw.at[i, 'Marker'] Size = raw.at[i, 'Size'] if (Color not in Setting or Color != ''): Width = raw.at[i, 'Width'] Color = raw.at[i, 'Color'] Alpha = raw.at[i, 'Alpha'] Marker = raw.at[i, 'Marker'] Size = raw.at[i, 'Size'] Setting = [Width, Color, Alpha, Marker, Size] r = np.arange(Dip - 90, Dip + 91, 1) BearR = [np.radians(-A + 90) for A in r] if (int(self.type_slider.value()) == 0): Line = (self.eqan(self.getangular(Dip_Angle, Dip, r))) else: Line = (self.eqar(self.getangular(Dip_Angle, Dip, r))) self.axes.plot(BearR, Line, color=Color, linewidth=Width, alpha=Alpha, label=Label) if (self.legend_cb.isChecked()): self.axes.legend(bbox_to_anchor=(1.5, 1), loc=2, borderaxespad=0, prop=fontprop)
[ "def", "lines", "(", "self", ",", "Width", "=", "1", ",", "Color", "=", "'k'", ")", ":", "self", ".", "axes", ".", "clear", "(", ")", "# self.axes.set_xlim(-90, 450)", "self", ".", "axes", ".", "set_ylim", "(", "0", ",", "90", ")", "titles", "=", "list", "(", "'NWSE'", ")", "titles", "=", "[", "'N'", ",", "'330'", ",", "'300'", ",", "'W'", ",", "'240'", ",", "'210'", ",", "'S'", ",", "'150'", ",", "'120'", ",", "'E'", ",", "'60'", ",", "'30'", "]", "self", ".", "n", "=", "len", "(", "titles", ")", "self", ".", "angles", "=", "np", ".", "arange", "(", "90", ",", "90", "+", "360", ",", "360.0", "/", "self", ".", "n", ")", "self", ".", "angles", "=", "np", ".", "array", "(", "[", "90.", ",", "120.", ",", "150.", ",", "180.", ",", "210.", ",", "240.", ",", "270.", ",", "300.", ",", "330.", ",", "360.", ",", "30.", ",", "60.", "]", ")", "self", ".", "axes", ".", "set_thetagrids", "(", "self", ".", "angles", ",", "labels", "=", "titles", ",", "fontsize", "=", "14", ")", "raw", "=", "self", ".", "_df", "Data", "=", "[", "]", "Labels", "=", "[", "]", "if", "(", "int", "(", "self", ".", "type_slider", ".", "value", "(", ")", ")", "==", "0", ")", ":", "list1", "=", "[", "self", ".", "eqan", "(", "x", ")", "for", "x", "in", "range", "(", "15", ",", "90", ",", "15", ")", "]", "else", ":", "list1", "=", "[", "self", ".", "eqar", "(", "x", ")", "for", "x", "in", "range", "(", "15", ",", "90", ",", "15", ")", "]", "list2", "=", "[", "str", "(", "x", ")", "for", "x", "in", "range", "(", "15", ",", "90", ",", "15", ")", "]", "self", ".", "axes", ".", "set_rgrids", "(", "list1", ",", "list2", ")", "for", "i", "in", "range", "(", "len", "(", "raw", ")", ")", ":", "Data", ".", "append", "(", "[", "raw", ".", "at", "[", "i", ",", "'Dip'", "]", ",", "raw", ".", "at", "[", "i", ",", "'Dip-Angle'", "]", ",", "raw", ".", "at", "[", "i", ",", "'Color'", "]", ",", "raw", ".", "at", "[", "i", ",", "'Width'", "]", ",", "raw", ".", "at", "[", "i", ",", "'Alpha'", "]", ",", "raw", ".", "at", "[", "i", ",", "'Label'", "]", "]", ")", "Dip", "=", "raw", ".", "at", "[", "i", ",", "'Dip'", "]", "Dip_Angle", "=", "raw", ".", "at", "[", "i", ",", "'Dip-Angle'", "]", "Label", "=", "raw", ".", "at", "[", "i", ",", "'Label'", "]", "if", "(", "Label", "not", "in", "Labels", ")", ":", "Labels", ".", "append", "(", "Label", ")", "else", ":", "Label", "=", "''", "Width", "=", "1", "Color", "=", "'red'", "Alpha", "=", "0.8", "Marker", "=", "'o'", "Size", "=", "50", "Setting", "=", "[", "Width", ",", "Color", ",", "Alpha", ",", "Marker", ",", "Size", "]", "Width", "=", "raw", ".", "at", "[", "i", ",", "'Width'", "]", "Color", "=", "raw", ".", "at", "[", "i", ",", "'Color'", "]", "Alpha", "=", "raw", ".", "at", "[", "i", ",", "'Alpha'", "]", "Marker", "=", "raw", ".", "at", "[", "i", ",", "'Marker'", "]", "Size", "=", "raw", ".", "at", "[", "i", ",", "'Size'", "]", "if", "(", "Color", "not", "in", "Setting", "or", "Color", "!=", "''", ")", ":", "Width", "=", "raw", ".", "at", "[", "i", ",", "'Width'", "]", "Color", "=", "raw", ".", "at", "[", "i", ",", "'Color'", "]", "Alpha", "=", "raw", ".", "at", "[", "i", ",", "'Alpha'", "]", "Marker", "=", "raw", ".", "at", "[", "i", ",", "'Marker'", "]", "Size", "=", "raw", ".", "at", "[", "i", ",", "'Size'", "]", "Setting", "=", "[", "Width", ",", "Color", ",", "Alpha", ",", "Marker", ",", "Size", "]", "r", "=", "np", ".", "arange", "(", "Dip", "-", "90", ",", "Dip", "+", "91", ",", "1", ")", "BearR", "=", "[", "np", ".", "radians", "(", "-", "A", "+", "90", ")", "for", "A", "in", "r", "]", "if", "(", "int", "(", "self", ".", "type_slider", ".", "value", "(", ")", ")", "==", "0", ")", ":", "Line", "=", "(", "self", ".", "eqan", "(", "self", ".", "getangular", "(", "Dip_Angle", ",", "Dip", ",", "r", ")", ")", ")", "else", ":", "Line", "=", "(", "self", ".", "eqar", "(", "self", ".", "getangular", "(", "Dip_Angle", ",", "Dip", ",", "r", ")", ")", ")", "self", ".", "axes", ".", "plot", "(", "BearR", ",", "Line", ",", "color", "=", "Color", ",", "linewidth", "=", "Width", ",", "alpha", "=", "Alpha", ",", "label", "=", "Label", ")", "# self.axes.thetagrids(range(360 + 90, 0 + 90, -30), [str(x) for x in range(0, 360, 30)])", "if", "(", "self", ".", "legend_cb", ".", "isChecked", "(", ")", ")", ":", "self", ".", "axes", ".", "legend", "(", "bbox_to_anchor", "=", "(", "1.5", ",", "1", ")", ",", "loc", "=", "2", ",", "borderaxespad", "=", "0", ",", "prop", "=", "fontprop", ")" ]
read the Excel, then draw the wulf net and Plot points, job done~
[ "read", "the", "Excel", "then", "draw", "the", "wulf", "net", "and", "Plot", "points", "job", "done~" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/Stereo.py#L142-L222
GeoPyTool/GeoPyTool
Experimental/Alpah_Shape_2D.py
add_edge
def add_edge(edges, edge_points, coords, i, j): """ Add a line between the i-th and j-th points, if not in the list already """ if (i, j) in edges or (j, i) in edges: # already added return( edges.add((i, j)), edge_points.append(coords[[i, j]]))
python
def add_edge(edges, edge_points, coords, i, j): if (i, j) in edges or (j, i) in edges: return( edges.add((i, j)), edge_points.append(coords[[i, j]]))
[ "def", "add_edge", "(", "edges", ",", "edge_points", ",", "coords", ",", "i", ",", "j", ")", ":", "if", "(", "i", ",", "j", ")", "in", "edges", "or", "(", "j", ",", "i", ")", "in", "edges", ":", "# already added", "return", "(", "edges", ".", "add", "(", "(", "i", ",", "j", ")", ")", ",", "edge_points", ".", "append", "(", "coords", "[", "[", "i", ",", "j", "]", "]", ")", ")" ]
Add a line between the i-th and j-th points, if not in the list already
[ "Add", "a", "line", "between", "the", "i", "-", "th", "and", "j", "-", "th", "points", "if", "not", "in", "the", "list", "already" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/Experimental/Alpah_Shape_2D.py#L28-L35
GeoPyTool/GeoPyTool
Experimental/Alpah_Shape_2D.py
alpha_shape
def alpha_shape(points, alpha): """ Compute the alpha shape (concave hull) of a set of points. @param points: Iterable container of points. @param alpha: alpha value to influence the gooeyness of the border. Smaller numbers don't fall inward as much as larger numbers. Too large, and you lose everything! """ if len(points) < 4: # When you have a triangle, there is no sense # in computing an alpha shape. return geometry.MultiPoint(list(points)).convex_hull #coords = np.array([point.coords[0] for point in points]) coords = np.array(points) print(coords) tri = Delaunay(coords) edges = set() edge_points = [] # loop over triangles: # ia, ib, ic = indices of corner points of the # triangle for ia, ib, ic in tri.vertices: pa = coords[ia] pb = coords[ib] pc = coords[ic] # Lengths of sides of triangle a = math.sqrt((pa[0]-pb[0])**2 + (pa[1]-pb[1])**2) b = math.sqrt((pb[0]-pc[0])**2 + (pb[1]-pc[1])**2) c = math.sqrt((pc[0]-pa[0])**2 + (pc[1]-pa[1])**2) # Semiperimeter of triangle s = (a + b + c)/2.0 # Area of triangle by Heron's formula area = math.sqrt(s*(s-a)*(s-b)*(s-c)) circum_r = a*b*c/(4.0*area) # Here's the radius filter. #print circum_r if circum_r < 1.0/alpha: add_edge(edges, edge_points, coords, ia, ib) add_edge(edges, edge_points, coords, ib, ic) add_edge(edges, edge_points, coords, ic, ia) m = geometry.MultiLineString(edge_points) triangles = list(polygonize(m)) return (cascaded_union(triangles), edge_points) print (cascaded_union(triangles), edge_points)
python
def alpha_shape(points, alpha): if len(points) < 4: return geometry.MultiPoint(list(points)).convex_hull coords = np.array(points) print(coords) tri = Delaunay(coords) edges = set() edge_points = [] for ia, ib, ic in tri.vertices: pa = coords[ia] pb = coords[ib] pc = coords[ic] a = math.sqrt((pa[0]-pb[0])**2 + (pa[1]-pb[1])**2) b = math.sqrt((pb[0]-pc[0])**2 + (pb[1]-pc[1])**2) c = math.sqrt((pc[0]-pa[0])**2 + (pc[1]-pa[1])**2) s = (a + b + c)/2.0 area = math.sqrt(s*(s-a)*(s-b)*(s-c)) circum_r = a*b*c/(4.0*area) if circum_r < 1.0/alpha: add_edge(edges, edge_points, coords, ia, ib) add_edge(edges, edge_points, coords, ib, ic) add_edge(edges, edge_points, coords, ic, ia) m = geometry.MultiLineString(edge_points) triangles = list(polygonize(m)) return (cascaded_union(triangles), edge_points) print (cascaded_union(triangles), edge_points)
[ "def", "alpha_shape", "(", "points", ",", "alpha", ")", ":", "if", "len", "(", "points", ")", "<", "4", ":", "# When you have a triangle, there is no sense", "# in computing an alpha shape.", "return", "geometry", ".", "MultiPoint", "(", "list", "(", "points", ")", ")", ".", "convex_hull", "#coords = np.array([point.coords[0] for point in points])", "coords", "=", "np", ".", "array", "(", "points", ")", "print", "(", "coords", ")", "tri", "=", "Delaunay", "(", "coords", ")", "edges", "=", "set", "(", ")", "edge_points", "=", "[", "]", "# loop over triangles:", "# ia, ib, ic = indices of corner points of the", "# triangle", "for", "ia", ",", "ib", ",", "ic", "in", "tri", ".", "vertices", ":", "pa", "=", "coords", "[", "ia", "]", "pb", "=", "coords", "[", "ib", "]", "pc", "=", "coords", "[", "ic", "]", "# Lengths of sides of triangle", "a", "=", "math", ".", "sqrt", "(", "(", "pa", "[", "0", "]", "-", "pb", "[", "0", "]", ")", "**", "2", "+", "(", "pa", "[", "1", "]", "-", "pb", "[", "1", "]", ")", "**", "2", ")", "b", "=", "math", ".", "sqrt", "(", "(", "pb", "[", "0", "]", "-", "pc", "[", "0", "]", ")", "**", "2", "+", "(", "pb", "[", "1", "]", "-", "pc", "[", "1", "]", ")", "**", "2", ")", "c", "=", "math", ".", "sqrt", "(", "(", "pc", "[", "0", "]", "-", "pa", "[", "0", "]", ")", "**", "2", "+", "(", "pc", "[", "1", "]", "-", "pa", "[", "1", "]", ")", "**", "2", ")", "# Semiperimeter of triangle", "s", "=", "(", "a", "+", "b", "+", "c", ")", "/", "2.0", "# Area of triangle by Heron's formula", "area", "=", "math", ".", "sqrt", "(", "s", "*", "(", "s", "-", "a", ")", "*", "(", "s", "-", "b", ")", "*", "(", "s", "-", "c", ")", ")", "circum_r", "=", "a", "*", "b", "*", "c", "/", "(", "4.0", "*", "area", ")", "# Here's the radius filter.", "#print circum_r", "if", "circum_r", "<", "1.0", "/", "alpha", ":", "add_edge", "(", "edges", ",", "edge_points", ",", "coords", ",", "ia", ",", "ib", ")", "add_edge", "(", "edges", ",", "edge_points", ",", "coords", ",", "ib", ",", "ic", ")", "add_edge", "(", "edges", ",", "edge_points", ",", "coords", ",", "ic", ",", "ia", ")", "m", "=", "geometry", ".", "MultiLineString", "(", "edge_points", ")", "triangles", "=", "list", "(", "polygonize", "(", "m", ")", ")", "return", "(", "cascaded_union", "(", "triangles", ")", ",", "edge_points", ")", "print", "(", "cascaded_union", "(", "triangles", ")", ",", "edge_points", ")" ]
Compute the alpha shape (concave hull) of a set of points. @param points: Iterable container of points. @param alpha: alpha value to influence the gooeyness of the border. Smaller numbers don't fall inward as much as larger numbers. Too large, and you lose everything!
[ "Compute", "the", "alpha", "shape", "(", "concave", "hull", ")", "of", "a", "set", "of", "points", "." ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/Experimental/Alpah_Shape_2D.py#L39-L89
GeoPyTool/GeoPyTool
geopytool/MyFA - Copy.py
MyFA.Distance_Calculation
def Distance_Calculation(self): print(self.whole_labels) distance_result={} #distance_result[self.whole_labels[i]] = [] print(distance_result) for i in range(len(self.whole_labels)): #print(self.whole_labels[i], self.fa_result[self.result_to_fit.index == self.whole_labels[i]][0]) print( self.whole_labels[i], len(self.fa_result[self.result_to_fit.index == self.whole_labels[i]])) pass ''' for i in range(len(self.whole_labels)): for j in range(len(self.whole_labels)): if i ==j: pass else: distance_result[self.whole_labels[i] + ' to ' + self.whole_labels[j]] = [] self.fa_result[self.result_to_fit.index == self.whole_labels[i]] self.fa_result[self.result_to_fit.index == self.whole_labels[j]] for m in range(len(self.fa_result[self.result_to_fit.index == self.whole_labels[i]])): for n in range(len(self.fa_result[self.result_to_fit.index == self.whole_labels[j]])): pass self.fa_result[self.result_to_fit.index == self.whole_labels[i]][m] #tmp_dist= self.Hsim_Distance(self.fa_result[self.result_to_fit.index == self.whole_labels[i]][m],self.fa_result[self.result_to_fit.index == self.whole_labels[j]][n]) #print(tmp_dist) #distance_result[self.whole_labels[i] + ' to ' + self.whole_labels[j]].append(tmp_dist) pass ''' #print(self.fa_result) try: self.fa_data_to_test[self.data_to_test_to_fit.index == self.whole_labels[0], 0] except Exception as e: pass
python
def Distance_Calculation(self): print(self.whole_labels) distance_result={} print(distance_result) for i in range(len(self.whole_labels)): print( self.whole_labels[i], len(self.fa_result[self.result_to_fit.index == self.whole_labels[i]])) pass try: self.fa_data_to_test[self.data_to_test_to_fit.index == self.whole_labels[0], 0] except Exception as e: pass
[ "def", "Distance_Calculation", "(", "self", ")", ":", "print", "(", "self", ".", "whole_labels", ")", "distance_result", "=", "{", "}", "#distance_result[self.whole_labels[i]] = []", "print", "(", "distance_result", ")", "for", "i", "in", "range", "(", "len", "(", "self", ".", "whole_labels", ")", ")", ":", "#print(self.whole_labels[i], self.fa_result[self.result_to_fit.index == self.whole_labels[i]][0])", "print", "(", "self", ".", "whole_labels", "[", "i", "]", ",", "len", "(", "self", ".", "fa_result", "[", "self", ".", "result_to_fit", ".", "index", "==", "self", ".", "whole_labels", "[", "i", "]", "]", ")", ")", "pass", "#print(self.fa_result)", "try", ":", "self", ".", "fa_data_to_test", "[", "self", ".", "data_to_test_to_fit", ".", "index", "==", "self", ".", "whole_labels", "[", "0", "]", ",", "0", "]", "except", "Exception", "as", "e", ":", "pass" ]
for i in range(len(self.whole_labels)): for j in range(len(self.whole_labels)): if i ==j: pass else: distance_result[self.whole_labels[i] + ' to ' + self.whole_labels[j]] = [] self.fa_result[self.result_to_fit.index == self.whole_labels[i]] self.fa_result[self.result_to_fit.index == self.whole_labels[j]] for m in range(len(self.fa_result[self.result_to_fit.index == self.whole_labels[i]])): for n in range(len(self.fa_result[self.result_to_fit.index == self.whole_labels[j]])): pass self.fa_result[self.result_to_fit.index == self.whole_labels[i]][m] #tmp_dist= self.Hsim_Distance(self.fa_result[self.result_to_fit.index == self.whole_labels[i]][m],self.fa_result[self.result_to_fit.index == self.whole_labels[j]][n]) #print(tmp_dist) #distance_result[self.whole_labels[i] + ' to ' + self.whole_labels[j]].append(tmp_dist) pass
[ "for", "i", "in", "range", "(", "len", "(", "self", ".", "whole_labels", "))", ":", "for", "j", "in", "range", "(", "len", "(", "self", ".", "whole_labels", "))", ":", "if", "i", "==", "j", ":", "pass", "else", ":", "distance_result", "[", "self", ".", "whole_labels", "[", "i", "]", "+", "to", "+", "self", ".", "whole_labels", "[", "j", "]]", "=", "[]" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/MyFA - Copy.py#L348-L395
GeoPyTool/GeoPyTool
geopytool/GLMultiDimension.py
GLMultiDimension.create_main_frame
def create_main_frame(self): self.main_frame = QWidget() #self.main_frame.setFixedSize(self.width(), self.width()) self.dpi = 128 self.ShapeGroups =200 self.view = gl.GLViewWidget() #self.view = pg.PlotWidget() #self.view.setFixedSize(self.width(),self.height()) self.view.setFixedSize(self.width(), self.width()) self.view.setParent(self.main_frame) # Other GUI controls self.save_button = QPushButton('&Save') self.save_button.clicked.connect(self.saveImgFile) self.draw_button = QPushButton('&Reset') self.draw_button.clicked.connect(self.Reset) self.load_button = QPushButton('&Load') #self.load_button.clicked.connect(self.Load) self.fit_cb= QCheckBox('&PolyFit') self.fit_cb.setChecked(False) self.fit_cb.stateChanged.connect(self.Magic) # int self.fit_label = QLabel('Exp') self.fit_seter = QLineEdit(self) self.fit_seter.textChanged[str].connect(self.FitChanged) self.shape_cb= QCheckBox('&Shape') self.shape_cb.setChecked(False) self.shape_cb.stateChanged.connect(self.Magic) # int self.Normalize_cb = QCheckBox('&Normalize') self.Normalize_cb.setChecked(False) self.Normalize_cb.stateChanged.connect(self.Magic) # int self.norm_slider_label = QLabel('Standard:' + self.NameChosen) self.norm_slider = QSlider(Qt.Horizontal) self.norm_slider.setRange(0, 4) self.norm_slider.setValue(0) self.norm_slider.setTracking(True) self.norm_slider.setTickPosition(QSlider.TicksBothSides) self.norm_slider.valueChanged.connect(self.Magic) # int self.x_element = QSlider(Qt.Horizontal) self.x_element.setRange(0, len(self.items) - 1) self.x_element.setValue(0) self.x_element.setTracking(True) self.x_element.setTickPosition(QSlider.TicksBothSides) self.x_element.valueChanged.connect(self.Magic) # int self.x_element_label = QLabel('X') self.logx_cb = QCheckBox('&Log') self.logx_cb.setChecked(False) self.logx_cb.stateChanged.connect(self.Magic) # int self.y_element = QSlider(Qt.Horizontal) self.y_element.setRange(0, len(self.items) - 1) self.y_element.setValue(1) self.y_element.setTracking(True) self.y_element.setTickPosition(QSlider.TicksBothSides) self.y_element.valueChanged.connect(self.Magic) # int self.y_element_label = QLabel('Y') self.logy_cb = QCheckBox('&Log') self.logy_cb.setChecked(False) self.logy_cb.stateChanged.connect(self.Magic) # int self.z_element = QSlider(Qt.Horizontal) self.z_element.setRange(0, len(self.items) - 1) self.z_element.setValue(2) self.z_element.setTracking(True) self.z_element.setTickPosition(QSlider.TicksBothSides) self.z_element.valueChanged.connect(self.Magic) # int self.z_element_label = QLabel('Z') self.logz_cb = QCheckBox('&Log') self.logz_cb.setChecked(False) self.logz_cb.stateChanged.connect(self.Magic) # int self.xlim_seter_left_label = QLabel('Xleft') self.xlim_seter_left = QLineEdit(self) self.xlim_seter_left.textChanged[str].connect(self.XleftChanged) self.xlim_seter_right_label = QLabel('Xright') self.xlim_seter_right = QLineEdit(self) self.xlim_seter_right.textChanged[str].connect(self.XrightChanged) self.ylim_seter_down_label = QLabel('Ydown') self.ylim_seter_down = QLineEdit(self) self.ylim_seter_down.textChanged[str].connect(self.YdownChanged) self.ylim_seter_up_label = QLabel('Yup') self.ylim_seter_up = QLineEdit(self) self.ylim_seter_up.textChanged[str].connect(self.YupChanged) self.hbox0 = QHBoxLayout() self.hbox1 = QHBoxLayout() self.hbox2 = QHBoxLayout() self.hbox3 = QHBoxLayout() self.hbox4 = QHBoxLayout() self.hbox5 = QHBoxLayout() self.hbox6 = QHBoxLayout() self.hbox7 = QHBoxLayout() ''' for w in [self.fit_cb,self.fit_label, self.fit_seter,self.xlim_seter_left_label,self.xlim_seter_left,self.xlim_seter_right_label,self.xlim_seter_right,self.ylim_seter_down_label,self.ylim_seter_down,self.ylim_seter_up_label,self.ylim_seter_up,self.shape_cb]: self.hbox0.addWidget(w) self.hbox0.setAlignment(w, Qt.AlignVCenter) ''' for w in [self.view]: self.hbox0.addWidget(w) self.hbox0.setAlignment(w, Qt.AlignVCenter) for w in [self.Normalize_cb, self.norm_slider_label, self.norm_slider]: self.hbox1.addWidget(w) self.hbox1.setAlignment(w, Qt.AlignVCenter) for w in [self.logx_cb, self.x_element_label, self.x_element]: self.hbox2.addWidget(w) self.hbox2.setAlignment(w, Qt.AlignVCenter) for w in [self.logy_cb, self.y_element_label, self.y_element]: self.hbox3.addWidget(w) self.hbox3.setAlignment(w, Qt.AlignVCenter) for w in [self.logz_cb, self.z_element_label, self.z_element]: self.hbox4.addWidget(w) self.hbox4.setAlignment(w, Qt.AlignVCenter) self.vbox = QVBoxLayout() #self.vbox.addWidget(self.view) self.vbox.addLayout(self.hbox0) self.vbox.addLayout(self.hbox1) self.vbox.addLayout(self.hbox2) self.vbox.addLayout(self.hbox3) self.vbox.addLayout(self.hbox4) self.main_frame.setLayout(self.vbox) self.setCentralWidget(self.main_frame)
python
def create_main_frame(self): self.main_frame = QWidget() self.dpi = 128 self.ShapeGroups =200 self.view = gl.GLViewWidget() self.view.setFixedSize(self.width(), self.width()) self.view.setParent(self.main_frame) self.save_button = QPushButton('&Save') self.save_button.clicked.connect(self.saveImgFile) self.draw_button = QPushButton('&Reset') self.draw_button.clicked.connect(self.Reset) self.load_button = QPushButton('&Load') self.fit_cb= QCheckBox('&PolyFit') self.fit_cb.setChecked(False) self.fit_cb.stateChanged.connect(self.Magic) self.fit_label = QLabel('Exp') self.fit_seter = QLineEdit(self) self.fit_seter.textChanged[str].connect(self.FitChanged) self.shape_cb= QCheckBox('&Shape') self.shape_cb.setChecked(False) self.shape_cb.stateChanged.connect(self.Magic) self.Normalize_cb = QCheckBox('&Normalize') self.Normalize_cb.setChecked(False) self.Normalize_cb.stateChanged.connect(self.Magic) self.norm_slider_label = QLabel('Standard:' + self.NameChosen) self.norm_slider = QSlider(Qt.Horizontal) self.norm_slider.setRange(0, 4) self.norm_slider.setValue(0) self.norm_slider.setTracking(True) self.norm_slider.setTickPosition(QSlider.TicksBothSides) self.norm_slider.valueChanged.connect(self.Magic) self.x_element = QSlider(Qt.Horizontal) self.x_element.setRange(0, len(self.items) - 1) self.x_element.setValue(0) self.x_element.setTracking(True) self.x_element.setTickPosition(QSlider.TicksBothSides) self.x_element.valueChanged.connect(self.Magic) self.x_element_label = QLabel('X') self.logx_cb = QCheckBox('&Log') self.logx_cb.setChecked(False) self.logx_cb.stateChanged.connect(self.Magic) self.y_element = QSlider(Qt.Horizontal) self.y_element.setRange(0, len(self.items) - 1) self.y_element.setValue(1) self.y_element.setTracking(True) self.y_element.setTickPosition(QSlider.TicksBothSides) self.y_element.valueChanged.connect(self.Magic) self.y_element_label = QLabel('Y') self.logy_cb = QCheckBox('&Log') self.logy_cb.setChecked(False) self.logy_cb.stateChanged.connect(self.Magic) self.z_element = QSlider(Qt.Horizontal) self.z_element.setRange(0, len(self.items) - 1) self.z_element.setValue(2) self.z_element.setTracking(True) self.z_element.setTickPosition(QSlider.TicksBothSides) self.z_element.valueChanged.connect(self.Magic) self.z_element_label = QLabel('Z') self.logz_cb = QCheckBox('&Log') self.logz_cb.setChecked(False) self.logz_cb.stateChanged.connect(self.Magic) self.xlim_seter_left_label = QLabel('Xleft') self.xlim_seter_left = QLineEdit(self) self.xlim_seter_left.textChanged[str].connect(self.XleftChanged) self.xlim_seter_right_label = QLabel('Xright') self.xlim_seter_right = QLineEdit(self) self.xlim_seter_right.textChanged[str].connect(self.XrightChanged) self.ylim_seter_down_label = QLabel('Ydown') self.ylim_seter_down = QLineEdit(self) self.ylim_seter_down.textChanged[str].connect(self.YdownChanged) self.ylim_seter_up_label = QLabel('Yup') self.ylim_seter_up = QLineEdit(self) self.ylim_seter_up.textChanged[str].connect(self.YupChanged) self.hbox0 = QHBoxLayout() self.hbox1 = QHBoxLayout() self.hbox2 = QHBoxLayout() self.hbox3 = QHBoxLayout() self.hbox4 = QHBoxLayout() self.hbox5 = QHBoxLayout() self.hbox6 = QHBoxLayout() self.hbox7 = QHBoxLayout() for w in [self.view]: self.hbox0.addWidget(w) self.hbox0.setAlignment(w, Qt.AlignVCenter) for w in [self.Normalize_cb, self.norm_slider_label, self.norm_slider]: self.hbox1.addWidget(w) self.hbox1.setAlignment(w, Qt.AlignVCenter) for w in [self.logx_cb, self.x_element_label, self.x_element]: self.hbox2.addWidget(w) self.hbox2.setAlignment(w, Qt.AlignVCenter) for w in [self.logy_cb, self.y_element_label, self.y_element]: self.hbox3.addWidget(w) self.hbox3.setAlignment(w, Qt.AlignVCenter) for w in [self.logz_cb, self.z_element_label, self.z_element]: self.hbox4.addWidget(w) self.hbox4.setAlignment(w, Qt.AlignVCenter) self.vbox = QVBoxLayout() self.vbox.addLayout(self.hbox0) self.vbox.addLayout(self.hbox1) self.vbox.addLayout(self.hbox2) self.vbox.addLayout(self.hbox3) self.vbox.addLayout(self.hbox4) self.main_frame.setLayout(self.vbox) self.setCentralWidget(self.main_frame)
[ "def", "create_main_frame", "(", "self", ")", ":", "self", ".", "main_frame", "=", "QWidget", "(", ")", "#self.main_frame.setFixedSize(self.width(), self.width())", "self", ".", "dpi", "=", "128", "self", ".", "ShapeGroups", "=", "200", "self", ".", "view", "=", "gl", ".", "GLViewWidget", "(", ")", "#self.view = pg.PlotWidget()", "#self.view.setFixedSize(self.width(),self.height())", "self", ".", "view", ".", "setFixedSize", "(", "self", ".", "width", "(", ")", ",", "self", ".", "width", "(", ")", ")", "self", ".", "view", ".", "setParent", "(", "self", ".", "main_frame", ")", "# Other GUI controls", "self", ".", "save_button", "=", "QPushButton", "(", "'&Save'", ")", "self", ".", "save_button", ".", "clicked", ".", "connect", "(", "self", ".", "saveImgFile", ")", "self", ".", "draw_button", "=", "QPushButton", "(", "'&Reset'", ")", "self", ".", "draw_button", ".", "clicked", ".", "connect", "(", "self", ".", "Reset", ")", "self", ".", "load_button", "=", "QPushButton", "(", "'&Load'", ")", "#self.load_button.clicked.connect(self.Load)", "self", ".", "fit_cb", "=", "QCheckBox", "(", "'&PolyFit'", ")", "self", ".", "fit_cb", ".", "setChecked", "(", "False", ")", "self", ".", "fit_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "fit_label", "=", "QLabel", "(", "'Exp'", ")", "self", ".", "fit_seter", "=", "QLineEdit", "(", "self", ")", "self", ".", "fit_seter", ".", "textChanged", "[", "str", "]", ".", "connect", "(", "self", ".", "FitChanged", ")", "self", ".", "shape_cb", "=", "QCheckBox", "(", "'&Shape'", ")", "self", ".", "shape_cb", ".", "setChecked", "(", "False", ")", "self", ".", "shape_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "Normalize_cb", "=", "QCheckBox", "(", "'&Normalize'", ")", "self", ".", "Normalize_cb", ".", "setChecked", "(", "False", ")", "self", ".", "Normalize_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "norm_slider_label", "=", "QLabel", "(", "'Standard:'", "+", "self", ".", "NameChosen", ")", "self", ".", "norm_slider", "=", "QSlider", "(", "Qt", ".", "Horizontal", ")", "self", ".", "norm_slider", ".", "setRange", "(", "0", ",", "4", ")", "self", ".", "norm_slider", ".", "setValue", "(", "0", ")", "self", ".", "norm_slider", ".", "setTracking", "(", "True", ")", "self", ".", "norm_slider", ".", "setTickPosition", "(", "QSlider", ".", "TicksBothSides", ")", "self", ".", "norm_slider", ".", "valueChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "x_element", "=", "QSlider", "(", "Qt", ".", "Horizontal", ")", "self", ".", "x_element", ".", "setRange", "(", "0", ",", "len", "(", "self", ".", "items", ")", "-", "1", ")", "self", ".", "x_element", ".", "setValue", "(", "0", ")", "self", ".", "x_element", ".", "setTracking", "(", "True", ")", "self", ".", "x_element", ".", "setTickPosition", "(", "QSlider", ".", "TicksBothSides", ")", "self", ".", "x_element", ".", "valueChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "x_element_label", "=", "QLabel", "(", "'X'", ")", "self", ".", "logx_cb", "=", "QCheckBox", "(", "'&Log'", ")", "self", ".", "logx_cb", ".", "setChecked", "(", "False", ")", "self", ".", "logx_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "y_element", "=", "QSlider", "(", "Qt", ".", "Horizontal", ")", "self", ".", "y_element", ".", "setRange", "(", "0", ",", "len", "(", "self", ".", "items", ")", "-", "1", ")", "self", ".", "y_element", ".", "setValue", "(", "1", ")", "self", ".", "y_element", ".", "setTracking", "(", "True", ")", "self", ".", "y_element", ".", "setTickPosition", "(", "QSlider", ".", "TicksBothSides", ")", "self", ".", "y_element", ".", "valueChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "y_element_label", "=", "QLabel", "(", "'Y'", ")", "self", ".", "logy_cb", "=", "QCheckBox", "(", "'&Log'", ")", "self", ".", "logy_cb", ".", "setChecked", "(", "False", ")", "self", ".", "logy_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "z_element", "=", "QSlider", "(", "Qt", ".", "Horizontal", ")", "self", ".", "z_element", ".", "setRange", "(", "0", ",", "len", "(", "self", ".", "items", ")", "-", "1", ")", "self", ".", "z_element", ".", "setValue", "(", "2", ")", "self", ".", "z_element", ".", "setTracking", "(", "True", ")", "self", ".", "z_element", ".", "setTickPosition", "(", "QSlider", ".", "TicksBothSides", ")", "self", ".", "z_element", ".", "valueChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "z_element_label", "=", "QLabel", "(", "'Z'", ")", "self", ".", "logz_cb", "=", "QCheckBox", "(", "'&Log'", ")", "self", ".", "logz_cb", ".", "setChecked", "(", "False", ")", "self", ".", "logz_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "xlim_seter_left_label", "=", "QLabel", "(", "'Xleft'", ")", "self", ".", "xlim_seter_left", "=", "QLineEdit", "(", "self", ")", "self", ".", "xlim_seter_left", ".", "textChanged", "[", "str", "]", ".", "connect", "(", "self", ".", "XleftChanged", ")", "self", ".", "xlim_seter_right_label", "=", "QLabel", "(", "'Xright'", ")", "self", ".", "xlim_seter_right", "=", "QLineEdit", "(", "self", ")", "self", ".", "xlim_seter_right", ".", "textChanged", "[", "str", "]", ".", "connect", "(", "self", ".", "XrightChanged", ")", "self", ".", "ylim_seter_down_label", "=", "QLabel", "(", "'Ydown'", ")", "self", ".", "ylim_seter_down", "=", "QLineEdit", "(", "self", ")", "self", ".", "ylim_seter_down", ".", "textChanged", "[", "str", "]", ".", "connect", "(", "self", ".", "YdownChanged", ")", "self", ".", "ylim_seter_up_label", "=", "QLabel", "(", "'Yup'", ")", "self", ".", "ylim_seter_up", "=", "QLineEdit", "(", "self", ")", "self", ".", "ylim_seter_up", ".", "textChanged", "[", "str", "]", ".", "connect", "(", "self", ".", "YupChanged", ")", "self", ".", "hbox0", "=", "QHBoxLayout", "(", ")", "self", ".", "hbox1", "=", "QHBoxLayout", "(", ")", "self", ".", "hbox2", "=", "QHBoxLayout", "(", ")", "self", ".", "hbox3", "=", "QHBoxLayout", "(", ")", "self", ".", "hbox4", "=", "QHBoxLayout", "(", ")", "self", ".", "hbox5", "=", "QHBoxLayout", "(", ")", "self", ".", "hbox6", "=", "QHBoxLayout", "(", ")", "self", ".", "hbox7", "=", "QHBoxLayout", "(", ")", "for", "w", "in", "[", "self", ".", "view", "]", ":", "self", ".", "hbox0", ".", "addWidget", "(", "w", ")", "self", ".", "hbox0", ".", "setAlignment", "(", "w", ",", "Qt", ".", "AlignVCenter", ")", "for", "w", "in", "[", "self", ".", "Normalize_cb", ",", "self", ".", "norm_slider_label", ",", "self", ".", "norm_slider", "]", ":", "self", ".", "hbox1", ".", "addWidget", "(", "w", ")", "self", ".", "hbox1", ".", "setAlignment", "(", "w", ",", "Qt", ".", "AlignVCenter", ")", "for", "w", "in", "[", "self", ".", "logx_cb", ",", "self", ".", "x_element_label", ",", "self", ".", "x_element", "]", ":", "self", ".", "hbox2", ".", "addWidget", "(", "w", ")", "self", ".", "hbox2", ".", "setAlignment", "(", "w", ",", "Qt", ".", "AlignVCenter", ")", "for", "w", "in", "[", "self", ".", "logy_cb", ",", "self", ".", "y_element_label", ",", "self", ".", "y_element", "]", ":", "self", ".", "hbox3", ".", "addWidget", "(", "w", ")", "self", ".", "hbox3", ".", "setAlignment", "(", "w", ",", "Qt", ".", "AlignVCenter", ")", "for", "w", "in", "[", "self", ".", "logz_cb", ",", "self", ".", "z_element_label", ",", "self", ".", "z_element", "]", ":", "self", ".", "hbox4", ".", "addWidget", "(", "w", ")", "self", ".", "hbox4", ".", "setAlignment", "(", "w", ",", "Qt", ".", "AlignVCenter", ")", "self", ".", "vbox", "=", "QVBoxLayout", "(", ")", "#self.vbox.addWidget(self.view)", "self", ".", "vbox", ".", "addLayout", "(", "self", ".", "hbox0", ")", "self", ".", "vbox", ".", "addLayout", "(", "self", ".", "hbox1", ")", "self", ".", "vbox", ".", "addLayout", "(", "self", ".", "hbox2", ")", "self", ".", "vbox", ".", "addLayout", "(", "self", ".", "hbox3", ")", "self", ".", "vbox", ".", "addLayout", "(", "self", ".", "hbox4", ")", "self", ".", "main_frame", ".", "setLayout", "(", "self", ".", "vbox", ")", "self", ".", "setCentralWidget", "(", "self", ".", "main_frame", ")" ]
for w in [self.fit_cb,self.fit_label, self.fit_seter,self.xlim_seter_left_label,self.xlim_seter_left,self.xlim_seter_right_label,self.xlim_seter_right,self.ylim_seter_down_label,self.ylim_seter_down,self.ylim_seter_up_label,self.ylim_seter_up,self.shape_cb]: self.hbox0.addWidget(w) self.hbox0.setAlignment(w, Qt.AlignVCenter)
[ "for", "w", "in", "[", "self", ".", "fit_cb", "self", ".", "fit_label", "self", ".", "fit_seter", "self", ".", "xlim_seter_left_label", "self", ".", "xlim_seter_left", "self", ".", "xlim_seter_right_label", "self", ".", "xlim_seter_right", "self", ".", "ylim_seter_down_label", "self", ".", "ylim_seter_down", "self", ".", "ylim_seter_up_label", "self", ".", "ylim_seter_up", "self", ".", "shape_cb", "]", ":", "self", ".", "hbox0", ".", "addWidget", "(", "w", ")", "self", ".", "hbox0", ".", "setAlignment", "(", "w", "Qt", ".", "AlignVCenter", ")" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/GLMultiDimension.py#L125-L291
GeoPyTool/GeoPyTool
geopytool/GLMultiDimension.py
GLMultiDimension.Magic
def Magic(self): #self.view.setFixedSize(self.width(), self.width()) self.WholeData = [] self.x_scale = self.width_plot / self.width_load self.y_scale = self.height_plot / self.height_load self.z_scale = self.depth_plot / self.depth_load # print(self.x_scale,' and ',self.x_scale) raw = self._df a = int(self.x_element.value()) b = int(self.y_element.value()) c = int(self.z_element.value()) self.x_element_label.setText(self.items[a]) self.y_element_label.setText(self.items[b]) self.z_element_label.setText(self.items[c]) if (self.Left != self.Right) and (self.Down != self.Up) and abs(self.Left) + abs(self.Right) + abs( self.Down) + abs(self.Up) != 0: self.extent = [self.Left, self.Right, self.Down, self.Up] elif (self.Left == self.Right and abs(self.Left) + abs(self.Right) != 0): reply = QMessageBox.warning(self, 'Warning', 'You set same value to Left and Right limits.') self.extent = 0 elif (self.Down == self.Up and abs(self.Down) + abs(self.Up) != 0): reply = QMessageBox.warning(self, 'Warning', 'You set same value to Up and Down limits.') self.extent = 0 else: self.extent = 0 standardnamechosen = self.StandardsName[int(self.norm_slider.value())] standardchosen = self.Standards[standardnamechosen] self.norm_slider_label.setText(standardnamechosen) PointLabels = [] XtoDraw = [] YtoDraw = [] ZtoDraw = [] Colors=[] Alphas=[] Markers=[] Names=[] for i in range(len(raw)): # raw.at[i, 'DataType'] == 'User' or raw.at[i, 'DataType'] == 'user' or raw.at[i, 'DataType'] == 'USER' TmpLabel = '' # self.WholeData.append(math.log(tmp, 10)) if (raw.at[i, 'Label'] in PointLabels or raw.at[i, 'Label'] == ''): TmpLabel = '' else: PointLabels.append(raw.at[i, 'Label']) TmpLabel = raw.at[i, 'Label'] x, y ,z = 0, 0, 0 xuse, yuse,zuse = 0, 0, 0 x, y,z = raw.at[i, self.items[a]], raw.at[i, self.items[b]],raw.at[i, self.items[c]] try: xuse = x yuse = y zuse = z self.xlabel = self.items[a] self.ylabel = self.items[b] self.zlabel = self.items[c] if (self.Normalize_cb.isChecked()): self.xlabel = self.items[a] + ' Norm by ' + standardnamechosen self.x_element_label.setText(self.xlabel) self.ylabel = self.items[b] + ' Norm by ' + standardnamechosen self.y_element_label.setText(self.ylabel) self.zlabel = self.items[c] + ' Norm by ' + standardnamechosen self.z_element_label.setText(self.zlabel) if self.items[a] in self.Element: xuse = xuse / standardchosen[self.items[a]] if self.items[b] in self.Element: yuse = yuse / standardchosen[self.items[b]] if self.items[c] in self.Element: zuse = zuse / standardchosen[self.items[c]] if (self.logx_cb.isChecked()): xuse = math.log(x, 10) self.xlabel = '$log10$ ' + self.xlabel if (self.logy_cb.isChecked()): yuse = math.log(y, 10) self.ylabel = '$log10$ ' + self.ylabel if (self.logz_cb.isChecked()): zuse = math.log(z, 10) self.zlabel = '$log10$ ' + self.zlabel XtoDraw.append(xuse) YtoDraw.append(yuse) ZtoDraw.append(zuse) Colors.append(raw.at[i, 'Color']) Alphas.append(raw.at[i, 'Alpha']) Names.append(raw.at[i, 'Label']) Markers.append(raw.at[i, 'Marker']) except(ValueError): pass if self.LimSet==False: self.Xleft, self.Xright, self.Ydown, self.Yup, self.Tail, self.Head = min(XtoDraw), max(XtoDraw), min(YtoDraw), max(YtoDraw), min(ZtoDraw), max(ZtoDraw) xmin, xmax = min(XtoDraw), max(XtoDraw) ymin, ymax = min(YtoDraw), max(YtoDraw) zmin, zmax = min(ZtoDraw), max(ZtoDraw) xmean = np.mean(XtoDraw) ymean = np.mean(YtoDraw) zmean = np.mean(ZtoDraw) Xoriginal = np.arange(xmin, xmax, (xmax - xmin) / 10) Yoriginal = np.arange(ymin, ymax, (ymax - ymin) / 10) Zoriginal = np.arange(zmin, zmax, (zmax - zmin) / 10) XonPlot = self.GetASequence(tail=self.ShapeGroups) YonPlot = self.GetASequence(tail=self.ShapeGroups) ZonPlot = self.GetASequence(tail=self.ShapeGroups) XonStick = [] YonStick = [] ZonStick = [] for i in range(len(XonPlot)): XonStick.append([XonPlot[i], Xoriginal[i]]) YonStick.append([YonPlot[i], Yoriginal[i]]) ZonStick.append([ZonPlot[i], Zoriginal[i]]) pass #print(XtoDraw,'\n', YtoDraw,'\n', ZtoDraw) toDf = {self.xlabel:XtoDraw, self.ylabel:YtoDraw, self.zlabel:ZtoDraw} newdf = pd.DataFrame(toDf) pos = newdf.as_matrix() print(pos) ThreeDimView = gl.GLScatterPlotItem(pos=pos, color=(100, 255, 255, 88), size=0.1, pxMode=False) print(xmean,'\n', ymean,'\n', zmean,'\n') self.view.pan(xmean, ymean, zmean) xgrid = gl.GLGridItem(size=QtGui.QVector3D(10, 10, 1), color=1) ygrid = gl.GLGridItem(size=QtGui.QVector3D(20, 20, 2), color=2) zgrid = gl.GLGridItem(size=QtGui.QVector3D(30, 30, 3), color=3) ## rotate x and y grids to face the correct direction xgrid.rotate(90, 0, 1, 0) ygrid.rotate(90, 1, 0, 0) xgrid.translate(xmean, ymean, zmean) ygrid.translate(xmean, ymean, zmean) zgrid.translate(xmean, ymean, zmean) ## scale each grid differently ''' xgrid.scale(12.8, 12.8, 12.8) ygrid.scale(12.8, 12.8, 12.8) zgrid.scale(12.8, 12.8, 12.8) ''' # xgrid.setTransform(xmean,ymean,zmean) self.view.addItem(xgrid) self.view.addItem(ygrid) self.view.addItem(zgrid) self.view.addItem(ThreeDimView)
python
def Magic(self): self.WholeData = [] self.x_scale = self.width_plot / self.width_load self.y_scale = self.height_plot / self.height_load self.z_scale = self.depth_plot / self.depth_load raw = self._df a = int(self.x_element.value()) b = int(self.y_element.value()) c = int(self.z_element.value()) self.x_element_label.setText(self.items[a]) self.y_element_label.setText(self.items[b]) self.z_element_label.setText(self.items[c]) if (self.Left != self.Right) and (self.Down != self.Up) and abs(self.Left) + abs(self.Right) + abs( self.Down) + abs(self.Up) != 0: self.extent = [self.Left, self.Right, self.Down, self.Up] elif (self.Left == self.Right and abs(self.Left) + abs(self.Right) != 0): reply = QMessageBox.warning(self, 'Warning', 'You set same value to Left and Right limits.') self.extent = 0 elif (self.Down == self.Up and abs(self.Down) + abs(self.Up) != 0): reply = QMessageBox.warning(self, 'Warning', 'You set same value to Up and Down limits.') self.extent = 0 else: self.extent = 0 standardnamechosen = self.StandardsName[int(self.norm_slider.value())] standardchosen = self.Standards[standardnamechosen] self.norm_slider_label.setText(standardnamechosen) PointLabels = [] XtoDraw = [] YtoDraw = [] ZtoDraw = [] Colors=[] Alphas=[] Markers=[] Names=[] for i in range(len(raw)): TmpLabel = '' if (raw.at[i, 'Label'] in PointLabels or raw.at[i, 'Label'] == ''): TmpLabel = '' else: PointLabels.append(raw.at[i, 'Label']) TmpLabel = raw.at[i, 'Label'] x, y ,z = 0, 0, 0 xuse, yuse,zuse = 0, 0, 0 x, y,z = raw.at[i, self.items[a]], raw.at[i, self.items[b]],raw.at[i, self.items[c]] try: xuse = x yuse = y zuse = z self.xlabel = self.items[a] self.ylabel = self.items[b] self.zlabel = self.items[c] if (self.Normalize_cb.isChecked()): self.xlabel = self.items[a] + ' Norm by ' + standardnamechosen self.x_element_label.setText(self.xlabel) self.ylabel = self.items[b] + ' Norm by ' + standardnamechosen self.y_element_label.setText(self.ylabel) self.zlabel = self.items[c] + ' Norm by ' + standardnamechosen self.z_element_label.setText(self.zlabel) if self.items[a] in self.Element: xuse = xuse / standardchosen[self.items[a]] if self.items[b] in self.Element: yuse = yuse / standardchosen[self.items[b]] if self.items[c] in self.Element: zuse = zuse / standardchosen[self.items[c]] if (self.logx_cb.isChecked()): xuse = math.log(x, 10) self.xlabel = '$log10$ ' + self.xlabel if (self.logy_cb.isChecked()): yuse = math.log(y, 10) self.ylabel = '$log10$ ' + self.ylabel if (self.logz_cb.isChecked()): zuse = math.log(z, 10) self.zlabel = '$log10$ ' + self.zlabel XtoDraw.append(xuse) YtoDraw.append(yuse) ZtoDraw.append(zuse) Colors.append(raw.at[i, 'Color']) Alphas.append(raw.at[i, 'Alpha']) Names.append(raw.at[i, 'Label']) Markers.append(raw.at[i, 'Marker']) except(ValueError): pass if self.LimSet==False: self.Xleft, self.Xright, self.Ydown, self.Yup, self.Tail, self.Head = min(XtoDraw), max(XtoDraw), min(YtoDraw), max(YtoDraw), min(ZtoDraw), max(ZtoDraw) xmin, xmax = min(XtoDraw), max(XtoDraw) ymin, ymax = min(YtoDraw), max(YtoDraw) zmin, zmax = min(ZtoDraw), max(ZtoDraw) xmean = np.mean(XtoDraw) ymean = np.mean(YtoDraw) zmean = np.mean(ZtoDraw) Xoriginal = np.arange(xmin, xmax, (xmax - xmin) / 10) Yoriginal = np.arange(ymin, ymax, (ymax - ymin) / 10) Zoriginal = np.arange(zmin, zmax, (zmax - zmin) / 10) XonPlot = self.GetASequence(tail=self.ShapeGroups) YonPlot = self.GetASequence(tail=self.ShapeGroups) ZonPlot = self.GetASequence(tail=self.ShapeGroups) XonStick = [] YonStick = [] ZonStick = [] for i in range(len(XonPlot)): XonStick.append([XonPlot[i], Xoriginal[i]]) YonStick.append([YonPlot[i], Yoriginal[i]]) ZonStick.append([ZonPlot[i], Zoriginal[i]]) pass toDf = {self.xlabel:XtoDraw, self.ylabel:YtoDraw, self.zlabel:ZtoDraw} newdf = pd.DataFrame(toDf) pos = newdf.as_matrix() print(pos) ThreeDimView = gl.GLScatterPlotItem(pos=pos, color=(100, 255, 255, 88), size=0.1, pxMode=False) print(xmean,'\n', ymean,'\n', zmean,'\n') self.view.pan(xmean, ymean, zmean) xgrid = gl.GLGridItem(size=QtGui.QVector3D(10, 10, 1), color=1) ygrid = gl.GLGridItem(size=QtGui.QVector3D(20, 20, 2), color=2) zgrid = gl.GLGridItem(size=QtGui.QVector3D(30, 30, 3), color=3) xgrid.rotate(90, 0, 1, 0) ygrid.rotate(90, 1, 0, 0) xgrid.translate(xmean, ymean, zmean) ygrid.translate(xmean, ymean, zmean) zgrid.translate(xmean, ymean, zmean) self.view.addItem(xgrid) self.view.addItem(ygrid) self.view.addItem(zgrid) self.view.addItem(ThreeDimView)
[ "def", "Magic", "(", "self", ")", ":", "#self.view.setFixedSize(self.width(), self.width())", "self", ".", "WholeData", "=", "[", "]", "self", ".", "x_scale", "=", "self", ".", "width_plot", "/", "self", ".", "width_load", "self", ".", "y_scale", "=", "self", ".", "height_plot", "/", "self", ".", "height_load", "self", ".", "z_scale", "=", "self", ".", "depth_plot", "/", "self", ".", "depth_load", "# print(self.x_scale,' and ',self.x_scale)", "raw", "=", "self", ".", "_df", "a", "=", "int", "(", "self", ".", "x_element", ".", "value", "(", ")", ")", "b", "=", "int", "(", "self", ".", "y_element", ".", "value", "(", ")", ")", "c", "=", "int", "(", "self", ".", "z_element", ".", "value", "(", ")", ")", "self", ".", "x_element_label", ".", "setText", "(", "self", ".", "items", "[", "a", "]", ")", "self", ".", "y_element_label", ".", "setText", "(", "self", ".", "items", "[", "b", "]", ")", "self", ".", "z_element_label", ".", "setText", "(", "self", ".", "items", "[", "c", "]", ")", "if", "(", "self", ".", "Left", "!=", "self", ".", "Right", ")", "and", "(", "self", ".", "Down", "!=", "self", ".", "Up", ")", "and", "abs", "(", "self", ".", "Left", ")", "+", "abs", "(", "self", ".", "Right", ")", "+", "abs", "(", "self", ".", "Down", ")", "+", "abs", "(", "self", ".", "Up", ")", "!=", "0", ":", "self", ".", "extent", "=", "[", "self", ".", "Left", ",", "self", ".", "Right", ",", "self", ".", "Down", ",", "self", ".", "Up", "]", "elif", "(", "self", ".", "Left", "==", "self", ".", "Right", "and", "abs", "(", "self", ".", "Left", ")", "+", "abs", "(", "self", ".", "Right", ")", "!=", "0", ")", ":", "reply", "=", "QMessageBox", ".", "warning", "(", "self", ",", "'Warning'", ",", "'You set same value to Left and Right limits.'", ")", "self", ".", "extent", "=", "0", "elif", "(", "self", ".", "Down", "==", "self", ".", "Up", "and", "abs", "(", "self", ".", "Down", ")", "+", "abs", "(", "self", ".", "Up", ")", "!=", "0", ")", ":", "reply", "=", "QMessageBox", ".", "warning", "(", "self", ",", "'Warning'", ",", "'You set same value to Up and Down limits.'", ")", "self", ".", "extent", "=", "0", "else", ":", "self", ".", "extent", "=", "0", "standardnamechosen", "=", "self", ".", "StandardsName", "[", "int", "(", "self", ".", "norm_slider", ".", "value", "(", ")", ")", "]", "standardchosen", "=", "self", ".", "Standards", "[", "standardnamechosen", "]", "self", ".", "norm_slider_label", ".", "setText", "(", "standardnamechosen", ")", "PointLabels", "=", "[", "]", "XtoDraw", "=", "[", "]", "YtoDraw", "=", "[", "]", "ZtoDraw", "=", "[", "]", "Colors", "=", "[", "]", "Alphas", "=", "[", "]", "Markers", "=", "[", "]", "Names", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "raw", ")", ")", ":", "# raw.at[i, 'DataType'] == 'User' or raw.at[i, 'DataType'] == 'user' or raw.at[i, 'DataType'] == 'USER'", "TmpLabel", "=", "''", "# self.WholeData.append(math.log(tmp, 10))", "if", "(", "raw", ".", "at", "[", "i", ",", "'Label'", "]", "in", "PointLabels", "or", "raw", ".", "at", "[", "i", ",", "'Label'", "]", "==", "''", ")", ":", "TmpLabel", "=", "''", "else", ":", "PointLabels", ".", "append", "(", "raw", ".", "at", "[", "i", ",", "'Label'", "]", ")", "TmpLabel", "=", "raw", ".", "at", "[", "i", ",", "'Label'", "]", "x", ",", "y", ",", "z", "=", "0", ",", "0", ",", "0", "xuse", ",", "yuse", ",", "zuse", "=", "0", ",", "0", ",", "0", "x", ",", "y", ",", "z", "=", "raw", ".", "at", "[", "i", ",", "self", ".", "items", "[", "a", "]", "]", ",", "raw", ".", "at", "[", "i", ",", "self", ".", "items", "[", "b", "]", "]", ",", "raw", ".", "at", "[", "i", ",", "self", ".", "items", "[", "c", "]", "]", "try", ":", "xuse", "=", "x", "yuse", "=", "y", "zuse", "=", "z", "self", ".", "xlabel", "=", "self", ".", "items", "[", "a", "]", "self", ".", "ylabel", "=", "self", ".", "items", "[", "b", "]", "self", ".", "zlabel", "=", "self", ".", "items", "[", "c", "]", "if", "(", "self", ".", "Normalize_cb", ".", "isChecked", "(", ")", ")", ":", "self", ".", "xlabel", "=", "self", ".", "items", "[", "a", "]", "+", "' Norm by '", "+", "standardnamechosen", "self", ".", "x_element_label", ".", "setText", "(", "self", ".", "xlabel", ")", "self", ".", "ylabel", "=", "self", ".", "items", "[", "b", "]", "+", "' Norm by '", "+", "standardnamechosen", "self", ".", "y_element_label", ".", "setText", "(", "self", ".", "ylabel", ")", "self", ".", "zlabel", "=", "self", ".", "items", "[", "c", "]", "+", "' Norm by '", "+", "standardnamechosen", "self", ".", "z_element_label", ".", "setText", "(", "self", ".", "zlabel", ")", "if", "self", ".", "items", "[", "a", "]", "in", "self", ".", "Element", ":", "xuse", "=", "xuse", "/", "standardchosen", "[", "self", ".", "items", "[", "a", "]", "]", "if", "self", ".", "items", "[", "b", "]", "in", "self", ".", "Element", ":", "yuse", "=", "yuse", "/", "standardchosen", "[", "self", ".", "items", "[", "b", "]", "]", "if", "self", ".", "items", "[", "c", "]", "in", "self", ".", "Element", ":", "zuse", "=", "zuse", "/", "standardchosen", "[", "self", ".", "items", "[", "c", "]", "]", "if", "(", "self", ".", "logx_cb", ".", "isChecked", "(", ")", ")", ":", "xuse", "=", "math", ".", "log", "(", "x", ",", "10", ")", "self", ".", "xlabel", "=", "'$log10$ '", "+", "self", ".", "xlabel", "if", "(", "self", ".", "logy_cb", ".", "isChecked", "(", ")", ")", ":", "yuse", "=", "math", ".", "log", "(", "y", ",", "10", ")", "self", ".", "ylabel", "=", "'$log10$ '", "+", "self", ".", "ylabel", "if", "(", "self", ".", "logz_cb", ".", "isChecked", "(", ")", ")", ":", "zuse", "=", "math", ".", "log", "(", "z", ",", "10", ")", "self", ".", "zlabel", "=", "'$log10$ '", "+", "self", ".", "zlabel", "XtoDraw", ".", "append", "(", "xuse", ")", "YtoDraw", ".", "append", "(", "yuse", ")", "ZtoDraw", ".", "append", "(", "zuse", ")", "Colors", ".", "append", "(", "raw", ".", "at", "[", "i", ",", "'Color'", "]", ")", "Alphas", ".", "append", "(", "raw", ".", "at", "[", "i", ",", "'Alpha'", "]", ")", "Names", ".", "append", "(", "raw", ".", "at", "[", "i", ",", "'Label'", "]", ")", "Markers", ".", "append", "(", "raw", ".", "at", "[", "i", ",", "'Marker'", "]", ")", "except", "(", "ValueError", ")", ":", "pass", "if", "self", ".", "LimSet", "==", "False", ":", "self", ".", "Xleft", ",", "self", ".", "Xright", ",", "self", ".", "Ydown", ",", "self", ".", "Yup", ",", "self", ".", "Tail", ",", "self", ".", "Head", "=", "min", "(", "XtoDraw", ")", ",", "max", "(", "XtoDraw", ")", ",", "min", "(", "YtoDraw", ")", ",", "max", "(", "YtoDraw", ")", ",", "min", "(", "ZtoDraw", ")", ",", "max", "(", "ZtoDraw", ")", "xmin", ",", "xmax", "=", "min", "(", "XtoDraw", ")", ",", "max", "(", "XtoDraw", ")", "ymin", ",", "ymax", "=", "min", "(", "YtoDraw", ")", ",", "max", "(", "YtoDraw", ")", "zmin", ",", "zmax", "=", "min", "(", "ZtoDraw", ")", ",", "max", "(", "ZtoDraw", ")", "xmean", "=", "np", ".", "mean", "(", "XtoDraw", ")", "ymean", "=", "np", ".", "mean", "(", "YtoDraw", ")", "zmean", "=", "np", ".", "mean", "(", "ZtoDraw", ")", "Xoriginal", "=", "np", ".", "arange", "(", "xmin", ",", "xmax", ",", "(", "xmax", "-", "xmin", ")", "/", "10", ")", "Yoriginal", "=", "np", ".", "arange", "(", "ymin", ",", "ymax", ",", "(", "ymax", "-", "ymin", ")", "/", "10", ")", "Zoriginal", "=", "np", ".", "arange", "(", "zmin", ",", "zmax", ",", "(", "zmax", "-", "zmin", ")", "/", "10", ")", "XonPlot", "=", "self", ".", "GetASequence", "(", "tail", "=", "self", ".", "ShapeGroups", ")", "YonPlot", "=", "self", ".", "GetASequence", "(", "tail", "=", "self", ".", "ShapeGroups", ")", "ZonPlot", "=", "self", ".", "GetASequence", "(", "tail", "=", "self", ".", "ShapeGroups", ")", "XonStick", "=", "[", "]", "YonStick", "=", "[", "]", "ZonStick", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "XonPlot", ")", ")", ":", "XonStick", ".", "append", "(", "[", "XonPlot", "[", "i", "]", ",", "Xoriginal", "[", "i", "]", "]", ")", "YonStick", ".", "append", "(", "[", "YonPlot", "[", "i", "]", ",", "Yoriginal", "[", "i", "]", "]", ")", "ZonStick", ".", "append", "(", "[", "ZonPlot", "[", "i", "]", ",", "Zoriginal", "[", "i", "]", "]", ")", "pass", "#print(XtoDraw,'\\n', YtoDraw,'\\n', ZtoDraw)", "toDf", "=", "{", "self", ".", "xlabel", ":", "XtoDraw", ",", "self", ".", "ylabel", ":", "YtoDraw", ",", "self", ".", "zlabel", ":", "ZtoDraw", "}", "newdf", "=", "pd", ".", "DataFrame", "(", "toDf", ")", "pos", "=", "newdf", ".", "as_matrix", "(", ")", "print", "(", "pos", ")", "ThreeDimView", "=", "gl", ".", "GLScatterPlotItem", "(", "pos", "=", "pos", ",", "color", "=", "(", "100", ",", "255", ",", "255", ",", "88", ")", ",", "size", "=", "0.1", ",", "pxMode", "=", "False", ")", "print", "(", "xmean", ",", "'\\n'", ",", "ymean", ",", "'\\n'", ",", "zmean", ",", "'\\n'", ")", "self", ".", "view", ".", "pan", "(", "xmean", ",", "ymean", ",", "zmean", ")", "xgrid", "=", "gl", ".", "GLGridItem", "(", "size", "=", "QtGui", ".", "QVector3D", "(", "10", ",", "10", ",", "1", ")", ",", "color", "=", "1", ")", "ygrid", "=", "gl", ".", "GLGridItem", "(", "size", "=", "QtGui", ".", "QVector3D", "(", "20", ",", "20", ",", "2", ")", ",", "color", "=", "2", ")", "zgrid", "=", "gl", ".", "GLGridItem", "(", "size", "=", "QtGui", ".", "QVector3D", "(", "30", ",", "30", ",", "3", ")", ",", "color", "=", "3", ")", "## rotate x and y grids to face the correct direction", "xgrid", ".", "rotate", "(", "90", ",", "0", ",", "1", ",", "0", ")", "ygrid", ".", "rotate", "(", "90", ",", "1", ",", "0", ",", "0", ")", "xgrid", ".", "translate", "(", "xmean", ",", "ymean", ",", "zmean", ")", "ygrid", ".", "translate", "(", "xmean", ",", "ymean", ",", "zmean", ")", "zgrid", ".", "translate", "(", "xmean", ",", "ymean", ",", "zmean", ")", "## scale each grid differently", "# xgrid.setTransform(xmean,ymean,zmean)", "self", ".", "view", ".", "addItem", "(", "xgrid", ")", "self", ".", "view", ".", "addItem", "(", "ygrid", ")", "self", ".", "view", ".", "addItem", "(", "zgrid", ")", "self", ".", "view", ".", "addItem", "(", "ThreeDimView", ")" ]
xgrid.scale(12.8, 12.8, 12.8) ygrid.scale(12.8, 12.8, 12.8) zgrid.scale(12.8, 12.8, 12.8)
[ "xgrid", ".", "scale", "(", "12", ".", "8", "12", ".", "8", "12", ".", "8", ")", "ygrid", ".", "scale", "(", "12", ".", "8", "12", ".", "8", "12", ".", "8", ")", "zgrid", ".", "scale", "(", "12", ".", "8", "12", ".", "8", "12", ".", "8", ")" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/GLMultiDimension.py#L507-L727
GeoPyTool/GeoPyTool
geopytool/XY.py
XY.create_main_frame
def create_main_frame(self): self.resize(800, 800) self.main_frame = QWidget() self.dpi = 128 self.fig = Figure((8.0, 8.0), dpi=self.dpi) self.fig.subplots_adjust(hspace=0.5, wspace=0.5, left=0.13, bottom=0.2, right=0.7, top=0.9) self.canvas = FigureCanvas(self.fig) self.canvas.setParent(self.main_frame) self.axes = self.fig.add_subplot(111) # self.axes.hold(False) # Create the navigation toolbar, tied to the canvas self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame) # Other GUI controls self.load_data_button = QPushButton('&Add Data to Compare') self.load_data_button.clicked.connect(self.loadDataToTest) self.save_plot_button = QPushButton('&Save IMG') self.save_plot_button .clicked.connect(self.saveImgFile) self.stat_button = QPushButton('&Show Stat') self.stat_button.clicked.connect(self.Stat) self.load_img_button = QPushButton('&Load Basemap') self.load_img_button.clicked.connect(self.Load) self.unload_img_button = QPushButton('&Unload Basemap') self.unload_img_button.clicked.connect(self.Unload) self.legend_cb = QCheckBox('&Legend') self.legend_cb.setChecked(True) self.legend_cb.stateChanged.connect(self.Magic) # int self.show_load_data_cb = QCheckBox('&Show Loaded Data') self.show_load_data_cb.setChecked(True) self.show_load_data_cb.stateChanged.connect(self.Magic) # int self.show_data_index_cb = QCheckBox('&Show Data Index') self.show_data_index_cb.setChecked(False) self.show_data_index_cb.stateChanged.connect(self.Magic) # int self.hyperplane_cb= QCheckBox('&Hyperplane') self.hyperplane_cb.setChecked(False) self.hyperplane_cb.stateChanged.connect(self.Magic) # int self.fit_cb= QCheckBox('&PolyFit') self.fit_cb.setChecked(False) self.fit_cb.stateChanged.connect(self.Magic) # int self.fit_seter = QLineEdit(self) self.fit_seter.textChanged[str].connect(self.FitChanged) self.fit_slider_label = QLabel('y= f(x) EXP') self.fit_slider = QSlider(Qt.Vertical) self.fit_slider.setRange(0, 1) self.fit_slider.setValue(0) self.fit_slider.setTracking(True) self.fit_slider.setTickPosition(QSlider.TicksBothSides) self.fit_slider.valueChanged.connect(self.Magic) # int self.shape_cb= QCheckBox('&Shape') self.shape_cb.setChecked(False) self.shape_cb.stateChanged.connect(self.Magic) # int #self.shape_label = QLabel('Step') #self.shape_seter = QLineEdit(self) #self.shape_seter.textChanged[str].connect(self.ShapeChanged) self.norm_cb = QCheckBox('&Norm') self.norm_cb.setChecked(False) self.norm_cb.stateChanged.connect(self.Magic) # int self.standard_slider = QSlider(Qt.Horizontal) self.standard_slider.setRange(0, len(self.StandardsName)) if len(self._given_Standard) > 0: self.standard_slider.setValue(len(self.StandardsName)) self.right_label = QLabel("Self Defined Standard") else: self.standard_slider.setValue(0) self.right_label = QLabel(self.StandardsName[int(self.standard_slider.value())]) self.standard_slider.setTracking(True) self.standard_slider.setTickPosition(QSlider.TicksBothSides) self.standard_slider.valueChanged.connect(self.Magic) # int self.left_label= QLabel('Standard' ) self.x_element = QSlider(Qt.Horizontal) self.x_element.setRange(0, len(self.items) - 1) self.x_element.setValue(0) self.x_element.setTracking(True) self.x_element.setTickPosition(QSlider.TicksBothSides) self.x_element.valueChanged.connect(self.ValueChooser) # int self.x_seter = QLineEdit(self) self.x_seter.textChanged[str].connect(self.LabelSeter) #self.x_calculator = QLineEdit(self) self.logx_cb = QCheckBox('&Log') self.logx_cb.setChecked(False) self.logx_cb.stateChanged.connect(self.Magic) # int self.y_element = QSlider(Qt.Horizontal) self.y_element.setRange(0, len(self.items) - 1) self.y_element.setValue(1) self.y_element.setTracking(True) self.y_element.setTickPosition(QSlider.TicksBothSides) self.y_element.valueChanged.connect(self.ValueChooser) # int self.y_seter = QLineEdit(self) self.y_seter.textChanged[str].connect(self.LabelSeter) #self.y_calculator = QLineEdit(self) self.logy_cb = QCheckBox('&Log') self.logy_cb.setChecked(False) self.logy_cb.stateChanged.connect(self.Magic) # int self.hyperplane_cb= QCheckBox('&Hyperplane') self.hyperplane_cb.setChecked(False) self.hyperplane_cb.stateChanged.connect(self.Magic) # int self.save_predict_button_selected = QPushButton('&Predict Selected') self.save_predict_button_selected.clicked.connect(self.showPredictResultSelected) self.save_predict_button = QPushButton('&Predict All') self.save_predict_button.clicked.connect(self.showPredictResult) self.load_data_button = QPushButton('&Add Data to Compare') self.load_data_button.clicked.connect(self.loadDataToTest) self.width_size_seter_label = QLabel('SVG Width') self.width_size_seter = QLineEdit(self) self.width_size_seter.textChanged[str].connect(self.WChanged) self.height_size_seter_label = QLabel('SVG Height') self.height_size_seter = QLineEdit(self) self.height_size_seter.textChanged[str].connect(self.HChanged) self.Left_size_seter_label = QLabel('PNG Left') self.Left_size_seter = QLineEdit(self) self.Left_size_seter.textChanged[str].connect(self.LeftChanged) self.Right_size_seter_label = QLabel('PNG Right') self.Right_size_seter = QLineEdit(self) self.Right_size_seter.textChanged[str].connect(self.RightChanged) self.Up_size_seter_label = QLabel('PNG Top') self.Up_size_seter = QLineEdit(self) self.Up_size_seter.textChanged[str].connect(self.UpChanged) self.Down_size_seter_label = QLabel('PNG Bottom') self.Down_size_seter = QLineEdit(self) self.Down_size_seter.textChanged[str].connect(self.DownChanged) # # Layout with box sizers # self.hbox = QHBoxLayout() self.hbox0 = QHBoxLayout() self.hbox1 = QHBoxLayout() self.hbox2 = QHBoxLayout() self.hbox3 = QHBoxLayout() self.hbox4 = QHBoxLayout() self.hbox5 = QHBoxLayout() w=self.width() h=self.height() #self.load_data_button.setFixedWidth(w/4) self.kernel_select = QSlider(Qt.Horizontal) self.kernel_select.setRange(0, len(self.kernel_list)-1) self.kernel_select.setValue(0) self.kernel_select.setTracking(True) self.kernel_select.setTickPosition(QSlider.TicksBothSides) self.kernel_select.valueChanged.connect(self.Magic) # int self.kernel_select_label = QLabel('Kernel') for w in [self.save_plot_button ,self.stat_button,self.load_data_button,self.save_predict_button,self.save_predict_button_selected]: self.hbox.addWidget(w) self.hbox.setAlignment(w, Qt.AlignVCenter) for w in [self.legend_cb,self.show_load_data_cb,self.show_data_index_cb, self.norm_cb,self.shape_cb,self.hyperplane_cb,self.kernel_select_label,self.kernel_select]: self.hbox0.addWidget(w) self.hbox0.setAlignment(w, Qt.AlignVCenter) for w in [self.left_label, self.standard_slider,self.right_label,self.fit_cb,self.fit_slider,self.fit_slider_label ,self.fit_seter]: self.hbox1.addWidget(w) self.hbox1.setAlignment(w, Qt.AlignVCenter) for w in [self.logx_cb,self.x_seter, self.x_element]: self.hbox2.addWidget(w) self.hbox2.setAlignment(w, Qt.AlignVCenter) for w in [self.logy_cb,self.y_seter, self.y_element]: self.hbox3.addWidget(w) self.hbox3.setAlignment(w, Qt.AlignVCenter) for w in [self.load_img_button, self.width_size_seter_label, self.width_size_seter, self.height_size_seter_label, self.height_size_seter]: self.hbox4.addWidget(w) self.hbox4.setAlignment(w, Qt.AlignLeft) for w in [self.unload_img_button,self.Left_size_seter_label, self.Left_size_seter, self.Right_size_seter_label, self.Right_size_seter,self.Down_size_seter_label, self.Down_size_seter, self.Up_size_seter_label ,self.Up_size_seter]: self.hbox5.addWidget(w) self.hbox5.setAlignment(w, Qt.AlignLeft) self.vbox = QVBoxLayout() self.vbox.addWidget(self.mpl_toolbar) self.vbox.addWidget(self.canvas) self.vbox.addLayout(self.hbox) self.vbox.addLayout(self.hbox0) self.vbox.addLayout(self.hbox1) self.vbox.addLayout(self.hbox2) self.vbox.addLayout(self.hbox3) self.vbox.addLayout(self.hbox4) self.vbox.addLayout(self.hbox5) self.textbox = GrowingTextEdit(self) self.vbox.addWidget(self.textbox) self.main_frame.setLayout(self.vbox) self.setCentralWidget(self.main_frame) w=self.width() h=self.height() self.x_seter.setFixedWidth(w/10) self.y_seter.setFixedWidth(w/10) ''' self.save_plot_button.setFixedWidth(w/10) self.stat_button.setFixedWidth(w/10) self.load_data_button.setFixedWidth(w/4) self.save_predict_button_selected.setFixedWidth(w/4) self.save_predict_button.setFixedWidth(w/4) ''' self.standard_slider.setFixedWidth(w/5) self.right_label.setFixedWidth(w/5) self.fit_seter.setFixedWidth(w/20) self.load_img_button.setFixedWidth(w/5) self.unload_img_button.setFixedWidth(w/5) self.width_size_seter_label.setFixedWidth(w/10) self.height_size_seter_label.setFixedWidth(w/10) self.width_size_seter.setMinimumWidth(w/20) self.height_size_seter.setMinimumWidth(w/20) self.Right_size_seter_label.setFixedWidth(w/10) self.Left_size_seter_label.setFixedWidth(w/10) self.Up_size_seter_label.setFixedWidth(w/10) self.Down_size_seter_label.setFixedWidth(w/10) self.Right_size_seter.setFixedWidth(w/20) self.Left_size_seter.setFixedWidth(w/20) self.Up_size_seter.setFixedWidth(w/20) self.Down_size_seter.setFixedWidth(w/20)
python
def create_main_frame(self): self.resize(800, 800) self.main_frame = QWidget() self.dpi = 128 self.fig = Figure((8.0, 8.0), dpi=self.dpi) self.fig.subplots_adjust(hspace=0.5, wspace=0.5, left=0.13, bottom=0.2, right=0.7, top=0.9) self.canvas = FigureCanvas(self.fig) self.canvas.setParent(self.main_frame) self.axes = self.fig.add_subplot(111) self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame) self.load_data_button = QPushButton('&Add Data to Compare') self.load_data_button.clicked.connect(self.loadDataToTest) self.save_plot_button = QPushButton('&Save IMG') self.save_plot_button .clicked.connect(self.saveImgFile) self.stat_button = QPushButton('&Show Stat') self.stat_button.clicked.connect(self.Stat) self.load_img_button = QPushButton('&Load Basemap') self.load_img_button.clicked.connect(self.Load) self.unload_img_button = QPushButton('&Unload Basemap') self.unload_img_button.clicked.connect(self.Unload) self.legend_cb = QCheckBox('&Legend') self.legend_cb.setChecked(True) self.legend_cb.stateChanged.connect(self.Magic) self.show_load_data_cb = QCheckBox('&Show Loaded Data') self.show_load_data_cb.setChecked(True) self.show_load_data_cb.stateChanged.connect(self.Magic) self.show_data_index_cb = QCheckBox('&Show Data Index') self.show_data_index_cb.setChecked(False) self.show_data_index_cb.stateChanged.connect(self.Magic) self.hyperplane_cb= QCheckBox('&Hyperplane') self.hyperplane_cb.setChecked(False) self.hyperplane_cb.stateChanged.connect(self.Magic) self.fit_cb= QCheckBox('&PolyFit') self.fit_cb.setChecked(False) self.fit_cb.stateChanged.connect(self.Magic) self.fit_seter = QLineEdit(self) self.fit_seter.textChanged[str].connect(self.FitChanged) self.fit_slider_label = QLabel('y= f(x) EXP') self.fit_slider = QSlider(Qt.Vertical) self.fit_slider.setRange(0, 1) self.fit_slider.setValue(0) self.fit_slider.setTracking(True) self.fit_slider.setTickPosition(QSlider.TicksBothSides) self.fit_slider.valueChanged.connect(self.Magic) self.shape_cb= QCheckBox('&Shape') self.shape_cb.setChecked(False) self.shape_cb.stateChanged.connect(self.Magic) self.norm_cb = QCheckBox('&Norm') self.norm_cb.setChecked(False) self.norm_cb.stateChanged.connect(self.Magic) self.standard_slider = QSlider(Qt.Horizontal) self.standard_slider.setRange(0, len(self.StandardsName)) if len(self._given_Standard) > 0: self.standard_slider.setValue(len(self.StandardsName)) self.right_label = QLabel("Self Defined Standard") else: self.standard_slider.setValue(0) self.right_label = QLabel(self.StandardsName[int(self.standard_slider.value())]) self.standard_slider.setTracking(True) self.standard_slider.setTickPosition(QSlider.TicksBothSides) self.standard_slider.valueChanged.connect(self.Magic) self.left_label= QLabel('Standard' ) self.x_element = QSlider(Qt.Horizontal) self.x_element.setRange(0, len(self.items) - 1) self.x_element.setValue(0) self.x_element.setTracking(True) self.x_element.setTickPosition(QSlider.TicksBothSides) self.x_element.valueChanged.connect(self.ValueChooser) self.x_seter = QLineEdit(self) self.x_seter.textChanged[str].connect(self.LabelSeter) self.logx_cb = QCheckBox('&Log') self.logx_cb.setChecked(False) self.logx_cb.stateChanged.connect(self.Magic) self.y_element = QSlider(Qt.Horizontal) self.y_element.setRange(0, len(self.items) - 1) self.y_element.setValue(1) self.y_element.setTracking(True) self.y_element.setTickPosition(QSlider.TicksBothSides) self.y_element.valueChanged.connect(self.ValueChooser) self.y_seter = QLineEdit(self) self.y_seter.textChanged[str].connect(self.LabelSeter) self.logy_cb = QCheckBox('&Log') self.logy_cb.setChecked(False) self.logy_cb.stateChanged.connect(self.Magic) self.hyperplane_cb= QCheckBox('&Hyperplane') self.hyperplane_cb.setChecked(False) self.hyperplane_cb.stateChanged.connect(self.Magic) self.save_predict_button_selected = QPushButton('&Predict Selected') self.save_predict_button_selected.clicked.connect(self.showPredictResultSelected) self.save_predict_button = QPushButton('&Predict All') self.save_predict_button.clicked.connect(self.showPredictResult) self.load_data_button = QPushButton('&Add Data to Compare') self.load_data_button.clicked.connect(self.loadDataToTest) self.width_size_seter_label = QLabel('SVG Width') self.width_size_seter = QLineEdit(self) self.width_size_seter.textChanged[str].connect(self.WChanged) self.height_size_seter_label = QLabel('SVG Height') self.height_size_seter = QLineEdit(self) self.height_size_seter.textChanged[str].connect(self.HChanged) self.Left_size_seter_label = QLabel('PNG Left') self.Left_size_seter = QLineEdit(self) self.Left_size_seter.textChanged[str].connect(self.LeftChanged) self.Right_size_seter_label = QLabel('PNG Right') self.Right_size_seter = QLineEdit(self) self.Right_size_seter.textChanged[str].connect(self.RightChanged) self.Up_size_seter_label = QLabel('PNG Top') self.Up_size_seter = QLineEdit(self) self.Up_size_seter.textChanged[str].connect(self.UpChanged) self.Down_size_seter_label = QLabel('PNG Bottom') self.Down_size_seter = QLineEdit(self) self.Down_size_seter.textChanged[str].connect(self.DownChanged) self.hbox = QHBoxLayout() self.hbox0 = QHBoxLayout() self.hbox1 = QHBoxLayout() self.hbox2 = QHBoxLayout() self.hbox3 = QHBoxLayout() self.hbox4 = QHBoxLayout() self.hbox5 = QHBoxLayout() w=self.width() h=self.height() self.kernel_select = QSlider(Qt.Horizontal) self.kernel_select.setRange(0, len(self.kernel_list)-1) self.kernel_select.setValue(0) self.kernel_select.setTracking(True) self.kernel_select.setTickPosition(QSlider.TicksBothSides) self.kernel_select.valueChanged.connect(self.Magic) self.kernel_select_label = QLabel('Kernel') for w in [self.save_plot_button ,self.stat_button,self.load_data_button,self.save_predict_button,self.save_predict_button_selected]: self.hbox.addWidget(w) self.hbox.setAlignment(w, Qt.AlignVCenter) for w in [self.legend_cb,self.show_load_data_cb,self.show_data_index_cb, self.norm_cb,self.shape_cb,self.hyperplane_cb,self.kernel_select_label,self.kernel_select]: self.hbox0.addWidget(w) self.hbox0.setAlignment(w, Qt.AlignVCenter) for w in [self.left_label, self.standard_slider,self.right_label,self.fit_cb,self.fit_slider,self.fit_slider_label ,self.fit_seter]: self.hbox1.addWidget(w) self.hbox1.setAlignment(w, Qt.AlignVCenter) for w in [self.logx_cb,self.x_seter, self.x_element]: self.hbox2.addWidget(w) self.hbox2.setAlignment(w, Qt.AlignVCenter) for w in [self.logy_cb,self.y_seter, self.y_element]: self.hbox3.addWidget(w) self.hbox3.setAlignment(w, Qt.AlignVCenter) for w in [self.load_img_button, self.width_size_seter_label, self.width_size_seter, self.height_size_seter_label, self.height_size_seter]: self.hbox4.addWidget(w) self.hbox4.setAlignment(w, Qt.AlignLeft) for w in [self.unload_img_button,self.Left_size_seter_label, self.Left_size_seter, self.Right_size_seter_label, self.Right_size_seter,self.Down_size_seter_label, self.Down_size_seter, self.Up_size_seter_label ,self.Up_size_seter]: self.hbox5.addWidget(w) self.hbox5.setAlignment(w, Qt.AlignLeft) self.vbox = QVBoxLayout() self.vbox.addWidget(self.mpl_toolbar) self.vbox.addWidget(self.canvas) self.vbox.addLayout(self.hbox) self.vbox.addLayout(self.hbox0) self.vbox.addLayout(self.hbox1) self.vbox.addLayout(self.hbox2) self.vbox.addLayout(self.hbox3) self.vbox.addLayout(self.hbox4) self.vbox.addLayout(self.hbox5) self.textbox = GrowingTextEdit(self) self.vbox.addWidget(self.textbox) self.main_frame.setLayout(self.vbox) self.setCentralWidget(self.main_frame) w=self.width() h=self.height() self.x_seter.setFixedWidth(w/10) self.y_seter.setFixedWidth(w/10) self.standard_slider.setFixedWidth(w/5) self.right_label.setFixedWidth(w/5) self.fit_seter.setFixedWidth(w/20) self.load_img_button.setFixedWidth(w/5) self.unload_img_button.setFixedWidth(w/5) self.width_size_seter_label.setFixedWidth(w/10) self.height_size_seter_label.setFixedWidth(w/10) self.width_size_seter.setMinimumWidth(w/20) self.height_size_seter.setMinimumWidth(w/20) self.Right_size_seter_label.setFixedWidth(w/10) self.Left_size_seter_label.setFixedWidth(w/10) self.Up_size_seter_label.setFixedWidth(w/10) self.Down_size_seter_label.setFixedWidth(w/10) self.Right_size_seter.setFixedWidth(w/20) self.Left_size_seter.setFixedWidth(w/20) self.Up_size_seter.setFixedWidth(w/20) self.Down_size_seter.setFixedWidth(w/20)
[ "def", "create_main_frame", "(", "self", ")", ":", "self", ".", "resize", "(", "800", ",", "800", ")", "self", ".", "main_frame", "=", "QWidget", "(", ")", "self", ".", "dpi", "=", "128", "self", ".", "fig", "=", "Figure", "(", "(", "8.0", ",", "8.0", ")", ",", "dpi", "=", "self", ".", "dpi", ")", "self", ".", "fig", ".", "subplots_adjust", "(", "hspace", "=", "0.5", ",", "wspace", "=", "0.5", ",", "left", "=", "0.13", ",", "bottom", "=", "0.2", ",", "right", "=", "0.7", ",", "top", "=", "0.9", ")", "self", ".", "canvas", "=", "FigureCanvas", "(", "self", ".", "fig", ")", "self", ".", "canvas", ".", "setParent", "(", "self", ".", "main_frame", ")", "self", ".", "axes", "=", "self", ".", "fig", ".", "add_subplot", "(", "111", ")", "# self.axes.hold(False)", "# Create the navigation toolbar, tied to the canvas", "self", ".", "mpl_toolbar", "=", "NavigationToolbar", "(", "self", ".", "canvas", ",", "self", ".", "main_frame", ")", "# Other GUI controls", "self", ".", "load_data_button", "=", "QPushButton", "(", "'&Add Data to Compare'", ")", "self", ".", "load_data_button", ".", "clicked", ".", "connect", "(", "self", ".", "loadDataToTest", ")", "self", ".", "save_plot_button", "=", "QPushButton", "(", "'&Save IMG'", ")", "self", ".", "save_plot_button", ".", "clicked", ".", "connect", "(", "self", ".", "saveImgFile", ")", "self", ".", "stat_button", "=", "QPushButton", "(", "'&Show Stat'", ")", "self", ".", "stat_button", ".", "clicked", ".", "connect", "(", "self", ".", "Stat", ")", "self", ".", "load_img_button", "=", "QPushButton", "(", "'&Load Basemap'", ")", "self", ".", "load_img_button", ".", "clicked", ".", "connect", "(", "self", ".", "Load", ")", "self", ".", "unload_img_button", "=", "QPushButton", "(", "'&Unload Basemap'", ")", "self", ".", "unload_img_button", ".", "clicked", ".", "connect", "(", "self", ".", "Unload", ")", "self", ".", "legend_cb", "=", "QCheckBox", "(", "'&Legend'", ")", "self", ".", "legend_cb", ".", "setChecked", "(", "True", ")", "self", ".", "legend_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "show_load_data_cb", "=", "QCheckBox", "(", "'&Show Loaded Data'", ")", "self", ".", "show_load_data_cb", ".", "setChecked", "(", "True", ")", "self", ".", "show_load_data_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "show_data_index_cb", "=", "QCheckBox", "(", "'&Show Data Index'", ")", "self", ".", "show_data_index_cb", ".", "setChecked", "(", "False", ")", "self", ".", "show_data_index_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "hyperplane_cb", "=", "QCheckBox", "(", "'&Hyperplane'", ")", "self", ".", "hyperplane_cb", ".", "setChecked", "(", "False", ")", "self", ".", "hyperplane_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "fit_cb", "=", "QCheckBox", "(", "'&PolyFit'", ")", "self", ".", "fit_cb", ".", "setChecked", "(", "False", ")", "self", ".", "fit_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "fit_seter", "=", "QLineEdit", "(", "self", ")", "self", ".", "fit_seter", ".", "textChanged", "[", "str", "]", ".", "connect", "(", "self", ".", "FitChanged", ")", "self", ".", "fit_slider_label", "=", "QLabel", "(", "'y= f(x) EXP'", ")", "self", ".", "fit_slider", "=", "QSlider", "(", "Qt", ".", "Vertical", ")", "self", ".", "fit_slider", ".", "setRange", "(", "0", ",", "1", ")", "self", ".", "fit_slider", ".", "setValue", "(", "0", ")", "self", ".", "fit_slider", ".", "setTracking", "(", "True", ")", "self", ".", "fit_slider", ".", "setTickPosition", "(", "QSlider", ".", "TicksBothSides", ")", "self", ".", "fit_slider", ".", "valueChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "shape_cb", "=", "QCheckBox", "(", "'&Shape'", ")", "self", ".", "shape_cb", ".", "setChecked", "(", "False", ")", "self", ".", "shape_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "#self.shape_label = QLabel('Step')", "#self.shape_seter = QLineEdit(self)", "#self.shape_seter.textChanged[str].connect(self.ShapeChanged)", "self", ".", "norm_cb", "=", "QCheckBox", "(", "'&Norm'", ")", "self", ".", "norm_cb", ".", "setChecked", "(", "False", ")", "self", ".", "norm_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "standard_slider", "=", "QSlider", "(", "Qt", ".", "Horizontal", ")", "self", ".", "standard_slider", ".", "setRange", "(", "0", ",", "len", "(", "self", ".", "StandardsName", ")", ")", "if", "len", "(", "self", ".", "_given_Standard", ")", ">", "0", ":", "self", ".", "standard_slider", ".", "setValue", "(", "len", "(", "self", ".", "StandardsName", ")", ")", "self", ".", "right_label", "=", "QLabel", "(", "\"Self Defined Standard\"", ")", "else", ":", "self", ".", "standard_slider", ".", "setValue", "(", "0", ")", "self", ".", "right_label", "=", "QLabel", "(", "self", ".", "StandardsName", "[", "int", "(", "self", ".", "standard_slider", ".", "value", "(", ")", ")", "]", ")", "self", ".", "standard_slider", ".", "setTracking", "(", "True", ")", "self", ".", "standard_slider", ".", "setTickPosition", "(", "QSlider", ".", "TicksBothSides", ")", "self", ".", "standard_slider", ".", "valueChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "left_label", "=", "QLabel", "(", "'Standard'", ")", "self", ".", "x_element", "=", "QSlider", "(", "Qt", ".", "Horizontal", ")", "self", ".", "x_element", ".", "setRange", "(", "0", ",", "len", "(", "self", ".", "items", ")", "-", "1", ")", "self", ".", "x_element", ".", "setValue", "(", "0", ")", "self", ".", "x_element", ".", "setTracking", "(", "True", ")", "self", ".", "x_element", ".", "setTickPosition", "(", "QSlider", ".", "TicksBothSides", ")", "self", ".", "x_element", ".", "valueChanged", ".", "connect", "(", "self", ".", "ValueChooser", ")", "# int", "self", ".", "x_seter", "=", "QLineEdit", "(", "self", ")", "self", ".", "x_seter", ".", "textChanged", "[", "str", "]", ".", "connect", "(", "self", ".", "LabelSeter", ")", "#self.x_calculator = QLineEdit(self)", "self", ".", "logx_cb", "=", "QCheckBox", "(", "'&Log'", ")", "self", ".", "logx_cb", ".", "setChecked", "(", "False", ")", "self", ".", "logx_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "y_element", "=", "QSlider", "(", "Qt", ".", "Horizontal", ")", "self", ".", "y_element", ".", "setRange", "(", "0", ",", "len", "(", "self", ".", "items", ")", "-", "1", ")", "self", ".", "y_element", ".", "setValue", "(", "1", ")", "self", ".", "y_element", ".", "setTracking", "(", "True", ")", "self", ".", "y_element", ".", "setTickPosition", "(", "QSlider", ".", "TicksBothSides", ")", "self", ".", "y_element", ".", "valueChanged", ".", "connect", "(", "self", ".", "ValueChooser", ")", "# int", "self", ".", "y_seter", "=", "QLineEdit", "(", "self", ")", "self", ".", "y_seter", ".", "textChanged", "[", "str", "]", ".", "connect", "(", "self", ".", "LabelSeter", ")", "#self.y_calculator = QLineEdit(self)", "self", ".", "logy_cb", "=", "QCheckBox", "(", "'&Log'", ")", "self", ".", "logy_cb", ".", "setChecked", "(", "False", ")", "self", ".", "logy_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "hyperplane_cb", "=", "QCheckBox", "(", "'&Hyperplane'", ")", "self", ".", "hyperplane_cb", ".", "setChecked", "(", "False", ")", "self", ".", "hyperplane_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "save_predict_button_selected", "=", "QPushButton", "(", "'&Predict Selected'", ")", "self", ".", "save_predict_button_selected", ".", "clicked", ".", "connect", "(", "self", ".", "showPredictResultSelected", ")", "self", ".", "save_predict_button", "=", "QPushButton", "(", "'&Predict All'", ")", "self", ".", "save_predict_button", ".", "clicked", ".", "connect", "(", "self", ".", "showPredictResult", ")", "self", ".", "load_data_button", "=", "QPushButton", "(", "'&Add Data to Compare'", ")", "self", ".", "load_data_button", ".", "clicked", ".", "connect", "(", "self", ".", "loadDataToTest", ")", "self", ".", "width_size_seter_label", "=", "QLabel", "(", "'SVG Width'", ")", "self", ".", "width_size_seter", "=", "QLineEdit", "(", "self", ")", "self", ".", "width_size_seter", ".", "textChanged", "[", "str", "]", ".", "connect", "(", "self", ".", "WChanged", ")", "self", ".", "height_size_seter_label", "=", "QLabel", "(", "'SVG Height'", ")", "self", ".", "height_size_seter", "=", "QLineEdit", "(", "self", ")", "self", ".", "height_size_seter", ".", "textChanged", "[", "str", "]", ".", "connect", "(", "self", ".", "HChanged", ")", "self", ".", "Left_size_seter_label", "=", "QLabel", "(", "'PNG Left'", ")", "self", ".", "Left_size_seter", "=", "QLineEdit", "(", "self", ")", "self", ".", "Left_size_seter", ".", "textChanged", "[", "str", "]", ".", "connect", "(", "self", ".", "LeftChanged", ")", "self", ".", "Right_size_seter_label", "=", "QLabel", "(", "'PNG Right'", ")", "self", ".", "Right_size_seter", "=", "QLineEdit", "(", "self", ")", "self", ".", "Right_size_seter", ".", "textChanged", "[", "str", "]", ".", "connect", "(", "self", ".", "RightChanged", ")", "self", ".", "Up_size_seter_label", "=", "QLabel", "(", "'PNG Top'", ")", "self", ".", "Up_size_seter", "=", "QLineEdit", "(", "self", ")", "self", ".", "Up_size_seter", ".", "textChanged", "[", "str", "]", ".", "connect", "(", "self", ".", "UpChanged", ")", "self", ".", "Down_size_seter_label", "=", "QLabel", "(", "'PNG Bottom'", ")", "self", ".", "Down_size_seter", "=", "QLineEdit", "(", "self", ")", "self", ".", "Down_size_seter", ".", "textChanged", "[", "str", "]", ".", "connect", "(", "self", ".", "DownChanged", ")", "#", "# Layout with box sizers", "#", "self", ".", "hbox", "=", "QHBoxLayout", "(", ")", "self", ".", "hbox0", "=", "QHBoxLayout", "(", ")", "self", ".", "hbox1", "=", "QHBoxLayout", "(", ")", "self", ".", "hbox2", "=", "QHBoxLayout", "(", ")", "self", ".", "hbox3", "=", "QHBoxLayout", "(", ")", "self", ".", "hbox4", "=", "QHBoxLayout", "(", ")", "self", ".", "hbox5", "=", "QHBoxLayout", "(", ")", "w", "=", "self", ".", "width", "(", ")", "h", "=", "self", ".", "height", "(", ")", "#self.load_data_button.setFixedWidth(w/4)", "self", ".", "kernel_select", "=", "QSlider", "(", "Qt", ".", "Horizontal", ")", "self", ".", "kernel_select", ".", "setRange", "(", "0", ",", "len", "(", "self", ".", "kernel_list", ")", "-", "1", ")", "self", ".", "kernel_select", ".", "setValue", "(", "0", ")", "self", ".", "kernel_select", ".", "setTracking", "(", "True", ")", "self", ".", "kernel_select", ".", "setTickPosition", "(", "QSlider", ".", "TicksBothSides", ")", "self", ".", "kernel_select", ".", "valueChanged", ".", "connect", "(", "self", ".", "Magic", ")", "# int", "self", ".", "kernel_select_label", "=", "QLabel", "(", "'Kernel'", ")", "for", "w", "in", "[", "self", ".", "save_plot_button", ",", "self", ".", "stat_button", ",", "self", ".", "load_data_button", ",", "self", ".", "save_predict_button", ",", "self", ".", "save_predict_button_selected", "]", ":", "self", ".", "hbox", ".", "addWidget", "(", "w", ")", "self", ".", "hbox", ".", "setAlignment", "(", "w", ",", "Qt", ".", "AlignVCenter", ")", "for", "w", "in", "[", "self", ".", "legend_cb", ",", "self", ".", "show_load_data_cb", ",", "self", ".", "show_data_index_cb", ",", "self", ".", "norm_cb", ",", "self", ".", "shape_cb", ",", "self", ".", "hyperplane_cb", ",", "self", ".", "kernel_select_label", ",", "self", ".", "kernel_select", "]", ":", "self", ".", "hbox0", ".", "addWidget", "(", "w", ")", "self", ".", "hbox0", ".", "setAlignment", "(", "w", ",", "Qt", ".", "AlignVCenter", ")", "for", "w", "in", "[", "self", ".", "left_label", ",", "self", ".", "standard_slider", ",", "self", ".", "right_label", ",", "self", ".", "fit_cb", ",", "self", ".", "fit_slider", ",", "self", ".", "fit_slider_label", ",", "self", ".", "fit_seter", "]", ":", "self", ".", "hbox1", ".", "addWidget", "(", "w", ")", "self", ".", "hbox1", ".", "setAlignment", "(", "w", ",", "Qt", ".", "AlignVCenter", ")", "for", "w", "in", "[", "self", ".", "logx_cb", ",", "self", ".", "x_seter", ",", "self", ".", "x_element", "]", ":", "self", ".", "hbox2", ".", "addWidget", "(", "w", ")", "self", ".", "hbox2", ".", "setAlignment", "(", "w", ",", "Qt", ".", "AlignVCenter", ")", "for", "w", "in", "[", "self", ".", "logy_cb", ",", "self", ".", "y_seter", ",", "self", ".", "y_element", "]", ":", "self", ".", "hbox3", ".", "addWidget", "(", "w", ")", "self", ".", "hbox3", ".", "setAlignment", "(", "w", ",", "Qt", ".", "AlignVCenter", ")", "for", "w", "in", "[", "self", ".", "load_img_button", ",", "self", ".", "width_size_seter_label", ",", "self", ".", "width_size_seter", ",", "self", ".", "height_size_seter_label", ",", "self", ".", "height_size_seter", "]", ":", "self", ".", "hbox4", ".", "addWidget", "(", "w", ")", "self", ".", "hbox4", ".", "setAlignment", "(", "w", ",", "Qt", ".", "AlignLeft", ")", "for", "w", "in", "[", "self", ".", "unload_img_button", ",", "self", ".", "Left_size_seter_label", ",", "self", ".", "Left_size_seter", ",", "self", ".", "Right_size_seter_label", ",", "self", ".", "Right_size_seter", ",", "self", ".", "Down_size_seter_label", ",", "self", ".", "Down_size_seter", ",", "self", ".", "Up_size_seter_label", ",", "self", ".", "Up_size_seter", "]", ":", "self", ".", "hbox5", ".", "addWidget", "(", "w", ")", "self", ".", "hbox5", ".", "setAlignment", "(", "w", ",", "Qt", ".", "AlignLeft", ")", "self", ".", "vbox", "=", "QVBoxLayout", "(", ")", "self", ".", "vbox", ".", "addWidget", "(", "self", ".", "mpl_toolbar", ")", "self", ".", "vbox", ".", "addWidget", "(", "self", ".", "canvas", ")", "self", ".", "vbox", ".", "addLayout", "(", "self", ".", "hbox", ")", "self", ".", "vbox", ".", "addLayout", "(", "self", ".", "hbox0", ")", "self", ".", "vbox", ".", "addLayout", "(", "self", ".", "hbox1", ")", "self", ".", "vbox", ".", "addLayout", "(", "self", ".", "hbox2", ")", "self", ".", "vbox", ".", "addLayout", "(", "self", ".", "hbox3", ")", "self", ".", "vbox", ".", "addLayout", "(", "self", ".", "hbox4", ")", "self", ".", "vbox", ".", "addLayout", "(", "self", ".", "hbox5", ")", "self", ".", "textbox", "=", "GrowingTextEdit", "(", "self", ")", "self", ".", "vbox", ".", "addWidget", "(", "self", ".", "textbox", ")", "self", ".", "main_frame", ".", "setLayout", "(", "self", ".", "vbox", ")", "self", ".", "setCentralWidget", "(", "self", ".", "main_frame", ")", "w", "=", "self", ".", "width", "(", ")", "h", "=", "self", ".", "height", "(", ")", "self", ".", "x_seter", ".", "setFixedWidth", "(", "w", "/", "10", ")", "self", ".", "y_seter", ".", "setFixedWidth", "(", "w", "/", "10", ")", "self", ".", "standard_slider", ".", "setFixedWidth", "(", "w", "/", "5", ")", "self", ".", "right_label", ".", "setFixedWidth", "(", "w", "/", "5", ")", "self", ".", "fit_seter", ".", "setFixedWidth", "(", "w", "/", "20", ")", "self", ".", "load_img_button", ".", "setFixedWidth", "(", "w", "/", "5", ")", "self", ".", "unload_img_button", ".", "setFixedWidth", "(", "w", "/", "5", ")", "self", ".", "width_size_seter_label", ".", "setFixedWidth", "(", "w", "/", "10", ")", "self", ".", "height_size_seter_label", ".", "setFixedWidth", "(", "w", "/", "10", ")", "self", ".", "width_size_seter", ".", "setMinimumWidth", "(", "w", "/", "20", ")", "self", ".", "height_size_seter", ".", "setMinimumWidth", "(", "w", "/", "20", ")", "self", ".", "Right_size_seter_label", ".", "setFixedWidth", "(", "w", "/", "10", ")", "self", ".", "Left_size_seter_label", ".", "setFixedWidth", "(", "w", "/", "10", ")", "self", ".", "Up_size_seter_label", ".", "setFixedWidth", "(", "w", "/", "10", ")", "self", ".", "Down_size_seter_label", ".", "setFixedWidth", "(", "w", "/", "10", ")", "self", ".", "Right_size_seter", ".", "setFixedWidth", "(", "w", "/", "20", ")", "self", ".", "Left_size_seter", ".", "setFixedWidth", "(", "w", "/", "20", ")", "self", ".", "Up_size_seter", ".", "setFixedWidth", "(", "w", "/", "20", ")", "self", ".", "Down_size_seter", ".", "setFixedWidth", "(", "w", "/", "20", ")" ]
self.save_plot_button.setFixedWidth(w/10) self.stat_button.setFixedWidth(w/10) self.load_data_button.setFixedWidth(w/4) self.save_predict_button_selected.setFixedWidth(w/4) self.save_predict_button.setFixedWidth(w/4)
[ "self", ".", "save_plot_button", ".", "setFixedWidth", "(", "w", "/", "10", ")", "self", ".", "stat_button", ".", "setFixedWidth", "(", "w", "/", "10", ")", "self", ".", "load_data_button", ".", "setFixedWidth", "(", "w", "/", "4", ")", "self", ".", "save_predict_button_selected", ".", "setFixedWidth", "(", "w", "/", "4", ")", "self", ".", "save_predict_button", ".", "setFixedWidth", "(", "w", "/", "4", ")" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/XY.py#L176-L498
GeoPyTool/GeoPyTool
geopytool/QAPF.py
QAPF.create_main_frame
def create_main_frame(self): self.resize(800, 1000) self.main_frame = QWidget() self.dpi = 128 self.fig = Figure((12, 11), dpi=self.dpi) self.fig.subplots_adjust(hspace=0.5, wspace=0.5, left=0.1, bottom=0.2, right=0.7, top=0.9) # 8 * np.sqrt(3) self.canvas = FigureCanvas(self.fig) self.canvas.setParent(self.main_frame) self.axes = self.fig.add_subplot(111) self.axes.axis('off') self.axes.set_xlim(-10, 110) self.axes.set_ylim(-105 * np.sqrt(3) / 2, 105 * np.sqrt(3) / 2) self.canvas = FigureCanvas(self.fig) self.canvas.setParent(self.main_frame) self.axes = self.fig.add_subplot(111) # Create the navigation toolbar, tied to the canvas self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame) # Other GUI controls self.save_button = QPushButton('&Save') self.save_button.clicked.connect(self.saveImgFile) #self.result_button = QPushButton('&Result') #self.result_button.clicked.connect(self.Explain) self.legend_cb = QCheckBox('&Legend') self.legend_cb.setChecked(True) self.legend_cb.stateChanged.connect(self.QAPF) # int self.slider_left_label = QLabel('Plutonic') self.slider_right_label = QLabel('Volcanic') self.slider = QSlider(Qt.Horizontal) self.slider.setRange(0, 1) self.slider.setValue(0) self.slider.setTracking(True) self.slider.setTickPosition(QSlider.TicksBothSides) self.slider.valueChanged.connect(self.QAPF) # int ''' self.Tag_cb = QCheckBox('&Plutonic') self.Tag_cb.setChecked(True) self.Tag_cb.stateChanged.connect(self.QAPF) # int if (self.Tag_cb.isChecked()): self.Tag_cb.setText('&Plutonic') else: self.Tag_cb.setText('&Volcanic') ''' self.detail_cb = QCheckBox('&Detail') self.detail_cb.setChecked(True) self.detail_cb.stateChanged.connect(self.QAPF) # int # # Layout with box sizers # self.hbox = QHBoxLayout() for w in [self.save_button, self.detail_cb, self.legend_cb,self.slider_left_label,self.slider,self.slider_right_label]: self.hbox.addWidget(w) self.hbox.setAlignment(w, Qt.AlignVCenter) self.vbox = QVBoxLayout() self.vbox.addWidget(self.mpl_toolbar) self.vbox.addWidget(self.canvas) self.vbox.addLayout(self.hbox) self.textbox = GrowingTextEdit(self) self.vbox.addWidget(self.textbox) self.main_frame.setLayout(self.vbox) self.setCentralWidget(self.main_frame) w=self.width() h=self.height() #setFixedWidth(w/10) self.slider.setMinimumWidth(w/10) self.slider_left_label.setMinimumWidth(w/10) self.slider_right_label.setMinimumWidth(w/10)
python
def create_main_frame(self): self.resize(800, 1000) self.main_frame = QWidget() self.dpi = 128 self.fig = Figure((12, 11), dpi=self.dpi) self.fig.subplots_adjust(hspace=0.5, wspace=0.5, left=0.1, bottom=0.2, right=0.7, top=0.9) self.canvas = FigureCanvas(self.fig) self.canvas.setParent(self.main_frame) self.axes = self.fig.add_subplot(111) self.axes.axis('off') self.axes.set_xlim(-10, 110) self.axes.set_ylim(-105 * np.sqrt(3) / 2, 105 * np.sqrt(3) / 2) self.canvas = FigureCanvas(self.fig) self.canvas.setParent(self.main_frame) self.axes = self.fig.add_subplot(111) self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame) self.save_button = QPushButton('&Save') self.save_button.clicked.connect(self.saveImgFile) self.legend_cb = QCheckBox('&Legend') self.legend_cb.setChecked(True) self.legend_cb.stateChanged.connect(self.QAPF) self.slider_left_label = QLabel('Plutonic') self.slider_right_label = QLabel('Volcanic') self.slider = QSlider(Qt.Horizontal) self.slider.setRange(0, 1) self.slider.setValue(0) self.slider.setTracking(True) self.slider.setTickPosition(QSlider.TicksBothSides) self.slider.valueChanged.connect(self.QAPF) self.detail_cb = QCheckBox('&Detail') self.detail_cb.setChecked(True) self.detail_cb.stateChanged.connect(self.QAPF) self.hbox = QHBoxLayout() for w in [self.save_button, self.detail_cb, self.legend_cb,self.slider_left_label,self.slider,self.slider_right_label]: self.hbox.addWidget(w) self.hbox.setAlignment(w, Qt.AlignVCenter) self.vbox = QVBoxLayout() self.vbox.addWidget(self.mpl_toolbar) self.vbox.addWidget(self.canvas) self.vbox.addLayout(self.hbox) self.textbox = GrowingTextEdit(self) self.vbox.addWidget(self.textbox) self.main_frame.setLayout(self.vbox) self.setCentralWidget(self.main_frame) w=self.width() h=self.height() self.slider.setMinimumWidth(w/10) self.slider_left_label.setMinimumWidth(w/10) self.slider_right_label.setMinimumWidth(w/10)
[ "def", "create_main_frame", "(", "self", ")", ":", "self", ".", "resize", "(", "800", ",", "1000", ")", "self", ".", "main_frame", "=", "QWidget", "(", ")", "self", ".", "dpi", "=", "128", "self", ".", "fig", "=", "Figure", "(", "(", "12", ",", "11", ")", ",", "dpi", "=", "self", ".", "dpi", ")", "self", ".", "fig", ".", "subplots_adjust", "(", "hspace", "=", "0.5", ",", "wspace", "=", "0.5", ",", "left", "=", "0.1", ",", "bottom", "=", "0.2", ",", "right", "=", "0.7", ",", "top", "=", "0.9", ")", "# 8 * np.sqrt(3)", "self", ".", "canvas", "=", "FigureCanvas", "(", "self", ".", "fig", ")", "self", ".", "canvas", ".", "setParent", "(", "self", ".", "main_frame", ")", "self", ".", "axes", "=", "self", ".", "fig", ".", "add_subplot", "(", "111", ")", "self", ".", "axes", ".", "axis", "(", "'off'", ")", "self", ".", "axes", ".", "set_xlim", "(", "-", "10", ",", "110", ")", "self", ".", "axes", ".", "set_ylim", "(", "-", "105", "*", "np", ".", "sqrt", "(", "3", ")", "/", "2", ",", "105", "*", "np", ".", "sqrt", "(", "3", ")", "/", "2", ")", "self", ".", "canvas", "=", "FigureCanvas", "(", "self", ".", "fig", ")", "self", ".", "canvas", ".", "setParent", "(", "self", ".", "main_frame", ")", "self", ".", "axes", "=", "self", ".", "fig", ".", "add_subplot", "(", "111", ")", "# Create the navigation toolbar, tied to the canvas", "self", ".", "mpl_toolbar", "=", "NavigationToolbar", "(", "self", ".", "canvas", ",", "self", ".", "main_frame", ")", "# Other GUI controls", "self", ".", "save_button", "=", "QPushButton", "(", "'&Save'", ")", "self", ".", "save_button", ".", "clicked", ".", "connect", "(", "self", ".", "saveImgFile", ")", "#self.result_button = QPushButton('&Result')", "#self.result_button.clicked.connect(self.Explain)", "self", ".", "legend_cb", "=", "QCheckBox", "(", "'&Legend'", ")", "self", ".", "legend_cb", ".", "setChecked", "(", "True", ")", "self", ".", "legend_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "QAPF", ")", "# int", "self", ".", "slider_left_label", "=", "QLabel", "(", "'Plutonic'", ")", "self", ".", "slider_right_label", "=", "QLabel", "(", "'Volcanic'", ")", "self", ".", "slider", "=", "QSlider", "(", "Qt", ".", "Horizontal", ")", "self", ".", "slider", ".", "setRange", "(", "0", ",", "1", ")", "self", ".", "slider", ".", "setValue", "(", "0", ")", "self", ".", "slider", ".", "setTracking", "(", "True", ")", "self", ".", "slider", ".", "setTickPosition", "(", "QSlider", ".", "TicksBothSides", ")", "self", ".", "slider", ".", "valueChanged", ".", "connect", "(", "self", ".", "QAPF", ")", "# int", "self", ".", "detail_cb", "=", "QCheckBox", "(", "'&Detail'", ")", "self", ".", "detail_cb", ".", "setChecked", "(", "True", ")", "self", ".", "detail_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "QAPF", ")", "# int", "#", "# Layout with box sizers", "#", "self", ".", "hbox", "=", "QHBoxLayout", "(", ")", "for", "w", "in", "[", "self", ".", "save_button", ",", "self", ".", "detail_cb", ",", "self", ".", "legend_cb", ",", "self", ".", "slider_left_label", ",", "self", ".", "slider", ",", "self", ".", "slider_right_label", "]", ":", "self", ".", "hbox", ".", "addWidget", "(", "w", ")", "self", ".", "hbox", ".", "setAlignment", "(", "w", ",", "Qt", ".", "AlignVCenter", ")", "self", ".", "vbox", "=", "QVBoxLayout", "(", ")", "self", ".", "vbox", ".", "addWidget", "(", "self", ".", "mpl_toolbar", ")", "self", ".", "vbox", ".", "addWidget", "(", "self", ".", "canvas", ")", "self", ".", "vbox", ".", "addLayout", "(", "self", ".", "hbox", ")", "self", ".", "textbox", "=", "GrowingTextEdit", "(", "self", ")", "self", ".", "vbox", ".", "addWidget", "(", "self", ".", "textbox", ")", "self", ".", "main_frame", ".", "setLayout", "(", "self", ".", "vbox", ")", "self", ".", "setCentralWidget", "(", "self", ".", "main_frame", ")", "w", "=", "self", ".", "width", "(", ")", "h", "=", "self", ".", "height", "(", ")", "#setFixedWidth(w/10)", "self", ".", "slider", ".", "setMinimumWidth", "(", "w", "/", "10", ")", "self", ".", "slider_left_label", ".", "setMinimumWidth", "(", "w", "/", "10", ")", "self", ".", "slider_right_label", ".", "setMinimumWidth", "(", "w", "/", "10", ")" ]
self.Tag_cb = QCheckBox('&Plutonic') self.Tag_cb.setChecked(True) self.Tag_cb.stateChanged.connect(self.QAPF) # int if (self.Tag_cb.isChecked()): self.Tag_cb.setText('&Plutonic') else: self.Tag_cb.setText('&Volcanic')
[ "self", ".", "Tag_cb", "=", "QCheckBox", "(", "&Plutonic", ")", "self", ".", "Tag_cb", ".", "setChecked", "(", "True", ")", "self", ".", "Tag_cb", ".", "stateChanged", ".", "connect", "(", "self", ".", "QAPF", ")", "#", "int", "if", "(", "self", ".", "Tag_cb", ".", "isChecked", "()", ")", ":", "self", ".", "Tag_cb", ".", "setText", "(", "&Plutonic", ")", "else", ":", "self", ".", "Tag_cb", ".", "setText", "(", "&Volcanic", ")" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/QAPF.py#L211-L303
GeoPyTool/GeoPyTool
geopytool/CustomClass.py
Tool.TriToBin
def TriToBin(self, x, y, z): ''' Turn an x-y-z triangular coord to an a-b coord. if z is negative, calc with its abs then return (a, -b). :param x,y,z: the three numbers of the triangular coord :type x,y,z: float or double are both OK, just numbers :return: the corresponding a-b coord :rtype: a tuple consist of a and b ''' if (z >= 0): if (x + y + z == 0): return (0, 0) else: Sum = x + y + z X = 100.0 * x / Sum Y = 100.0 * y / Sum Z = 100.0 * z / Sum if (X + Y != 0): a = Z / 2.0 + (100.0 - Z) * Y / (Y + X) else: a = Z / 2.0 b = Z / 2.0 * (np.sqrt(3)) return (a, b) else: z = abs(z) if (x + y + z == 0): return (0, 0) else: Sum = x + y + z X = 100.0 * x / Sum Y = 100.0 * y / Sum Z = 100.0 * z / Sum if (X + Y != 0): a = Z / 2.0 + (100.0 - Z) * Y / (Y + X) else: a = Z / 2.0 b = Z / 2.0 * (np.sqrt(3)) return (a, -b)
python
def TriToBin(self, x, y, z): if (z >= 0): if (x + y + z == 0): return (0, 0) else: Sum = x + y + z X = 100.0 * x / Sum Y = 100.0 * y / Sum Z = 100.0 * z / Sum if (X + Y != 0): a = Z / 2.0 + (100.0 - Z) * Y / (Y + X) else: a = Z / 2.0 b = Z / 2.0 * (np.sqrt(3)) return (a, b) else: z = abs(z) if (x + y + z == 0): return (0, 0) else: Sum = x + y + z X = 100.0 * x / Sum Y = 100.0 * y / Sum Z = 100.0 * z / Sum if (X + Y != 0): a = Z / 2.0 + (100.0 - Z) * Y / (Y + X) else: a = Z / 2.0 b = Z / 2.0 * (np.sqrt(3)) return (a, -b)
[ "def", "TriToBin", "(", "self", ",", "x", ",", "y", ",", "z", ")", ":", "if", "(", "z", ">=", "0", ")", ":", "if", "(", "x", "+", "y", "+", "z", "==", "0", ")", ":", "return", "(", "0", ",", "0", ")", "else", ":", "Sum", "=", "x", "+", "y", "+", "z", "X", "=", "100.0", "*", "x", "/", "Sum", "Y", "=", "100.0", "*", "y", "/", "Sum", "Z", "=", "100.0", "*", "z", "/", "Sum", "if", "(", "X", "+", "Y", "!=", "0", ")", ":", "a", "=", "Z", "/", "2.0", "+", "(", "100.0", "-", "Z", ")", "*", "Y", "/", "(", "Y", "+", "X", ")", "else", ":", "a", "=", "Z", "/", "2.0", "b", "=", "Z", "/", "2.0", "*", "(", "np", ".", "sqrt", "(", "3", ")", ")", "return", "(", "a", ",", "b", ")", "else", ":", "z", "=", "abs", "(", "z", ")", "if", "(", "x", "+", "y", "+", "z", "==", "0", ")", ":", "return", "(", "0", ",", "0", ")", "else", ":", "Sum", "=", "x", "+", "y", "+", "z", "X", "=", "100.0", "*", "x", "/", "Sum", "Y", "=", "100.0", "*", "y", "/", "Sum", "Z", "=", "100.0", "*", "z", "/", "Sum", "if", "(", "X", "+", "Y", "!=", "0", ")", ":", "a", "=", "Z", "/", "2.0", "+", "(", "100.0", "-", "Z", ")", "*", "Y", "/", "(", "Y", "+", "X", ")", "else", ":", "a", "=", "Z", "/", "2.0", "b", "=", "Z", "/", "2.0", "*", "(", "np", ".", "sqrt", "(", "3", ")", ")", "return", "(", "a", ",", "-", "b", ")" ]
Turn an x-y-z triangular coord to an a-b coord. if z is negative, calc with its abs then return (a, -b). :param x,y,z: the three numbers of the triangular coord :type x,y,z: float or double are both OK, just numbers :return: the corresponding a-b coord :rtype: a tuple consist of a and b
[ "Turn", "an", "x", "-", "y", "-", "z", "triangular", "coord", "to", "an", "a", "-", "b", "coord", ".", "if", "z", "is", "negative", "calc", "with", "its", "abs", "then", "return", "(", "a", "-", "b", ")", ".", ":", "param", "x", "y", "z", ":", "the", "three", "numbers", "of", "the", "triangular", "coord", ":", "type", "x", "y", "z", ":", "float", "or", "double", "are", "both", "OK", "just", "numbers", ":", "return", ":", "the", "corresponding", "a", "-", "b", "coord", ":", "rtype", ":", "a", "tuple", "consist", "of", "a", "and", "b" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/CustomClass.py#L28-L67
GeoPyTool/GeoPyTool
geopytool/CustomClass.py
Tool.BinToTri
def BinToTri(self, a, b): ''' Turn an a-b coord to an x-y-z triangular coord . if z is negative, calc with its abs then return (a, -b). :param a,b: the numbers of the a-b coord :type a,b: float or double are both OK, just numbers :return: the corresponding x-y-z triangular coord :rtype: a tuple consist of x,y,z ''' if (b >= 0): y = a - b / np.sqrt(3) z = b * 2 / np.sqrt(3) x = 100 - (a + b / np.sqrt(3)) return (x, y, z) else: y = a + b / np.sqrt(3) z = b * 2 / np.sqrt(3) x = 100 - (a - b / np.sqrt(3)) return (x, y, z)
python
def BinToTri(self, a, b): if (b >= 0): y = a - b / np.sqrt(3) z = b * 2 / np.sqrt(3) x = 100 - (a + b / np.sqrt(3)) return (x, y, z) else: y = a + b / np.sqrt(3) z = b * 2 / np.sqrt(3) x = 100 - (a - b / np.sqrt(3)) return (x, y, z)
[ "def", "BinToTri", "(", "self", ",", "a", ",", "b", ")", ":", "if", "(", "b", ">=", "0", ")", ":", "y", "=", "a", "-", "b", "/", "np", ".", "sqrt", "(", "3", ")", "z", "=", "b", "*", "2", "/", "np", ".", "sqrt", "(", "3", ")", "x", "=", "100", "-", "(", "a", "+", "b", "/", "np", ".", "sqrt", "(", "3", ")", ")", "return", "(", "x", ",", "y", ",", "z", ")", "else", ":", "y", "=", "a", "+", "b", "/", "np", ".", "sqrt", "(", "3", ")", "z", "=", "b", "*", "2", "/", "np", ".", "sqrt", "(", "3", ")", "x", "=", "100", "-", "(", "a", "-", "b", "/", "np", ".", "sqrt", "(", "3", ")", ")", "return", "(", "x", ",", "y", ",", "z", ")" ]
Turn an a-b coord to an x-y-z triangular coord . if z is negative, calc with its abs then return (a, -b). :param a,b: the numbers of the a-b coord :type a,b: float or double are both OK, just numbers :return: the corresponding x-y-z triangular coord :rtype: a tuple consist of x,y,z
[ "Turn", "an", "a", "-", "b", "coord", "to", "an", "x", "-", "y", "-", "z", "triangular", "coord", ".", "if", "z", "is", "negative", "calc", "with", "its", "abs", "then", "return", "(", "a", "-", "b", ")", ".", ":", "param", "a", "b", ":", "the", "numbers", "of", "the", "a", "-", "b", "coord", ":", "type", "a", "b", ":", "float", "or", "double", "are", "both", "OK", "just", "numbers", ":", "return", ":", "the", "corresponding", "x", "-", "y", "-", "z", "triangular", "coord", ":", "rtype", ":", "a", "tuple", "consist", "of", "x", "y", "z" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/CustomClass.py#L69-L89
GeoPyTool/GeoPyTool
geopytool/CustomClass.py
Tool.Cross
def Cross(self, A=[(0, 0), (10, 10)], B=[(0, 10), (100, 0)]): ''' Return the crosspoint of two line A and B. :param A: first line :type A: a list consist of two tuples, beginning and end point of the line :param B: second line :type B: a list consist of two tuples, beginning and end point of the line :return: the crosspoint of A and B :rtype: a list consist of two numbers, the x-y of the crosspoint ''' x0, y0 = A[0] x1, y1 = A[1] x2, y2 = B[0] x3, y3 = B[1] b1 = (y1 - y0) / (x1 - x0) b2 = (y3 - y2) / (x3 - x2) c1 = y0 - b1 * x0 c2 = y2 - b2 * x2 x = (c2 - c1) / (b1 - b2) y = b1 * x + c1 return ([x, y])
python
def Cross(self, A=[(0, 0), (10, 10)], B=[(0, 10), (100, 0)]): x0, y0 = A[0] x1, y1 = A[1] x2, y2 = B[0] x3, y3 = B[1] b1 = (y1 - y0) / (x1 - x0) b2 = (y3 - y2) / (x3 - x2) c1 = y0 - b1 * x0 c2 = y2 - b2 * x2 x = (c2 - c1) / (b1 - b2) y = b1 * x + c1 return ([x, y])
[ "def", "Cross", "(", "self", ",", "A", "=", "[", "(", "0", ",", "0", ")", ",", "(", "10", ",", "10", ")", "]", ",", "B", "=", "[", "(", "0", ",", "10", ")", ",", "(", "100", ",", "0", ")", "]", ")", ":", "x0", ",", "y0", "=", "A", "[", "0", "]", "x1", ",", "y1", "=", "A", "[", "1", "]", "x2", ",", "y2", "=", "B", "[", "0", "]", "x3", ",", "y3", "=", "B", "[", "1", "]", "b1", "=", "(", "y1", "-", "y0", ")", "/", "(", "x1", "-", "x0", ")", "b2", "=", "(", "y3", "-", "y2", ")", "/", "(", "x3", "-", "x2", ")", "c1", "=", "y0", "-", "b1", "*", "x0", "c2", "=", "y2", "-", "b2", "*", "x2", "x", "=", "(", "c2", "-", "c1", ")", "/", "(", "b1", "-", "b2", ")", "y", "=", "b1", "*", "x", "+", "c1", "return", "(", "[", "x", ",", "y", "]", ")" ]
Return the crosspoint of two line A and B. :param A: first line :type A: a list consist of two tuples, beginning and end point of the line :param B: second line :type B: a list consist of two tuples, beginning and end point of the line :return: the crosspoint of A and B :rtype: a list consist of two numbers, the x-y of the crosspoint
[ "Return", "the", "crosspoint", "of", "two", "line", "A", "and", "B", ".", ":", "param", "A", ":", "first", "line", ":", "type", "A", ":", "a", "list", "consist", "of", "two", "tuples", "beginning", "and", "end", "point", "of", "the", "line", ":", "param", "B", ":", "second", "line", ":", "type", "B", ":", "a", "list", "consist", "of", "two", "tuples", "beginning", "and", "end", "point", "of", "the", "line", ":", "return", ":", "the", "crosspoint", "of", "A", "and", "B", ":", "rtype", ":", "a", "list", "consist", "of", "two", "numbers", "the", "x", "-", "y", "of", "the", "crosspoint" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/CustomClass.py#L91-L116
GeoPyTool/GeoPyTool
geopytool/CustomClass.py
Tool.TriCross
def TriCross(self, A=[(100, 0, 0), (0, 50, 60)], B=[(50, 50, 0), (0, 0, 100)]): ''' Return the crosspoint of two line A and B in triangular coord. :param A: first line :type A: a list consist of two tuples, beginning and end point of the line :param B: second line :type B: a list consist of two tuples, beginning and end point of the line :return: the crosspoint of A and B :rtype: a list consist of three numbers, the x-y-z of the triangular coord ''' x0, y0 = self.TriToBin(A[0][0], A[0][1], A[0][2]) x1, y1 = self.TriToBin(A[1][0], A[1][1], A[1][2]) x2, y2 = self.TriToBin(B[0][0], B[0][1], B[0][2]) x3, y3 = self.TriToBin(B[1][0], B[1][1], B[1][2]) b1 = (y1 - y0) / (x1 - x0) b2 = (y3 - y2) / (x3 - x2) c1 = y0 - b1 * x0 c2 = y2 - b2 * x2 x = (c2 - c1) / (b1 - b2) y = b1 * x + c1 result = self.BinToTri(x, y) return (result)
python
def TriCross(self, A=[(100, 0, 0), (0, 50, 60)], B=[(50, 50, 0), (0, 0, 100)]): x0, y0 = self.TriToBin(A[0][0], A[0][1], A[0][2]) x1, y1 = self.TriToBin(A[1][0], A[1][1], A[1][2]) x2, y2 = self.TriToBin(B[0][0], B[0][1], B[0][2]) x3, y3 = self.TriToBin(B[1][0], B[1][1], B[1][2]) b1 = (y1 - y0) / (x1 - x0) b2 = (y3 - y2) / (x3 - x2) c1 = y0 - b1 * x0 c2 = y2 - b2 * x2 x = (c2 - c1) / (b1 - b2) y = b1 * x + c1 result = self.BinToTri(x, y) return (result)
[ "def", "TriCross", "(", "self", ",", "A", "=", "[", "(", "100", ",", "0", ",", "0", ")", ",", "(", "0", ",", "50", ",", "60", ")", "]", ",", "B", "=", "[", "(", "50", ",", "50", ",", "0", ")", ",", "(", "0", ",", "0", ",", "100", ")", "]", ")", ":", "x0", ",", "y0", "=", "self", ".", "TriToBin", "(", "A", "[", "0", "]", "[", "0", "]", ",", "A", "[", "0", "]", "[", "1", "]", ",", "A", "[", "0", "]", "[", "2", "]", ")", "x1", ",", "y1", "=", "self", ".", "TriToBin", "(", "A", "[", "1", "]", "[", "0", "]", ",", "A", "[", "1", "]", "[", "1", "]", ",", "A", "[", "1", "]", "[", "2", "]", ")", "x2", ",", "y2", "=", "self", ".", "TriToBin", "(", "B", "[", "0", "]", "[", "0", "]", ",", "B", "[", "0", "]", "[", "1", "]", ",", "B", "[", "0", "]", "[", "2", "]", ")", "x3", ",", "y3", "=", "self", ".", "TriToBin", "(", "B", "[", "1", "]", "[", "0", "]", ",", "B", "[", "1", "]", "[", "1", "]", ",", "B", "[", "1", "]", "[", "2", "]", ")", "b1", "=", "(", "y1", "-", "y0", ")", "/", "(", "x1", "-", "x0", ")", "b2", "=", "(", "y3", "-", "y2", ")", "/", "(", "x3", "-", "x2", ")", "c1", "=", "y0", "-", "b1", "*", "x0", "c2", "=", "y2", "-", "b2", "*", "x2", "x", "=", "(", "c2", "-", "c1", ")", "/", "(", "b1", "-", "b2", ")", "y", "=", "b1", "*", "x", "+", "c1", "result", "=", "self", ".", "BinToTri", "(", "x", ",", "y", ")", "return", "(", "result", ")" ]
Return the crosspoint of two line A and B in triangular coord. :param A: first line :type A: a list consist of two tuples, beginning and end point of the line :param B: second line :type B: a list consist of two tuples, beginning and end point of the line :return: the crosspoint of A and B :rtype: a list consist of three numbers, the x-y-z of the triangular coord
[ "Return", "the", "crosspoint", "of", "two", "line", "A", "and", "B", "in", "triangular", "coord", ".", ":", "param", "A", ":", "first", "line", ":", "type", "A", ":", "a", "list", "consist", "of", "two", "tuples", "beginning", "and", "end", "point", "of", "the", "line", ":", "param", "B", ":", "second", "line", ":", "type", "B", ":", "a", "list", "consist", "of", "two", "tuples", "beginning", "and", "end", "point", "of", "the", "line", ":", "return", ":", "the", "crosspoint", "of", "A", "and", "B", ":", "rtype", ":", "a", "list", "consist", "of", "three", "numbers", "the", "x", "-", "y", "-", "z", "of", "the", "triangular", "coord" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/CustomClass.py#L118-L144
GeoPyTool/GeoPyTool
geopytool/CustomClass.py
Tool.Fill
def Fill(self, P=[(100, 0), (85, 15), (0, 3)], Color='blue', Alpha=0.3): ''' Fill a region in planimetric rectangular coord. :param P: the peak points of the region in planimetric rectangular coord :type P: a list consist of at least three tuples, which are the points in planimetric rectangular coord :param Color: the color used to fill the region :type Color: a string; b: blue, g: green, r: red, c: cyan, m: magenta, y: yellow, k: black, w: white :param Alpha: the transparency used to fill the region :type Alpha: a float number from 0 to 1, higher darker, lower more transparent ''' a = [] b = [] for i in P: a.append(i[0]) b.append(i[1]) return (a, b)
python
def Fill(self, P=[(100, 0), (85, 15), (0, 3)], Color='blue', Alpha=0.3): a = [] b = [] for i in P: a.append(i[0]) b.append(i[1]) return (a, b)
[ "def", "Fill", "(", "self", ",", "P", "=", "[", "(", "100", ",", "0", ")", ",", "(", "85", ",", "15", ")", ",", "(", "0", ",", "3", ")", "]", ",", "Color", "=", "'blue'", ",", "Alpha", "=", "0.3", ")", ":", "a", "=", "[", "]", "b", "=", "[", "]", "for", "i", "in", "P", ":", "a", ".", "append", "(", "i", "[", "0", "]", ")", "b", ".", "append", "(", "i", "[", "1", "]", ")", "return", "(", "a", ",", "b", ")" ]
Fill a region in planimetric rectangular coord. :param P: the peak points of the region in planimetric rectangular coord :type P: a list consist of at least three tuples, which are the points in planimetric rectangular coord :param Color: the color used to fill the region :type Color: a string; b: blue, g: green, r: red, c: cyan, m: magenta, y: yellow, k: black, w: white :param Alpha: the transparency used to fill the region :type Alpha: a float number from 0 to 1, higher darker, lower more transparent
[ "Fill", "a", "region", "in", "planimetric", "rectangular", "coord", ".", ":", "param", "P", ":", "the", "peak", "points", "of", "the", "region", "in", "planimetric", "rectangular", "coord", ":", "type", "P", ":", "a", "list", "consist", "of", "at", "least", "three", "tuples", "which", "are", "the", "points", "in", "planimetric", "rectangular", "coord", ":", "param", "Color", ":", "the", "color", "used", "to", "fill", "the", "region", ":", "type", "Color", ":", "a", "string", ";", "b", ":", "blue", "g", ":", "green", "r", ":", "red", "c", ":", "cyan", "m", ":", "magenta", "y", ":", "yellow", "k", ":", "black", "w", ":", "white", ":", "param", "Alpha", ":", "the", "transparency", "used", "to", "fill", "the", "region", ":", "type", "Alpha", ":", "a", "float", "number", "from", "0", "to", "1", "higher", "darker", "lower", "more", "transparent" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/CustomClass.py#L146-L164
GeoPyTool/GeoPyTool
geopytool/CustomClass.py
Tool.TriFill
def TriFill(self, P=[(100, 0, 0), (85, 15, 0), (0, 3, 97)], Color='blue', Alpha=0.3): ''' Fill a region in triangular coord. :param P: the peak points of the region in triangular coord :type P: a list consist of at least three tuples, which are the points in triangular coord :param Color: the color used to fill the region :type Color: a string; b: blue, g: green, r: red, c: cyan, m: magenta, y: yellow, k: black, w: white :param Alpha: the transparency used to fill the region :type Alpha: a float number from 0 to 1, higher darker, lower more transparent ''' a = [] b = [] for i in P: a.append(self.TriToBin(i[0], i[1], i[2])[0]) b.append(self.TriToBin(i[0], i[1], i[2])[1]) return (a, b)
python
def TriFill(self, P=[(100, 0, 0), (85, 15, 0), (0, 3, 97)], Color='blue', Alpha=0.3): a = [] b = [] for i in P: a.append(self.TriToBin(i[0], i[1], i[2])[0]) b.append(self.TriToBin(i[0], i[1], i[2])[1]) return (a, b)
[ "def", "TriFill", "(", "self", ",", "P", "=", "[", "(", "100", ",", "0", ",", "0", ")", ",", "(", "85", ",", "15", ",", "0", ")", ",", "(", "0", ",", "3", ",", "97", ")", "]", ",", "Color", "=", "'blue'", ",", "Alpha", "=", "0.3", ")", ":", "a", "=", "[", "]", "b", "=", "[", "]", "for", "i", "in", "P", ":", "a", ".", "append", "(", "self", ".", "TriToBin", "(", "i", "[", "0", "]", ",", "i", "[", "1", "]", ",", "i", "[", "2", "]", ")", "[", "0", "]", ")", "b", ".", "append", "(", "self", ".", "TriToBin", "(", "i", "[", "0", "]", ",", "i", "[", "1", "]", ",", "i", "[", "2", "]", ")", "[", "1", "]", ")", "return", "(", "a", ",", "b", ")" ]
Fill a region in triangular coord. :param P: the peak points of the region in triangular coord :type P: a list consist of at least three tuples, which are the points in triangular coord :param Color: the color used to fill the region :type Color: a string; b: blue, g: green, r: red, c: cyan, m: magenta, y: yellow, k: black, w: white :param Alpha: the transparency used to fill the region :type Alpha: a float number from 0 to 1, higher darker, lower more transparent
[ "Fill", "a", "region", "in", "triangular", "coord", ".", ":", "param", "P", ":", "the", "peak", "points", "of", "the", "region", "in", "triangular", "coord", ":", "type", "P", ":", "a", "list", "consist", "of", "at", "least", "three", "tuples", "which", "are", "the", "points", "in", "triangular", "coord", ":", "param", "Color", ":", "the", "color", "used", "to", "fill", "the", "region", ":", "type", "Color", ":", "a", "string", ";", "b", ":", "blue", "g", ":", "green", "r", ":", "red", "c", ":", "cyan", "m", ":", "magenta", "y", ":", "yellow", "k", ":", "black", "w", ":", "white", ":", "param", "Alpha", ":", "the", "transparency", "used", "to", "fill", "the", "region", ":", "type", "Alpha", ":", "a", "float", "number", "from", "0", "to", "1", "higher", "darker", "lower", "more", "transparent" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/CustomClass.py#L166-L185
GeoPyTool/GeoPyTool
geopytool/CustomClass.py
Line.sequence
def sequence(self): ''' sort the points in the line with given option ''' if (len(self.Points[0]) == 2): if (self.Sort == 'X' or self.Sort == 'x'): self.Points.sort(key=lambda x: x[0]) self.order(self.Points) elif (self.Sort == 'Y' or self.Sort == 'y'): self.Points.sort(key=lambda x: x[1]) self.order(self.Points) else: self.order(self.Points) if (len(self.Points[0]) == 3): if (self.Sort == 'X' or self.Sort == 'x'): self.Points.sort(key=lambda x: x[0]) self.order(self.Points) elif (self.Sort == 'Y' or self.Sort == 'y'): self.Points.sort(key=lambda x: x[1]) self.order(self.Points) elif (self.Sort == 'Z' or self.Sort == 'Z'): self.Points.sort(key=lambda x: x[2]) self.order(self.Points) else: self.order(self.Points)
python
def sequence(self): if (len(self.Points[0]) == 2): if (self.Sort == 'X' or self.Sort == 'x'): self.Points.sort(key=lambda x: x[0]) self.order(self.Points) elif (self.Sort == 'Y' or self.Sort == 'y'): self.Points.sort(key=lambda x: x[1]) self.order(self.Points) else: self.order(self.Points) if (len(self.Points[0]) == 3): if (self.Sort == 'X' or self.Sort == 'x'): self.Points.sort(key=lambda x: x[0]) self.order(self.Points) elif (self.Sort == 'Y' or self.Sort == 'y'): self.Points.sort(key=lambda x: x[1]) self.order(self.Points) elif (self.Sort == 'Z' or self.Sort == 'Z'): self.Points.sort(key=lambda x: x[2]) self.order(self.Points) else: self.order(self.Points)
[ "def", "sequence", "(", "self", ")", ":", "if", "(", "len", "(", "self", ".", "Points", "[", "0", "]", ")", "==", "2", ")", ":", "if", "(", "self", ".", "Sort", "==", "'X'", "or", "self", ".", "Sort", "==", "'x'", ")", ":", "self", ".", "Points", ".", "sort", "(", "key", "=", "lambda", "x", ":", "x", "[", "0", "]", ")", "self", ".", "order", "(", "self", ".", "Points", ")", "elif", "(", "self", ".", "Sort", "==", "'Y'", "or", "self", ".", "Sort", "==", "'y'", ")", ":", "self", ".", "Points", ".", "sort", "(", "key", "=", "lambda", "x", ":", "x", "[", "1", "]", ")", "self", ".", "order", "(", "self", ".", "Points", ")", "else", ":", "self", ".", "order", "(", "self", ".", "Points", ")", "if", "(", "len", "(", "self", ".", "Points", "[", "0", "]", ")", "==", "3", ")", ":", "if", "(", "self", ".", "Sort", "==", "'X'", "or", "self", ".", "Sort", "==", "'x'", ")", ":", "self", ".", "Points", ".", "sort", "(", "key", "=", "lambda", "x", ":", "x", "[", "0", "]", ")", "self", ".", "order", "(", "self", ".", "Points", ")", "elif", "(", "self", ".", "Sort", "==", "'Y'", "or", "self", ".", "Sort", "==", "'y'", ")", ":", "self", ".", "Points", ".", "sort", "(", "key", "=", "lambda", "x", ":", "x", "[", "1", "]", ")", "self", ".", "order", "(", "self", ".", "Points", ")", "elif", "(", "self", ".", "Sort", "==", "'Z'", "or", "self", ".", "Sort", "==", "'Z'", ")", ":", "self", ".", "Points", ".", "sort", "(", "key", "=", "lambda", "x", ":", "x", "[", "2", "]", ")", "self", ".", "order", "(", "self", ".", "Points", ")", "else", ":", "self", ".", "order", "(", "self", ".", "Points", ")" ]
sort the points in the line with given option
[ "sort", "the", "points", "in", "the", "line", "with", "given", "option" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/CustomClass.py#L367-L394
GeoPyTool/GeoPyTool
geopytool/CustomClass.py
TableViewer.resizeEvent
def resizeEvent(self, evt=None): w = self.width() h = self.height() ''' if h<=360: h=360 self.resize(w,h) if w<=640: w = 640 self.resize(w, h) ''' step = (w * 94 / 100) / 5 foot = h * 3 / 48
python
def resizeEvent(self, evt=None): w = self.width() h = self.height() step = (w * 94 / 100) / 5 foot = h * 3 / 48
[ "def", "resizeEvent", "(", "self", ",", "evt", "=", "None", ")", ":", "w", "=", "self", ".", "width", "(", ")", "h", "=", "self", ".", "height", "(", ")", "step", "=", "(", "w", "*", "94", "/", "100", ")", "/", "5", "foot", "=", "h", "*", "3", "/", "48" ]
if h<=360: h=360 self.resize(w,h) if w<=640: w = 640 self.resize(w, h)
[ "if", "h<", "=", "360", ":", "h", "=", "360", "self", ".", "resize", "(", "w", "h", ")", "if", "w<", "=", "640", ":", "w", "=", "640", "self", ".", "resize", "(", "w", "h", ")" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/CustomClass.py#L813-L827
GeoPyTool/GeoPyTool
geopytool/K2OSiO2.py
K2OSiO2.K2OSiO2
def K2OSiO2(self, Left=35, Right=79, X0=30, X1=90, X_Gap=7, Base=0, Top=19, Y0=1, Y1=19, Y_Gap=19, FontSize=12, xlabel=r'$SiO_2 wt\%$', ylabel=r'$K_2O wt\%$', width=12, height=12, dpi=300): self.setWindowTitle('K2OSiO2 diagram ') self.axes.clear() #self.axes.axis('off') self.axes.set_xlabel(self.xlabel) self.axes.set_ylabel(self.ylabel) self.axes.spines['right'].set_color('none') self.axes.spines['top'].set_color('none') ''' self.axes.set_xticks([30,40,50,60,70,80,90]) self.axes.set_xticklabels([30,40,50,60,70,80,90]) self.axes.set_yticks([0, 5, 10, 15, 20]) self.axes.set_yticklabels([0, 5, 10, 15, 20]) self.axes.set_ylim(bottom=0) ''' all_labels=[] all_colors=[] all_markers=[] all_alpha=[] for i in range(len(self._df)): target = self._df.at[i, 'Label'] color = self._df.at[i, 'Color'] marker = self._df.at[i, 'Marker'] alpha = self._df.at[i, 'Alpha'] if target not in self.SVM_labels: self.SVM_labels.append(target) if target not in all_labels: all_labels.append(target) all_colors.append(color) all_markers.append(marker) all_alpha.append(alpha) self.whole_labels = all_labels PointLabels = [] PointColors = [] x = [] y = [] title = 'K2O-SiO2diagram' self.setWindowTitle(title) self.textbox.setText(self.reference) k_1=(2.9-1.2)/(68-48) y_1= 1.2+ (85-48)*k_1 y_0= 1.2+ (45-48)*k_1 self.DrawLine([(45, y_0),(48, 1.2), (68,2.9),(85,y_1)]) k_2=(1.2-0.3)/(68-48) y_2= 0.3+ (85-48)*k_2 y_3= 0.3+ (45-48)*k_2 self.DrawLine([(45, y_3),(48, 0.3), (68, 1.2),(85,y_2)]) Labels=['High K','Medium K','Low K'] Locations=[(80,5),(80,3),(80,1)] X_offset, Y_offset=0,0 for k in range(len(Labels)): self.axes.annotate(Labels[k], Locations[k], xycoords='data', xytext=(X_offset, Y_offset), textcoords='offset points', fontsize=9, color='grey', alpha=0.8) self.Check() if self.OutPutCheck==True: pass if (self._changed): df = self.CleanDataFile(self._df) for i in range(len(df)): TmpLabel = '' if (df.at[i, 'Label'] in PointLabels or df.at[i, 'Label'] == ''): TmpLabel = '' else: PointLabels.append(df.at[i, 'Label']) TmpLabel = df.at[i, 'Label'] TmpColor = '' if (df.at[i, 'Color'] in PointColors or df.at[i, 'Color'] == ''): TmpColor = '' else: PointColors.append(df.at[i, 'Color']) TmpColor = df.at[i, 'Color'] x.append(df.at[i, 'SiO2']) y.append(df.at[i, 'K2O']) Size = df.at[i, 'Size'] Color = df.at[i, 'Color'] # print(Color, df.at[i, 'SiO2'], (df.at[i, 'Na2O'] + df.at[i, 'K2O'])) Alpha = df.at[i, 'Alpha'] Marker = df.at[i, 'Marker'] Label = df.at[i, 'Label'] xtest=df.at[i, 'SiO2'] ytest=df.at[i, 'K2O'] for j in self.ItemNames: if self.SelectDic[j].contains_point([xtest,ytest]): self.LabelList.append(Label) self.TypeList.append(j) break pass self.axes.scatter(df.at[i, 'SiO2'], df.at[i, 'K2O'], marker=df.at[i, 'Marker'], s=df.at[i, 'Size'], color=df.at[i, 'Color'], alpha=df.at[i, 'Alpha'], label=TmpLabel) XtoFit = {} YtoFit = {} SVM_X=[] SVM_Y=[] for i in PointLabels: XtoFit[i]=[] YtoFit[i]=[] for i in range(len(df)): Alpha = df.at[i, 'Alpha'] Marker = df.at[i, 'Marker'] Label = df.at[i, 'Label'] xtest=df.at[i, 'SiO2'] ytest=df.at[i, 'K2O'] XtoFit[Label].append(xtest) YtoFit[Label].append(ytest) SVM_X.append(xtest) SVM_Y.append(ytest) if (self.shape_cb.isChecked()): for i in PointLabels: if XtoFit[i] != YtoFit[i]: xmin, xmax = min(XtoFit[i]), max(XtoFit[i]) ymin, ymax = min(YtoFit[i]), max(YtoFit[i]) DensityColorMap = 'Greys' DensityAlpha = 0.1 DensityLineColor = PointColors[PointLabels.index(i)] DensityLineAlpha = 0.3 # Peform the kernel density estimate xx, yy = np.mgrid[xmin:xmax:200j, ymin:ymax:200j] # print(self.ShapeGroups) # command='''xx, yy = np.mgrid[xmin:xmax:'''+str(self.ShapeGroups)+ '''j, ymin:ymax:''' +str(self.ShapeGroups)+'''j]''' # exec(command) # print(xx, yy) positions = np.vstack([xx.ravel(), yy.ravel()]) values = np.vstack([XtoFit[i], YtoFit[i]]) kernelstatus = True try: st.gaussian_kde(values) except Exception as e: self.ErrorEvent(text=repr(e)) kernelstatus = False if kernelstatus == True: kernel = st.gaussian_kde(values) f = np.reshape(kernel(positions).T, xx.shape) # Contourf plot cfset = self.axes.contourf(xx, yy, f, cmap=DensityColorMap, alpha=DensityAlpha) ## Or kernel density estimate plot instead of the contourf plot # self.axes.imshow(np.rot90(f), cmap='Blues', extent=[xmin, xmax, ymin, ymax]) # Contour plot cset = self.axes.contour(xx, yy, f, colors=DensityLineColor, alpha=DensityLineAlpha) # Label plot #self.axes.clabel(cset, inline=1, fontsize=10) if (len(self.data_to_test) > 0): contained = True missing = 'Miss setting infor:' for i in ['Label', 'Color', 'Marker', 'Alpha']: if i not in self.data_to_test.columns.values.tolist(): contained = False missing = missing + '\n' + i if contained == True: for i in self.data_to_test.columns.values.tolist(): if i not in self._df.columns.values.tolist(): self.data_to_test = self.data_to_test.drop(columns=i) # print(self.data_to_test) test_labels = [] test_colors = [] test_markers = [] test_alpha = [] for i in range(len(self.data_to_test)): # print(self.data_to_test.at[i, 'Label']) target = self.data_to_test.at[i, 'Label'] color = self.data_to_test.at[i, 'Color'] marker = self.data_to_test.at[i, 'Marker'] alpha = self.data_to_test.at[i, 'Alpha'] if target not in test_labels and target not in all_labels: test_labels.append(target) test_colors.append(color) test_markers.append(marker) test_alpha.append(alpha) self.whole_labels = self.whole_labels + test_labels self.load_settings_backup = self.data_to_test Load_ItemsToTest = ['Label', 'Number', 'Tag', 'Name', 'Author', 'DataType', 'Marker', 'Color', 'Size', 'Alpha', 'Style', 'Width'] for i in self.data_to_test.columns.values.tolist(): if i not in Load_ItemsToTest: self.load_settings_backup = self.load_settings_backup.drop(i, 1) print(self.load_settings_backup, self.data_to_test) print(self.load_settings_backup.shape, self.data_to_test.shape) try: for i in range(len(self.data_to_test)): target = self.data_to_test.at[i, 'Label'] if target not in all_labels: all_labels.append(target) tmp_label = self.data_to_test.at[i, 'Label'] else: tmp_label='' x_load_test = self.data_to_test.at[i, 'SiO2'] y_load_test = self.data_to_test.at[i, 'K2O'] for j in self.ItemNames: if self.SelectDic[j].contains_point([x_load_test, y_load_test]): self.LabelList.append(self.data_to_test.at[i, 'Label']) self.TypeList.append(j) break pass if (self.show_load_data_cb.isChecked()): self.axes.scatter(self.data_to_test.at[i, 'SiO2'],self.data_to_test.at[i, 'K2O'], marker=self.data_to_test.at[i, 'Marker'], s=self.data_to_test.at[i, 'Size'], color=self.data_to_test.at[i, 'Color'], alpha=self.data_to_test.at[i, 'Alpha'], label=tmp_label) except Exception as e: self.ErrorEvent(text=repr(e)) if (self.legend_cb.isChecked()): self.axes.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0, prop=fontprop) self.All_X=SVM_X self.All_Y=SVM_Y if (self.hyperplane_cb.isChecked()): clf = svm.SVC(C=1.0, kernel='linear',probability= True) svm_x= SVM_X svm_y= SVM_Y print(len(svm_x),len(svm_y),len(df.index)) xx, yy = np.meshgrid(np.arange(min(svm_x), max(svm_x), np.ptp(svm_x) / 500), np.arange(min(svm_y), max(svm_y), np.ptp(svm_y) / 500)) le = LabelEncoder() le.fit(self._df.Label) class_label = le.transform(self._df.Label) svm_train= pd.concat([pd.DataFrame(svm_x),pd.DataFrame(svm_y)], axis=1) svm_train=svm_train.values clf.fit(svm_train,class_label) Z = clf.predict(np.c_[xx.ravel(), yy.ravel()]) Z = Z.reshape(xx.shape) self.axes.contourf(xx, yy, Z, cmap='hot', alpha=0.2) if (self.show_data_index_cb.isChecked()): if 'Index' in self._df.columns.values: for i in range(len(self._df)): self.axes.annotate(self._df.at[i, 'Index'], xy=(self.All_X[i], self.All_Y[i]), color=self._df.at[i, 'Color'], alpha=self._df.at[i, 'Alpha']) else: for i in range(len(self._df)): self.axes.annotate('No' + str(i + 1), xy=(self.All_X[i], self.All_Y[i]), color=self._df.at[i, 'Color'], alpha=self._df.at[i, 'Alpha']) self.canvas.draw() self.OutPutTitle='K2OSiO2' self.OutPutData = pd.DataFrame( {'Label': self.LabelList, 'RockType': self.TypeList }) self.OutPutFig=self.fig
python
def K2OSiO2(self, Left=35, Right=79, X0=30, X1=90, X_Gap=7, Base=0, Top=19, Y0=1, Y1=19, Y_Gap=19, FontSize=12, xlabel=r'$SiO_2 wt\%$', ylabel=r'$K_2O wt\%$', width=12, height=12, dpi=300): self.setWindowTitle('K2OSiO2 diagram ') self.axes.clear() self.axes.set_xlabel(self.xlabel) self.axes.set_ylabel(self.ylabel) self.axes.spines['right'].set_color('none') self.axes.spines['top'].set_color('none') all_labels=[] all_colors=[] all_markers=[] all_alpha=[] for i in range(len(self._df)): target = self._df.at[i, 'Label'] color = self._df.at[i, 'Color'] marker = self._df.at[i, 'Marker'] alpha = self._df.at[i, 'Alpha'] if target not in self.SVM_labels: self.SVM_labels.append(target) if target not in all_labels: all_labels.append(target) all_colors.append(color) all_markers.append(marker) all_alpha.append(alpha) self.whole_labels = all_labels PointLabels = [] PointColors = [] x = [] y = [] title = 'K2O-SiO2diagram' self.setWindowTitle(title) self.textbox.setText(self.reference) k_1=(2.9-1.2)/(68-48) y_1= 1.2+ (85-48)*k_1 y_0= 1.2+ (45-48)*k_1 self.DrawLine([(45, y_0),(48, 1.2), (68,2.9),(85,y_1)]) k_2=(1.2-0.3)/(68-48) y_2= 0.3+ (85-48)*k_2 y_3= 0.3+ (45-48)*k_2 self.DrawLine([(45, y_3),(48, 0.3), (68, 1.2),(85,y_2)]) Labels=['High K','Medium K','Low K'] Locations=[(80,5),(80,3),(80,1)] X_offset, Y_offset=0,0 for k in range(len(Labels)): self.axes.annotate(Labels[k], Locations[k], xycoords='data', xytext=(X_offset, Y_offset), textcoords='offset points', fontsize=9, color='grey', alpha=0.8) self.Check() if self.OutPutCheck==True: pass if (self._changed): df = self.CleanDataFile(self._df) for i in range(len(df)): TmpLabel = '' if (df.at[i, 'Label'] in PointLabels or df.at[i, 'Label'] == ''): TmpLabel = '' else: PointLabels.append(df.at[i, 'Label']) TmpLabel = df.at[i, 'Label'] TmpColor = '' if (df.at[i, 'Color'] in PointColors or df.at[i, 'Color'] == ''): TmpColor = '' else: PointColors.append(df.at[i, 'Color']) TmpColor = df.at[i, 'Color'] x.append(df.at[i, 'SiO2']) y.append(df.at[i, 'K2O']) Size = df.at[i, 'Size'] Color = df.at[i, 'Color'] Alpha = df.at[i, 'Alpha'] Marker = df.at[i, 'Marker'] Label = df.at[i, 'Label'] xtest=df.at[i, 'SiO2'] ytest=df.at[i, 'K2O'] for j in self.ItemNames: if self.SelectDic[j].contains_point([xtest,ytest]): self.LabelList.append(Label) self.TypeList.append(j) break pass self.axes.scatter(df.at[i, 'SiO2'], df.at[i, 'K2O'], marker=df.at[i, 'Marker'], s=df.at[i, 'Size'], color=df.at[i, 'Color'], alpha=df.at[i, 'Alpha'], label=TmpLabel) XtoFit = {} YtoFit = {} SVM_X=[] SVM_Y=[] for i in PointLabels: XtoFit[i]=[] YtoFit[i]=[] for i in range(len(df)): Alpha = df.at[i, 'Alpha'] Marker = df.at[i, 'Marker'] Label = df.at[i, 'Label'] xtest=df.at[i, 'SiO2'] ytest=df.at[i, 'K2O'] XtoFit[Label].append(xtest) YtoFit[Label].append(ytest) SVM_X.append(xtest) SVM_Y.append(ytest) if (self.shape_cb.isChecked()): for i in PointLabels: if XtoFit[i] != YtoFit[i]: xmin, xmax = min(XtoFit[i]), max(XtoFit[i]) ymin, ymax = min(YtoFit[i]), max(YtoFit[i]) DensityColorMap = 'Greys' DensityAlpha = 0.1 DensityLineColor = PointColors[PointLabels.index(i)] DensityLineAlpha = 0.3 xx, yy = np.mgrid[xmin:xmax:200j, ymin:ymax:200j] positions = np.vstack([xx.ravel(), yy.ravel()]) values = np.vstack([XtoFit[i], YtoFit[i]]) kernelstatus = True try: st.gaussian_kde(values) except Exception as e: self.ErrorEvent(text=repr(e)) kernelstatus = False if kernelstatus == True: kernel = st.gaussian_kde(values) f = np.reshape(kernel(positions).T, xx.shape) cfset = self.axes.contourf(xx, yy, f, cmap=DensityColorMap, alpha=DensityAlpha) cset = self.axes.contour(xx, yy, f, colors=DensityLineColor, alpha=DensityLineAlpha) if (len(self.data_to_test) > 0): contained = True missing = 'Miss setting infor:' for i in ['Label', 'Color', 'Marker', 'Alpha']: if i not in self.data_to_test.columns.values.tolist(): contained = False missing = missing + '\n' + i if contained == True: for i in self.data_to_test.columns.values.tolist(): if i not in self._df.columns.values.tolist(): self.data_to_test = self.data_to_test.drop(columns=i) test_labels = [] test_colors = [] test_markers = [] test_alpha = [] for i in range(len(self.data_to_test)): target = self.data_to_test.at[i, 'Label'] color = self.data_to_test.at[i, 'Color'] marker = self.data_to_test.at[i, 'Marker'] alpha = self.data_to_test.at[i, 'Alpha'] if target not in test_labels and target not in all_labels: test_labels.append(target) test_colors.append(color) test_markers.append(marker) test_alpha.append(alpha) self.whole_labels = self.whole_labels + test_labels self.load_settings_backup = self.data_to_test Load_ItemsToTest = ['Label', 'Number', 'Tag', 'Name', 'Author', 'DataType', 'Marker', 'Color', 'Size', 'Alpha', 'Style', 'Width'] for i in self.data_to_test.columns.values.tolist(): if i not in Load_ItemsToTest: self.load_settings_backup = self.load_settings_backup.drop(i, 1) print(self.load_settings_backup, self.data_to_test) print(self.load_settings_backup.shape, self.data_to_test.shape) try: for i in range(len(self.data_to_test)): target = self.data_to_test.at[i, 'Label'] if target not in all_labels: all_labels.append(target) tmp_label = self.data_to_test.at[i, 'Label'] else: tmp_label='' x_load_test = self.data_to_test.at[i, 'SiO2'] y_load_test = self.data_to_test.at[i, 'K2O'] for j in self.ItemNames: if self.SelectDic[j].contains_point([x_load_test, y_load_test]): self.LabelList.append(self.data_to_test.at[i, 'Label']) self.TypeList.append(j) break pass if (self.show_load_data_cb.isChecked()): self.axes.scatter(self.data_to_test.at[i, 'SiO2'],self.data_to_test.at[i, 'K2O'], marker=self.data_to_test.at[i, 'Marker'], s=self.data_to_test.at[i, 'Size'], color=self.data_to_test.at[i, 'Color'], alpha=self.data_to_test.at[i, 'Alpha'], label=tmp_label) except Exception as e: self.ErrorEvent(text=repr(e)) if (self.legend_cb.isChecked()): self.axes.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0, prop=fontprop) self.All_X=SVM_X self.All_Y=SVM_Y if (self.hyperplane_cb.isChecked()): clf = svm.SVC(C=1.0, kernel='linear',probability= True) svm_x= SVM_X svm_y= SVM_Y print(len(svm_x),len(svm_y),len(df.index)) xx, yy = np.meshgrid(np.arange(min(svm_x), max(svm_x), np.ptp(svm_x) / 500), np.arange(min(svm_y), max(svm_y), np.ptp(svm_y) / 500)) le = LabelEncoder() le.fit(self._df.Label) class_label = le.transform(self._df.Label) svm_train= pd.concat([pd.DataFrame(svm_x),pd.DataFrame(svm_y)], axis=1) svm_train=svm_train.values clf.fit(svm_train,class_label) Z = clf.predict(np.c_[xx.ravel(), yy.ravel()]) Z = Z.reshape(xx.shape) self.axes.contourf(xx, yy, Z, cmap='hot', alpha=0.2) if (self.show_data_index_cb.isChecked()): if 'Index' in self._df.columns.values: for i in range(len(self._df)): self.axes.annotate(self._df.at[i, 'Index'], xy=(self.All_X[i], self.All_Y[i]), color=self._df.at[i, 'Color'], alpha=self._df.at[i, 'Alpha']) else: for i in range(len(self._df)): self.axes.annotate('No' + str(i + 1), xy=(self.All_X[i], self.All_Y[i]), color=self._df.at[i, 'Color'], alpha=self._df.at[i, 'Alpha']) self.canvas.draw() self.OutPutTitle='K2OSiO2' self.OutPutData = pd.DataFrame( {'Label': self.LabelList, 'RockType': self.TypeList }) self.OutPutFig=self.fig
[ "def", "K2OSiO2", "(", "self", ",", "Left", "=", "35", ",", "Right", "=", "79", ",", "X0", "=", "30", ",", "X1", "=", "90", ",", "X_Gap", "=", "7", ",", "Base", "=", "0", ",", "Top", "=", "19", ",", "Y0", "=", "1", ",", "Y1", "=", "19", ",", "Y_Gap", "=", "19", ",", "FontSize", "=", "12", ",", "xlabel", "=", "r'$SiO_2 wt\\%$'", ",", "ylabel", "=", "r'$K_2O wt\\%$'", ",", "width", "=", "12", ",", "height", "=", "12", ",", "dpi", "=", "300", ")", ":", "self", ".", "setWindowTitle", "(", "'K2OSiO2 diagram '", ")", "self", ".", "axes", ".", "clear", "(", ")", "#self.axes.axis('off')", "self", ".", "axes", ".", "set_xlabel", "(", "self", ".", "xlabel", ")", "self", ".", "axes", ".", "set_ylabel", "(", "self", ".", "ylabel", ")", "self", ".", "axes", ".", "spines", "[", "'right'", "]", ".", "set_color", "(", "'none'", ")", "self", ".", "axes", ".", "spines", "[", "'top'", "]", ".", "set_color", "(", "'none'", ")", "all_labels", "=", "[", "]", "all_colors", "=", "[", "]", "all_markers", "=", "[", "]", "all_alpha", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "self", ".", "_df", ")", ")", ":", "target", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Label'", "]", "color", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Color'", "]", "marker", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Marker'", "]", "alpha", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Alpha'", "]", "if", "target", "not", "in", "self", ".", "SVM_labels", ":", "self", ".", "SVM_labels", ".", "append", "(", "target", ")", "if", "target", "not", "in", "all_labels", ":", "all_labels", ".", "append", "(", "target", ")", "all_colors", ".", "append", "(", "color", ")", "all_markers", ".", "append", "(", "marker", ")", "all_alpha", ".", "append", "(", "alpha", ")", "self", ".", "whole_labels", "=", "all_labels", "PointLabels", "=", "[", "]", "PointColors", "=", "[", "]", "x", "=", "[", "]", "y", "=", "[", "]", "title", "=", "'K2O-SiO2diagram'", "self", ".", "setWindowTitle", "(", "title", ")", "self", ".", "textbox", ".", "setText", "(", "self", ".", "reference", ")", "k_1", "=", "(", "2.9", "-", "1.2", ")", "/", "(", "68", "-", "48", ")", "y_1", "=", "1.2", "+", "(", "85", "-", "48", ")", "*", "k_1", "y_0", "=", "1.2", "+", "(", "45", "-", "48", ")", "*", "k_1", "self", ".", "DrawLine", "(", "[", "(", "45", ",", "y_0", ")", ",", "(", "48", ",", "1.2", ")", ",", "(", "68", ",", "2.9", ")", ",", "(", "85", ",", "y_1", ")", "]", ")", "k_2", "=", "(", "1.2", "-", "0.3", ")", "/", "(", "68", "-", "48", ")", "y_2", "=", "0.3", "+", "(", "85", "-", "48", ")", "*", "k_2", "y_3", "=", "0.3", "+", "(", "45", "-", "48", ")", "*", "k_2", "self", ".", "DrawLine", "(", "[", "(", "45", ",", "y_3", ")", ",", "(", "48", ",", "0.3", ")", ",", "(", "68", ",", "1.2", ")", ",", "(", "85", ",", "y_2", ")", "]", ")", "Labels", "=", "[", "'High K'", ",", "'Medium K'", ",", "'Low K'", "]", "Locations", "=", "[", "(", "80", ",", "5", ")", ",", "(", "80", ",", "3", ")", ",", "(", "80", ",", "1", ")", "]", "X_offset", ",", "Y_offset", "=", "0", ",", "0", "for", "k", "in", "range", "(", "len", "(", "Labels", ")", ")", ":", "self", ".", "axes", ".", "annotate", "(", "Labels", "[", "k", "]", ",", "Locations", "[", "k", "]", ",", "xycoords", "=", "'data'", ",", "xytext", "=", "(", "X_offset", ",", "Y_offset", ")", ",", "textcoords", "=", "'offset points'", ",", "fontsize", "=", "9", ",", "color", "=", "'grey'", ",", "alpha", "=", "0.8", ")", "self", ".", "Check", "(", ")", "if", "self", ".", "OutPutCheck", "==", "True", ":", "pass", "if", "(", "self", ".", "_changed", ")", ":", "df", "=", "self", ".", "CleanDataFile", "(", "self", ".", "_df", ")", "for", "i", "in", "range", "(", "len", "(", "df", ")", ")", ":", "TmpLabel", "=", "''", "if", "(", "df", ".", "at", "[", "i", ",", "'Label'", "]", "in", "PointLabels", "or", "df", ".", "at", "[", "i", ",", "'Label'", "]", "==", "''", ")", ":", "TmpLabel", "=", "''", "else", ":", "PointLabels", ".", "append", "(", "df", ".", "at", "[", "i", ",", "'Label'", "]", ")", "TmpLabel", "=", "df", ".", "at", "[", "i", ",", "'Label'", "]", "TmpColor", "=", "''", "if", "(", "df", ".", "at", "[", "i", ",", "'Color'", "]", "in", "PointColors", "or", "df", ".", "at", "[", "i", ",", "'Color'", "]", "==", "''", ")", ":", "TmpColor", "=", "''", "else", ":", "PointColors", ".", "append", "(", "df", ".", "at", "[", "i", ",", "'Color'", "]", ")", "TmpColor", "=", "df", ".", "at", "[", "i", ",", "'Color'", "]", "x", ".", "append", "(", "df", ".", "at", "[", "i", ",", "'SiO2'", "]", ")", "y", ".", "append", "(", "df", ".", "at", "[", "i", ",", "'K2O'", "]", ")", "Size", "=", "df", ".", "at", "[", "i", ",", "'Size'", "]", "Color", "=", "df", ".", "at", "[", "i", ",", "'Color'", "]", "# print(Color, df.at[i, 'SiO2'], (df.at[i, 'Na2O'] + df.at[i, 'K2O']))", "Alpha", "=", "df", ".", "at", "[", "i", ",", "'Alpha'", "]", "Marker", "=", "df", ".", "at", "[", "i", ",", "'Marker'", "]", "Label", "=", "df", ".", "at", "[", "i", ",", "'Label'", "]", "xtest", "=", "df", ".", "at", "[", "i", ",", "'SiO2'", "]", "ytest", "=", "df", ".", "at", "[", "i", ",", "'K2O'", "]", "for", "j", "in", "self", ".", "ItemNames", ":", "if", "self", ".", "SelectDic", "[", "j", "]", ".", "contains_point", "(", "[", "xtest", ",", "ytest", "]", ")", ":", "self", ".", "LabelList", ".", "append", "(", "Label", ")", "self", ".", "TypeList", ".", "append", "(", "j", ")", "break", "pass", "self", ".", "axes", ".", "scatter", "(", "df", ".", "at", "[", "i", ",", "'SiO2'", "]", ",", "df", ".", "at", "[", "i", ",", "'K2O'", "]", ",", "marker", "=", "df", ".", "at", "[", "i", ",", "'Marker'", "]", ",", "s", "=", "df", ".", "at", "[", "i", ",", "'Size'", "]", ",", "color", "=", "df", ".", "at", "[", "i", ",", "'Color'", "]", ",", "alpha", "=", "df", ".", "at", "[", "i", ",", "'Alpha'", "]", ",", "label", "=", "TmpLabel", ")", "XtoFit", "=", "{", "}", "YtoFit", "=", "{", "}", "SVM_X", "=", "[", "]", "SVM_Y", "=", "[", "]", "for", "i", "in", "PointLabels", ":", "XtoFit", "[", "i", "]", "=", "[", "]", "YtoFit", "[", "i", "]", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "df", ")", ")", ":", "Alpha", "=", "df", ".", "at", "[", "i", ",", "'Alpha'", "]", "Marker", "=", "df", ".", "at", "[", "i", ",", "'Marker'", "]", "Label", "=", "df", ".", "at", "[", "i", ",", "'Label'", "]", "xtest", "=", "df", ".", "at", "[", "i", ",", "'SiO2'", "]", "ytest", "=", "df", ".", "at", "[", "i", ",", "'K2O'", "]", "XtoFit", "[", "Label", "]", ".", "append", "(", "xtest", ")", "YtoFit", "[", "Label", "]", ".", "append", "(", "ytest", ")", "SVM_X", ".", "append", "(", "xtest", ")", "SVM_Y", ".", "append", "(", "ytest", ")", "if", "(", "self", ".", "shape_cb", ".", "isChecked", "(", ")", ")", ":", "for", "i", "in", "PointLabels", ":", "if", "XtoFit", "[", "i", "]", "!=", "YtoFit", "[", "i", "]", ":", "xmin", ",", "xmax", "=", "min", "(", "XtoFit", "[", "i", "]", ")", ",", "max", "(", "XtoFit", "[", "i", "]", ")", "ymin", ",", "ymax", "=", "min", "(", "YtoFit", "[", "i", "]", ")", ",", "max", "(", "YtoFit", "[", "i", "]", ")", "DensityColorMap", "=", "'Greys'", "DensityAlpha", "=", "0.1", "DensityLineColor", "=", "PointColors", "[", "PointLabels", ".", "index", "(", "i", ")", "]", "DensityLineAlpha", "=", "0.3", "# Peform the kernel density estimate", "xx", ",", "yy", "=", "np", ".", "mgrid", "[", "xmin", ":", "xmax", ":", "200j", ",", "ymin", ":", "ymax", ":", "200j", "]", "# print(self.ShapeGroups)", "# command='''xx, yy = np.mgrid[xmin:xmax:'''+str(self.ShapeGroups)+ '''j, ymin:ymax:''' +str(self.ShapeGroups)+'''j]'''", "# exec(command)", "# print(xx, yy)", "positions", "=", "np", ".", "vstack", "(", "[", "xx", ".", "ravel", "(", ")", ",", "yy", ".", "ravel", "(", ")", "]", ")", "values", "=", "np", ".", "vstack", "(", "[", "XtoFit", "[", "i", "]", ",", "YtoFit", "[", "i", "]", "]", ")", "kernelstatus", "=", "True", "try", ":", "st", ".", "gaussian_kde", "(", "values", ")", "except", "Exception", "as", "e", ":", "self", ".", "ErrorEvent", "(", "text", "=", "repr", "(", "e", ")", ")", "kernelstatus", "=", "False", "if", "kernelstatus", "==", "True", ":", "kernel", "=", "st", ".", "gaussian_kde", "(", "values", ")", "f", "=", "np", ".", "reshape", "(", "kernel", "(", "positions", ")", ".", "T", ",", "xx", ".", "shape", ")", "# Contourf plot", "cfset", "=", "self", ".", "axes", ".", "contourf", "(", "xx", ",", "yy", ",", "f", ",", "cmap", "=", "DensityColorMap", ",", "alpha", "=", "DensityAlpha", ")", "## Or kernel density estimate plot instead of the contourf plot", "# self.axes.imshow(np.rot90(f), cmap='Blues', extent=[xmin, xmax, ymin, ymax])", "# Contour plot", "cset", "=", "self", ".", "axes", ".", "contour", "(", "xx", ",", "yy", ",", "f", ",", "colors", "=", "DensityLineColor", ",", "alpha", "=", "DensityLineAlpha", ")", "# Label plot", "#self.axes.clabel(cset, inline=1, fontsize=10)", "if", "(", "len", "(", "self", ".", "data_to_test", ")", ">", "0", ")", ":", "contained", "=", "True", "missing", "=", "'Miss setting infor:'", "for", "i", "in", "[", "'Label'", ",", "'Color'", ",", "'Marker'", ",", "'Alpha'", "]", ":", "if", "i", "not", "in", "self", ".", "data_to_test", ".", "columns", ".", "values", ".", "tolist", "(", ")", ":", "contained", "=", "False", "missing", "=", "missing", "+", "'\\n'", "+", "i", "if", "contained", "==", "True", ":", "for", "i", "in", "self", ".", "data_to_test", ".", "columns", ".", "values", ".", "tolist", "(", ")", ":", "if", "i", "not", "in", "self", ".", "_df", ".", "columns", ".", "values", ".", "tolist", "(", ")", ":", "self", ".", "data_to_test", "=", "self", ".", "data_to_test", ".", "drop", "(", "columns", "=", "i", ")", "# print(self.data_to_test)", "test_labels", "=", "[", "]", "test_colors", "=", "[", "]", "test_markers", "=", "[", "]", "test_alpha", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "self", ".", "data_to_test", ")", ")", ":", "# print(self.data_to_test.at[i, 'Label'])", "target", "=", "self", ".", "data_to_test", ".", "at", "[", "i", ",", "'Label'", "]", "color", "=", "self", ".", "data_to_test", ".", "at", "[", "i", ",", "'Color'", "]", "marker", "=", "self", ".", "data_to_test", ".", "at", "[", "i", ",", "'Marker'", "]", "alpha", "=", "self", ".", "data_to_test", ".", "at", "[", "i", ",", "'Alpha'", "]", "if", "target", "not", "in", "test_labels", "and", "target", "not", "in", "all_labels", ":", "test_labels", ".", "append", "(", "target", ")", "test_colors", ".", "append", "(", "color", ")", "test_markers", ".", "append", "(", "marker", ")", "test_alpha", ".", "append", "(", "alpha", ")", "self", ".", "whole_labels", "=", "self", ".", "whole_labels", "+", "test_labels", "self", ".", "load_settings_backup", "=", "self", ".", "data_to_test", "Load_ItemsToTest", "=", "[", "'Label'", ",", "'Number'", ",", "'Tag'", ",", "'Name'", ",", "'Author'", ",", "'DataType'", ",", "'Marker'", ",", "'Color'", ",", "'Size'", ",", "'Alpha'", ",", "'Style'", ",", "'Width'", "]", "for", "i", "in", "self", ".", "data_to_test", ".", "columns", ".", "values", ".", "tolist", "(", ")", ":", "if", "i", "not", "in", "Load_ItemsToTest", ":", "self", ".", "load_settings_backup", "=", "self", ".", "load_settings_backup", ".", "drop", "(", "i", ",", "1", ")", "print", "(", "self", ".", "load_settings_backup", ",", "self", ".", "data_to_test", ")", "print", "(", "self", ".", "load_settings_backup", ".", "shape", ",", "self", ".", "data_to_test", ".", "shape", ")", "try", ":", "for", "i", "in", "range", "(", "len", "(", "self", ".", "data_to_test", ")", ")", ":", "target", "=", "self", ".", "data_to_test", ".", "at", "[", "i", ",", "'Label'", "]", "if", "target", "not", "in", "all_labels", ":", "all_labels", ".", "append", "(", "target", ")", "tmp_label", "=", "self", ".", "data_to_test", ".", "at", "[", "i", ",", "'Label'", "]", "else", ":", "tmp_label", "=", "''", "x_load_test", "=", "self", ".", "data_to_test", ".", "at", "[", "i", ",", "'SiO2'", "]", "y_load_test", "=", "self", ".", "data_to_test", ".", "at", "[", "i", ",", "'K2O'", "]", "for", "j", "in", "self", ".", "ItemNames", ":", "if", "self", ".", "SelectDic", "[", "j", "]", ".", "contains_point", "(", "[", "x_load_test", ",", "y_load_test", "]", ")", ":", "self", ".", "LabelList", ".", "append", "(", "self", ".", "data_to_test", ".", "at", "[", "i", ",", "'Label'", "]", ")", "self", ".", "TypeList", ".", "append", "(", "j", ")", "break", "pass", "if", "(", "self", ".", "show_load_data_cb", ".", "isChecked", "(", ")", ")", ":", "self", ".", "axes", ".", "scatter", "(", "self", ".", "data_to_test", ".", "at", "[", "i", ",", "'SiO2'", "]", ",", "self", ".", "data_to_test", ".", "at", "[", "i", ",", "'K2O'", "]", ",", "marker", "=", "self", ".", "data_to_test", ".", "at", "[", "i", ",", "'Marker'", "]", ",", "s", "=", "self", ".", "data_to_test", ".", "at", "[", "i", ",", "'Size'", "]", ",", "color", "=", "self", ".", "data_to_test", ".", "at", "[", "i", ",", "'Color'", "]", ",", "alpha", "=", "self", ".", "data_to_test", ".", "at", "[", "i", ",", "'Alpha'", "]", ",", "label", "=", "tmp_label", ")", "except", "Exception", "as", "e", ":", "self", ".", "ErrorEvent", "(", "text", "=", "repr", "(", "e", ")", ")", "if", "(", "self", ".", "legend_cb", ".", "isChecked", "(", ")", ")", ":", "self", ".", "axes", ".", "legend", "(", "bbox_to_anchor", "=", "(", "1.05", ",", "1", ")", ",", "loc", "=", "2", ",", "borderaxespad", "=", "0", ",", "prop", "=", "fontprop", ")", "self", ".", "All_X", "=", "SVM_X", "self", ".", "All_Y", "=", "SVM_Y", "if", "(", "self", ".", "hyperplane_cb", ".", "isChecked", "(", ")", ")", ":", "clf", "=", "svm", ".", "SVC", "(", "C", "=", "1.0", ",", "kernel", "=", "'linear'", ",", "probability", "=", "True", ")", "svm_x", "=", "SVM_X", "svm_y", "=", "SVM_Y", "print", "(", "len", "(", "svm_x", ")", ",", "len", "(", "svm_y", ")", ",", "len", "(", "df", ".", "index", ")", ")", "xx", ",", "yy", "=", "np", ".", "meshgrid", "(", "np", ".", "arange", "(", "min", "(", "svm_x", ")", ",", "max", "(", "svm_x", ")", ",", "np", ".", "ptp", "(", "svm_x", ")", "/", "500", ")", ",", "np", ".", "arange", "(", "min", "(", "svm_y", ")", ",", "max", "(", "svm_y", ")", ",", "np", ".", "ptp", "(", "svm_y", ")", "/", "500", ")", ")", "le", "=", "LabelEncoder", "(", ")", "le", ".", "fit", "(", "self", ".", "_df", ".", "Label", ")", "class_label", "=", "le", ".", "transform", "(", "self", ".", "_df", ".", "Label", ")", "svm_train", "=", "pd", ".", "concat", "(", "[", "pd", ".", "DataFrame", "(", "svm_x", ")", ",", "pd", ".", "DataFrame", "(", "svm_y", ")", "]", ",", "axis", "=", "1", ")", "svm_train", "=", "svm_train", ".", "values", "clf", ".", "fit", "(", "svm_train", ",", "class_label", ")", "Z", "=", "clf", ".", "predict", "(", "np", ".", "c_", "[", "xx", ".", "ravel", "(", ")", ",", "yy", ".", "ravel", "(", ")", "]", ")", "Z", "=", "Z", ".", "reshape", "(", "xx", ".", "shape", ")", "self", ".", "axes", ".", "contourf", "(", "xx", ",", "yy", ",", "Z", ",", "cmap", "=", "'hot'", ",", "alpha", "=", "0.2", ")", "if", "(", "self", ".", "show_data_index_cb", ".", "isChecked", "(", ")", ")", ":", "if", "'Index'", "in", "self", ".", "_df", ".", "columns", ".", "values", ":", "for", "i", "in", "range", "(", "len", "(", "self", ".", "_df", ")", ")", ":", "self", ".", "axes", ".", "annotate", "(", "self", ".", "_df", ".", "at", "[", "i", ",", "'Index'", "]", ",", "xy", "=", "(", "self", ".", "All_X", "[", "i", "]", ",", "self", ".", "All_Y", "[", "i", "]", ")", ",", "color", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Color'", "]", ",", "alpha", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Alpha'", "]", ")", "else", ":", "for", "i", "in", "range", "(", "len", "(", "self", ".", "_df", ")", ")", ":", "self", ".", "axes", ".", "annotate", "(", "'No'", "+", "str", "(", "i", "+", "1", ")", ",", "xy", "=", "(", "self", ".", "All_X", "[", "i", "]", ",", "self", ".", "All_Y", "[", "i", "]", ")", ",", "color", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Color'", "]", ",", "alpha", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Alpha'", "]", ")", "self", ".", "canvas", ".", "draw", "(", ")", "self", ".", "OutPutTitle", "=", "'K2OSiO2'", "self", ".", "OutPutData", "=", "pd", ".", "DataFrame", "(", "{", "'Label'", ":", "self", ".", "LabelList", ",", "'RockType'", ":", "self", ".", "TypeList", "}", ")", "self", ".", "OutPutFig", "=", "self", ".", "fig" ]
self.axes.set_xticks([30,40,50,60,70,80,90]) self.axes.set_xticklabels([30,40,50,60,70,80,90]) self.axes.set_yticks([0, 5, 10, 15, 20]) self.axes.set_yticklabels([0, 5, 10, 15, 20]) self.axes.set_ylim(bottom=0)
[ "self", ".", "axes", ".", "set_xticks", "(", "[", "30", "40", "50", "60", "70", "80", "90", "]", ")", "self", ".", "axes", ".", "set_xticklabels", "(", "[", "30", "40", "50", "60", "70", "80", "90", "]", ")" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/K2OSiO2.py#L122-L471
GeoPyTool/GeoPyTool
geopytool/REE.py
REE.REE
def REE(self, Left=0, Right=16, X0=1, X1=15, X_Gap=15, Base=-1, Top=6, Y0=-1, Y1=3, Y_Gap=5, FontSize=12, xLabel=r'$REE-Standardlized-Pattern$', yLabel='', width=12, height=12, dpi=300): self.axes.clear() self.axes.spines['right'].set_color('none') self.axes.spines['top'].set_color('none') self.WholeData = [] self.OutPutData = pd.DataFrame() self.LabelList=[] self.algebraDeltaEuList=[] self.geometricDeltaEuList=[] self.LaPrDeltaCeList=[] self.LaNdDeltaCeList=[] self.LaSmList=[] self.LaYbList=[] self.GdYbList=[] self.LREEList=[] self.MREEList=[] self.HREEList=[] self.ALLREEList=[] self.BinHREEList=[] self.BinLREEList=[] self.L_HREEList=[] self.AllAlpha=[] self.AllWidth = [] self.AllSize = [] #raw = self._df raw = self.CleanDataFile(self._df) self.FontSize = FontSize PointLabels = [] k = 0 slider_value=int(self.standard_slider.value()) item_value=int(self.item_slider.value()) if slider_value < len(self.StandardsName): standardnamechosen = self.StandardsName[slider_value] standardchosen = self.Standards[standardnamechosen] self.textbox.setText(self.reference+"\nStandard Chosen: "+self.StandardsName[slider_value]) right_label_text=self.StandardsName[slider_value] elif len(self._given_Standard)<=0: standardnamechosen = self.StandardsName[slider_value-1] standardchosen = self.Standards[standardnamechosen] self.textbox.setText(self.reference+"\nStandard Chosen: "+self.StandardsName[slider_value-1]) right_label_text = self.StandardsName[slider_value-1] else: standardchosen = self._given_Standard self.textbox.setText(self.reference + "\n You are using Self Defined Standard") right_label_text = "Self Defined Standard" for i in range(len(raw)): # raw.at[i, 'DataType'] == 'User' or raw.at[i, 'DataType'] == 'user' or raw.at[i, 'DataType'] == 'USER' TmpLabel = '' LinesX = [] LinesY = [] TmpEu = raw.at[i, 'Eu'] / standardchosen['Eu'] TmpSm = raw.at[i, 'Sm'] / standardchosen['Sm'] TmpGd = raw.at[i, 'Gd'] / standardchosen['Gd'] TmpCe = raw.at[i, 'Ce'] / standardchosen['Ce'] TmpLa = raw.at[i, 'La'] / standardchosen['La'] TmpPr = raw.at[i, 'Pr'] / standardchosen['Pr'] TmpNd = raw.at[i, 'Nd'] / standardchosen['Nd'] TmpYb = raw.at[i, 'Yb'] / standardchosen['Yb'] algebraEu = 2*TmpEu/(TmpSm+TmpGd) geometricEu = TmpEu/np.power((TmpSm*TmpGd),0.5) firstCe=2*TmpCe/(TmpLa+TmpPr) secondCe=3*TmpCe/(2*TmpLa+TmpNd) LaYb=TmpLa/TmpYb LaSm=TmpLa/TmpSm GdYb=TmpGd/TmpYb tmpLREEResult = 0 tmpMREEResult = 0 tmpHREEResult = 0 tmpWholeResult = 0 tmpBinLREE=0 tmpBinHREE=0 for j in self.Element: if j in self.LREE: tmpLREEResult += raw.at[i, j] elif j in self.MREE: tmpMREEResult += raw.at[i, j] elif j in self.HREE: tmpHREEResult += raw.at[i, j] if j in self.BinLREE: tmpBinLREE += raw.at[i, j] elif j in self.BinHREE: tmpBinHREE += raw.at[i, j] tmpWholeResult+= raw.at[i, j] self.LabelList.append(raw.at[i, 'Label']) self.algebraDeltaEuList.append( algebraEu ) self.geometricDeltaEuList.append( geometricEu ) self.LaPrDeltaCeList.append(firstCe) self.LaNdDeltaCeList.append(secondCe) self.LaSmList.append(LaSm) self.LaYbList.append(LaYb) self.GdYbList.append(GdYb) self.LREEList.append( tmpLREEResult ) self.MREEList.append( tmpMREEResult ) self.HREEList.append( tmpHREEResult ) self.ALLREEList.append( tmpWholeResult ) self.BinHREEList.append(tmpBinHREE) self.BinLREEList.append(tmpBinLREE) self.L_HREEList.append(tmpBinLREE/tmpBinHREE) ''' for i in self.data_to_norm.columns.values.tolist(): if i not in self.Element: self.data_to_norm = self.data_to_norm.drop(i, 1) ''' Y_bottom=0 Y_top=0 for j in range(len(self.Element)): tmp = raw.at[i, self.Element[j]] / standardchosen[self.Element[j]] self.data_to_norm.at[i, self.Element[j]] = tmp tmpflag = 1 a = 0 try: a = math.log(tmp, 10) except(ValueError): tmpflag = 0 pass if (tmpflag == 1): if Y_bottom >a:Y_bottom =a if Y_top<a:Y_top=a self.axes.set_ylim(Y_bottom, Y_top+1) if item_value == 0: self.item_left_label.setText('Show All') for j in range(len(self.Element)): tmp = raw.at[i, self.Element[j]] / standardchosen[self.Element[j]] self.data_to_norm.at[i, self.Element[j]] = tmp tmpflag = 1 a = 0 try: a = math.log(tmp, 10) except(ValueError): tmpflag = 0 pass if (tmpflag == 1): if (raw.at[i, 'Label'] in PointLabels or raw.at[i, 'Label'] == ''): self.WholeData.append(math.log(tmp, 10)) TmpLabel = '' else: PointLabels.append(raw.at[i, 'Label']) TmpLabel = raw.at[i, 'Label'] LinesY.append(a) LinesX.append(j + 1) self.axes.scatter(j + 1, math.log(tmp, 10), marker=raw.at[i, 'Marker'], s=raw.at[i, 'Size'], color=raw.at[i, 'Color'], alpha=raw.at[i, 'Alpha'], label=TmpLabel) self.axes.plot(LinesX, LinesY, color=raw.at[i, 'Color'], linewidth=raw.at[i, 'Width'], linestyle=raw.at[i, 'Style'], alpha=raw.at[i, 'Alpha']) if (self.show_data_index_cb.isChecked()): if 'Index' in self._df_back.columns.values: self.axes.annotate(self._df_back.at[i, 'Index'], xy=(LinesX[-1], LinesY[-1]), color=self._df.at[i, 'Color'], alpha=self._df.at[i, 'Alpha']) else: self.axes.annotate('No' + str(i + 1), xy=(LinesX[-1], LinesY[-1]), color=self._df.at[i, 'Color'], alpha=self._df.at[i, 'Alpha']) else: self.item_left_label.setText(self.AllLabel[item_value-1]) for j in range(len(self.Element)): tmp = raw.at[i, self.Element[j]] / standardchosen[self.Element[j]] self.data_to_norm.at[i, self.Element[j]] = tmp tmpflag = 1 a = 0 try: a = math.log(tmp, 10) except(ValueError): tmpflag = 0 pass if (tmpflag == 1): if (raw.at[i, 'Label'] in PointLabels or raw.at[i, 'Label'] == ''): TmpLabel = '' else: PointLabels.append(raw.at[i, 'Label']) TmpLabel = raw.at[i, 'Label'] alpha= raw.at[i, 'Alpha'] linewidth= raw.at[i, 'Width'] pointsize= raw.at[i, 'Size'] if raw.at[i, 'Label'] == self.AllLabel[item_value - 1]: LinesY.append(a) LinesX.append(j + 1) self.WholeData.append(math.log(tmp, 10)) self.axes.scatter(j + 1, math.log(tmp, 10), marker=raw.at[i, 'Marker'], s=pointsize, color=raw.at[i, 'Color'], alpha=alpha, label=TmpLabel) self.axes.plot(LinesX, LinesY, color=raw.at[i, 'Color'], linewidth=linewidth,linestyle=raw.at[i, 'Style'], alpha=alpha) print(LinesX,LinesY) if (self.show_data_index_cb.isChecked()): if len(LinesX) > 0 and len(LinesY) > 0: if 'Index' in self._df_back.columns.values: self.axes.annotate(self._df_back.at[i, 'Index'], xy=(LinesX[-1], LinesY[-1]), color=self._df.at[i, 'Color'], alpha=self._df.at[i, 'Alpha']) else: self.axes.annotate('No' + str(i + 1), xy=(LinesX[-1], LinesY[-1]), color=self._df.at[i, 'Color'], alpha=self._df.at[i, 'Alpha']) Tale = 0 Head = 0 if (len(self.WholeData) > 0): Tale = min(self.WholeData) Head = max(self.WholeData)+0.5 Location = round(Tale - (Head - Tale) / 5) count = round((Head - Tale) / 5 * 7) + 1 if (self.legend_cb.isChecked()): self.axes.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0, prop=fontprop) self.standard_right_label.setText(right_label_text) self.yticks = [Location+i for i in range(count)] self.yticklabels = [str(np.power(10.0, (Location + i))) for i in range(count)] self.axes.set_yticks(self.yticks) self.axes.set_yticklabels(self.yticklabels, fontsize=6) #self.axes.set_yscale('log') self.axes.set_xticks(self.xticks) self.axes.set_xticklabels(self.xticklabels, rotation=-45, fontsize=6) self.canvas.draw() self.OutPutTitle='REE' #print(len(self.algebraDeltaEuList)) self.OutPutData = pd.DataFrame( {'Label': self.LabelList, 'Eu/Eu*(algebra)': self.algebraDeltaEuList, 'Eu/Eu*(square)': self.geometricDeltaEuList, 'Ce/Ce*(LaPr)': self.LaPrDeltaCeList, 'Ce/Ce*(LaNd)': self.LaNdDeltaCeList, '(La/Sm)N':self.LaSmList, '(La/Yb)N':self.LaYbList, '(Gd/Yb)N':self.GdYbList, 'trisection LREE': self.LREEList, 'trisection MREE': self.MREEList, 'trisection HREE': self.HREEList, 'bisection LREE': self.BinLREEList, 'bisection HREE': self.BinHREEList, 'LREE/HREE':self.L_HREEList, 'ALLREE': self.ALLREEList }) #print('middle ',len(self.OutPutData['Eu/Eu*(algebra)'])) ''' self.LaPrDeltaCeList.append(firstCe) self.LaNdDeltaCeList.append(secondCe) ''' self.OutPutFig=self.fig
python
def REE(self, Left=0, Right=16, X0=1, X1=15, X_Gap=15, Base=-1, Top=6, Y0=-1, Y1=3, Y_Gap=5, FontSize=12, xLabel=r'$REE-Standardlized-Pattern$', yLabel='', width=12, height=12, dpi=300): self.axes.clear() self.axes.spines['right'].set_color('none') self.axes.spines['top'].set_color('none') self.WholeData = [] self.OutPutData = pd.DataFrame() self.LabelList=[] self.algebraDeltaEuList=[] self.geometricDeltaEuList=[] self.LaPrDeltaCeList=[] self.LaNdDeltaCeList=[] self.LaSmList=[] self.LaYbList=[] self.GdYbList=[] self.LREEList=[] self.MREEList=[] self.HREEList=[] self.ALLREEList=[] self.BinHREEList=[] self.BinLREEList=[] self.L_HREEList=[] self.AllAlpha=[] self.AllWidth = [] self.AllSize = [] raw = self.CleanDataFile(self._df) self.FontSize = FontSize PointLabels = [] k = 0 slider_value=int(self.standard_slider.value()) item_value=int(self.item_slider.value()) if slider_value < len(self.StandardsName): standardnamechosen = self.StandardsName[slider_value] standardchosen = self.Standards[standardnamechosen] self.textbox.setText(self.reference+"\nStandard Chosen: "+self.StandardsName[slider_value]) right_label_text=self.StandardsName[slider_value] elif len(self._given_Standard)<=0: standardnamechosen = self.StandardsName[slider_value-1] standardchosen = self.Standards[standardnamechosen] self.textbox.setText(self.reference+"\nStandard Chosen: "+self.StandardsName[slider_value-1]) right_label_text = self.StandardsName[slider_value-1] else: standardchosen = self._given_Standard self.textbox.setText(self.reference + "\n You are using Self Defined Standard") right_label_text = "Self Defined Standard" for i in range(len(raw)): TmpLabel = '' LinesX = [] LinesY = [] TmpEu = raw.at[i, 'Eu'] / standardchosen['Eu'] TmpSm = raw.at[i, 'Sm'] / standardchosen['Sm'] TmpGd = raw.at[i, 'Gd'] / standardchosen['Gd'] TmpCe = raw.at[i, 'Ce'] / standardchosen['Ce'] TmpLa = raw.at[i, 'La'] / standardchosen['La'] TmpPr = raw.at[i, 'Pr'] / standardchosen['Pr'] TmpNd = raw.at[i, 'Nd'] / standardchosen['Nd'] TmpYb = raw.at[i, 'Yb'] / standardchosen['Yb'] algebraEu = 2*TmpEu/(TmpSm+TmpGd) geometricEu = TmpEu/np.power((TmpSm*TmpGd),0.5) firstCe=2*TmpCe/(TmpLa+TmpPr) secondCe=3*TmpCe/(2*TmpLa+TmpNd) LaYb=TmpLa/TmpYb LaSm=TmpLa/TmpSm GdYb=TmpGd/TmpYb tmpLREEResult = 0 tmpMREEResult = 0 tmpHREEResult = 0 tmpWholeResult = 0 tmpBinLREE=0 tmpBinHREE=0 for j in self.Element: if j in self.LREE: tmpLREEResult += raw.at[i, j] elif j in self.MREE: tmpMREEResult += raw.at[i, j] elif j in self.HREE: tmpHREEResult += raw.at[i, j] if j in self.BinLREE: tmpBinLREE += raw.at[i, j] elif j in self.BinHREE: tmpBinHREE += raw.at[i, j] tmpWholeResult+= raw.at[i, j] self.LabelList.append(raw.at[i, 'Label']) self.algebraDeltaEuList.append( algebraEu ) self.geometricDeltaEuList.append( geometricEu ) self.LaPrDeltaCeList.append(firstCe) self.LaNdDeltaCeList.append(secondCe) self.LaSmList.append(LaSm) self.LaYbList.append(LaYb) self.GdYbList.append(GdYb) self.LREEList.append( tmpLREEResult ) self.MREEList.append( tmpMREEResult ) self.HREEList.append( tmpHREEResult ) self.ALLREEList.append( tmpWholeResult ) self.BinHREEList.append(tmpBinHREE) self.BinLREEList.append(tmpBinLREE) self.L_HREEList.append(tmpBinLREE/tmpBinHREE) Y_bottom=0 Y_top=0 for j in range(len(self.Element)): tmp = raw.at[i, self.Element[j]] / standardchosen[self.Element[j]] self.data_to_norm.at[i, self.Element[j]] = tmp tmpflag = 1 a = 0 try: a = math.log(tmp, 10) except(ValueError): tmpflag = 0 pass if (tmpflag == 1): if Y_bottom >a:Y_bottom =a if Y_top<a:Y_top=a self.axes.set_ylim(Y_bottom, Y_top+1) if item_value == 0: self.item_left_label.setText('Show All') for j in range(len(self.Element)): tmp = raw.at[i, self.Element[j]] / standardchosen[self.Element[j]] self.data_to_norm.at[i, self.Element[j]] = tmp tmpflag = 1 a = 0 try: a = math.log(tmp, 10) except(ValueError): tmpflag = 0 pass if (tmpflag == 1): if (raw.at[i, 'Label'] in PointLabels or raw.at[i, 'Label'] == ''): self.WholeData.append(math.log(tmp, 10)) TmpLabel = '' else: PointLabels.append(raw.at[i, 'Label']) TmpLabel = raw.at[i, 'Label'] LinesY.append(a) LinesX.append(j + 1) self.axes.scatter(j + 1, math.log(tmp, 10), marker=raw.at[i, 'Marker'], s=raw.at[i, 'Size'], color=raw.at[i, 'Color'], alpha=raw.at[i, 'Alpha'], label=TmpLabel) self.axes.plot(LinesX, LinesY, color=raw.at[i, 'Color'], linewidth=raw.at[i, 'Width'], linestyle=raw.at[i, 'Style'], alpha=raw.at[i, 'Alpha']) if (self.show_data_index_cb.isChecked()): if 'Index' in self._df_back.columns.values: self.axes.annotate(self._df_back.at[i, 'Index'], xy=(LinesX[-1], LinesY[-1]), color=self._df.at[i, 'Color'], alpha=self._df.at[i, 'Alpha']) else: self.axes.annotate('No' + str(i + 1), xy=(LinesX[-1], LinesY[-1]), color=self._df.at[i, 'Color'], alpha=self._df.at[i, 'Alpha']) else: self.item_left_label.setText(self.AllLabel[item_value-1]) for j in range(len(self.Element)): tmp = raw.at[i, self.Element[j]] / standardchosen[self.Element[j]] self.data_to_norm.at[i, self.Element[j]] = tmp tmpflag = 1 a = 0 try: a = math.log(tmp, 10) except(ValueError): tmpflag = 0 pass if (tmpflag == 1): if (raw.at[i, 'Label'] in PointLabels or raw.at[i, 'Label'] == ''): TmpLabel = '' else: PointLabels.append(raw.at[i, 'Label']) TmpLabel = raw.at[i, 'Label'] alpha= raw.at[i, 'Alpha'] linewidth= raw.at[i, 'Width'] pointsize= raw.at[i, 'Size'] if raw.at[i, 'Label'] == self.AllLabel[item_value - 1]: LinesY.append(a) LinesX.append(j + 1) self.WholeData.append(math.log(tmp, 10)) self.axes.scatter(j + 1, math.log(tmp, 10), marker=raw.at[i, 'Marker'], s=pointsize, color=raw.at[i, 'Color'], alpha=alpha, label=TmpLabel) self.axes.plot(LinesX, LinesY, color=raw.at[i, 'Color'], linewidth=linewidth,linestyle=raw.at[i, 'Style'], alpha=alpha) print(LinesX,LinesY) if (self.show_data_index_cb.isChecked()): if len(LinesX) > 0 and len(LinesY) > 0: if 'Index' in self._df_back.columns.values: self.axes.annotate(self._df_back.at[i, 'Index'], xy=(LinesX[-1], LinesY[-1]), color=self._df.at[i, 'Color'], alpha=self._df.at[i, 'Alpha']) else: self.axes.annotate('No' + str(i + 1), xy=(LinesX[-1], LinesY[-1]), color=self._df.at[i, 'Color'], alpha=self._df.at[i, 'Alpha']) Tale = 0 Head = 0 if (len(self.WholeData) > 0): Tale = min(self.WholeData) Head = max(self.WholeData)+0.5 Location = round(Tale - (Head - Tale) / 5) count = round((Head - Tale) / 5 * 7) + 1 if (self.legend_cb.isChecked()): self.axes.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0, prop=fontprop) self.standard_right_label.setText(right_label_text) self.yticks = [Location+i for i in range(count)] self.yticklabels = [str(np.power(10.0, (Location + i))) for i in range(count)] self.axes.set_yticks(self.yticks) self.axes.set_yticklabels(self.yticklabels, fontsize=6) self.axes.set_xticks(self.xticks) self.axes.set_xticklabels(self.xticklabels, rotation=-45, fontsize=6) self.canvas.draw() self.OutPutTitle='REE' self.OutPutData = pd.DataFrame( {'Label': self.LabelList, 'Eu/Eu*(algebra)': self.algebraDeltaEuList, 'Eu/Eu*(square)': self.geometricDeltaEuList, 'Ce/Ce*(LaPr)': self.LaPrDeltaCeList, 'Ce/Ce*(LaNd)': self.LaNdDeltaCeList, '(La/Sm)N':self.LaSmList, '(La/Yb)N':self.LaYbList, '(Gd/Yb)N':self.GdYbList, 'trisection LREE': self.LREEList, 'trisection MREE': self.MREEList, 'trisection HREE': self.HREEList, 'bisection LREE': self.BinLREEList, 'bisection HREE': self.BinHREEList, 'LREE/HREE':self.L_HREEList, 'ALLREE': self.ALLREEList }) self.OutPutFig=self.fig
[ "def", "REE", "(", "self", ",", "Left", "=", "0", ",", "Right", "=", "16", ",", "X0", "=", "1", ",", "X1", "=", "15", ",", "X_Gap", "=", "15", ",", "Base", "=", "-", "1", ",", "Top", "=", "6", ",", "Y0", "=", "-", "1", ",", "Y1", "=", "3", ",", "Y_Gap", "=", "5", ",", "FontSize", "=", "12", ",", "xLabel", "=", "r'$REE-Standardlized-Pattern$'", ",", "yLabel", "=", "''", ",", "width", "=", "12", ",", "height", "=", "12", ",", "dpi", "=", "300", ")", ":", "self", ".", "axes", ".", "clear", "(", ")", "self", ".", "axes", ".", "spines", "[", "'right'", "]", ".", "set_color", "(", "'none'", ")", "self", ".", "axes", ".", "spines", "[", "'top'", "]", ".", "set_color", "(", "'none'", ")", "self", ".", "WholeData", "=", "[", "]", "self", ".", "OutPutData", "=", "pd", ".", "DataFrame", "(", ")", "self", ".", "LabelList", "=", "[", "]", "self", ".", "algebraDeltaEuList", "=", "[", "]", "self", ".", "geometricDeltaEuList", "=", "[", "]", "self", ".", "LaPrDeltaCeList", "=", "[", "]", "self", ".", "LaNdDeltaCeList", "=", "[", "]", "self", ".", "LaSmList", "=", "[", "]", "self", ".", "LaYbList", "=", "[", "]", "self", ".", "GdYbList", "=", "[", "]", "self", ".", "LREEList", "=", "[", "]", "self", ".", "MREEList", "=", "[", "]", "self", ".", "HREEList", "=", "[", "]", "self", ".", "ALLREEList", "=", "[", "]", "self", ".", "BinHREEList", "=", "[", "]", "self", ".", "BinLREEList", "=", "[", "]", "self", ".", "L_HREEList", "=", "[", "]", "self", ".", "AllAlpha", "=", "[", "]", "self", ".", "AllWidth", "=", "[", "]", "self", ".", "AllSize", "=", "[", "]", "#raw = self._df", "raw", "=", "self", ".", "CleanDataFile", "(", "self", ".", "_df", ")", "self", ".", "FontSize", "=", "FontSize", "PointLabels", "=", "[", "]", "k", "=", "0", "slider_value", "=", "int", "(", "self", ".", "standard_slider", ".", "value", "(", ")", ")", "item_value", "=", "int", "(", "self", ".", "item_slider", ".", "value", "(", ")", ")", "if", "slider_value", "<", "len", "(", "self", ".", "StandardsName", ")", ":", "standardnamechosen", "=", "self", ".", "StandardsName", "[", "slider_value", "]", "standardchosen", "=", "self", ".", "Standards", "[", "standardnamechosen", "]", "self", ".", "textbox", ".", "setText", "(", "self", ".", "reference", "+", "\"\\nStandard Chosen: \"", "+", "self", ".", "StandardsName", "[", "slider_value", "]", ")", "right_label_text", "=", "self", ".", "StandardsName", "[", "slider_value", "]", "elif", "len", "(", "self", ".", "_given_Standard", ")", "<=", "0", ":", "standardnamechosen", "=", "self", ".", "StandardsName", "[", "slider_value", "-", "1", "]", "standardchosen", "=", "self", ".", "Standards", "[", "standardnamechosen", "]", "self", ".", "textbox", ".", "setText", "(", "self", ".", "reference", "+", "\"\\nStandard Chosen: \"", "+", "self", ".", "StandardsName", "[", "slider_value", "-", "1", "]", ")", "right_label_text", "=", "self", ".", "StandardsName", "[", "slider_value", "-", "1", "]", "else", ":", "standardchosen", "=", "self", ".", "_given_Standard", "self", ".", "textbox", ".", "setText", "(", "self", ".", "reference", "+", "\"\\n You are using Self Defined Standard\"", ")", "right_label_text", "=", "\"Self Defined Standard\"", "for", "i", "in", "range", "(", "len", "(", "raw", ")", ")", ":", "# raw.at[i, 'DataType'] == 'User' or raw.at[i, 'DataType'] == 'user' or raw.at[i, 'DataType'] == 'USER'", "TmpLabel", "=", "''", "LinesX", "=", "[", "]", "LinesY", "=", "[", "]", "TmpEu", "=", "raw", ".", "at", "[", "i", ",", "'Eu'", "]", "/", "standardchosen", "[", "'Eu'", "]", "TmpSm", "=", "raw", ".", "at", "[", "i", ",", "'Sm'", "]", "/", "standardchosen", "[", "'Sm'", "]", "TmpGd", "=", "raw", ".", "at", "[", "i", ",", "'Gd'", "]", "/", "standardchosen", "[", "'Gd'", "]", "TmpCe", "=", "raw", ".", "at", "[", "i", ",", "'Ce'", "]", "/", "standardchosen", "[", "'Ce'", "]", "TmpLa", "=", "raw", ".", "at", "[", "i", ",", "'La'", "]", "/", "standardchosen", "[", "'La'", "]", "TmpPr", "=", "raw", ".", "at", "[", "i", ",", "'Pr'", "]", "/", "standardchosen", "[", "'Pr'", "]", "TmpNd", "=", "raw", ".", "at", "[", "i", ",", "'Nd'", "]", "/", "standardchosen", "[", "'Nd'", "]", "TmpYb", "=", "raw", ".", "at", "[", "i", ",", "'Yb'", "]", "/", "standardchosen", "[", "'Yb'", "]", "algebraEu", "=", "2", "*", "TmpEu", "/", "(", "TmpSm", "+", "TmpGd", ")", "geometricEu", "=", "TmpEu", "/", "np", ".", "power", "(", "(", "TmpSm", "*", "TmpGd", ")", ",", "0.5", ")", "firstCe", "=", "2", "*", "TmpCe", "/", "(", "TmpLa", "+", "TmpPr", ")", "secondCe", "=", "3", "*", "TmpCe", "/", "(", "2", "*", "TmpLa", "+", "TmpNd", ")", "LaYb", "=", "TmpLa", "/", "TmpYb", "LaSm", "=", "TmpLa", "/", "TmpSm", "GdYb", "=", "TmpGd", "/", "TmpYb", "tmpLREEResult", "=", "0", "tmpMREEResult", "=", "0", "tmpHREEResult", "=", "0", "tmpWholeResult", "=", "0", "tmpBinLREE", "=", "0", "tmpBinHREE", "=", "0", "for", "j", "in", "self", ".", "Element", ":", "if", "j", "in", "self", ".", "LREE", ":", "tmpLREEResult", "+=", "raw", ".", "at", "[", "i", ",", "j", "]", "elif", "j", "in", "self", ".", "MREE", ":", "tmpMREEResult", "+=", "raw", ".", "at", "[", "i", ",", "j", "]", "elif", "j", "in", "self", ".", "HREE", ":", "tmpHREEResult", "+=", "raw", ".", "at", "[", "i", ",", "j", "]", "if", "j", "in", "self", ".", "BinLREE", ":", "tmpBinLREE", "+=", "raw", ".", "at", "[", "i", ",", "j", "]", "elif", "j", "in", "self", ".", "BinHREE", ":", "tmpBinHREE", "+=", "raw", ".", "at", "[", "i", ",", "j", "]", "tmpWholeResult", "+=", "raw", ".", "at", "[", "i", ",", "j", "]", "self", ".", "LabelList", ".", "append", "(", "raw", ".", "at", "[", "i", ",", "'Label'", "]", ")", "self", ".", "algebraDeltaEuList", ".", "append", "(", "algebraEu", ")", "self", ".", "geometricDeltaEuList", ".", "append", "(", "geometricEu", ")", "self", ".", "LaPrDeltaCeList", ".", "append", "(", "firstCe", ")", "self", ".", "LaNdDeltaCeList", ".", "append", "(", "secondCe", ")", "self", ".", "LaSmList", ".", "append", "(", "LaSm", ")", "self", ".", "LaYbList", ".", "append", "(", "LaYb", ")", "self", ".", "GdYbList", ".", "append", "(", "GdYb", ")", "self", ".", "LREEList", ".", "append", "(", "tmpLREEResult", ")", "self", ".", "MREEList", ".", "append", "(", "tmpMREEResult", ")", "self", ".", "HREEList", ".", "append", "(", "tmpHREEResult", ")", "self", ".", "ALLREEList", ".", "append", "(", "tmpWholeResult", ")", "self", ".", "BinHREEList", ".", "append", "(", "tmpBinHREE", ")", "self", ".", "BinLREEList", ".", "append", "(", "tmpBinLREE", ")", "self", ".", "L_HREEList", ".", "append", "(", "tmpBinLREE", "/", "tmpBinHREE", ")", "'''\n for i in self.data_to_norm.columns.values.tolist():\n if i not in self.Element:\n self.data_to_norm = self.data_to_norm.drop(i, 1) \n '''", "Y_bottom", "=", "0", "Y_top", "=", "0", "for", "j", "in", "range", "(", "len", "(", "self", ".", "Element", ")", ")", ":", "tmp", "=", "raw", ".", "at", "[", "i", ",", "self", ".", "Element", "[", "j", "]", "]", "/", "standardchosen", "[", "self", ".", "Element", "[", "j", "]", "]", "self", ".", "data_to_norm", ".", "at", "[", "i", ",", "self", ".", "Element", "[", "j", "]", "]", "=", "tmp", "tmpflag", "=", "1", "a", "=", "0", "try", ":", "a", "=", "math", ".", "log", "(", "tmp", ",", "10", ")", "except", "(", "ValueError", ")", ":", "tmpflag", "=", "0", "pass", "if", "(", "tmpflag", "==", "1", ")", ":", "if", "Y_bottom", ">", "a", ":", "Y_bottom", "=", "a", "if", "Y_top", "<", "a", ":", "Y_top", "=", "a", "self", ".", "axes", ".", "set_ylim", "(", "Y_bottom", ",", "Y_top", "+", "1", ")", "if", "item_value", "==", "0", ":", "self", ".", "item_left_label", ".", "setText", "(", "'Show All'", ")", "for", "j", "in", "range", "(", "len", "(", "self", ".", "Element", ")", ")", ":", "tmp", "=", "raw", ".", "at", "[", "i", ",", "self", ".", "Element", "[", "j", "]", "]", "/", "standardchosen", "[", "self", ".", "Element", "[", "j", "]", "]", "self", ".", "data_to_norm", ".", "at", "[", "i", ",", "self", ".", "Element", "[", "j", "]", "]", "=", "tmp", "tmpflag", "=", "1", "a", "=", "0", "try", ":", "a", "=", "math", ".", "log", "(", "tmp", ",", "10", ")", "except", "(", "ValueError", ")", ":", "tmpflag", "=", "0", "pass", "if", "(", "tmpflag", "==", "1", ")", ":", "if", "(", "raw", ".", "at", "[", "i", ",", "'Label'", "]", "in", "PointLabels", "or", "raw", ".", "at", "[", "i", ",", "'Label'", "]", "==", "''", ")", ":", "self", ".", "WholeData", ".", "append", "(", "math", ".", "log", "(", "tmp", ",", "10", ")", ")", "TmpLabel", "=", "''", "else", ":", "PointLabels", ".", "append", "(", "raw", ".", "at", "[", "i", ",", "'Label'", "]", ")", "TmpLabel", "=", "raw", ".", "at", "[", "i", ",", "'Label'", "]", "LinesY", ".", "append", "(", "a", ")", "LinesX", ".", "append", "(", "j", "+", "1", ")", "self", ".", "axes", ".", "scatter", "(", "j", "+", "1", ",", "math", ".", "log", "(", "tmp", ",", "10", ")", ",", "marker", "=", "raw", ".", "at", "[", "i", ",", "'Marker'", "]", ",", "s", "=", "raw", ".", "at", "[", "i", ",", "'Size'", "]", ",", "color", "=", "raw", ".", "at", "[", "i", ",", "'Color'", "]", ",", "alpha", "=", "raw", ".", "at", "[", "i", ",", "'Alpha'", "]", ",", "label", "=", "TmpLabel", ")", "self", ".", "axes", ".", "plot", "(", "LinesX", ",", "LinesY", ",", "color", "=", "raw", ".", "at", "[", "i", ",", "'Color'", "]", ",", "linewidth", "=", "raw", ".", "at", "[", "i", ",", "'Width'", "]", ",", "linestyle", "=", "raw", ".", "at", "[", "i", ",", "'Style'", "]", ",", "alpha", "=", "raw", ".", "at", "[", "i", ",", "'Alpha'", "]", ")", "if", "(", "self", ".", "show_data_index_cb", ".", "isChecked", "(", ")", ")", ":", "if", "'Index'", "in", "self", ".", "_df_back", ".", "columns", ".", "values", ":", "self", ".", "axes", ".", "annotate", "(", "self", ".", "_df_back", ".", "at", "[", "i", ",", "'Index'", "]", ",", "xy", "=", "(", "LinesX", "[", "-", "1", "]", ",", "LinesY", "[", "-", "1", "]", ")", ",", "color", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Color'", "]", ",", "alpha", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Alpha'", "]", ")", "else", ":", "self", ".", "axes", ".", "annotate", "(", "'No'", "+", "str", "(", "i", "+", "1", ")", ",", "xy", "=", "(", "LinesX", "[", "-", "1", "]", ",", "LinesY", "[", "-", "1", "]", ")", ",", "color", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Color'", "]", ",", "alpha", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Alpha'", "]", ")", "else", ":", "self", ".", "item_left_label", ".", "setText", "(", "self", ".", "AllLabel", "[", "item_value", "-", "1", "]", ")", "for", "j", "in", "range", "(", "len", "(", "self", ".", "Element", ")", ")", ":", "tmp", "=", "raw", ".", "at", "[", "i", ",", "self", ".", "Element", "[", "j", "]", "]", "/", "standardchosen", "[", "self", ".", "Element", "[", "j", "]", "]", "self", ".", "data_to_norm", ".", "at", "[", "i", ",", "self", ".", "Element", "[", "j", "]", "]", "=", "tmp", "tmpflag", "=", "1", "a", "=", "0", "try", ":", "a", "=", "math", ".", "log", "(", "tmp", ",", "10", ")", "except", "(", "ValueError", ")", ":", "tmpflag", "=", "0", "pass", "if", "(", "tmpflag", "==", "1", ")", ":", "if", "(", "raw", ".", "at", "[", "i", ",", "'Label'", "]", "in", "PointLabels", "or", "raw", ".", "at", "[", "i", ",", "'Label'", "]", "==", "''", ")", ":", "TmpLabel", "=", "''", "else", ":", "PointLabels", ".", "append", "(", "raw", ".", "at", "[", "i", ",", "'Label'", "]", ")", "TmpLabel", "=", "raw", ".", "at", "[", "i", ",", "'Label'", "]", "alpha", "=", "raw", ".", "at", "[", "i", ",", "'Alpha'", "]", "linewidth", "=", "raw", ".", "at", "[", "i", ",", "'Width'", "]", "pointsize", "=", "raw", ".", "at", "[", "i", ",", "'Size'", "]", "if", "raw", ".", "at", "[", "i", ",", "'Label'", "]", "==", "self", ".", "AllLabel", "[", "item_value", "-", "1", "]", ":", "LinesY", ".", "append", "(", "a", ")", "LinesX", ".", "append", "(", "j", "+", "1", ")", "self", ".", "WholeData", ".", "append", "(", "math", ".", "log", "(", "tmp", ",", "10", ")", ")", "self", ".", "axes", ".", "scatter", "(", "j", "+", "1", ",", "math", ".", "log", "(", "tmp", ",", "10", ")", ",", "marker", "=", "raw", ".", "at", "[", "i", ",", "'Marker'", "]", ",", "s", "=", "pointsize", ",", "color", "=", "raw", ".", "at", "[", "i", ",", "'Color'", "]", ",", "alpha", "=", "alpha", ",", "label", "=", "TmpLabel", ")", "self", ".", "axes", ".", "plot", "(", "LinesX", ",", "LinesY", ",", "color", "=", "raw", ".", "at", "[", "i", ",", "'Color'", "]", ",", "linewidth", "=", "linewidth", ",", "linestyle", "=", "raw", ".", "at", "[", "i", ",", "'Style'", "]", ",", "alpha", "=", "alpha", ")", "print", "(", "LinesX", ",", "LinesY", ")", "if", "(", "self", ".", "show_data_index_cb", ".", "isChecked", "(", ")", ")", ":", "if", "len", "(", "LinesX", ")", ">", "0", "and", "len", "(", "LinesY", ")", ">", "0", ":", "if", "'Index'", "in", "self", ".", "_df_back", ".", "columns", ".", "values", ":", "self", ".", "axes", ".", "annotate", "(", "self", ".", "_df_back", ".", "at", "[", "i", ",", "'Index'", "]", ",", "xy", "=", "(", "LinesX", "[", "-", "1", "]", ",", "LinesY", "[", "-", "1", "]", ")", ",", "color", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Color'", "]", ",", "alpha", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Alpha'", "]", ")", "else", ":", "self", ".", "axes", ".", "annotate", "(", "'No'", "+", "str", "(", "i", "+", "1", ")", ",", "xy", "=", "(", "LinesX", "[", "-", "1", "]", ",", "LinesY", "[", "-", "1", "]", ")", ",", "color", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Color'", "]", ",", "alpha", "=", "self", ".", "_df", ".", "at", "[", "i", ",", "'Alpha'", "]", ")", "Tale", "=", "0", "Head", "=", "0", "if", "(", "len", "(", "self", ".", "WholeData", ")", ">", "0", ")", ":", "Tale", "=", "min", "(", "self", ".", "WholeData", ")", "Head", "=", "max", "(", "self", ".", "WholeData", ")", "+", "0.5", "Location", "=", "round", "(", "Tale", "-", "(", "Head", "-", "Tale", ")", "/", "5", ")", "count", "=", "round", "(", "(", "Head", "-", "Tale", ")", "/", "5", "*", "7", ")", "+", "1", "if", "(", "self", ".", "legend_cb", ".", "isChecked", "(", ")", ")", ":", "self", ".", "axes", ".", "legend", "(", "bbox_to_anchor", "=", "(", "1.05", ",", "1", ")", ",", "loc", "=", "2", ",", "borderaxespad", "=", "0", ",", "prop", "=", "fontprop", ")", "self", ".", "standard_right_label", ".", "setText", "(", "right_label_text", ")", "self", ".", "yticks", "=", "[", "Location", "+", "i", "for", "i", "in", "range", "(", "count", ")", "]", "self", ".", "yticklabels", "=", "[", "str", "(", "np", ".", "power", "(", "10.0", ",", "(", "Location", "+", "i", ")", ")", ")", "for", "i", "in", "range", "(", "count", ")", "]", "self", ".", "axes", ".", "set_yticks", "(", "self", ".", "yticks", ")", "self", ".", "axes", ".", "set_yticklabels", "(", "self", ".", "yticklabels", ",", "fontsize", "=", "6", ")", "#self.axes.set_yscale('log')", "self", ".", "axes", ".", "set_xticks", "(", "self", ".", "xticks", ")", "self", ".", "axes", ".", "set_xticklabels", "(", "self", ".", "xticklabels", ",", "rotation", "=", "-", "45", ",", "fontsize", "=", "6", ")", "self", ".", "canvas", ".", "draw", "(", ")", "self", ".", "OutPutTitle", "=", "'REE'", "#print(len(self.algebraDeltaEuList))", "self", ".", "OutPutData", "=", "pd", ".", "DataFrame", "(", "{", "'Label'", ":", "self", ".", "LabelList", ",", "'Eu/Eu*(algebra)'", ":", "self", ".", "algebraDeltaEuList", ",", "'Eu/Eu*(square)'", ":", "self", ".", "geometricDeltaEuList", ",", "'Ce/Ce*(LaPr)'", ":", "self", ".", "LaPrDeltaCeList", ",", "'Ce/Ce*(LaNd)'", ":", "self", ".", "LaNdDeltaCeList", ",", "'(La/Sm)N'", ":", "self", ".", "LaSmList", ",", "'(La/Yb)N'", ":", "self", ".", "LaYbList", ",", "'(Gd/Yb)N'", ":", "self", ".", "GdYbList", ",", "'trisection LREE'", ":", "self", ".", "LREEList", ",", "'trisection MREE'", ":", "self", ".", "MREEList", ",", "'trisection HREE'", ":", "self", ".", "HREEList", ",", "'bisection LREE'", ":", "self", ".", "BinLREEList", ",", "'bisection HREE'", ":", "self", ".", "BinHREEList", ",", "'LREE/HREE'", ":", "self", ".", "L_HREEList", ",", "'ALLREE'", ":", "self", ".", "ALLREEList", "}", ")", "#print('middle ',len(self.OutPutData['Eu/Eu*(algebra)']))", "self", ".", "OutPutFig", "=", "self", ".", "fig" ]
self.LaPrDeltaCeList.append(firstCe) self.LaNdDeltaCeList.append(secondCe)
[ "self", ".", "LaPrDeltaCeList", ".", "append", "(", "firstCe", ")", "self", ".", "LaNdDeltaCeList", ".", "append", "(", "secondCe", ")" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/REE.py#L252-L584
GeoPyTool/GeoPyTool
geopytool/NewCIPW.py
CIPW.create_main_frame
def create_main_frame(self): self.resize(800, 600) self.main_frame = QWidget() self.dpi = 128 self.save_button = QPushButton('&Save Result') self.save_button.clicked.connect(self.saveResult) self.qapf_button = QPushButton('&QAPF') self.qapf_button.clicked.connect(self.QAPF) ''' self.tableView = CustomQTableView(self.main_frame) self.tableView.setObjectName('tableView') self.tableView.setSortingEnabled(True) ''' self.tableViewMole = CustomQTableView(self.main_frame) self.tableViewMole.setObjectName('tableViewMole') self.tableViewMole.setSortingEnabled(True) self.tableViewWeight = CustomQTableView(self.main_frame) self.tableViewWeight.setObjectName('tableViewWeight') self.tableViewWeight.setSortingEnabled(True) self.tableViewVolume = CustomQTableView(self.main_frame) self.tableViewVolume.setObjectName('tableViewVolume') self.tableViewVolume.setSortingEnabled(True) self.tableViewCalced = CustomQTableView(self.main_frame) self.tableViewCalced.setObjectName('tableViewCalced') self.tableViewCalced.setSortingEnabled(True) # # Layout with box sizers # self.hbox = QHBoxLayout() for w in [self.qapf_button]: self.hbox.addWidget(w) self.hbox.setAlignment(w, Qt.AlignVCenter) self.vbox = QVBoxLayout() self.vbox.addWidget(self.tableViewMole) self.vbox.addWidget(self.tableViewWeight) self.vbox.addWidget(self.tableViewVolume) self.vbox.addWidget(self.tableViewCalced) self.vbox.addWidget(self.save_button) self.vbox.addLayout(self.hbox) self.main_frame.setLayout(self.vbox) self.setCentralWidget(self.main_frame)
python
def create_main_frame(self): self.resize(800, 600) self.main_frame = QWidget() self.dpi = 128 self.save_button = QPushButton('&Save Result') self.save_button.clicked.connect(self.saveResult) self.qapf_button = QPushButton('&QAPF') self.qapf_button.clicked.connect(self.QAPF) self.tableViewMole = CustomQTableView(self.main_frame) self.tableViewMole.setObjectName('tableViewMole') self.tableViewMole.setSortingEnabled(True) self.tableViewWeight = CustomQTableView(self.main_frame) self.tableViewWeight.setObjectName('tableViewWeight') self.tableViewWeight.setSortingEnabled(True) self.tableViewVolume = CustomQTableView(self.main_frame) self.tableViewVolume.setObjectName('tableViewVolume') self.tableViewVolume.setSortingEnabled(True) self.tableViewCalced = CustomQTableView(self.main_frame) self.tableViewCalced.setObjectName('tableViewCalced') self.tableViewCalced.setSortingEnabled(True) self.hbox = QHBoxLayout() for w in [self.qapf_button]: self.hbox.addWidget(w) self.hbox.setAlignment(w, Qt.AlignVCenter) self.vbox = QVBoxLayout() self.vbox.addWidget(self.tableViewMole) self.vbox.addWidget(self.tableViewWeight) self.vbox.addWidget(self.tableViewVolume) self.vbox.addWidget(self.tableViewCalced) self.vbox.addWidget(self.save_button) self.vbox.addLayout(self.hbox) self.main_frame.setLayout(self.vbox) self.setCentralWidget(self.main_frame)
[ "def", "create_main_frame", "(", "self", ")", ":", "self", ".", "resize", "(", "800", ",", "600", ")", "self", ".", "main_frame", "=", "QWidget", "(", ")", "self", ".", "dpi", "=", "128", "self", ".", "save_button", "=", "QPushButton", "(", "'&Save Result'", ")", "self", ".", "save_button", ".", "clicked", ".", "connect", "(", "self", ".", "saveResult", ")", "self", ".", "qapf_button", "=", "QPushButton", "(", "'&QAPF'", ")", "self", ".", "qapf_button", ".", "clicked", ".", "connect", "(", "self", ".", "QAPF", ")", "self", ".", "tableViewMole", "=", "CustomQTableView", "(", "self", ".", "main_frame", ")", "self", ".", "tableViewMole", ".", "setObjectName", "(", "'tableViewMole'", ")", "self", ".", "tableViewMole", ".", "setSortingEnabled", "(", "True", ")", "self", ".", "tableViewWeight", "=", "CustomQTableView", "(", "self", ".", "main_frame", ")", "self", ".", "tableViewWeight", ".", "setObjectName", "(", "'tableViewWeight'", ")", "self", ".", "tableViewWeight", ".", "setSortingEnabled", "(", "True", ")", "self", ".", "tableViewVolume", "=", "CustomQTableView", "(", "self", ".", "main_frame", ")", "self", ".", "tableViewVolume", ".", "setObjectName", "(", "'tableViewVolume'", ")", "self", ".", "tableViewVolume", ".", "setSortingEnabled", "(", "True", ")", "self", ".", "tableViewCalced", "=", "CustomQTableView", "(", "self", ".", "main_frame", ")", "self", ".", "tableViewCalced", ".", "setObjectName", "(", "'tableViewCalced'", ")", "self", ".", "tableViewCalced", ".", "setSortingEnabled", "(", "True", ")", "#", "# Layout with box sizers", "#", "self", ".", "hbox", "=", "QHBoxLayout", "(", ")", "for", "w", "in", "[", "self", ".", "qapf_button", "]", ":", "self", ".", "hbox", ".", "addWidget", "(", "w", ")", "self", ".", "hbox", ".", "setAlignment", "(", "w", ",", "Qt", ".", "AlignVCenter", ")", "self", ".", "vbox", "=", "QVBoxLayout", "(", ")", "self", ".", "vbox", ".", "addWidget", "(", "self", ".", "tableViewMole", ")", "self", ".", "vbox", ".", "addWidget", "(", "self", ".", "tableViewWeight", ")", "self", ".", "vbox", ".", "addWidget", "(", "self", ".", "tableViewVolume", ")", "self", ".", "vbox", ".", "addWidget", "(", "self", ".", "tableViewCalced", ")", "self", ".", "vbox", ".", "addWidget", "(", "self", ".", "save_button", ")", "self", ".", "vbox", ".", "addLayout", "(", "self", ".", "hbox", ")", "self", ".", "main_frame", ".", "setLayout", "(", "self", ".", "vbox", ")", "self", ".", "setCentralWidget", "(", "self", ".", "main_frame", ")" ]
self.tableView = CustomQTableView(self.main_frame) self.tableView.setObjectName('tableView') self.tableView.setSortingEnabled(True)
[ "self", ".", "tableView", "=", "CustomQTableView", "(", "self", ".", "main_frame", ")", "self", ".", "tableView", ".", "setObjectName", "(", "tableView", ")", "self", ".", "tableView", ".", "setSortingEnabled", "(", "True", ")" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/NewCIPW.py#L162-L221
GeoPyTool/GeoPyTool
geopytool/NewCIPW.py
CIPW.singleCalc
def singleCalc(self, m={'Al2O3': 13.01, 'Alpha': 0.6, 'Ba': 188.0, 'Be': 0.85, 'CaO': 8.35, 'Ce': 28.2, 'Co': 45.2, 'Cr': 117.0, 'Cs': 0.83, 'Cu': 53.5, 'Dy': 5.58, 'Er': 2.96, 'Eu': 1.79, 'Fe2O3': 14.47, 'FeO': 5.51, 'Ga': 19.4, 'Gd': 5.24, 'Hf': 3.38, 'Ho': 1.1, 'K2O': 0.72, 'LOI': 5.05, 'La': 11.4, 'Label': 'ZhangSH2016', 'Li': 15.0, 'Lu': 0.39, 'Mg#': 41.9, 'MgO': 5.26, 'MnO': 0.21, 'Na2O': 1.88, 'Nb': 12.6, 'Nd': 18.4, 'Ni': 69.4, 'P2O5': 0.23, 'Pb': 3.17, 'Pr': 3.95, 'Rb': 18.4, 'Sc': 37.4, 'SiO2': 48.17, 'Size': 10, 'Sm': 5.08, 'Sr': 357, 'Ta': 0.77, 'Tb': 0.88, 'Th': 1.85, 'TiO2': 2.56, 'Tl': 0.06, 'Tm': 0.44, 'Total': 99.91, 'U': 0.41, 'V': 368.0, 'Y': 29.7, 'Yb': 2.68, 'Zn': 100.0, 'Zr': 130.0, }): DataResult={} DataWeight={} DataVolume={} DataCalced={} DataResult.update({'Label': m['Label']}) DataWeight.update({'Label': m['Label']}) DataVolume.update({'Label': m['Label']}) DataCalced.update({'Label': m['Label']}) DataResult.update({'Width': m['Width']}) DataWeight.update({'Width': m['Width']}) DataVolume.update({'Width': m['Width']}) DataCalced.update({'Width': m['Width']}) DataResult.update({'Style': m['Style']}) DataWeight.update({'Style': m['Style']}) DataVolume.update({'Style': m['Style']}) DataCalced.update({'Style': m['Style']}) DataResult.update({'Alpha': m['Alpha']}) DataWeight.update({'Alpha': m['Alpha']}) DataVolume.update({'Alpha': m['Alpha']}) DataCalced.update({'Alpha': m['Alpha']}) DataResult.update({'Size': m['Size']}) DataWeight.update({'Size': m['Size']}) DataVolume.update({'Size': m['Size']}) DataCalced.update({'Size': m['Size']}) DataResult.update({'Color': m['Color']}) DataWeight.update({'Color': m['Color']}) DataVolume.update({'Color': m['Color']}) DataCalced.update({'Color': m['Color']}) DataResult.update({'Marker': m['Marker']}) DataWeight.update({'Marker': m['Marker']}) DataVolume.update({'Marker': m['Marker']}) DataCalced.update({'Marker': m['Marker']}) WholeMass = 0 EachMole = {} for j in self.Elements: ''' Get the Whole Mole of the dataset ''' try: T_TMP = m[j] except(KeyError): T_TMP = 0 if j == 'Sr': TMP = T_TMP / (87.62 / 103.619 * 10000) elif j == 'Ba': TMP = T_TMP / (137.327 / 153.326 * 10000) elif j == 'Ni': TMP = T_TMP / (58.6934 / 74.69239999999999 * 10000) elif j == 'Cr': TMP = T_TMP / ((2 * 51.9961) / 151.98919999999998 * 10000) elif j == 'Zr': # Zr Multi 2 here TMP = T_TMP / ((2 * 91.224) / 123.22200000000001 * 10000) else: TMP = T_TMP V = TMP try: WholeMass += float(V) except ValueError: pass WeightCorrectionFactor = (100 / WholeMass) for j in self.Elements: ''' Get the Mole percentage of each element ''' try: T_TMP = m[j] except(KeyError): T_TMP = 0 if j == 'Sr': TMP = T_TMP / (87.62 / 103.619 * 10000) elif j == 'Ba': TMP = T_TMP / (137.327 / 153.326 * 10000) elif j == 'Ni': TMP = T_TMP / (58.6934 / 74.69239999999999 * 10000) elif j == 'Cr': TMP = T_TMP / ((2 * 51.9961) / 151.98919999999998 * 10000) elif j == 'Zr': # Zr not Multiple by 2 Here TMP = T_TMP / ((91.224) / 123.22200000000001 * 10000) else: TMP = T_TMP try: M = TMP / self.BaseMass[j] * WeightCorrectionFactor except TypeError: pass # M= TMP/NewMass(j) * WeightCorrectionFactor EachMole.update({j: M}) # self.DataMole.append(EachMole) DataCalculating = EachMole Fe3 = DataCalculating['Fe2O3'] Fe2 = DataCalculating['FeO'] Mg = DataCalculating['MgO'] Ca = DataCalculating['CaO'] Na = DataCalculating['Na2O'] try: DataCalced.update({'Fe3+/(Total Fe) in rock (Mole)': 100 * Fe3 * 2 / (Fe3 * 2 + Fe2)}) except(ZeroDivisionError): DataCalced.update({'Fe3+/(Total Fe) in rock (Mole)': 0}) pass try: DataCalced.update({'Mg/(Mg+Total Fe) in rock (Mole)': 100 * Mg / (Mg + Fe3 * 2 + Fe2)}) except(ZeroDivisionError): DataCalced.update({'Mg/(Mg+Total Fe) in rock (Mole)': 0}) pass try: DataCalced.update({'Mg/(Mg+Fe2+) in rock (Mole)': 100 * Mg / (Mg + Fe2)}) except(ZeroDivisionError): DataCalced.update({'Mg/(Mg+Fe2+) in rock (Mole)': 0}) pass try: DataCalced.update({'Ca/(Ca+Na) in rock (Mole)': 100 * Ca / (Ca + Na * 2)}) except(ZeroDivisionError): DataCalced.update({'Ca/(Ca+Na) in rock (Mole)': 0}) pass DataCalculating['CaO'] += DataCalculating['Sr'] DataCalculating['Sr'] = 0 DataCalculating['K2O'] += 2 * DataCalculating['Ba'] DataCalculating['Ba'] = 0 try: if DataCalculating['CaO'] >= 10 / 3 * DataCalculating['P2O5']: DataCalculating['CaO'] -= 10 / 3 * DataCalculating['P2O5'] else: DataCalculating['CaO'] = 0 except(ZeroDivisionError): pass DataCalculating['P2O5'] = DataCalculating['P2O5'] / 1.5 Apatite = DataCalculating['P2O5'] # IF(S19>=T15,S19-T15,0) if DataCalculating['F'] >= DataCalculating['P2O5']: DataCalculating['F'] -= DataCalculating['P2O5'] else: DataCalculating['F'] = 0 if DataCalculating['F'] >= DataCalculating['P2O5']: DataCalculating['F'] -= DataCalculating['P2O5'] else: DataCalculating['F'] = 0 if DataCalculating['Na2O'] >= DataCalculating['Cl']: DataCalculating['Na2O'] -= DataCalculating['Cl'] else: DataCalculating['Na2O'] = 0 Halite = DataCalculating['Cl'] # IF(U12>=(U19/2),U12-(U19/2),0) if DataCalculating['CaO'] >= 0.5 * DataCalculating['F']: DataCalculating['CaO'] -= 0.5 * DataCalculating['F'] else: DataCalculating['CaO'] = 0 DataCalculating['F'] *= 0.5 Fluorite = DataCalculating['F'] # =IF(V17>0,IF(V13>=V17,'Thenardite',IF(V13>0,'Both','Anhydrite')),'None') AorT = 0 if DataCalculating['SO3'] <= 0: AorT = 'None' else: if DataCalculating['Na2O'] >= DataCalculating['SO3']: AorT = 'Thenardite' else: if DataCalculating['Na2O'] > 0: AorT = 'Both' else: AorT = 'Anhydrite' # =IF(W26='Anhydrite',V17,IF(W26='Both',V12,0)) # =IF(W26='Thenardite',V17,IF(W26='Both',V17-W17,0)) if AorT == 'Anhydrite': DataCalculating['Sr'] = 0 elif AorT == 'Thenardite': DataCalculating['Sr'] = DataCalculating['SO3'] DataCalculating['SO3'] = 0 elif AorT == 'Both': DataCalculating['Sr'] = DataCalculating['SO3'] - DataCalculating['CaO'] DataCalculating['SO3'] = DataCalculating['CaO'] else: DataCalculating['SO3'] = 0 DataCalculating['Sr'] = 0 DataCalculating['CaO'] -= DataCalculating['SO3'] DataCalculating['Na2O'] -= DataCalculating['Sr'] Anhydrite = DataCalculating['SO3'] Thenardite = DataCalculating['Sr'] Pyrite = 0.5 * DataCalculating['S'] # =IF(W9>=(W18*0.5),W9-(W18*0.5),0) if DataCalculating['FeO'] >= DataCalculating['S'] * 0.5: DataCalculating['FeO'] -= DataCalculating['S'] * 0.5 else: DataCalculating['FeO'] = 0 # =IF(X24>0,IF(X9>=X24,'Chromite',IF(X9>0,'Both','Magnesiochromite')),'None') if DataCalculating['Cr'] > 0: if DataCalculating['FeO'] >= DataCalculating['Cr']: CorM = 'Chromite' elif DataCalculating['FeO'] > 0: CorM = 'Both' else: CorM = 'Magnesiochromite' else: CorM = 'None' # =IF(Y26='Chromite',X24,IF(Y26='Both',X9,0)) # =IF(Y26='Magnesiochromite',X24,IF(Y26='Both',X24-Y24,0)) if CorM == 'Chromite': DataCalculating['Cr'] = DataCalculating['Cr'] DataCalculating['Ni'] = 0 elif CorM == 'Magnesiochromite': DataCalculating['Ni'] = DataCalculating['Cr'] DataCalculating['Cr'] = 0 elif CorM == 'Both': DataCalculating['Ni'] = DataCalculating['Cr'] - DataCalculating['FeO'] DataCalculating['Cr'] = DataCalculating['FeO'] else: DataCalculating['Cr'] = 0 DataCalculating['Ni'] = 0 DataCalculating['MgO'] -= DataCalculating['Ni'] Magnesiochromite = DataCalculating['Ni'] Chromite = DataCalculating['Cr'] # =IF(X9>=Y24,X9-Y24,0) if DataCalculating['FeO'] >= DataCalculating['Cr']: DataCalculating['FeO'] -= DataCalculating['Cr'] else: DataCalculating['FeO'] = 0 # =IF(Y6>0,IF(Y9>=Y6,'Ilmenite',IF(Y9>0,'Both','Sphene')),'None') if DataCalculating['TiO2'] < 0: IorS = 'None' else: if DataCalculating['FeO'] >= DataCalculating['TiO2']: IorS = 'Ilmenite' else: if DataCalculating['FeO'] > 0: IorS = 'Both' else: IorS = 'Sphene' # =IF(Z26='Ilmenite',Y6,IF(Z26='Both',Y9,0)) # =IF(Z26='Sphene',Y6,IF(Z26='Both',Y6-Z6,0)) if IorS == 'Ilmenite': DataCalculating['TiO2'] = DataCalculating['TiO2'] DataCalculating['MnO'] = 0 elif IorS == 'Sphene': DataCalculating['MnO'] = DataCalculating['TiO2'] DataCalculating['TiO2'] = 0 elif IorS == 'Both': DataCalculating['MnO'] = DataCalculating['TiO2'] - DataCalculating['FeO'] DataCalculating['TiO2'] = DataCalculating['FeO'] else: DataCalculating['TiO2'] = 0 DataCalculating['MnO'] = 0 DataCalculating['FeO'] -= DataCalculating['TiO2'] Ilmenite = DataCalculating['TiO2'] # =IF(Z16>0,IF(Z12>=Z16,'Calcite',IF(Z12>0,'Both','Na2CO3')),'None') if DataCalculating['CO2'] <= 0: CorN = 'None' else: if DataCalculating['CaO'] >= DataCalculating['CO2']: CorN = 'Calcite' else: if DataCalculating['CaO'] > 0: CorN = 'Both' else: CorN = 'Na2CO3' # =IF(AA26='Calcite',Z16,IF(AA26='Both',Z12,0)) # =IF(AA26='Na2CO3',Z16,IF(AA26='Both',Z16-AA16,0)) if CorN == 'None': DataCalculating['CO2'] = 0 DataCalculating['SO3'] = 0 elif CorN == 'Calcite': DataCalculating['CO2'] = DataCalculating['CO2'] DataCalculating['SO3'] = 0 elif CorN == 'Na2CO3': DataCalculating['SO3'] = DataCalculating['SO3'] DataCalculating['CO2'] = 0 elif CorN == 'Both': DataCalculating['SO3'] = DataCalculating['CO2'] - DataCalculating['CaO'] DataCalculating['CO2'] = DataCalculating['CaO'] DataCalculating['CaO'] -= DataCalculating['CO2'] Calcite = DataCalculating['CO2'] Na2CO3 = DataCalculating['SO3'] # =IF(AA17>Z13,0,Z13-AA17) if DataCalculating['SO3'] > DataCalculating['Na2O']: DataCalculating['Na2O'] = 0 else: DataCalculating['Na2O'] -= DataCalculating['SO3'] DataCalculating['SiO2'] -= DataCalculating['Zr'] Zircon = DataCalculating['Zr'] # =IF(AB14>0,IF(AB7>=AB14,'Orthoclase',IF(AB7>0,'Both','K2SiO3')),'None') if DataCalculating['K2O'] <= 0: OorK = 'None' else: if DataCalculating['Al2O3'] >= DataCalculating['K2O']: OorK = 'Orthoclase' else: if DataCalculating['Al2O3'] > 0: OorK = 'Both' else: OorK = 'K2SiO3' # =IF(AC26='Orthoclase',AB14,IF(AC26='Both',AB7,0)) # =IF(AC26='K2SiO3',AB14,IF(AC26='Both',AB14-AB7,0)) if OorK == 'None': DataCalculating['K2O'] = 0 DataCalculating['P2O5'] = 0 elif OorK == 'Orthoclase': DataCalculating['K2O'] = DataCalculating['K2O'] DataCalculating['P2O5'] = 0 elif OorK == 'K2SiO3': DataCalculating['P2O5'] = DataCalculating['K2O'] DataCalculating['K2O'] = 0 elif OorK == 'Both': DataCalculating['P2O5'] = DataCalculating['K2O'] - DataCalculating['Al2O3'] DataCalculating['K2O'] = DataCalculating['Al2O3'] DataCalculating['Al2O3'] -= DataCalculating['K2O'] # =IF(AC13>0,IF(AC7>=AC13,'Albite',IF(AC7>0,'Both','Na2SiO3')),'None') if DataCalculating['Na2O'] <= 0: AorN = 'None' else: if DataCalculating['Al2O3'] >= DataCalculating['Na2O']: AorN = 'Albite' else: if DataCalculating['Al2O3'] > 0: AorN = 'Both' else: AorN = 'Na2SiO3' # =IF(AND(AC7>=AC13,AC7>0),AC7-AC13,0) if DataCalculating['Al2O3'] >= DataCalculating['Na2O'] and DataCalculating['Al2O3'] > 0: DataCalculating['Al2O3'] -= DataCalculating['Na2O'] else: DataCalculating['Al2O3'] = 0 # =IF(AD26='Albite',AC13,IF(AD26='Both',AC7,0)) # =IF(AD26='Na2SiO3',AC13,IF(AD26='Both',AC13-AD13,0)) if AorN == 'Albite': DataCalculating['Cl'] = 0 elif AorN == 'Both': DataCalculating['Cl'] = DataCalculating['Na2O'] - DataCalculating['Al2O3'] DataCalculating['Na2O'] = DataCalculating['Al2O3'] elif AorN == 'Na2SiO3': DataCalculating['Cl'] = DataCalculating['Na2O'] DataCalculating['Na2O'] = 0 elif AorN == 'None': DataCalculating['Na2O'] = 0 DataCalculating['Cl'] = 0 # =IF(AD7>0,IF(AD12>0,'Anorthite','None'),'None') ''' Seem like should be =IF(AD7>0,IF(AD12>AD7,'Anorthite','Corundum'),'None') If Al2O3 is left after alloting orthoclase and albite, then: Anorthite = Al2O3, CaO = CaO - Al2O3, SiO2 = SiO2 - 2 Al2O3, Al2O3 = 0 If Al2O3 exceeds CaO in the preceding calculation, then: Anorthite = CaO, Al2O3 = Al2O3 - CaO, SiO2 = SiO2 - 2 CaO Corundum = Al2O3, CaO =0, Al2O3 = 0 if DataCalculating['Al2O3']<=0: AorC='None' else: if DataCalculating['CaO']>DataCalculating['Al2O3']: AorC= 'Anorthite' else: Aorc='Corundum' ''' if DataCalculating['Al2O3'] <= 0: AorC = 'None' else: if DataCalculating['CaO'] > 0: AorC = 'Anorthite' else: Aorc = 'None' # =IF(AE26='Anorthite',IF(AD12>AD7,0,AD7-AD12),AD7) # =IF(AE26='Anorthite',IF(AD7>AD12,0,AD12-AD7),AD12) # =IF(AE26='Anorthite',IF(AD7>AD12,AD12,AD7),0) if AorC == 'Anorthite': if DataCalculating['Al2O3'] >= DataCalculating['CaO']: DataCalculating['Sr'] = DataCalculating['CaO'] DataCalculating['Al2O3'] -= DataCalculating['CaO'] DataCalculating['CaO'] = 0 else: DataCalculating['Sr'] = DataCalculating['Al2O3'] DataCalculating['CaO'] -= DataCalculating['Al2O3'] DataCalculating['Al2O3'] = 0 else: DataCalculating['Sr'] = 0 Corundum = DataCalculating['Al2O3'] Anorthite = DataCalculating['Sr'] # =IF(AE10>0,IF(AE12>=AE10,'Sphene',IF(AE12>0,'Both','Rutile')),'None') if DataCalculating['MnO'] <= 0: SorR = 'None' else: if DataCalculating['CaO'] >= DataCalculating['MnO']: SorR = 'Sphene' elif DataCalculating['CaO'] > 0: SorR = 'Both' else: SorR = 'Rutile' # =IF(AF26='Sphene',AE10,IF(AF26='Both',AE12,0)) # =IF(AF26='Rutile',AE10,IF(AF26='Both',AE10-AE12,0)) if SorR == 'Sphene': DataCalculating['MnO'] = DataCalculating['MnO'] DataCalculating['S'] = 0 elif SorR == 'Rutile': DataCalculating['S'] = DataCalculating['MnO'] DataCalculating['MnO'] = 0 elif SorR == 'Both': DataCalculating['S'] = DataCalculating['MnO'] - DataCalculating['CaO'] DataCalculating['MnO'] = DataCalculating['CaO'] elif SorR == 'None': DataCalculating['MnO'] = 0 DataCalculating['S'] = 0 DataCalculating['CaO'] -= DataCalculating['MnO'] Rutile = DataCalculating['S'] # =IF(AND(AF20>0),IF(AF8>=AF20,'Acmite',IF(AF8>0,'Both','Na2SiO3')),'None') if DataCalculating['Cl'] <= 0: ACorN = 'None' else: if DataCalculating['Fe2O3'] >= DataCalculating['Cl']: ACorN = 'Acmite' else: if DataCalculating['Fe2O3'] > 0: ACorN = 'Both' else: ACorN = 'Na2SiO3' # =IF(AG26='Acmite',AF20,IF(AG26='Both',AF8,0)) # =IF(AG26='Na2SiO3',AF20,IF(AG26='Both',AF20-AG19,0)) if ACorN == 'Acmite': DataCalculating['F'] = DataCalculating['Cl'] DataCalculating['Cl'] = 0 elif ACorN == 'Na2SiO3': DataCalculating['Cl'] = DataCalculating['Cl'] DataCalculating['F'] = 0 elif ACorN == 'Both': DataCalculating['F'] = DataCalculating['Fe2O3'] DataCalculating['Cl'] = DataCalculating['Cl'] - DataCalculating['F'] elif ACorN == 'None': DataCalculating['F'] = 0 DataCalculating['Cl'] = 0 DataCalculating['Fe2O3'] -= DataCalculating['F'] Acmite = DataCalculating['F'] # =IF(AG8>0,IF(AG9>=AG8,'Magnetite',IF(AG9>0,'Both','Hematite')),'None') if DataCalculating['Fe2O3'] <= 0: MorH = 'None' else: if DataCalculating['FeO'] >= DataCalculating['Fe2O3']: MorH = 'Magnetite' else: if DataCalculating['FeO'] > 0: MorH = 'Both' else: MorH = 'Hematite' # =IF(AH26='Magnetite',AG8,IF(AH26='Both',AG9,0)) # =IF(AH26='Hematite',AG8,IF(AH26='Both',AG8-AG9,0)) if MorH == 'Magnetite': DataCalculating['Fe2O3'] = DataCalculating['Fe2O3'] DataCalculating['Ba'] = 0 elif MorH == 'Hematite': DataCalculating['Fe2O3'] = 0 DataCalculating['Ba'] = DataCalculating['FeO'] elif MorH == 'Both': DataCalculating['Fe2O3'] = DataCalculating['FeO'] DataCalculating['Ba'] = DataCalculating['Fe2O3'] - DataCalculating['FeO'] elif MorH == 'None': DataCalculating['Fe2O3'] = 0 DataCalculating['Ba'] == 0 DataCalculating['FeO'] -= DataCalculating['Fe2O3'] Magnetite = DataCalculating['Fe2O3'] Hematite = DataCalculating['Ba'] # =IF(AH11>0,AH11/(AH11+AH9),0) Fe2 = DataCalculating['FeO'] Mg = DataCalculating['MgO'] if Mg > 0: DataCalced.update({'Mg/(Mg+Fe2+) in silicates': 100 * Mg / (Mg + Fe2)}) else: DataCalced.update({'Mg/(Mg+Fe2+) in silicates': 0}) DataCalculating['FeO'] += DataCalculating['MgO'] DataCalculating['MgO'] = 0 # =IF(AI12>0,IF(AI9>=AI12,'Diopside',IF(AI9>0,'Both','Wollastonite')),'None') if DataCalculating['CaO'] <= 0: DorW = 'None' else: if DataCalculating['FeO'] >= DataCalculating['CaO']: DorW = 'Diopside' else: if DataCalculating['FeO'] > 0: DorW = 'Both' else: DorW = 'Wollastonite' # =IF(AJ26='Diopside',AI12,IF(AJ26='Both',AI9,0)) # =IF(AJ26='Wollastonite',AI12,IF(AJ26='Both',AI12-AI9,0)) if DorW == 'Diopside': DataCalculating['CaO'] = DataCalculating['CaO'] DataCalculating['S'] = 0 elif DorW == 'Wollastonite': DataCalculating['S'] = DataCalculating['CaO'] DataCalculating['CaO'] = 0 elif DorW == 'Both': DataCalculating['S'] = DataCalculating['CaO'] - DataCalculating['FeO'] DataCalculating['CaO'] = DataCalculating['FeO'] elif DorW == 'None': DataCalculating['CaO'] = 0 DataCalculating['S'] = 0 DataCalculating['FeO'] -= DataCalculating['CaO'] Diopside = DataCalculating['CaO'] Quartz = DataCalculating['SiO2'] Zircon = DataCalculating['Zr'] K2SiO3 = DataCalculating['P2O5'] Na2SiO3 = DataCalculating['Cl'] Sphene = DataCalculating['MnO'] Hypersthene = DataCalculating['FeO'] Albite = DataCalculating['Na2O'] Orthoclase = DataCalculating['K2O'] Wollastonite = DataCalculating['S'] # =AJ5-(AL6)-(AL7)-(AL8*2)-(AL12)-(AL9)-(AL10*4)-(AL11*2)-(AL13)-(AL14*6)-(AL15*6)-(AL16) Quartz -= (Zircon + K2SiO3 + Anorthite * 2 + Na2SiO3 + Acmite * 4 + Diopside * 2 + Sphene + Hypersthene + Albite * 6 + Orthoclase * 6 + Wollastonite) # =IF(AL5>0,AL5,0) if Quartz > 0: Quartz = Quartz else: Quartz = 0 # =IF(AL13>0,IF(AL5>=0,'Hypersthene',IF(AL13+(2*AL5)>0,'Both','Olivine')),'None') if Hypersthene <= 0: HorO = 'None' else: if Quartz >= 0: HorO = 'Hypersthene' else: if Hypersthene + 2 * Quartz > 0: HorO = 'Both' else: HorO = 'Olivine' # =IF(AN26='Hypersthene',AL13,IF(AN26='Both',AL13+(2*AL5),0)) # =IF(AN26='Olivine',AL13*0.5,IF(AN26='Both',ABS(AL5),0)) Old_Hypersthene = Hypersthene if HorO == 'Hypersthene': Hypersthene = Hypersthene Olivine = 0 elif HorO == 'Both': Hypersthene = Hypersthene + Quartz * 2 Olivine = abs(Quartz) elif HorO == 'Olivine': Olivine = Hypersthene / 2 Hypersthene = 0 elif HorO == 'None': Hypersthene = 0 Olivine = 0 # =AL5+AL13-(AN13+AN17) Quartz += Old_Hypersthene - (Hypersthene + Olivine) # =IF(AL12>0,IF(AN5>=0,'Sphene',IF(AL12+AN5>0,'Both','Perovskite')),'None') if Sphene <= 0: SorP = 'None' else: if Quartz >= 0: SorP = 'Sphene' else: if Sphene + Quartz > 0: SorP = 'Both' else: SorP = 'Perovskite' # =IF(AO26='Sphene',AL12,IF(AO26='Both',AL12+AN5,0)) # =IF(AO26='Perovskite',AL12,IF(AO26='Both',AL12-AO12,0)) Old_Sphene = Sphene if SorP == 'Sphene': Sphene = Sphene Perovskite = 0 elif SorP == 'Perovskite': Perovskite = Sphene Sphene = 0 elif SorP == 'Both': Sphene += Quartz Perovskite = Old_Sphene - Sphene elif SorP == 'None': Sphene = 0 Perovskite = 0 Quartz += Old_Sphene - Sphene # =IF(AL14>0,IF(AO5>=0,'Albite',IF(AL14+(AO5/4)>0,'Both','Nepheline')),'None') if Albite <= 0: AlorNe = 'None' else: if Quartz >= 0: AlorNe = 'Albite' else: if Albite + (Quartz / 4) > 0: AlorNe = 'Both' else: AlorNe = 'Nepheline' # =AO5+(6*AL14)-(AP14*6)-(AP19*2) # =IF(AP26='Albite',AL14,IF(AP26='Both',AL14+(AO5/4),0)) # =IF(AP26='Nepheline',AL14,IF(AP26='Both',AL14-AP14,0)) Old_Albite = Albite if AlorNe == 'Albite': Albite = Albite Nepheline = 0 elif AlorNe == 'Nepheline': Nepheline = Albite Albite = 0 elif AlorNe == 'Both': Albite += Quartz / 4 Nepheline = Old_Albite - Albite elif AlorNe == 'None': Nepheline = 0 Albite = 0 Quartz += (6 * Old_Albite) - (Albite * 6) - (Nepheline * 2) # =IF(AL8=0,0,AL8/(AL8+(AP14*2))) if Anorthite == 0: DataCalced.update({'Plagioclase An content': 0}) else: DataCalced.update({'Plagioclase An content': 100 * Anorthite / (Anorthite + 2 * Albite)}) # =IF(AL15>0,IF(AP5>=0,'Orthoclase',IF(AL15+(AP5/2)>0,'Both','Leucite')),'None') if Orthoclase <= 0: OorL = 'None' else: if Quartz >= 0: OorL = 'Orthoclase' else: if Orthoclase + Quartz / 2 > 0: OorL = 'Both' else: OorL = 'Leucite' # =IF(AQ26='Orthoclase',AL15,IF(AQ26='Both',AL15+(AP5/2),0)) # =IF(AQ26='Leucite',AL15,IF(AQ26='Both',AL15-AQ15,0)) Old_Orthoclase = Orthoclase if OorL == 'Orthoclase': Orthoclase = Orthoclase Leucite = 0 elif OorL == 'Leucite': Leucite = Orthoclase Orthoclase = 0 elif OorL == 'Both': Orthoclase += Quartz / 2 Leucite = Old_Orthoclase - Orthoclase elif OorL == 'None': Orthoclase = 0 Leucite = 0 # =AP5+(AL15*6)-(AQ15*6)-(AQ20*4) Quartz += (Old_Orthoclase * 6) - (Orthoclase * 6) - (Leucite * 4) # =IF(AL16>0,IF(AQ5>=0,'Wollastonite',IF(AL16+(AQ5*2)>0,'Both','Larnite')),'None') if Wollastonite <= 0: WorB = 'None' else: if Quartz >= 0: WorB = 'Wollastonite' else: if Wollastonite + Quartz / 2 > 0: WorB = 'Both' else: WorB = 'Larnite' # =IF(AR26='Wollastonite',AL16,IF(AR26='Both',AL16+(2*AQ5),0)) # =IF(AR26='Larnite',AL16/2,IF(AR26='Both',(AL16-AR16)/2,0)) Old_Wollastonite = Wollastonite if WorB == 'Wollastonite': Wollastonite = Wollastonite Larnite = 0 elif WorB == 'Larnite': Larnite = Wollastonite / 2 Wollastonite = 0 elif WorB == 'Both': Wollastonite += Quartz * 2 Larnite = (Old_Wollastonite - Wollastonite) / 2 elif WorB == 'None': Wollastonite = 0 Larnite = 0 # =AQ5+AL16-AR16-AR21 Quartz += Old_Wollastonite - Wollastonite - Larnite # =IF(AL11>0,IF(AR5>=0,'Diopside',IF(AL11+AR5>0,'Both','LarniteOlivine')),'None') if Diopside <= 0: DorL = 'None' else: if Quartz >= 0: DorL = 'Diopside' else: if Diopside + Quartz > 0: DorL = 'Both' else: DorL = 'LarniteOlivine' # =IF(AS26='Diopside',AL11,IF(AS26='Both',AL11+AR5,0)) # =(IF(AS26='LarniteOlivine',AL11/2,IF(AS26='Both',(AL11-AS11)/2,0)))+AN17 # =(IF(AS26='LarniteOlivine',AL11/2,IF(AS26='Both',(AL11-AS11)/2,0)))+AR21 Old_Diopside = Diopside Old_Larnite = Larnite Old_Olivine = Olivine if DorL == 'Diopside': Diopside = Diopside elif DorL == 'LarniteOlivine': Larnite += Diopside / 2 Olivine += Diopside / 2 Diopside = 0 elif DorL == 'Both': Diopside += Quartz Larnite += Old_Diopside - Diopside Olivine += Old_Diopside - Diopside elif DorL == 'None': Diopside = 0 # =AR5+(AL11*2)+AN17+AR21-AS21-(AS11*2)-AS17 Quartz += (Old_Diopside * 2) + Old_Olivine + Old_Larnite - Larnite - (Diopside * 2) - Olivine # =IF(AQ20>0,IF(AS5>=0,'Leucite',IF(AQ20+(AS5/2)>0,'Both','Kalsilite')),'None') if Leucite <= 0: LorK = 'None' else: if Quartz >= 0: LorK = 'Leucite' else: if Leucite + Quartz / 2 > 0: LorK = 'Both' else: LorK = 'Kalsilite' # =IF(AT26='Leucite',AQ20,IF(AT26='Both',AQ20+(AS5/2),0)) # =IF(AT26='Kalsilite',AQ20,IF(AT26='Both',AQ20-AT20,0)) Old_Leucite = Leucite if LorK == 'Leucite': Leucite = Leucite Kalsilite = 0 elif LorK == 'Kalsilite': Kalsilite = Leucite Leucite = 0 elif LorK == 'Both': Leucite += Quartz / 2 Kalsilite = Old_Leucite - Leucite elif LorK == 'None': Leucite = 0 Kalsilite = 0 # =AS5+(AQ20*4)-(AT20*4)-(AT22*2) Quartz += Old_Leucite * 4 - Leucite * 4 - Kalsilite * 2 Q = Quartz A = Orthoclase P = Anorthite + Albite F = Nepheline + Leucite + Kalsilite DataResult.update({'Quartz': Quartz}) DataResult.update({'Zircon': Zircon}) DataResult.update({'K2SiO3': K2SiO3}) DataResult.update({'Anorthite': Anorthite}) DataResult.update({'Na2SiO3': Na2SiO3}) DataResult.update({'Acmite': Acmite}) DataResult.update({'Diopside': Diopside}) DataResult.update({'Sphene': Sphene}) DataResult.update({'Hypersthene': Hypersthene}) DataResult.update({'Albite': Albite}) DataResult.update({'Orthoclase': Orthoclase}) DataResult.update({'Wollastonite': Wollastonite}) DataResult.update({'Olivine': Olivine}) DataResult.update({'Perovskite': Perovskite}) DataResult.update({'Nepheline': Nepheline}) DataResult.update({'Leucite': Leucite}) DataResult.update({'Larnite': Larnite}) DataResult.update({'Kalsilite': Kalsilite}) DataResult.update({'Apatite': Apatite}) DataResult.update({'Halite': Halite}) DataResult.update({'Fluorite': Fluorite}) DataResult.update({'Anhydrite': Anhydrite}) DataResult.update({'Thenardite': Thenardite}) DataResult.update({'Pyrite': Pyrite}) DataResult.update({'Magnesiochromite': Magnesiochromite}) DataResult.update({'Chromite': Chromite}) DataResult.update({'Ilmenite': Ilmenite}) DataResult.update({'Calcite': Calcite}) DataResult.update({'Na2CO3': Na2CO3}) DataResult.update({'Corundum': Corundum}) DataResult.update({'Rutile': Rutile}) DataResult.update({'Magnetite': Magnetite}) DataResult.update({'Hematite': Hematite}) DataResult.update({'Q Mole': Q}) DataResult.update({'A Mole': A}) DataResult.update({'P Mole': P}) DataResult.update({'F Mole': F}) DataWeight.update({'Quartz': Quartz * self.DataBase['Quartz'][0]}) DataWeight.update({'Zircon': Zircon * self.DataBase['Zircon'][0]}) DataWeight.update({'K2SiO3': K2SiO3 * self.DataBase['K2SiO3'][0]}) DataWeight.update({'Anorthite': Anorthite * self.DataBase['Anorthite'][0]}) DataWeight.update({'Na2SiO3': Na2SiO3 * self.DataBase['Na2SiO3'][0]}) DataWeight.update({'Acmite': Acmite * self.DataBase['Acmite'][0]}) DataWeight.update({'Diopside': Diopside * self.DataBase['Diopside'][0]}) DataWeight.update({'Sphene': Sphene * self.DataBase['Sphene'][0]}) DataWeight.update({'Hypersthene': Hypersthene * self.DataBase['Hypersthene'][0]}) DataWeight.update({'Albite': Albite * self.DataBase['Albite'][0]}) DataWeight.update({'Orthoclase': Orthoclase * self.DataBase['Orthoclase'][0]}) DataWeight.update({'Wollastonite': Wollastonite * self.DataBase['Wollastonite'][0]}) DataWeight.update({'Olivine': Olivine * self.DataBase['Olivine'][0]}) DataWeight.update({'Perovskite': Perovskite * self.DataBase['Perovskite'][0]}) DataWeight.update({'Nepheline': Nepheline * self.DataBase['Nepheline'][0]}) DataWeight.update({'Leucite': Leucite * self.DataBase['Leucite'][0]}) DataWeight.update({'Larnite': Larnite * self.DataBase['Larnite'][0]}) DataWeight.update({'Kalsilite': Kalsilite * self.DataBase['Kalsilite'][0]}) DataWeight.update({'Apatite': Apatite * self.DataBase['Apatite'][0]}) DataWeight.update({'Halite': Halite * self.DataBase['Halite'][0]}) DataWeight.update({'Fluorite': Fluorite * self.DataBase['Fluorite'][0]}) DataWeight.update({'Anhydrite': Anhydrite * self.DataBase['Anhydrite'][0]}) DataWeight.update({'Thenardite': Thenardite * self.DataBase['Thenardite'][0]}) DataWeight.update({'Pyrite': Pyrite * self.DataBase['Pyrite'][0]}) DataWeight.update({'Magnesiochromite': Magnesiochromite * self.DataBase['Magnesiochromite'][0]}) DataWeight.update({'Chromite': Chromite * self.DataBase['Chromite'][0]}) DataWeight.update({'Ilmenite': Ilmenite * self.DataBase['Ilmenite'][0]}) DataWeight.update({'Calcite': Calcite * self.DataBase['Calcite'][0]}) DataWeight.update({'Na2CO3': Na2CO3 * self.DataBase['Na2CO3'][0]}) DataWeight.update({'Corundum': Corundum * self.DataBase['Corundum'][0]}) DataWeight.update({'Rutile': Rutile * self.DataBase['Rutile'][0]}) DataWeight.update({'Magnetite': Magnetite * self.DataBase['Magnetite'][0]}) DataWeight.update({'Hematite': Hematite * self.DataBase['Hematite'][0]}) DataWeight.update({'Q Weight': Quartz * self.DataBase['Quartz'][0]}) DataWeight.update({'A Weight': Orthoclase * self.DataBase['Orthoclase'][0]}) DataWeight.update({'P Weight': Anorthite * self.DataBase['Anorthite'][0] + Albite * self.DataBase['Albite'][0]}) DataWeight.update({'F Weight': Nepheline * self.DataBase['Nepheline'][0] + Leucite * self.DataBase['Leucite'][0] + Kalsilite * self.DataBase['Kalsilite'][0]}) WholeVolume = 0 WholeMole = 0 tmpVolume = [] tmpVolume.append(Quartz * self.DataBase['Quartz'][0] / self.DataBase['Quartz'][1]) tmpVolume.append(Zircon * self.DataBase['Zircon'][0] / self.DataBase['Zircon'][1]) tmpVolume.append(K2SiO3 * self.DataBase['K2SiO3'][0] / self.DataBase['K2SiO3'][1]) tmpVolume.append(Anorthite * self.DataBase['Anorthite'][0] / self.DataBase['Anorthite'][1]) tmpVolume.append(Na2SiO3 * self.DataBase['Na2SiO3'][0] / self.DataBase['Na2SiO3'][1]) tmpVolume.append(Acmite * self.DataBase['Acmite'][0] / self.DataBase['Acmite'][1]) tmpVolume.append(Diopside * self.DataBase['Diopside'][0] / self.DataBase['Diopside'][1]) tmpVolume.append(Sphene * self.DataBase['Sphene'][0] / self.DataBase['Sphene'][1]) tmpVolume.append(Hypersthene * self.DataBase['Hypersthene'][0] / self.DataBase['Hypersthene'][1]) tmpVolume.append(Albite * self.DataBase['Albite'][0] / self.DataBase['Albite'][1]) tmpVolume.append(Orthoclase * self.DataBase['Orthoclase'][0] / self.DataBase['Orthoclase'][1]) tmpVolume.append(Wollastonite * self.DataBase['Wollastonite'][0] / self.DataBase['Wollastonite'][1]) tmpVolume.append(Olivine * self.DataBase['Olivine'][0] / self.DataBase['Olivine'][1]) tmpVolume.append(Perovskite * self.DataBase['Perovskite'][0] / self.DataBase['Perovskite'][1]) tmpVolume.append(Nepheline * self.DataBase['Nepheline'][0] / self.DataBase['Nepheline'][1]) tmpVolume.append(Leucite * self.DataBase['Leucite'][0] / self.DataBase['Leucite'][1]) tmpVolume.append(Larnite * self.DataBase['Larnite'][0] / self.DataBase['Larnite'][1]) tmpVolume.append(Kalsilite * self.DataBase['Kalsilite'][0] / self.DataBase['Kalsilite'][1]) tmpVolume.append(Apatite * self.DataBase['Apatite'][0] / self.DataBase['Apatite'][1]) tmpVolume.append(Halite * self.DataBase['Halite'][0] / self.DataBase['Halite'][1]) tmpVolume.append(Fluorite * self.DataBase['Fluorite'][0] / self.DataBase['Fluorite'][1]) tmpVolume.append(Anhydrite * self.DataBase['Anhydrite'][0] / self.DataBase['Anhydrite'][1]) tmpVolume.append(Thenardite * self.DataBase['Thenardite'][0] / self.DataBase['Thenardite'][1]) tmpVolume.append(Pyrite * self.DataBase['Pyrite'][0] / self.DataBase['Pyrite'][1]) tmpVolume.append(Magnesiochromite * self.DataBase['Magnesiochromite'][0] / self.DataBase['Magnesiochromite'][1]) tmpVolume.append(Chromite * self.DataBase['Chromite'][0] / self.DataBase['Chromite'][1]) tmpVolume.append(Ilmenite * self.DataBase['Ilmenite'][0] / self.DataBase['Ilmenite'][1]) tmpVolume.append(Calcite * self.DataBase['Calcite'][0] / self.DataBase['Calcite'][1]) tmpVolume.append(Na2CO3 * self.DataBase['Na2CO3'][0] / self.DataBase['Na2CO3'][1]) tmpVolume.append(Corundum * self.DataBase['Corundum'][0] / self.DataBase['Corundum'][1]) tmpVolume.append(Rutile * self.DataBase['Rutile'][0] / self.DataBase['Rutile'][1]) tmpVolume.append(Magnetite * self.DataBase['Magnetite'][0] / self.DataBase['Magnetite'][1]) tmpVolume.append(Hematite * self.DataBase['Hematite'][0] / self.DataBase['Hematite'][1]) WholeVolume = sum(tmpVolume) DataVolume.update( {'Quartz': (Quartz * self.DataBase['Quartz'][0] / self.DataBase['Quartz'][1]) / WholeVolume * 100}) DataVolume.update( {'Zircon': (Zircon * self.DataBase['Zircon'][0] / self.DataBase['Zircon'][1]) / WholeVolume * 100}) DataVolume.update( {'K2SiO3': (K2SiO3 * self.DataBase['K2SiO3'][0] / self.DataBase['K2SiO3'][1]) / WholeVolume * 100}) DataVolume.update({'Anorthite': (Anorthite * self.DataBase['Anorthite'][0] / self.DataBase['Anorthite'][ 1]) / WholeVolume * 100}) DataVolume.update( {'Na2SiO3': (Na2SiO3 * self.DataBase['Na2SiO3'][0] / self.DataBase['Na2SiO3'][1]) / WholeVolume * 100}) DataVolume.update( {'Acmite': (Acmite * self.DataBase['Acmite'][0] / self.DataBase['Acmite'][1]) / WholeVolume * 100}) DataVolume.update( {'Diopside': (Diopside * self.DataBase['Diopside'][0] / self.DataBase['Diopside'][1]) / WholeVolume * 100}) DataVolume.update( {'Sphene': (Sphene * self.DataBase['Sphene'][0] / self.DataBase['Sphene'][1]) / WholeVolume * 100}) DataVolume.update({'Hypersthene': (Hypersthene * self.DataBase['Hypersthene'][0] / self.DataBase['Hypersthene'][ 1]) / WholeVolume * 100}) DataVolume.update( {'Albite': (Albite * self.DataBase['Albite'][0] / self.DataBase['Albite'][1]) / WholeVolume * 100}) DataVolume.update({'Orthoclase': (Orthoclase * self.DataBase['Orthoclase'][0] / self.DataBase['Orthoclase'][ 1]) / WholeVolume * 100}) DataVolume.update({'Wollastonite': (Wollastonite * self.DataBase['Wollastonite'][0] / self.DataBase['Wollastonite'][1]) / WholeVolume * 100}) DataVolume.update( {'Olivine': (Olivine * self.DataBase['Olivine'][0] / self.DataBase['Olivine'][1]) / WholeVolume * 100}) DataVolume.update({'Perovskite': (Perovskite * self.DataBase['Perovskite'][0] / self.DataBase['Perovskite'][ 1]) / WholeVolume * 100}) DataVolume.update({'Nepheline': (Nepheline * self.DataBase['Nepheline'][0] / self.DataBase['Nepheline'][ 1]) / WholeVolume * 100}) DataVolume.update( {'Leucite': (Leucite * self.DataBase['Leucite'][0] / self.DataBase['Leucite'][1]) / WholeVolume * 100}) DataVolume.update( {'Larnite': (Larnite * self.DataBase['Larnite'][0] / self.DataBase['Larnite'][1]) / WholeVolume * 100}) DataVolume.update({'Kalsilite': (Kalsilite * self.DataBase['Kalsilite'][0] / self.DataBase['Kalsilite'][ 1]) / WholeVolume * 100}) DataVolume.update( {'Apatite': (Apatite * self.DataBase['Apatite'][0] / self.DataBase['Apatite'][1]) / WholeVolume * 100}) DataVolume.update( {'Halite': (Halite * self.DataBase['Halite'][0] / self.DataBase['Halite'][1]) / WholeVolume * 100}) DataVolume.update( {'Fluorite': (Fluorite * self.DataBase['Fluorite'][0] / self.DataBase['Fluorite'][1]) / WholeVolume * 100}) DataVolume.update({'Anhydrite': (Anhydrite * self.DataBase['Anhydrite'][0] / self.DataBase['Anhydrite'][ 1]) / WholeVolume * 100}) DataVolume.update({'Thenardite': (Thenardite * self.DataBase['Thenardite'][0] / self.DataBase['Thenardite'][ 1]) / WholeVolume * 100}) DataVolume.update( {'Pyrite': (Pyrite * self.DataBase['Pyrite'][0] / self.DataBase['Pyrite'][1]) / WholeVolume * 100}) DataVolume.update({'Magnesiochromite': (Magnesiochromite * self.DataBase['Magnesiochromite'][0] / self.DataBase['Magnesiochromite'][1]) / WholeVolume * 100}) DataVolume.update( {'Chromite': (Chromite * self.DataBase['Chromite'][0] / self.DataBase['Chromite'][1]) / WholeVolume * 100}) DataVolume.update( {'Ilmenite': (Ilmenite * self.DataBase['Ilmenite'][0] / self.DataBase['Ilmenite'][1]) / WholeVolume * 100}) DataVolume.update( {'Calcite': (Calcite * self.DataBase['Calcite'][0] / self.DataBase['Calcite'][1]) / WholeVolume * 100}) DataVolume.update( {'Na2CO3': (Na2CO3 * self.DataBase['Na2CO3'][0] / self.DataBase['Na2CO3'][1]) / WholeVolume * 100}) DataVolume.update( {'Corundum': (Corundum * self.DataBase['Corundum'][0] / self.DataBase['Corundum'][1]) / WholeVolume * 100}) DataVolume.update( {'Rutile': (Rutile * self.DataBase['Rutile'][0] / self.DataBase['Rutile'][1]) / WholeVolume * 100}) DataVolume.update({'Magnetite': (Magnetite * self.DataBase['Magnetite'][0] / self.DataBase['Magnetite'][ 1]) / WholeVolume * 100}) DataVolume.update( {'Hematite': (Hematite * self.DataBase['Hematite'][0] / self.DataBase['Hematite'][1]) / WholeVolume * 100}) DataVolume.update({'Q': DataVolume['Quartz']}) DataVolume.update({'A': DataVolume['Orthoclase']}) DataVolume.update({'P': DataVolume['Anorthite'] + DataVolume['Albite']}) DataVolume.update({'F': DataVolume['Nepheline'] + DataVolume['Leucite'] + DataVolume['Kalsilite']}) DI = 0 # for i in ['Quartz', 'Anorthite', 'Albite', 'Orthoclase', 'Nepheline', 'Leucite', 'Kalsilite']: # exec('DI+=' + i + '*self.DataBase[\'' + i + '\'][0]') DI = Quartz + Anorthite + Albite + Orthoclase + Nepheline + Leucite + Kalsilite DiWeight=0 DiVolume=0 DiWeight = DataWeight['Quartz']+DataWeight['Anorthite']+DataWeight['Albite']+DataWeight['Orthoclase']+DataWeight['Nepheline']+DataWeight['Leucite']+DataWeight['Kalsilite'] DiVolume = DataVolume['Quartz']+DataVolume['Anorthite']+DataVolume['Albite']+DataVolume['Orthoclase']+DataVolume['Nepheline']+DataVolume['Leucite']+DataVolume['Kalsilite'] # print('\n\n DI is\n',DI,'\n\n') DataCalced.update({'Differentiation Index Weight': DiWeight}) DataCalced.update({'Differentiation Index Volume': DiVolume}) return (DataResult, DataWeight, DataVolume, DataCalced)
python
def singleCalc(self, m={'Al2O3': 13.01, 'Alpha': 0.6, 'Ba': 188.0, 'Be': 0.85, 'CaO': 8.35, 'Ce': 28.2, 'Co': 45.2, 'Cr': 117.0, 'Cs': 0.83, 'Cu': 53.5, 'Dy': 5.58, 'Er': 2.96, 'Eu': 1.79, 'Fe2O3': 14.47, 'FeO': 5.51, 'Ga': 19.4, 'Gd': 5.24, 'Hf': 3.38, 'Ho': 1.1, 'K2O': 0.72, 'LOI': 5.05, 'La': 11.4, 'Label': 'ZhangSH2016', 'Li': 15.0, 'Lu': 0.39, 'Mg 'MnO': 0.21, 'Na2O': 1.88, 'Nb': 12.6, 'Nd': 18.4, 'Ni': 69.4, 'P2O5': 0.23, 'Pb': 3.17, 'Pr': 3.95, 'Rb': 18.4, 'Sc': 37.4, 'SiO2': 48.17, 'Size': 10, 'Sm': 5.08, 'Sr': 357, 'Ta': 0.77, 'Tb': 0.88, 'Th': 1.85, 'TiO2': 2.56, 'Tl': 0.06, 'Tm': 0.44, 'Total': 99.91, 'U': 0.41, 'V': 368.0, 'Y': 29.7, 'Yb': 2.68, 'Zn': 100.0, 'Zr': 130.0, }): DataResult={} DataWeight={} DataVolume={} DataCalced={} DataResult.update({'Label': m['Label']}) DataWeight.update({'Label': m['Label']}) DataVolume.update({'Label': m['Label']}) DataCalced.update({'Label': m['Label']}) DataResult.update({'Width': m['Width']}) DataWeight.update({'Width': m['Width']}) DataVolume.update({'Width': m['Width']}) DataCalced.update({'Width': m['Width']}) DataResult.update({'Style': m['Style']}) DataWeight.update({'Style': m['Style']}) DataVolume.update({'Style': m['Style']}) DataCalced.update({'Style': m['Style']}) DataResult.update({'Alpha': m['Alpha']}) DataWeight.update({'Alpha': m['Alpha']}) DataVolume.update({'Alpha': m['Alpha']}) DataCalced.update({'Alpha': m['Alpha']}) DataResult.update({'Size': m['Size']}) DataWeight.update({'Size': m['Size']}) DataVolume.update({'Size': m['Size']}) DataCalced.update({'Size': m['Size']}) DataResult.update({'Color': m['Color']}) DataWeight.update({'Color': m['Color']}) DataVolume.update({'Color': m['Color']}) DataCalced.update({'Color': m['Color']}) DataResult.update({'Marker': m['Marker']}) DataWeight.update({'Marker': m['Marker']}) DataVolume.update({'Marker': m['Marker']}) DataCalced.update({'Marker': m['Marker']}) WholeMass = 0 EachMole = {} for j in self.Elements: try: T_TMP = m[j] except(KeyError): T_TMP = 0 if j == 'Sr': TMP = T_TMP / (87.62 / 103.619 * 10000) elif j == 'Ba': TMP = T_TMP / (137.327 / 153.326 * 10000) elif j == 'Ni': TMP = T_TMP / (58.6934 / 74.69239999999999 * 10000) elif j == 'Cr': TMP = T_TMP / ((2 * 51.9961) / 151.98919999999998 * 10000) elif j == 'Zr': TMP = T_TMP / ((2 * 91.224) / 123.22200000000001 * 10000) else: TMP = T_TMP V = TMP try: WholeMass += float(V) except ValueError: pass WeightCorrectionFactor = (100 / WholeMass) for j in self.Elements: try: T_TMP = m[j] except(KeyError): T_TMP = 0 if j == 'Sr': TMP = T_TMP / (87.62 / 103.619 * 10000) elif j == 'Ba': TMP = T_TMP / (137.327 / 153.326 * 10000) elif j == 'Ni': TMP = T_TMP / (58.6934 / 74.69239999999999 * 10000) elif j == 'Cr': TMP = T_TMP / ((2 * 51.9961) / 151.98919999999998 * 10000) elif j == 'Zr': TMP = T_TMP / ((91.224) / 123.22200000000001 * 10000) else: TMP = T_TMP try: M = TMP / self.BaseMass[j] * WeightCorrectionFactor except TypeError: pass EachMole.update({j: M}) DataCalculating = EachMole Fe3 = DataCalculating['Fe2O3'] Fe2 = DataCalculating['FeO'] Mg = DataCalculating['MgO'] Ca = DataCalculating['CaO'] Na = DataCalculating['Na2O'] try: DataCalced.update({'Fe3+/(Total Fe) in rock (Mole)': 100 * Fe3 * 2 / (Fe3 * 2 + Fe2)}) except(ZeroDivisionError): DataCalced.update({'Fe3+/(Total Fe) in rock (Mole)': 0}) pass try: DataCalced.update({'Mg/(Mg+Total Fe) in rock (Mole)': 100 * Mg / (Mg + Fe3 * 2 + Fe2)}) except(ZeroDivisionError): DataCalced.update({'Mg/(Mg+Total Fe) in rock (Mole)': 0}) pass try: DataCalced.update({'Mg/(Mg+Fe2+) in rock (Mole)': 100 * Mg / (Mg + Fe2)}) except(ZeroDivisionError): DataCalced.update({'Mg/(Mg+Fe2+) in rock (Mole)': 0}) pass try: DataCalced.update({'Ca/(Ca+Na) in rock (Mole)': 100 * Ca / (Ca + Na * 2)}) except(ZeroDivisionError): DataCalced.update({'Ca/(Ca+Na) in rock (Mole)': 0}) pass DataCalculating['CaO'] += DataCalculating['Sr'] DataCalculating['Sr'] = 0 DataCalculating['K2O'] += 2 * DataCalculating['Ba'] DataCalculating['Ba'] = 0 try: if DataCalculating['CaO'] >= 10 / 3 * DataCalculating['P2O5']: DataCalculating['CaO'] -= 10 / 3 * DataCalculating['P2O5'] else: DataCalculating['CaO'] = 0 except(ZeroDivisionError): pass DataCalculating['P2O5'] = DataCalculating['P2O5'] / 1.5 Apatite = DataCalculating['P2O5'] if DataCalculating['F'] >= DataCalculating['P2O5']: DataCalculating['F'] -= DataCalculating['P2O5'] else: DataCalculating['F'] = 0 if DataCalculating['F'] >= DataCalculating['P2O5']: DataCalculating['F'] -= DataCalculating['P2O5'] else: DataCalculating['F'] = 0 if DataCalculating['Na2O'] >= DataCalculating['Cl']: DataCalculating['Na2O'] -= DataCalculating['Cl'] else: DataCalculating['Na2O'] = 0 Halite = DataCalculating['Cl'] if DataCalculating['CaO'] >= 0.5 * DataCalculating['F']: DataCalculating['CaO'] -= 0.5 * DataCalculating['F'] else: DataCalculating['CaO'] = 0 DataCalculating['F'] *= 0.5 Fluorite = DataCalculating['F'] AorT = 0 if DataCalculating['SO3'] <= 0: AorT = 'None' else: if DataCalculating['Na2O'] >= DataCalculating['SO3']: AorT = 'Thenardite' else: if DataCalculating['Na2O'] > 0: AorT = 'Both' else: AorT = 'Anhydrite' if AorT == 'Anhydrite': DataCalculating['Sr'] = 0 elif AorT == 'Thenardite': DataCalculating['Sr'] = DataCalculating['SO3'] DataCalculating['SO3'] = 0 elif AorT == 'Both': DataCalculating['Sr'] = DataCalculating['SO3'] - DataCalculating['CaO'] DataCalculating['SO3'] = DataCalculating['CaO'] else: DataCalculating['SO3'] = 0 DataCalculating['Sr'] = 0 DataCalculating['CaO'] -= DataCalculating['SO3'] DataCalculating['Na2O'] -= DataCalculating['Sr'] Anhydrite = DataCalculating['SO3'] Thenardite = DataCalculating['Sr'] Pyrite = 0.5 * DataCalculating['S'] if DataCalculating['FeO'] >= DataCalculating['S'] * 0.5: DataCalculating['FeO'] -= DataCalculating['S'] * 0.5 else: DataCalculating['FeO'] = 0 if DataCalculating['Cr'] > 0: if DataCalculating['FeO'] >= DataCalculating['Cr']: CorM = 'Chromite' elif DataCalculating['FeO'] > 0: CorM = 'Both' else: CorM = 'Magnesiochromite' else: CorM = 'None' if CorM == 'Chromite': DataCalculating['Cr'] = DataCalculating['Cr'] DataCalculating['Ni'] = 0 elif CorM == 'Magnesiochromite': DataCalculating['Ni'] = DataCalculating['Cr'] DataCalculating['Cr'] = 0 elif CorM == 'Both': DataCalculating['Ni'] = DataCalculating['Cr'] - DataCalculating['FeO'] DataCalculating['Cr'] = DataCalculating['FeO'] else: DataCalculating['Cr'] = 0 DataCalculating['Ni'] = 0 DataCalculating['MgO'] -= DataCalculating['Ni'] Magnesiochromite = DataCalculating['Ni'] Chromite = DataCalculating['Cr'] if DataCalculating['FeO'] >= DataCalculating['Cr']: DataCalculating['FeO'] -= DataCalculating['Cr'] else: DataCalculating['FeO'] = 0 if DataCalculating['TiO2'] < 0: IorS = 'None' else: if DataCalculating['FeO'] >= DataCalculating['TiO2']: IorS = 'Ilmenite' else: if DataCalculating['FeO'] > 0: IorS = 'Both' else: IorS = 'Sphene' if IorS == 'Ilmenite': DataCalculating['TiO2'] = DataCalculating['TiO2'] DataCalculating['MnO'] = 0 elif IorS == 'Sphene': DataCalculating['MnO'] = DataCalculating['TiO2'] DataCalculating['TiO2'] = 0 elif IorS == 'Both': DataCalculating['MnO'] = DataCalculating['TiO2'] - DataCalculating['FeO'] DataCalculating['TiO2'] = DataCalculating['FeO'] else: DataCalculating['TiO2'] = 0 DataCalculating['MnO'] = 0 DataCalculating['FeO'] -= DataCalculating['TiO2'] Ilmenite = DataCalculating['TiO2'] if DataCalculating['CO2'] <= 0: CorN = 'None' else: if DataCalculating['CaO'] >= DataCalculating['CO2']: CorN = 'Calcite' else: if DataCalculating['CaO'] > 0: CorN = 'Both' else: CorN = 'Na2CO3' if CorN == 'None': DataCalculating['CO2'] = 0 DataCalculating['SO3'] = 0 elif CorN == 'Calcite': DataCalculating['CO2'] = DataCalculating['CO2'] DataCalculating['SO3'] = 0 elif CorN == 'Na2CO3': DataCalculating['SO3'] = DataCalculating['SO3'] DataCalculating['CO2'] = 0 elif CorN == 'Both': DataCalculating['SO3'] = DataCalculating['CO2'] - DataCalculating['CaO'] DataCalculating['CO2'] = DataCalculating['CaO'] DataCalculating['CaO'] -= DataCalculating['CO2'] Calcite = DataCalculating['CO2'] Na2CO3 = DataCalculating['SO3'] if DataCalculating['SO3'] > DataCalculating['Na2O']: DataCalculating['Na2O'] = 0 else: DataCalculating['Na2O'] -= DataCalculating['SO3'] DataCalculating['SiO2'] -= DataCalculating['Zr'] Zircon = DataCalculating['Zr'] if DataCalculating['K2O'] <= 0: OorK = 'None' else: if DataCalculating['Al2O3'] >= DataCalculating['K2O']: OorK = 'Orthoclase' else: if DataCalculating['Al2O3'] > 0: OorK = 'Both' else: OorK = 'K2SiO3' if OorK == 'None': DataCalculating['K2O'] = 0 DataCalculating['P2O5'] = 0 elif OorK == 'Orthoclase': DataCalculating['K2O'] = DataCalculating['K2O'] DataCalculating['P2O5'] = 0 elif OorK == 'K2SiO3': DataCalculating['P2O5'] = DataCalculating['K2O'] DataCalculating['K2O'] = 0 elif OorK == 'Both': DataCalculating['P2O5'] = DataCalculating['K2O'] - DataCalculating['Al2O3'] DataCalculating['K2O'] = DataCalculating['Al2O3'] DataCalculating['Al2O3'] -= DataCalculating['K2O'] if DataCalculating['Na2O'] <= 0: AorN = 'None' else: if DataCalculating['Al2O3'] >= DataCalculating['Na2O']: AorN = 'Albite' else: if DataCalculating['Al2O3'] > 0: AorN = 'Both' else: AorN = 'Na2SiO3' if DataCalculating['Al2O3'] >= DataCalculating['Na2O'] and DataCalculating['Al2O3'] > 0: DataCalculating['Al2O3'] -= DataCalculating['Na2O'] else: DataCalculating['Al2O3'] = 0 if AorN == 'Albite': DataCalculating['Cl'] = 0 elif AorN == 'Both': DataCalculating['Cl'] = DataCalculating['Na2O'] - DataCalculating['Al2O3'] DataCalculating['Na2O'] = DataCalculating['Al2O3'] elif AorN == 'Na2SiO3': DataCalculating['Cl'] = DataCalculating['Na2O'] DataCalculating['Na2O'] = 0 elif AorN == 'None': DataCalculating['Na2O'] = 0 DataCalculating['Cl'] = 0 if DataCalculating['Al2O3'] <= 0: AorC = 'None' else: if DataCalculating['CaO'] > 0: AorC = 'Anorthite' else: Aorc = 'None' if AorC == 'Anorthite': if DataCalculating['Al2O3'] >= DataCalculating['CaO']: DataCalculating['Sr'] = DataCalculating['CaO'] DataCalculating['Al2O3'] -= DataCalculating['CaO'] DataCalculating['CaO'] = 0 else: DataCalculating['Sr'] = DataCalculating['Al2O3'] DataCalculating['CaO'] -= DataCalculating['Al2O3'] DataCalculating['Al2O3'] = 0 else: DataCalculating['Sr'] = 0 Corundum = DataCalculating['Al2O3'] Anorthite = DataCalculating['Sr'] if DataCalculating['MnO'] <= 0: SorR = 'None' else: if DataCalculating['CaO'] >= DataCalculating['MnO']: SorR = 'Sphene' elif DataCalculating['CaO'] > 0: SorR = 'Both' else: SorR = 'Rutile' if SorR == 'Sphene': DataCalculating['MnO'] = DataCalculating['MnO'] DataCalculating['S'] = 0 elif SorR == 'Rutile': DataCalculating['S'] = DataCalculating['MnO'] DataCalculating['MnO'] = 0 elif SorR == 'Both': DataCalculating['S'] = DataCalculating['MnO'] - DataCalculating['CaO'] DataCalculating['MnO'] = DataCalculating['CaO'] elif SorR == 'None': DataCalculating['MnO'] = 0 DataCalculating['S'] = 0 DataCalculating['CaO'] -= DataCalculating['MnO'] Rutile = DataCalculating['S'] if DataCalculating['Cl'] <= 0: ACorN = 'None' else: if DataCalculating['Fe2O3'] >= DataCalculating['Cl']: ACorN = 'Acmite' else: if DataCalculating['Fe2O3'] > 0: ACorN = 'Both' else: ACorN = 'Na2SiO3' if ACorN == 'Acmite': DataCalculating['F'] = DataCalculating['Cl'] DataCalculating['Cl'] = 0 elif ACorN == 'Na2SiO3': DataCalculating['Cl'] = DataCalculating['Cl'] DataCalculating['F'] = 0 elif ACorN == 'Both': DataCalculating['F'] = DataCalculating['Fe2O3'] DataCalculating['Cl'] = DataCalculating['Cl'] - DataCalculating['F'] elif ACorN == 'None': DataCalculating['F'] = 0 DataCalculating['Cl'] = 0 DataCalculating['Fe2O3'] -= DataCalculating['F'] Acmite = DataCalculating['F'] if DataCalculating['Fe2O3'] <= 0: MorH = 'None' else: if DataCalculating['FeO'] >= DataCalculating['Fe2O3']: MorH = 'Magnetite' else: if DataCalculating['FeO'] > 0: MorH = 'Both' else: MorH = 'Hematite' if MorH == 'Magnetite': DataCalculating['Fe2O3'] = DataCalculating['Fe2O3'] DataCalculating['Ba'] = 0 elif MorH == 'Hematite': DataCalculating['Fe2O3'] = 0 DataCalculating['Ba'] = DataCalculating['FeO'] elif MorH == 'Both': DataCalculating['Fe2O3'] = DataCalculating['FeO'] DataCalculating['Ba'] = DataCalculating['Fe2O3'] - DataCalculating['FeO'] elif MorH == 'None': DataCalculating['Fe2O3'] = 0 DataCalculating['Ba'] == 0 DataCalculating['FeO'] -= DataCalculating['Fe2O3'] Magnetite = DataCalculating['Fe2O3'] Hematite = DataCalculating['Ba'] Fe2 = DataCalculating['FeO'] Mg = DataCalculating['MgO'] if Mg > 0: DataCalced.update({'Mg/(Mg+Fe2+) in silicates': 100 * Mg / (Mg + Fe2)}) else: DataCalced.update({'Mg/(Mg+Fe2+) in silicates': 0}) DataCalculating['FeO'] += DataCalculating['MgO'] DataCalculating['MgO'] = 0 if DataCalculating['CaO'] <= 0: DorW = 'None' else: if DataCalculating['FeO'] >= DataCalculating['CaO']: DorW = 'Diopside' else: if DataCalculating['FeO'] > 0: DorW = 'Both' else: DorW = 'Wollastonite' if DorW == 'Diopside': DataCalculating['CaO'] = DataCalculating['CaO'] DataCalculating['S'] = 0 elif DorW == 'Wollastonite': DataCalculating['S'] = DataCalculating['CaO'] DataCalculating['CaO'] = 0 elif DorW == 'Both': DataCalculating['S'] = DataCalculating['CaO'] - DataCalculating['FeO'] DataCalculating['CaO'] = DataCalculating['FeO'] elif DorW == 'None': DataCalculating['CaO'] = 0 DataCalculating['S'] = 0 DataCalculating['FeO'] -= DataCalculating['CaO'] Diopside = DataCalculating['CaO'] Quartz = DataCalculating['SiO2'] Zircon = DataCalculating['Zr'] K2SiO3 = DataCalculating['P2O5'] Na2SiO3 = DataCalculating['Cl'] Sphene = DataCalculating['MnO'] Hypersthene = DataCalculating['FeO'] Albite = DataCalculating['Na2O'] Orthoclase = DataCalculating['K2O'] Wollastonite = DataCalculating['S'] Quartz -= (Zircon + K2SiO3 + Anorthite * 2 + Na2SiO3 + Acmite * 4 + Diopside * 2 + Sphene + Hypersthene + Albite * 6 + Orthoclase * 6 + Wollastonite) if Quartz > 0: Quartz = Quartz else: Quartz = 0 if Hypersthene <= 0: HorO = 'None' else: if Quartz >= 0: HorO = 'Hypersthene' else: if Hypersthene + 2 * Quartz > 0: HorO = 'Both' else: HorO = 'Olivine' Old_Hypersthene = Hypersthene if HorO == 'Hypersthene': Hypersthene = Hypersthene Olivine = 0 elif HorO == 'Both': Hypersthene = Hypersthene + Quartz * 2 Olivine = abs(Quartz) elif HorO == 'Olivine': Olivine = Hypersthene / 2 Hypersthene = 0 elif HorO == 'None': Hypersthene = 0 Olivine = 0 Quartz += Old_Hypersthene - (Hypersthene + Olivine) if Sphene <= 0: SorP = 'None' else: if Quartz >= 0: SorP = 'Sphene' else: if Sphene + Quartz > 0: SorP = 'Both' else: SorP = 'Perovskite' Old_Sphene = Sphene if SorP == 'Sphene': Sphene = Sphene Perovskite = 0 elif SorP == 'Perovskite': Perovskite = Sphene Sphene = 0 elif SorP == 'Both': Sphene += Quartz Perovskite = Old_Sphene - Sphene elif SorP == 'None': Sphene = 0 Perovskite = 0 Quartz += Old_Sphene - Sphene if Albite <= 0: AlorNe = 'None' else: if Quartz >= 0: AlorNe = 'Albite' else: if Albite + (Quartz / 4) > 0: AlorNe = 'Both' else: AlorNe = 'Nepheline' Old_Albite = Albite if AlorNe == 'Albite': Albite = Albite Nepheline = 0 elif AlorNe == 'Nepheline': Nepheline = Albite Albite = 0 elif AlorNe == 'Both': Albite += Quartz / 4 Nepheline = Old_Albite - Albite elif AlorNe == 'None': Nepheline = 0 Albite = 0 Quartz += (6 * Old_Albite) - (Albite * 6) - (Nepheline * 2) if Anorthite == 0: DataCalced.update({'Plagioclase An content': 0}) else: DataCalced.update({'Plagioclase An content': 100 * Anorthite / (Anorthite + 2 * Albite)}) if Orthoclase <= 0: OorL = 'None' else: if Quartz >= 0: OorL = 'Orthoclase' else: if Orthoclase + Quartz / 2 > 0: OorL = 'Both' else: OorL = 'Leucite' Old_Orthoclase = Orthoclase if OorL == 'Orthoclase': Orthoclase = Orthoclase Leucite = 0 elif OorL == 'Leucite': Leucite = Orthoclase Orthoclase = 0 elif OorL == 'Both': Orthoclase += Quartz / 2 Leucite = Old_Orthoclase - Orthoclase elif OorL == 'None': Orthoclase = 0 Leucite = 0 Quartz += (Old_Orthoclase * 6) - (Orthoclase * 6) - (Leucite * 4) if Wollastonite <= 0: WorB = 'None' else: if Quartz >= 0: WorB = 'Wollastonite' else: if Wollastonite + Quartz / 2 > 0: WorB = 'Both' else: WorB = 'Larnite' Old_Wollastonite = Wollastonite if WorB == 'Wollastonite': Wollastonite = Wollastonite Larnite = 0 elif WorB == 'Larnite': Larnite = Wollastonite / 2 Wollastonite = 0 elif WorB == 'Both': Wollastonite += Quartz * 2 Larnite = (Old_Wollastonite - Wollastonite) / 2 elif WorB == 'None': Wollastonite = 0 Larnite = 0 Quartz += Old_Wollastonite - Wollastonite - Larnite if Diopside <= 0: DorL = 'None' else: if Quartz >= 0: DorL = 'Diopside' else: if Diopside + Quartz > 0: DorL = 'Both' else: DorL = 'LarniteOlivine' Old_Diopside = Diopside Old_Larnite = Larnite Old_Olivine = Olivine if DorL == 'Diopside': Diopside = Diopside elif DorL == 'LarniteOlivine': Larnite += Diopside / 2 Olivine += Diopside / 2 Diopside = 0 elif DorL == 'Both': Diopside += Quartz Larnite += Old_Diopside - Diopside Olivine += Old_Diopside - Diopside elif DorL == 'None': Diopside = 0 Quartz += (Old_Diopside * 2) + Old_Olivine + Old_Larnite - Larnite - (Diopside * 2) - Olivine if Leucite <= 0: LorK = 'None' else: if Quartz >= 0: LorK = 'Leucite' else: if Leucite + Quartz / 2 > 0: LorK = 'Both' else: LorK = 'Kalsilite' Old_Leucite = Leucite if LorK == 'Leucite': Leucite = Leucite Kalsilite = 0 elif LorK == 'Kalsilite': Kalsilite = Leucite Leucite = 0 elif LorK == 'Both': Leucite += Quartz / 2 Kalsilite = Old_Leucite - Leucite elif LorK == 'None': Leucite = 0 Kalsilite = 0 Quartz += Old_Leucite * 4 - Leucite * 4 - Kalsilite * 2 Q = Quartz A = Orthoclase P = Anorthite + Albite F = Nepheline + Leucite + Kalsilite DataResult.update({'Quartz': Quartz}) DataResult.update({'Zircon': Zircon}) DataResult.update({'K2SiO3': K2SiO3}) DataResult.update({'Anorthite': Anorthite}) DataResult.update({'Na2SiO3': Na2SiO3}) DataResult.update({'Acmite': Acmite}) DataResult.update({'Diopside': Diopside}) DataResult.update({'Sphene': Sphene}) DataResult.update({'Hypersthene': Hypersthene}) DataResult.update({'Albite': Albite}) DataResult.update({'Orthoclase': Orthoclase}) DataResult.update({'Wollastonite': Wollastonite}) DataResult.update({'Olivine': Olivine}) DataResult.update({'Perovskite': Perovskite}) DataResult.update({'Nepheline': Nepheline}) DataResult.update({'Leucite': Leucite}) DataResult.update({'Larnite': Larnite}) DataResult.update({'Kalsilite': Kalsilite}) DataResult.update({'Apatite': Apatite}) DataResult.update({'Halite': Halite}) DataResult.update({'Fluorite': Fluorite}) DataResult.update({'Anhydrite': Anhydrite}) DataResult.update({'Thenardite': Thenardite}) DataResult.update({'Pyrite': Pyrite}) DataResult.update({'Magnesiochromite': Magnesiochromite}) DataResult.update({'Chromite': Chromite}) DataResult.update({'Ilmenite': Ilmenite}) DataResult.update({'Calcite': Calcite}) DataResult.update({'Na2CO3': Na2CO3}) DataResult.update({'Corundum': Corundum}) DataResult.update({'Rutile': Rutile}) DataResult.update({'Magnetite': Magnetite}) DataResult.update({'Hematite': Hematite}) DataResult.update({'Q Mole': Q}) DataResult.update({'A Mole': A}) DataResult.update({'P Mole': P}) DataResult.update({'F Mole': F}) DataWeight.update({'Quartz': Quartz * self.DataBase['Quartz'][0]}) DataWeight.update({'Zircon': Zircon * self.DataBase['Zircon'][0]}) DataWeight.update({'K2SiO3': K2SiO3 * self.DataBase['K2SiO3'][0]}) DataWeight.update({'Anorthite': Anorthite * self.DataBase['Anorthite'][0]}) DataWeight.update({'Na2SiO3': Na2SiO3 * self.DataBase['Na2SiO3'][0]}) DataWeight.update({'Acmite': Acmite * self.DataBase['Acmite'][0]}) DataWeight.update({'Diopside': Diopside * self.DataBase['Diopside'][0]}) DataWeight.update({'Sphene': Sphene * self.DataBase['Sphene'][0]}) DataWeight.update({'Hypersthene': Hypersthene * self.DataBase['Hypersthene'][0]}) DataWeight.update({'Albite': Albite * self.DataBase['Albite'][0]}) DataWeight.update({'Orthoclase': Orthoclase * self.DataBase['Orthoclase'][0]}) DataWeight.update({'Wollastonite': Wollastonite * self.DataBase['Wollastonite'][0]}) DataWeight.update({'Olivine': Olivine * self.DataBase['Olivine'][0]}) DataWeight.update({'Perovskite': Perovskite * self.DataBase['Perovskite'][0]}) DataWeight.update({'Nepheline': Nepheline * self.DataBase['Nepheline'][0]}) DataWeight.update({'Leucite': Leucite * self.DataBase['Leucite'][0]}) DataWeight.update({'Larnite': Larnite * self.DataBase['Larnite'][0]}) DataWeight.update({'Kalsilite': Kalsilite * self.DataBase['Kalsilite'][0]}) DataWeight.update({'Apatite': Apatite * self.DataBase['Apatite'][0]}) DataWeight.update({'Halite': Halite * self.DataBase['Halite'][0]}) DataWeight.update({'Fluorite': Fluorite * self.DataBase['Fluorite'][0]}) DataWeight.update({'Anhydrite': Anhydrite * self.DataBase['Anhydrite'][0]}) DataWeight.update({'Thenardite': Thenardite * self.DataBase['Thenardite'][0]}) DataWeight.update({'Pyrite': Pyrite * self.DataBase['Pyrite'][0]}) DataWeight.update({'Magnesiochromite': Magnesiochromite * self.DataBase['Magnesiochromite'][0]}) DataWeight.update({'Chromite': Chromite * self.DataBase['Chromite'][0]}) DataWeight.update({'Ilmenite': Ilmenite * self.DataBase['Ilmenite'][0]}) DataWeight.update({'Calcite': Calcite * self.DataBase['Calcite'][0]}) DataWeight.update({'Na2CO3': Na2CO3 * self.DataBase['Na2CO3'][0]}) DataWeight.update({'Corundum': Corundum * self.DataBase['Corundum'][0]}) DataWeight.update({'Rutile': Rutile * self.DataBase['Rutile'][0]}) DataWeight.update({'Magnetite': Magnetite * self.DataBase['Magnetite'][0]}) DataWeight.update({'Hematite': Hematite * self.DataBase['Hematite'][0]}) DataWeight.update({'Q Weight': Quartz * self.DataBase['Quartz'][0]}) DataWeight.update({'A Weight': Orthoclase * self.DataBase['Orthoclase'][0]}) DataWeight.update({'P Weight': Anorthite * self.DataBase['Anorthite'][0] + Albite * self.DataBase['Albite'][0]}) DataWeight.update({'F Weight': Nepheline * self.DataBase['Nepheline'][0] + Leucite * self.DataBase['Leucite'][0] + Kalsilite * self.DataBase['Kalsilite'][0]}) WholeVolume = 0 WholeMole = 0 tmpVolume = [] tmpVolume.append(Quartz * self.DataBase['Quartz'][0] / self.DataBase['Quartz'][1]) tmpVolume.append(Zircon * self.DataBase['Zircon'][0] / self.DataBase['Zircon'][1]) tmpVolume.append(K2SiO3 * self.DataBase['K2SiO3'][0] / self.DataBase['K2SiO3'][1]) tmpVolume.append(Anorthite * self.DataBase['Anorthite'][0] / self.DataBase['Anorthite'][1]) tmpVolume.append(Na2SiO3 * self.DataBase['Na2SiO3'][0] / self.DataBase['Na2SiO3'][1]) tmpVolume.append(Acmite * self.DataBase['Acmite'][0] / self.DataBase['Acmite'][1]) tmpVolume.append(Diopside * self.DataBase['Diopside'][0] / self.DataBase['Diopside'][1]) tmpVolume.append(Sphene * self.DataBase['Sphene'][0] / self.DataBase['Sphene'][1]) tmpVolume.append(Hypersthene * self.DataBase['Hypersthene'][0] / self.DataBase['Hypersthene'][1]) tmpVolume.append(Albite * self.DataBase['Albite'][0] / self.DataBase['Albite'][1]) tmpVolume.append(Orthoclase * self.DataBase['Orthoclase'][0] / self.DataBase['Orthoclase'][1]) tmpVolume.append(Wollastonite * self.DataBase['Wollastonite'][0] / self.DataBase['Wollastonite'][1]) tmpVolume.append(Olivine * self.DataBase['Olivine'][0] / self.DataBase['Olivine'][1]) tmpVolume.append(Perovskite * self.DataBase['Perovskite'][0] / self.DataBase['Perovskite'][1]) tmpVolume.append(Nepheline * self.DataBase['Nepheline'][0] / self.DataBase['Nepheline'][1]) tmpVolume.append(Leucite * self.DataBase['Leucite'][0] / self.DataBase['Leucite'][1]) tmpVolume.append(Larnite * self.DataBase['Larnite'][0] / self.DataBase['Larnite'][1]) tmpVolume.append(Kalsilite * self.DataBase['Kalsilite'][0] / self.DataBase['Kalsilite'][1]) tmpVolume.append(Apatite * self.DataBase['Apatite'][0] / self.DataBase['Apatite'][1]) tmpVolume.append(Halite * self.DataBase['Halite'][0] / self.DataBase['Halite'][1]) tmpVolume.append(Fluorite * self.DataBase['Fluorite'][0] / self.DataBase['Fluorite'][1]) tmpVolume.append(Anhydrite * self.DataBase['Anhydrite'][0] / self.DataBase['Anhydrite'][1]) tmpVolume.append(Thenardite * self.DataBase['Thenardite'][0] / self.DataBase['Thenardite'][1]) tmpVolume.append(Pyrite * self.DataBase['Pyrite'][0] / self.DataBase['Pyrite'][1]) tmpVolume.append(Magnesiochromite * self.DataBase['Magnesiochromite'][0] / self.DataBase['Magnesiochromite'][1]) tmpVolume.append(Chromite * self.DataBase['Chromite'][0] / self.DataBase['Chromite'][1]) tmpVolume.append(Ilmenite * self.DataBase['Ilmenite'][0] / self.DataBase['Ilmenite'][1]) tmpVolume.append(Calcite * self.DataBase['Calcite'][0] / self.DataBase['Calcite'][1]) tmpVolume.append(Na2CO3 * self.DataBase['Na2CO3'][0] / self.DataBase['Na2CO3'][1]) tmpVolume.append(Corundum * self.DataBase['Corundum'][0] / self.DataBase['Corundum'][1]) tmpVolume.append(Rutile * self.DataBase['Rutile'][0] / self.DataBase['Rutile'][1]) tmpVolume.append(Magnetite * self.DataBase['Magnetite'][0] / self.DataBase['Magnetite'][1]) tmpVolume.append(Hematite * self.DataBase['Hematite'][0] / self.DataBase['Hematite'][1]) WholeVolume = sum(tmpVolume) DataVolume.update( {'Quartz': (Quartz * self.DataBase['Quartz'][0] / self.DataBase['Quartz'][1]) / WholeVolume * 100}) DataVolume.update( {'Zircon': (Zircon * self.DataBase['Zircon'][0] / self.DataBase['Zircon'][1]) / WholeVolume * 100}) DataVolume.update( {'K2SiO3': (K2SiO3 * self.DataBase['K2SiO3'][0] / self.DataBase['K2SiO3'][1]) / WholeVolume * 100}) DataVolume.update({'Anorthite': (Anorthite * self.DataBase['Anorthite'][0] / self.DataBase['Anorthite'][ 1]) / WholeVolume * 100}) DataVolume.update( {'Na2SiO3': (Na2SiO3 * self.DataBase['Na2SiO3'][0] / self.DataBase['Na2SiO3'][1]) / WholeVolume * 100}) DataVolume.update( {'Acmite': (Acmite * self.DataBase['Acmite'][0] / self.DataBase['Acmite'][1]) / WholeVolume * 100}) DataVolume.update( {'Diopside': (Diopside * self.DataBase['Diopside'][0] / self.DataBase['Diopside'][1]) / WholeVolume * 100}) DataVolume.update( {'Sphene': (Sphene * self.DataBase['Sphene'][0] / self.DataBase['Sphene'][1]) / WholeVolume * 100}) DataVolume.update({'Hypersthene': (Hypersthene * self.DataBase['Hypersthene'][0] / self.DataBase['Hypersthene'][ 1]) / WholeVolume * 100}) DataVolume.update( {'Albite': (Albite * self.DataBase['Albite'][0] / self.DataBase['Albite'][1]) / WholeVolume * 100}) DataVolume.update({'Orthoclase': (Orthoclase * self.DataBase['Orthoclase'][0] / self.DataBase['Orthoclase'][ 1]) / WholeVolume * 100}) DataVolume.update({'Wollastonite': (Wollastonite * self.DataBase['Wollastonite'][0] / self.DataBase['Wollastonite'][1]) / WholeVolume * 100}) DataVolume.update( {'Olivine': (Olivine * self.DataBase['Olivine'][0] / self.DataBase['Olivine'][1]) / WholeVolume * 100}) DataVolume.update({'Perovskite': (Perovskite * self.DataBase['Perovskite'][0] / self.DataBase['Perovskite'][ 1]) / WholeVolume * 100}) DataVolume.update({'Nepheline': (Nepheline * self.DataBase['Nepheline'][0] / self.DataBase['Nepheline'][ 1]) / WholeVolume * 100}) DataVolume.update( {'Leucite': (Leucite * self.DataBase['Leucite'][0] / self.DataBase['Leucite'][1]) / WholeVolume * 100}) DataVolume.update( {'Larnite': (Larnite * self.DataBase['Larnite'][0] / self.DataBase['Larnite'][1]) / WholeVolume * 100}) DataVolume.update({'Kalsilite': (Kalsilite * self.DataBase['Kalsilite'][0] / self.DataBase['Kalsilite'][ 1]) / WholeVolume * 100}) DataVolume.update( {'Apatite': (Apatite * self.DataBase['Apatite'][0] / self.DataBase['Apatite'][1]) / WholeVolume * 100}) DataVolume.update( {'Halite': (Halite * self.DataBase['Halite'][0] / self.DataBase['Halite'][1]) / WholeVolume * 100}) DataVolume.update( {'Fluorite': (Fluorite * self.DataBase['Fluorite'][0] / self.DataBase['Fluorite'][1]) / WholeVolume * 100}) DataVolume.update({'Anhydrite': (Anhydrite * self.DataBase['Anhydrite'][0] / self.DataBase['Anhydrite'][ 1]) / WholeVolume * 100}) DataVolume.update({'Thenardite': (Thenardite * self.DataBase['Thenardite'][0] / self.DataBase['Thenardite'][ 1]) / WholeVolume * 100}) DataVolume.update( {'Pyrite': (Pyrite * self.DataBase['Pyrite'][0] / self.DataBase['Pyrite'][1]) / WholeVolume * 100}) DataVolume.update({'Magnesiochromite': (Magnesiochromite * self.DataBase['Magnesiochromite'][0] / self.DataBase['Magnesiochromite'][1]) / WholeVolume * 100}) DataVolume.update( {'Chromite': (Chromite * self.DataBase['Chromite'][0] / self.DataBase['Chromite'][1]) / WholeVolume * 100}) DataVolume.update( {'Ilmenite': (Ilmenite * self.DataBase['Ilmenite'][0] / self.DataBase['Ilmenite'][1]) / WholeVolume * 100}) DataVolume.update( {'Calcite': (Calcite * self.DataBase['Calcite'][0] / self.DataBase['Calcite'][1]) / WholeVolume * 100}) DataVolume.update( {'Na2CO3': (Na2CO3 * self.DataBase['Na2CO3'][0] / self.DataBase['Na2CO3'][1]) / WholeVolume * 100}) DataVolume.update( {'Corundum': (Corundum * self.DataBase['Corundum'][0] / self.DataBase['Corundum'][1]) / WholeVolume * 100}) DataVolume.update( {'Rutile': (Rutile * self.DataBase['Rutile'][0] / self.DataBase['Rutile'][1]) / WholeVolume * 100}) DataVolume.update({'Magnetite': (Magnetite * self.DataBase['Magnetite'][0] / self.DataBase['Magnetite'][ 1]) / WholeVolume * 100}) DataVolume.update( {'Hematite': (Hematite * self.DataBase['Hematite'][0] / self.DataBase['Hematite'][1]) / WholeVolume * 100}) DataVolume.update({'Q': DataVolume['Quartz']}) DataVolume.update({'A': DataVolume['Orthoclase']}) DataVolume.update({'P': DataVolume['Anorthite'] + DataVolume['Albite']}) DataVolume.update({'F': DataVolume['Nepheline'] + DataVolume['Leucite'] + DataVolume['Kalsilite']}) DI = 0 DI = Quartz + Anorthite + Albite + Orthoclase + Nepheline + Leucite + Kalsilite DiWeight=0 DiVolume=0 DiWeight = DataWeight['Quartz']+DataWeight['Anorthite']+DataWeight['Albite']+DataWeight['Orthoclase']+DataWeight['Nepheline']+DataWeight['Leucite']+DataWeight['Kalsilite'] DiVolume = DataVolume['Quartz']+DataVolume['Anorthite']+DataVolume['Albite']+DataVolume['Orthoclase']+DataVolume['Nepheline']+DataVolume['Leucite']+DataVolume['Kalsilite'] DataCalced.update({'Differentiation Index Weight': DiWeight}) DataCalced.update({'Differentiation Index Volume': DiVolume}) return (DataResult, DataWeight, DataVolume, DataCalced)
[ "def", "singleCalc", "(", "self", ",", "m", "=", "{", "'Al2O3'", ":", "13.01", ",", "'Alpha'", ":", "0.6", ",", "'Ba'", ":", "188.0", ",", "'Be'", ":", "0.85", ",", "'CaO'", ":", "8.35", ",", "'Ce'", ":", "28.2", ",", "'Co'", ":", "45.2", ",", "'Cr'", ":", "117.0", ",", "'Cs'", ":", "0.83", ",", "'Cu'", ":", "53.5", ",", "'Dy'", ":", "5.58", ",", "'Er'", ":", "2.96", ",", "'Eu'", ":", "1.79", ",", "'Fe2O3'", ":", "14.47", ",", "'FeO'", ":", "5.51", ",", "'Ga'", ":", "19.4", ",", "'Gd'", ":", "5.24", ",", "'Hf'", ":", "3.38", ",", "'Ho'", ":", "1.1", ",", "'K2O'", ":", "0.72", ",", "'LOI'", ":", "5.05", ",", "'La'", ":", "11.4", ",", "'Label'", ":", "'ZhangSH2016'", ",", "'Li'", ":", "15.0", ",", "'Lu'", ":", "0.39", ",", "'Mg#'", ":", "41.9", ",", "'MgO'", ":", "5.26", ",", "'MnO'", ":", "0.21", ",", "'Na2O'", ":", "1.88", ",", "'Nb'", ":", "12.6", ",", "'Nd'", ":", "18.4", ",", "'Ni'", ":", "69.4", ",", "'P2O5'", ":", "0.23", ",", "'Pb'", ":", "3.17", ",", "'Pr'", ":", "3.95", ",", "'Rb'", ":", "18.4", ",", "'Sc'", ":", "37.4", ",", "'SiO2'", ":", "48.17", ",", "'Size'", ":", "10", ",", "'Sm'", ":", "5.08", ",", "'Sr'", ":", "357", ",", "'Ta'", ":", "0.77", ",", "'Tb'", ":", "0.88", ",", "'Th'", ":", "1.85", ",", "'TiO2'", ":", "2.56", ",", "'Tl'", ":", "0.06", ",", "'Tm'", ":", "0.44", ",", "'Total'", ":", "99.91", ",", "'U'", ":", "0.41", ",", "'V'", ":", "368.0", ",", "'Y'", ":", "29.7", ",", "'Yb'", ":", "2.68", ",", "'Zn'", ":", "100.0", ",", "'Zr'", ":", "130.0", ",", "}", ")", ":", "DataResult", "=", "{", "}", "DataWeight", "=", "{", "}", "DataVolume", "=", "{", "}", "DataCalced", "=", "{", "}", "DataResult", ".", "update", "(", "{", "'Label'", ":", "m", "[", "'Label'", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Label'", ":", "m", "[", "'Label'", "]", "}", ")", "DataVolume", ".", "update", "(", "{", "'Label'", ":", "m", "[", "'Label'", "]", "}", ")", "DataCalced", ".", "update", "(", "{", "'Label'", ":", "m", "[", "'Label'", "]", "}", ")", "DataResult", ".", "update", "(", "{", "'Width'", ":", "m", "[", "'Width'", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Width'", ":", "m", "[", "'Width'", "]", "}", ")", "DataVolume", ".", "update", "(", "{", "'Width'", ":", "m", "[", "'Width'", "]", "}", ")", "DataCalced", ".", "update", "(", "{", "'Width'", ":", "m", "[", "'Width'", "]", "}", ")", "DataResult", ".", "update", "(", "{", "'Style'", ":", "m", "[", "'Style'", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Style'", ":", "m", "[", "'Style'", "]", "}", ")", "DataVolume", ".", "update", "(", "{", "'Style'", ":", "m", "[", "'Style'", "]", "}", ")", "DataCalced", ".", "update", "(", "{", "'Style'", ":", "m", "[", "'Style'", "]", "}", ")", "DataResult", ".", "update", "(", "{", "'Alpha'", ":", "m", "[", "'Alpha'", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Alpha'", ":", "m", "[", "'Alpha'", "]", "}", ")", "DataVolume", ".", "update", "(", "{", "'Alpha'", ":", "m", "[", "'Alpha'", "]", "}", ")", "DataCalced", ".", "update", "(", "{", "'Alpha'", ":", "m", "[", "'Alpha'", "]", "}", ")", "DataResult", ".", "update", "(", "{", "'Size'", ":", "m", "[", "'Size'", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Size'", ":", "m", "[", "'Size'", "]", "}", ")", "DataVolume", ".", "update", "(", "{", "'Size'", ":", "m", "[", "'Size'", "]", "}", ")", "DataCalced", ".", "update", "(", "{", "'Size'", ":", "m", "[", "'Size'", "]", "}", ")", "DataResult", ".", "update", "(", "{", "'Color'", ":", "m", "[", "'Color'", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Color'", ":", "m", "[", "'Color'", "]", "}", ")", "DataVolume", ".", "update", "(", "{", "'Color'", ":", "m", "[", "'Color'", "]", "}", ")", "DataCalced", ".", "update", "(", "{", "'Color'", ":", "m", "[", "'Color'", "]", "}", ")", "DataResult", ".", "update", "(", "{", "'Marker'", ":", "m", "[", "'Marker'", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Marker'", ":", "m", "[", "'Marker'", "]", "}", ")", "DataVolume", ".", "update", "(", "{", "'Marker'", ":", "m", "[", "'Marker'", "]", "}", ")", "DataCalced", ".", "update", "(", "{", "'Marker'", ":", "m", "[", "'Marker'", "]", "}", ")", "WholeMass", "=", "0", "EachMole", "=", "{", "}", "for", "j", "in", "self", ".", "Elements", ":", "'''\n Get the Whole Mole of the dataset\n '''", "try", ":", "T_TMP", "=", "m", "[", "j", "]", "except", "(", "KeyError", ")", ":", "T_TMP", "=", "0", "if", "j", "==", "'Sr'", ":", "TMP", "=", "T_TMP", "/", "(", "87.62", "/", "103.619", "*", "10000", ")", "elif", "j", "==", "'Ba'", ":", "TMP", "=", "T_TMP", "/", "(", "137.327", "/", "153.326", "*", "10000", ")", "elif", "j", "==", "'Ni'", ":", "TMP", "=", "T_TMP", "/", "(", "58.6934", "/", "74.69239999999999", "*", "10000", ")", "elif", "j", "==", "'Cr'", ":", "TMP", "=", "T_TMP", "/", "(", "(", "2", "*", "51.9961", ")", "/", "151.98919999999998", "*", "10000", ")", "elif", "j", "==", "'Zr'", ":", "# Zr Multi 2 here", "TMP", "=", "T_TMP", "/", "(", "(", "2", "*", "91.224", ")", "/", "123.22200000000001", "*", "10000", ")", "else", ":", "TMP", "=", "T_TMP", "V", "=", "TMP", "try", ":", "WholeMass", "+=", "float", "(", "V", ")", "except", "ValueError", ":", "pass", "WeightCorrectionFactor", "=", "(", "100", "/", "WholeMass", ")", "for", "j", "in", "self", ".", "Elements", ":", "'''\n Get the Mole percentage of each element\n '''", "try", ":", "T_TMP", "=", "m", "[", "j", "]", "except", "(", "KeyError", ")", ":", "T_TMP", "=", "0", "if", "j", "==", "'Sr'", ":", "TMP", "=", "T_TMP", "/", "(", "87.62", "/", "103.619", "*", "10000", ")", "elif", "j", "==", "'Ba'", ":", "TMP", "=", "T_TMP", "/", "(", "137.327", "/", "153.326", "*", "10000", ")", "elif", "j", "==", "'Ni'", ":", "TMP", "=", "T_TMP", "/", "(", "58.6934", "/", "74.69239999999999", "*", "10000", ")", "elif", "j", "==", "'Cr'", ":", "TMP", "=", "T_TMP", "/", "(", "(", "2", "*", "51.9961", ")", "/", "151.98919999999998", "*", "10000", ")", "elif", "j", "==", "'Zr'", ":", "# Zr not Multiple by 2 Here", "TMP", "=", "T_TMP", "/", "(", "(", "91.224", ")", "/", "123.22200000000001", "*", "10000", ")", "else", ":", "TMP", "=", "T_TMP", "try", ":", "M", "=", "TMP", "/", "self", ".", "BaseMass", "[", "j", "]", "*", "WeightCorrectionFactor", "except", "TypeError", ":", "pass", "# M= TMP/NewMass(j) * WeightCorrectionFactor", "EachMole", ".", "update", "(", "{", "j", ":", "M", "}", ")", "# self.DataMole.append(EachMole)", "DataCalculating", "=", "EachMole", "Fe3", "=", "DataCalculating", "[", "'Fe2O3'", "]", "Fe2", "=", "DataCalculating", "[", "'FeO'", "]", "Mg", "=", "DataCalculating", "[", "'MgO'", "]", "Ca", "=", "DataCalculating", "[", "'CaO'", "]", "Na", "=", "DataCalculating", "[", "'Na2O'", "]", "try", ":", "DataCalced", ".", "update", "(", "{", "'Fe3+/(Total Fe) in rock (Mole)'", ":", "100", "*", "Fe3", "*", "2", "/", "(", "Fe3", "*", "2", "+", "Fe2", ")", "}", ")", "except", "(", "ZeroDivisionError", ")", ":", "DataCalced", ".", "update", "(", "{", "'Fe3+/(Total Fe) in rock (Mole)'", ":", "0", "}", ")", "pass", "try", ":", "DataCalced", ".", "update", "(", "{", "'Mg/(Mg+Total Fe) in rock (Mole)'", ":", "100", "*", "Mg", "/", "(", "Mg", "+", "Fe3", "*", "2", "+", "Fe2", ")", "}", ")", "except", "(", "ZeroDivisionError", ")", ":", "DataCalced", ".", "update", "(", "{", "'Mg/(Mg+Total Fe) in rock (Mole)'", ":", "0", "}", ")", "pass", "try", ":", "DataCalced", ".", "update", "(", "{", "'Mg/(Mg+Fe2+) in rock (Mole)'", ":", "100", "*", "Mg", "/", "(", "Mg", "+", "Fe2", ")", "}", ")", "except", "(", "ZeroDivisionError", ")", ":", "DataCalced", ".", "update", "(", "{", "'Mg/(Mg+Fe2+) in rock (Mole)'", ":", "0", "}", ")", "pass", "try", ":", "DataCalced", ".", "update", "(", "{", "'Ca/(Ca+Na) in rock (Mole)'", ":", "100", "*", "Ca", "/", "(", "Ca", "+", "Na", "*", "2", ")", "}", ")", "except", "(", "ZeroDivisionError", ")", ":", "DataCalced", ".", "update", "(", "{", "'Ca/(Ca+Na) in rock (Mole)'", ":", "0", "}", ")", "pass", "DataCalculating", "[", "'CaO'", "]", "+=", "DataCalculating", "[", "'Sr'", "]", "DataCalculating", "[", "'Sr'", "]", "=", "0", "DataCalculating", "[", "'K2O'", "]", "+=", "2", "*", "DataCalculating", "[", "'Ba'", "]", "DataCalculating", "[", "'Ba'", "]", "=", "0", "try", ":", "if", "DataCalculating", "[", "'CaO'", "]", ">=", "10", "/", "3", "*", "DataCalculating", "[", "'P2O5'", "]", ":", "DataCalculating", "[", "'CaO'", "]", "-=", "10", "/", "3", "*", "DataCalculating", "[", "'P2O5'", "]", "else", ":", "DataCalculating", "[", "'CaO'", "]", "=", "0", "except", "(", "ZeroDivisionError", ")", ":", "pass", "DataCalculating", "[", "'P2O5'", "]", "=", "DataCalculating", "[", "'P2O5'", "]", "/", "1.5", "Apatite", "=", "DataCalculating", "[", "'P2O5'", "]", "# IF(S19>=T15,S19-T15,0)", "if", "DataCalculating", "[", "'F'", "]", ">=", "DataCalculating", "[", "'P2O5'", "]", ":", "DataCalculating", "[", "'F'", "]", "-=", "DataCalculating", "[", "'P2O5'", "]", "else", ":", "DataCalculating", "[", "'F'", "]", "=", "0", "if", "DataCalculating", "[", "'F'", "]", ">=", "DataCalculating", "[", "'P2O5'", "]", ":", "DataCalculating", "[", "'F'", "]", "-=", "DataCalculating", "[", "'P2O5'", "]", "else", ":", "DataCalculating", "[", "'F'", "]", "=", "0", "if", "DataCalculating", "[", "'Na2O'", "]", ">=", "DataCalculating", "[", "'Cl'", "]", ":", "DataCalculating", "[", "'Na2O'", "]", "-=", "DataCalculating", "[", "'Cl'", "]", "else", ":", "DataCalculating", "[", "'Na2O'", "]", "=", "0", "Halite", "=", "DataCalculating", "[", "'Cl'", "]", "# IF(U12>=(U19/2),U12-(U19/2),0)", "if", "DataCalculating", "[", "'CaO'", "]", ">=", "0.5", "*", "DataCalculating", "[", "'F'", "]", ":", "DataCalculating", "[", "'CaO'", "]", "-=", "0.5", "*", "DataCalculating", "[", "'F'", "]", "else", ":", "DataCalculating", "[", "'CaO'", "]", "=", "0", "DataCalculating", "[", "'F'", "]", "*=", "0.5", "Fluorite", "=", "DataCalculating", "[", "'F'", "]", "# =IF(V17>0,IF(V13>=V17,'Thenardite',IF(V13>0,'Both','Anhydrite')),'None')", "AorT", "=", "0", "if", "DataCalculating", "[", "'SO3'", "]", "<=", "0", ":", "AorT", "=", "'None'", "else", ":", "if", "DataCalculating", "[", "'Na2O'", "]", ">=", "DataCalculating", "[", "'SO3'", "]", ":", "AorT", "=", "'Thenardite'", "else", ":", "if", "DataCalculating", "[", "'Na2O'", "]", ">", "0", ":", "AorT", "=", "'Both'", "else", ":", "AorT", "=", "'Anhydrite'", "# =IF(W26='Anhydrite',V17,IF(W26='Both',V12,0))", "# =IF(W26='Thenardite',V17,IF(W26='Both',V17-W17,0))", "if", "AorT", "==", "'Anhydrite'", ":", "DataCalculating", "[", "'Sr'", "]", "=", "0", "elif", "AorT", "==", "'Thenardite'", ":", "DataCalculating", "[", "'Sr'", "]", "=", "DataCalculating", "[", "'SO3'", "]", "DataCalculating", "[", "'SO3'", "]", "=", "0", "elif", "AorT", "==", "'Both'", ":", "DataCalculating", "[", "'Sr'", "]", "=", "DataCalculating", "[", "'SO3'", "]", "-", "DataCalculating", "[", "'CaO'", "]", "DataCalculating", "[", "'SO3'", "]", "=", "DataCalculating", "[", "'CaO'", "]", "else", ":", "DataCalculating", "[", "'SO3'", "]", "=", "0", "DataCalculating", "[", "'Sr'", "]", "=", "0", "DataCalculating", "[", "'CaO'", "]", "-=", "DataCalculating", "[", "'SO3'", "]", "DataCalculating", "[", "'Na2O'", "]", "-=", "DataCalculating", "[", "'Sr'", "]", "Anhydrite", "=", "DataCalculating", "[", "'SO3'", "]", "Thenardite", "=", "DataCalculating", "[", "'Sr'", "]", "Pyrite", "=", "0.5", "*", "DataCalculating", "[", "'S'", "]", "# =IF(W9>=(W18*0.5),W9-(W18*0.5),0)", "if", "DataCalculating", "[", "'FeO'", "]", ">=", "DataCalculating", "[", "'S'", "]", "*", "0.5", ":", "DataCalculating", "[", "'FeO'", "]", "-=", "DataCalculating", "[", "'S'", "]", "*", "0.5", "else", ":", "DataCalculating", "[", "'FeO'", "]", "=", "0", "# =IF(X24>0,IF(X9>=X24,'Chromite',IF(X9>0,'Both','Magnesiochromite')),'None')", "if", "DataCalculating", "[", "'Cr'", "]", ">", "0", ":", "if", "DataCalculating", "[", "'FeO'", "]", ">=", "DataCalculating", "[", "'Cr'", "]", ":", "CorM", "=", "'Chromite'", "elif", "DataCalculating", "[", "'FeO'", "]", ">", "0", ":", "CorM", "=", "'Both'", "else", ":", "CorM", "=", "'Magnesiochromite'", "else", ":", "CorM", "=", "'None'", "# =IF(Y26='Chromite',X24,IF(Y26='Both',X9,0))", "# =IF(Y26='Magnesiochromite',X24,IF(Y26='Both',X24-Y24,0))", "if", "CorM", "==", "'Chromite'", ":", "DataCalculating", "[", "'Cr'", "]", "=", "DataCalculating", "[", "'Cr'", "]", "DataCalculating", "[", "'Ni'", "]", "=", "0", "elif", "CorM", "==", "'Magnesiochromite'", ":", "DataCalculating", "[", "'Ni'", "]", "=", "DataCalculating", "[", "'Cr'", "]", "DataCalculating", "[", "'Cr'", "]", "=", "0", "elif", "CorM", "==", "'Both'", ":", "DataCalculating", "[", "'Ni'", "]", "=", "DataCalculating", "[", "'Cr'", "]", "-", "DataCalculating", "[", "'FeO'", "]", "DataCalculating", "[", "'Cr'", "]", "=", "DataCalculating", "[", "'FeO'", "]", "else", ":", "DataCalculating", "[", "'Cr'", "]", "=", "0", "DataCalculating", "[", "'Ni'", "]", "=", "0", "DataCalculating", "[", "'MgO'", "]", "-=", "DataCalculating", "[", "'Ni'", "]", "Magnesiochromite", "=", "DataCalculating", "[", "'Ni'", "]", "Chromite", "=", "DataCalculating", "[", "'Cr'", "]", "# =IF(X9>=Y24,X9-Y24,0)", "if", "DataCalculating", "[", "'FeO'", "]", ">=", "DataCalculating", "[", "'Cr'", "]", ":", "DataCalculating", "[", "'FeO'", "]", "-=", "DataCalculating", "[", "'Cr'", "]", "else", ":", "DataCalculating", "[", "'FeO'", "]", "=", "0", "# =IF(Y6>0,IF(Y9>=Y6,'Ilmenite',IF(Y9>0,'Both','Sphene')),'None')", "if", "DataCalculating", "[", "'TiO2'", "]", "<", "0", ":", "IorS", "=", "'None'", "else", ":", "if", "DataCalculating", "[", "'FeO'", "]", ">=", "DataCalculating", "[", "'TiO2'", "]", ":", "IorS", "=", "'Ilmenite'", "else", ":", "if", "DataCalculating", "[", "'FeO'", "]", ">", "0", ":", "IorS", "=", "'Both'", "else", ":", "IorS", "=", "'Sphene'", "# =IF(Z26='Ilmenite',Y6,IF(Z26='Both',Y9,0))", "# =IF(Z26='Sphene',Y6,IF(Z26='Both',Y6-Z6,0))", "if", "IorS", "==", "'Ilmenite'", ":", "DataCalculating", "[", "'TiO2'", "]", "=", "DataCalculating", "[", "'TiO2'", "]", "DataCalculating", "[", "'MnO'", "]", "=", "0", "elif", "IorS", "==", "'Sphene'", ":", "DataCalculating", "[", "'MnO'", "]", "=", "DataCalculating", "[", "'TiO2'", "]", "DataCalculating", "[", "'TiO2'", "]", "=", "0", "elif", "IorS", "==", "'Both'", ":", "DataCalculating", "[", "'MnO'", "]", "=", "DataCalculating", "[", "'TiO2'", "]", "-", "DataCalculating", "[", "'FeO'", "]", "DataCalculating", "[", "'TiO2'", "]", "=", "DataCalculating", "[", "'FeO'", "]", "else", ":", "DataCalculating", "[", "'TiO2'", "]", "=", "0", "DataCalculating", "[", "'MnO'", "]", "=", "0", "DataCalculating", "[", "'FeO'", "]", "-=", "DataCalculating", "[", "'TiO2'", "]", "Ilmenite", "=", "DataCalculating", "[", "'TiO2'", "]", "# =IF(Z16>0,IF(Z12>=Z16,'Calcite',IF(Z12>0,'Both','Na2CO3')),'None')", "if", "DataCalculating", "[", "'CO2'", "]", "<=", "0", ":", "CorN", "=", "'None'", "else", ":", "if", "DataCalculating", "[", "'CaO'", "]", ">=", "DataCalculating", "[", "'CO2'", "]", ":", "CorN", "=", "'Calcite'", "else", ":", "if", "DataCalculating", "[", "'CaO'", "]", ">", "0", ":", "CorN", "=", "'Both'", "else", ":", "CorN", "=", "'Na2CO3'", "# =IF(AA26='Calcite',Z16,IF(AA26='Both',Z12,0))", "# =IF(AA26='Na2CO3',Z16,IF(AA26='Both',Z16-AA16,0))", "if", "CorN", "==", "'None'", ":", "DataCalculating", "[", "'CO2'", "]", "=", "0", "DataCalculating", "[", "'SO3'", "]", "=", "0", "elif", "CorN", "==", "'Calcite'", ":", "DataCalculating", "[", "'CO2'", "]", "=", "DataCalculating", "[", "'CO2'", "]", "DataCalculating", "[", "'SO3'", "]", "=", "0", "elif", "CorN", "==", "'Na2CO3'", ":", "DataCalculating", "[", "'SO3'", "]", "=", "DataCalculating", "[", "'SO3'", "]", "DataCalculating", "[", "'CO2'", "]", "=", "0", "elif", "CorN", "==", "'Both'", ":", "DataCalculating", "[", "'SO3'", "]", "=", "DataCalculating", "[", "'CO2'", "]", "-", "DataCalculating", "[", "'CaO'", "]", "DataCalculating", "[", "'CO2'", "]", "=", "DataCalculating", "[", "'CaO'", "]", "DataCalculating", "[", "'CaO'", "]", "-=", "DataCalculating", "[", "'CO2'", "]", "Calcite", "=", "DataCalculating", "[", "'CO2'", "]", "Na2CO3", "=", "DataCalculating", "[", "'SO3'", "]", "# =IF(AA17>Z13,0,Z13-AA17)", "if", "DataCalculating", "[", "'SO3'", "]", ">", "DataCalculating", "[", "'Na2O'", "]", ":", "DataCalculating", "[", "'Na2O'", "]", "=", "0", "else", ":", "DataCalculating", "[", "'Na2O'", "]", "-=", "DataCalculating", "[", "'SO3'", "]", "DataCalculating", "[", "'SiO2'", "]", "-=", "DataCalculating", "[", "'Zr'", "]", "Zircon", "=", "DataCalculating", "[", "'Zr'", "]", "# =IF(AB14>0,IF(AB7>=AB14,'Orthoclase',IF(AB7>0,'Both','K2SiO3')),'None')", "if", "DataCalculating", "[", "'K2O'", "]", "<=", "0", ":", "OorK", "=", "'None'", "else", ":", "if", "DataCalculating", "[", "'Al2O3'", "]", ">=", "DataCalculating", "[", "'K2O'", "]", ":", "OorK", "=", "'Orthoclase'", "else", ":", "if", "DataCalculating", "[", "'Al2O3'", "]", ">", "0", ":", "OorK", "=", "'Both'", "else", ":", "OorK", "=", "'K2SiO3'", "# =IF(AC26='Orthoclase',AB14,IF(AC26='Both',AB7,0))", "# =IF(AC26='K2SiO3',AB14,IF(AC26='Both',AB14-AB7,0))", "if", "OorK", "==", "'None'", ":", "DataCalculating", "[", "'K2O'", "]", "=", "0", "DataCalculating", "[", "'P2O5'", "]", "=", "0", "elif", "OorK", "==", "'Orthoclase'", ":", "DataCalculating", "[", "'K2O'", "]", "=", "DataCalculating", "[", "'K2O'", "]", "DataCalculating", "[", "'P2O5'", "]", "=", "0", "elif", "OorK", "==", "'K2SiO3'", ":", "DataCalculating", "[", "'P2O5'", "]", "=", "DataCalculating", "[", "'K2O'", "]", "DataCalculating", "[", "'K2O'", "]", "=", "0", "elif", "OorK", "==", "'Both'", ":", "DataCalculating", "[", "'P2O5'", "]", "=", "DataCalculating", "[", "'K2O'", "]", "-", "DataCalculating", "[", "'Al2O3'", "]", "DataCalculating", "[", "'K2O'", "]", "=", "DataCalculating", "[", "'Al2O3'", "]", "DataCalculating", "[", "'Al2O3'", "]", "-=", "DataCalculating", "[", "'K2O'", "]", "# =IF(AC13>0,IF(AC7>=AC13,'Albite',IF(AC7>0,'Both','Na2SiO3')),'None')", "if", "DataCalculating", "[", "'Na2O'", "]", "<=", "0", ":", "AorN", "=", "'None'", "else", ":", "if", "DataCalculating", "[", "'Al2O3'", "]", ">=", "DataCalculating", "[", "'Na2O'", "]", ":", "AorN", "=", "'Albite'", "else", ":", "if", "DataCalculating", "[", "'Al2O3'", "]", ">", "0", ":", "AorN", "=", "'Both'", "else", ":", "AorN", "=", "'Na2SiO3'", "# =IF(AND(AC7>=AC13,AC7>0),AC7-AC13,0)", "if", "DataCalculating", "[", "'Al2O3'", "]", ">=", "DataCalculating", "[", "'Na2O'", "]", "and", "DataCalculating", "[", "'Al2O3'", "]", ">", "0", ":", "DataCalculating", "[", "'Al2O3'", "]", "-=", "DataCalculating", "[", "'Na2O'", "]", "else", ":", "DataCalculating", "[", "'Al2O3'", "]", "=", "0", "# =IF(AD26='Albite',AC13,IF(AD26='Both',AC7,0))", "# =IF(AD26='Na2SiO3',AC13,IF(AD26='Both',AC13-AD13,0))", "if", "AorN", "==", "'Albite'", ":", "DataCalculating", "[", "'Cl'", "]", "=", "0", "elif", "AorN", "==", "'Both'", ":", "DataCalculating", "[", "'Cl'", "]", "=", "DataCalculating", "[", "'Na2O'", "]", "-", "DataCalculating", "[", "'Al2O3'", "]", "DataCalculating", "[", "'Na2O'", "]", "=", "DataCalculating", "[", "'Al2O3'", "]", "elif", "AorN", "==", "'Na2SiO3'", ":", "DataCalculating", "[", "'Cl'", "]", "=", "DataCalculating", "[", "'Na2O'", "]", "DataCalculating", "[", "'Na2O'", "]", "=", "0", "elif", "AorN", "==", "'None'", ":", "DataCalculating", "[", "'Na2O'", "]", "=", "0", "DataCalculating", "[", "'Cl'", "]", "=", "0", "# =IF(AD7>0,IF(AD12>0,'Anorthite','None'),'None')", "if", "DataCalculating", "[", "'Al2O3'", "]", "<=", "0", ":", "AorC", "=", "'None'", "else", ":", "if", "DataCalculating", "[", "'CaO'", "]", ">", "0", ":", "AorC", "=", "'Anorthite'", "else", ":", "Aorc", "=", "'None'", "# =IF(AE26='Anorthite',IF(AD12>AD7,0,AD7-AD12),AD7)", "# =IF(AE26='Anorthite',IF(AD7>AD12,0,AD12-AD7),AD12)", "# =IF(AE26='Anorthite',IF(AD7>AD12,AD12,AD7),0)", "if", "AorC", "==", "'Anorthite'", ":", "if", "DataCalculating", "[", "'Al2O3'", "]", ">=", "DataCalculating", "[", "'CaO'", "]", ":", "DataCalculating", "[", "'Sr'", "]", "=", "DataCalculating", "[", "'CaO'", "]", "DataCalculating", "[", "'Al2O3'", "]", "-=", "DataCalculating", "[", "'CaO'", "]", "DataCalculating", "[", "'CaO'", "]", "=", "0", "else", ":", "DataCalculating", "[", "'Sr'", "]", "=", "DataCalculating", "[", "'Al2O3'", "]", "DataCalculating", "[", "'CaO'", "]", "-=", "DataCalculating", "[", "'Al2O3'", "]", "DataCalculating", "[", "'Al2O3'", "]", "=", "0", "else", ":", "DataCalculating", "[", "'Sr'", "]", "=", "0", "Corundum", "=", "DataCalculating", "[", "'Al2O3'", "]", "Anorthite", "=", "DataCalculating", "[", "'Sr'", "]", "# =IF(AE10>0,IF(AE12>=AE10,'Sphene',IF(AE12>0,'Both','Rutile')),'None')", "if", "DataCalculating", "[", "'MnO'", "]", "<=", "0", ":", "SorR", "=", "'None'", "else", ":", "if", "DataCalculating", "[", "'CaO'", "]", ">=", "DataCalculating", "[", "'MnO'", "]", ":", "SorR", "=", "'Sphene'", "elif", "DataCalculating", "[", "'CaO'", "]", ">", "0", ":", "SorR", "=", "'Both'", "else", ":", "SorR", "=", "'Rutile'", "# =IF(AF26='Sphene',AE10,IF(AF26='Both',AE12,0))", "# =IF(AF26='Rutile',AE10,IF(AF26='Both',AE10-AE12,0))", "if", "SorR", "==", "'Sphene'", ":", "DataCalculating", "[", "'MnO'", "]", "=", "DataCalculating", "[", "'MnO'", "]", "DataCalculating", "[", "'S'", "]", "=", "0", "elif", "SorR", "==", "'Rutile'", ":", "DataCalculating", "[", "'S'", "]", "=", "DataCalculating", "[", "'MnO'", "]", "DataCalculating", "[", "'MnO'", "]", "=", "0", "elif", "SorR", "==", "'Both'", ":", "DataCalculating", "[", "'S'", "]", "=", "DataCalculating", "[", "'MnO'", "]", "-", "DataCalculating", "[", "'CaO'", "]", "DataCalculating", "[", "'MnO'", "]", "=", "DataCalculating", "[", "'CaO'", "]", "elif", "SorR", "==", "'None'", ":", "DataCalculating", "[", "'MnO'", "]", "=", "0", "DataCalculating", "[", "'S'", "]", "=", "0", "DataCalculating", "[", "'CaO'", "]", "-=", "DataCalculating", "[", "'MnO'", "]", "Rutile", "=", "DataCalculating", "[", "'S'", "]", "# =IF(AND(AF20>0),IF(AF8>=AF20,'Acmite',IF(AF8>0,'Both','Na2SiO3')),'None')", "if", "DataCalculating", "[", "'Cl'", "]", "<=", "0", ":", "ACorN", "=", "'None'", "else", ":", "if", "DataCalculating", "[", "'Fe2O3'", "]", ">=", "DataCalculating", "[", "'Cl'", "]", ":", "ACorN", "=", "'Acmite'", "else", ":", "if", "DataCalculating", "[", "'Fe2O3'", "]", ">", "0", ":", "ACorN", "=", "'Both'", "else", ":", "ACorN", "=", "'Na2SiO3'", "# =IF(AG26='Acmite',AF20,IF(AG26='Both',AF8,0))", "# =IF(AG26='Na2SiO3',AF20,IF(AG26='Both',AF20-AG19,0))", "if", "ACorN", "==", "'Acmite'", ":", "DataCalculating", "[", "'F'", "]", "=", "DataCalculating", "[", "'Cl'", "]", "DataCalculating", "[", "'Cl'", "]", "=", "0", "elif", "ACorN", "==", "'Na2SiO3'", ":", "DataCalculating", "[", "'Cl'", "]", "=", "DataCalculating", "[", "'Cl'", "]", "DataCalculating", "[", "'F'", "]", "=", "0", "elif", "ACorN", "==", "'Both'", ":", "DataCalculating", "[", "'F'", "]", "=", "DataCalculating", "[", "'Fe2O3'", "]", "DataCalculating", "[", "'Cl'", "]", "=", "DataCalculating", "[", "'Cl'", "]", "-", "DataCalculating", "[", "'F'", "]", "elif", "ACorN", "==", "'None'", ":", "DataCalculating", "[", "'F'", "]", "=", "0", "DataCalculating", "[", "'Cl'", "]", "=", "0", "DataCalculating", "[", "'Fe2O3'", "]", "-=", "DataCalculating", "[", "'F'", "]", "Acmite", "=", "DataCalculating", "[", "'F'", "]", "# =IF(AG8>0,IF(AG9>=AG8,'Magnetite',IF(AG9>0,'Both','Hematite')),'None')", "if", "DataCalculating", "[", "'Fe2O3'", "]", "<=", "0", ":", "MorH", "=", "'None'", "else", ":", "if", "DataCalculating", "[", "'FeO'", "]", ">=", "DataCalculating", "[", "'Fe2O3'", "]", ":", "MorH", "=", "'Magnetite'", "else", ":", "if", "DataCalculating", "[", "'FeO'", "]", ">", "0", ":", "MorH", "=", "'Both'", "else", ":", "MorH", "=", "'Hematite'", "# =IF(AH26='Magnetite',AG8,IF(AH26='Both',AG9,0))", "# =IF(AH26='Hematite',AG8,IF(AH26='Both',AG8-AG9,0))", "if", "MorH", "==", "'Magnetite'", ":", "DataCalculating", "[", "'Fe2O3'", "]", "=", "DataCalculating", "[", "'Fe2O3'", "]", "DataCalculating", "[", "'Ba'", "]", "=", "0", "elif", "MorH", "==", "'Hematite'", ":", "DataCalculating", "[", "'Fe2O3'", "]", "=", "0", "DataCalculating", "[", "'Ba'", "]", "=", "DataCalculating", "[", "'FeO'", "]", "elif", "MorH", "==", "'Both'", ":", "DataCalculating", "[", "'Fe2O3'", "]", "=", "DataCalculating", "[", "'FeO'", "]", "DataCalculating", "[", "'Ba'", "]", "=", "DataCalculating", "[", "'Fe2O3'", "]", "-", "DataCalculating", "[", "'FeO'", "]", "elif", "MorH", "==", "'None'", ":", "DataCalculating", "[", "'Fe2O3'", "]", "=", "0", "DataCalculating", "[", "'Ba'", "]", "==", "0", "DataCalculating", "[", "'FeO'", "]", "-=", "DataCalculating", "[", "'Fe2O3'", "]", "Magnetite", "=", "DataCalculating", "[", "'Fe2O3'", "]", "Hematite", "=", "DataCalculating", "[", "'Ba'", "]", "# =IF(AH11>0,AH11/(AH11+AH9),0)", "Fe2", "=", "DataCalculating", "[", "'FeO'", "]", "Mg", "=", "DataCalculating", "[", "'MgO'", "]", "if", "Mg", ">", "0", ":", "DataCalced", ".", "update", "(", "{", "'Mg/(Mg+Fe2+) in silicates'", ":", "100", "*", "Mg", "/", "(", "Mg", "+", "Fe2", ")", "}", ")", "else", ":", "DataCalced", ".", "update", "(", "{", "'Mg/(Mg+Fe2+) in silicates'", ":", "0", "}", ")", "DataCalculating", "[", "'FeO'", "]", "+=", "DataCalculating", "[", "'MgO'", "]", "DataCalculating", "[", "'MgO'", "]", "=", "0", "# =IF(AI12>0,IF(AI9>=AI12,'Diopside',IF(AI9>0,'Both','Wollastonite')),'None')", "if", "DataCalculating", "[", "'CaO'", "]", "<=", "0", ":", "DorW", "=", "'None'", "else", ":", "if", "DataCalculating", "[", "'FeO'", "]", ">=", "DataCalculating", "[", "'CaO'", "]", ":", "DorW", "=", "'Diopside'", "else", ":", "if", "DataCalculating", "[", "'FeO'", "]", ">", "0", ":", "DorW", "=", "'Both'", "else", ":", "DorW", "=", "'Wollastonite'", "# =IF(AJ26='Diopside',AI12,IF(AJ26='Both',AI9,0))", "# =IF(AJ26='Wollastonite',AI12,IF(AJ26='Both',AI12-AI9,0))", "if", "DorW", "==", "'Diopside'", ":", "DataCalculating", "[", "'CaO'", "]", "=", "DataCalculating", "[", "'CaO'", "]", "DataCalculating", "[", "'S'", "]", "=", "0", "elif", "DorW", "==", "'Wollastonite'", ":", "DataCalculating", "[", "'S'", "]", "=", "DataCalculating", "[", "'CaO'", "]", "DataCalculating", "[", "'CaO'", "]", "=", "0", "elif", "DorW", "==", "'Both'", ":", "DataCalculating", "[", "'S'", "]", "=", "DataCalculating", "[", "'CaO'", "]", "-", "DataCalculating", "[", "'FeO'", "]", "DataCalculating", "[", "'CaO'", "]", "=", "DataCalculating", "[", "'FeO'", "]", "elif", "DorW", "==", "'None'", ":", "DataCalculating", "[", "'CaO'", "]", "=", "0", "DataCalculating", "[", "'S'", "]", "=", "0", "DataCalculating", "[", "'FeO'", "]", "-=", "DataCalculating", "[", "'CaO'", "]", "Diopside", "=", "DataCalculating", "[", "'CaO'", "]", "Quartz", "=", "DataCalculating", "[", "'SiO2'", "]", "Zircon", "=", "DataCalculating", "[", "'Zr'", "]", "K2SiO3", "=", "DataCalculating", "[", "'P2O5'", "]", "Na2SiO3", "=", "DataCalculating", "[", "'Cl'", "]", "Sphene", "=", "DataCalculating", "[", "'MnO'", "]", "Hypersthene", "=", "DataCalculating", "[", "'FeO'", "]", "Albite", "=", "DataCalculating", "[", "'Na2O'", "]", "Orthoclase", "=", "DataCalculating", "[", "'K2O'", "]", "Wollastonite", "=", "DataCalculating", "[", "'S'", "]", "# =AJ5-(AL6)-(AL7)-(AL8*2)-(AL12)-(AL9)-(AL10*4)-(AL11*2)-(AL13)-(AL14*6)-(AL15*6)-(AL16)", "Quartz", "-=", "(", "Zircon", "+", "K2SiO3", "+", "Anorthite", "*", "2", "+", "Na2SiO3", "+", "Acmite", "*", "4", "+", "Diopside", "*", "2", "+", "Sphene", "+", "Hypersthene", "+", "Albite", "*", "6", "+", "Orthoclase", "*", "6", "+", "Wollastonite", ")", "# =IF(AL5>0,AL5,0)", "if", "Quartz", ">", "0", ":", "Quartz", "=", "Quartz", "else", ":", "Quartz", "=", "0", "# =IF(AL13>0,IF(AL5>=0,'Hypersthene',IF(AL13+(2*AL5)>0,'Both','Olivine')),'None')", "if", "Hypersthene", "<=", "0", ":", "HorO", "=", "'None'", "else", ":", "if", "Quartz", ">=", "0", ":", "HorO", "=", "'Hypersthene'", "else", ":", "if", "Hypersthene", "+", "2", "*", "Quartz", ">", "0", ":", "HorO", "=", "'Both'", "else", ":", "HorO", "=", "'Olivine'", "# =IF(AN26='Hypersthene',AL13,IF(AN26='Both',AL13+(2*AL5),0))", "# =IF(AN26='Olivine',AL13*0.5,IF(AN26='Both',ABS(AL5),0))", "Old_Hypersthene", "=", "Hypersthene", "if", "HorO", "==", "'Hypersthene'", ":", "Hypersthene", "=", "Hypersthene", "Olivine", "=", "0", "elif", "HorO", "==", "'Both'", ":", "Hypersthene", "=", "Hypersthene", "+", "Quartz", "*", "2", "Olivine", "=", "abs", "(", "Quartz", ")", "elif", "HorO", "==", "'Olivine'", ":", "Olivine", "=", "Hypersthene", "/", "2", "Hypersthene", "=", "0", "elif", "HorO", "==", "'None'", ":", "Hypersthene", "=", "0", "Olivine", "=", "0", "# =AL5+AL13-(AN13+AN17)", "Quartz", "+=", "Old_Hypersthene", "-", "(", "Hypersthene", "+", "Olivine", ")", "# =IF(AL12>0,IF(AN5>=0,'Sphene',IF(AL12+AN5>0,'Both','Perovskite')),'None')", "if", "Sphene", "<=", "0", ":", "SorP", "=", "'None'", "else", ":", "if", "Quartz", ">=", "0", ":", "SorP", "=", "'Sphene'", "else", ":", "if", "Sphene", "+", "Quartz", ">", "0", ":", "SorP", "=", "'Both'", "else", ":", "SorP", "=", "'Perovskite'", "# =IF(AO26='Sphene',AL12,IF(AO26='Both',AL12+AN5,0))", "# =IF(AO26='Perovskite',AL12,IF(AO26='Both',AL12-AO12,0))", "Old_Sphene", "=", "Sphene", "if", "SorP", "==", "'Sphene'", ":", "Sphene", "=", "Sphene", "Perovskite", "=", "0", "elif", "SorP", "==", "'Perovskite'", ":", "Perovskite", "=", "Sphene", "Sphene", "=", "0", "elif", "SorP", "==", "'Both'", ":", "Sphene", "+=", "Quartz", "Perovskite", "=", "Old_Sphene", "-", "Sphene", "elif", "SorP", "==", "'None'", ":", "Sphene", "=", "0", "Perovskite", "=", "0", "Quartz", "+=", "Old_Sphene", "-", "Sphene", "# =IF(AL14>0,IF(AO5>=0,'Albite',IF(AL14+(AO5/4)>0,'Both','Nepheline')),'None')", "if", "Albite", "<=", "0", ":", "AlorNe", "=", "'None'", "else", ":", "if", "Quartz", ">=", "0", ":", "AlorNe", "=", "'Albite'", "else", ":", "if", "Albite", "+", "(", "Quartz", "/", "4", ")", ">", "0", ":", "AlorNe", "=", "'Both'", "else", ":", "AlorNe", "=", "'Nepheline'", "# =AO5+(6*AL14)-(AP14*6)-(AP19*2)", "# =IF(AP26='Albite',AL14,IF(AP26='Both',AL14+(AO5/4),0))", "# =IF(AP26='Nepheline',AL14,IF(AP26='Both',AL14-AP14,0))", "Old_Albite", "=", "Albite", "if", "AlorNe", "==", "'Albite'", ":", "Albite", "=", "Albite", "Nepheline", "=", "0", "elif", "AlorNe", "==", "'Nepheline'", ":", "Nepheline", "=", "Albite", "Albite", "=", "0", "elif", "AlorNe", "==", "'Both'", ":", "Albite", "+=", "Quartz", "/", "4", "Nepheline", "=", "Old_Albite", "-", "Albite", "elif", "AlorNe", "==", "'None'", ":", "Nepheline", "=", "0", "Albite", "=", "0", "Quartz", "+=", "(", "6", "*", "Old_Albite", ")", "-", "(", "Albite", "*", "6", ")", "-", "(", "Nepheline", "*", "2", ")", "# =IF(AL8=0,0,AL8/(AL8+(AP14*2)))", "if", "Anorthite", "==", "0", ":", "DataCalced", ".", "update", "(", "{", "'Plagioclase An content'", ":", "0", "}", ")", "else", ":", "DataCalced", ".", "update", "(", "{", "'Plagioclase An content'", ":", "100", "*", "Anorthite", "/", "(", "Anorthite", "+", "2", "*", "Albite", ")", "}", ")", "# =IF(AL15>0,IF(AP5>=0,'Orthoclase',IF(AL15+(AP5/2)>0,'Both','Leucite')),'None')", "if", "Orthoclase", "<=", "0", ":", "OorL", "=", "'None'", "else", ":", "if", "Quartz", ">=", "0", ":", "OorL", "=", "'Orthoclase'", "else", ":", "if", "Orthoclase", "+", "Quartz", "/", "2", ">", "0", ":", "OorL", "=", "'Both'", "else", ":", "OorL", "=", "'Leucite'", "# =IF(AQ26='Orthoclase',AL15,IF(AQ26='Both',AL15+(AP5/2),0))", "# =IF(AQ26='Leucite',AL15,IF(AQ26='Both',AL15-AQ15,0))", "Old_Orthoclase", "=", "Orthoclase", "if", "OorL", "==", "'Orthoclase'", ":", "Orthoclase", "=", "Orthoclase", "Leucite", "=", "0", "elif", "OorL", "==", "'Leucite'", ":", "Leucite", "=", "Orthoclase", "Orthoclase", "=", "0", "elif", "OorL", "==", "'Both'", ":", "Orthoclase", "+=", "Quartz", "/", "2", "Leucite", "=", "Old_Orthoclase", "-", "Orthoclase", "elif", "OorL", "==", "'None'", ":", "Orthoclase", "=", "0", "Leucite", "=", "0", "# =AP5+(AL15*6)-(AQ15*6)-(AQ20*4)", "Quartz", "+=", "(", "Old_Orthoclase", "*", "6", ")", "-", "(", "Orthoclase", "*", "6", ")", "-", "(", "Leucite", "*", "4", ")", "# =IF(AL16>0,IF(AQ5>=0,'Wollastonite',IF(AL16+(AQ5*2)>0,'Both','Larnite')),'None')", "if", "Wollastonite", "<=", "0", ":", "WorB", "=", "'None'", "else", ":", "if", "Quartz", ">=", "0", ":", "WorB", "=", "'Wollastonite'", "else", ":", "if", "Wollastonite", "+", "Quartz", "/", "2", ">", "0", ":", "WorB", "=", "'Both'", "else", ":", "WorB", "=", "'Larnite'", "# =IF(AR26='Wollastonite',AL16,IF(AR26='Both',AL16+(2*AQ5),0))", "# =IF(AR26='Larnite',AL16/2,IF(AR26='Both',(AL16-AR16)/2,0))", "Old_Wollastonite", "=", "Wollastonite", "if", "WorB", "==", "'Wollastonite'", ":", "Wollastonite", "=", "Wollastonite", "Larnite", "=", "0", "elif", "WorB", "==", "'Larnite'", ":", "Larnite", "=", "Wollastonite", "/", "2", "Wollastonite", "=", "0", "elif", "WorB", "==", "'Both'", ":", "Wollastonite", "+=", "Quartz", "*", "2", "Larnite", "=", "(", "Old_Wollastonite", "-", "Wollastonite", ")", "/", "2", "elif", "WorB", "==", "'None'", ":", "Wollastonite", "=", "0", "Larnite", "=", "0", "# =AQ5+AL16-AR16-AR21", "Quartz", "+=", "Old_Wollastonite", "-", "Wollastonite", "-", "Larnite", "# =IF(AL11>0,IF(AR5>=0,'Diopside',IF(AL11+AR5>0,'Both','LarniteOlivine')),'None')", "if", "Diopside", "<=", "0", ":", "DorL", "=", "'None'", "else", ":", "if", "Quartz", ">=", "0", ":", "DorL", "=", "'Diopside'", "else", ":", "if", "Diopside", "+", "Quartz", ">", "0", ":", "DorL", "=", "'Both'", "else", ":", "DorL", "=", "'LarniteOlivine'", "# =IF(AS26='Diopside',AL11,IF(AS26='Both',AL11+AR5,0))", "# =(IF(AS26='LarniteOlivine',AL11/2,IF(AS26='Both',(AL11-AS11)/2,0)))+AN17", "# =(IF(AS26='LarniteOlivine',AL11/2,IF(AS26='Both',(AL11-AS11)/2,0)))+AR21", "Old_Diopside", "=", "Diopside", "Old_Larnite", "=", "Larnite", "Old_Olivine", "=", "Olivine", "if", "DorL", "==", "'Diopside'", ":", "Diopside", "=", "Diopside", "elif", "DorL", "==", "'LarniteOlivine'", ":", "Larnite", "+=", "Diopside", "/", "2", "Olivine", "+=", "Diopside", "/", "2", "Diopside", "=", "0", "elif", "DorL", "==", "'Both'", ":", "Diopside", "+=", "Quartz", "Larnite", "+=", "Old_Diopside", "-", "Diopside", "Olivine", "+=", "Old_Diopside", "-", "Diopside", "elif", "DorL", "==", "'None'", ":", "Diopside", "=", "0", "# =AR5+(AL11*2)+AN17+AR21-AS21-(AS11*2)-AS17", "Quartz", "+=", "(", "Old_Diopside", "*", "2", ")", "+", "Old_Olivine", "+", "Old_Larnite", "-", "Larnite", "-", "(", "Diopside", "*", "2", ")", "-", "Olivine", "# =IF(AQ20>0,IF(AS5>=0,'Leucite',IF(AQ20+(AS5/2)>0,'Both','Kalsilite')),'None')", "if", "Leucite", "<=", "0", ":", "LorK", "=", "'None'", "else", ":", "if", "Quartz", ">=", "0", ":", "LorK", "=", "'Leucite'", "else", ":", "if", "Leucite", "+", "Quartz", "/", "2", ">", "0", ":", "LorK", "=", "'Both'", "else", ":", "LorK", "=", "'Kalsilite'", "# =IF(AT26='Leucite',AQ20,IF(AT26='Both',AQ20+(AS5/2),0))", "# =IF(AT26='Kalsilite',AQ20,IF(AT26='Both',AQ20-AT20,0))", "Old_Leucite", "=", "Leucite", "if", "LorK", "==", "'Leucite'", ":", "Leucite", "=", "Leucite", "Kalsilite", "=", "0", "elif", "LorK", "==", "'Kalsilite'", ":", "Kalsilite", "=", "Leucite", "Leucite", "=", "0", "elif", "LorK", "==", "'Both'", ":", "Leucite", "+=", "Quartz", "/", "2", "Kalsilite", "=", "Old_Leucite", "-", "Leucite", "elif", "LorK", "==", "'None'", ":", "Leucite", "=", "0", "Kalsilite", "=", "0", "# =AS5+(AQ20*4)-(AT20*4)-(AT22*2)", "Quartz", "+=", "Old_Leucite", "*", "4", "-", "Leucite", "*", "4", "-", "Kalsilite", "*", "2", "Q", "=", "Quartz", "A", "=", "Orthoclase", "P", "=", "Anorthite", "+", "Albite", "F", "=", "Nepheline", "+", "Leucite", "+", "Kalsilite", "DataResult", ".", "update", "(", "{", "'Quartz'", ":", "Quartz", "}", ")", "DataResult", ".", "update", "(", "{", "'Zircon'", ":", "Zircon", "}", ")", "DataResult", ".", "update", "(", "{", "'K2SiO3'", ":", "K2SiO3", "}", ")", "DataResult", ".", "update", "(", "{", "'Anorthite'", ":", "Anorthite", "}", ")", "DataResult", ".", "update", "(", "{", "'Na2SiO3'", ":", "Na2SiO3", "}", ")", "DataResult", ".", "update", "(", "{", "'Acmite'", ":", "Acmite", "}", ")", "DataResult", ".", "update", "(", "{", "'Diopside'", ":", "Diopside", "}", ")", "DataResult", ".", "update", "(", "{", "'Sphene'", ":", "Sphene", "}", ")", "DataResult", ".", "update", "(", "{", "'Hypersthene'", ":", "Hypersthene", "}", ")", "DataResult", ".", "update", "(", "{", "'Albite'", ":", "Albite", "}", ")", "DataResult", ".", "update", "(", "{", "'Orthoclase'", ":", "Orthoclase", "}", ")", "DataResult", ".", "update", "(", "{", "'Wollastonite'", ":", "Wollastonite", "}", ")", "DataResult", ".", "update", "(", "{", "'Olivine'", ":", "Olivine", "}", ")", "DataResult", ".", "update", "(", "{", "'Perovskite'", ":", "Perovskite", "}", ")", "DataResult", ".", "update", "(", "{", "'Nepheline'", ":", "Nepheline", "}", ")", "DataResult", ".", "update", "(", "{", "'Leucite'", ":", "Leucite", "}", ")", "DataResult", ".", "update", "(", "{", "'Larnite'", ":", "Larnite", "}", ")", "DataResult", ".", "update", "(", "{", "'Kalsilite'", ":", "Kalsilite", "}", ")", "DataResult", ".", "update", "(", "{", "'Apatite'", ":", "Apatite", "}", ")", "DataResult", ".", "update", "(", "{", "'Halite'", ":", "Halite", "}", ")", "DataResult", ".", "update", "(", "{", "'Fluorite'", ":", "Fluorite", "}", ")", "DataResult", ".", "update", "(", "{", "'Anhydrite'", ":", "Anhydrite", "}", ")", "DataResult", ".", "update", "(", "{", "'Thenardite'", ":", "Thenardite", "}", ")", "DataResult", ".", "update", "(", "{", "'Pyrite'", ":", "Pyrite", "}", ")", "DataResult", ".", "update", "(", "{", "'Magnesiochromite'", ":", "Magnesiochromite", "}", ")", "DataResult", ".", "update", "(", "{", "'Chromite'", ":", "Chromite", "}", ")", "DataResult", ".", "update", "(", "{", "'Ilmenite'", ":", "Ilmenite", "}", ")", "DataResult", ".", "update", "(", "{", "'Calcite'", ":", "Calcite", "}", ")", "DataResult", ".", "update", "(", "{", "'Na2CO3'", ":", "Na2CO3", "}", ")", "DataResult", ".", "update", "(", "{", "'Corundum'", ":", "Corundum", "}", ")", "DataResult", ".", "update", "(", "{", "'Rutile'", ":", "Rutile", "}", ")", "DataResult", ".", "update", "(", "{", "'Magnetite'", ":", "Magnetite", "}", ")", "DataResult", ".", "update", "(", "{", "'Hematite'", ":", "Hematite", "}", ")", "DataResult", ".", "update", "(", "{", "'Q Mole'", ":", "Q", "}", ")", "DataResult", ".", "update", "(", "{", "'A Mole'", ":", "A", "}", ")", "DataResult", ".", "update", "(", "{", "'P Mole'", ":", "P", "}", ")", "DataResult", ".", "update", "(", "{", "'F Mole'", ":", "F", "}", ")", "DataWeight", ".", "update", "(", "{", "'Quartz'", ":", "Quartz", "*", "self", ".", "DataBase", "[", "'Quartz'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Zircon'", ":", "Zircon", "*", "self", ".", "DataBase", "[", "'Zircon'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'K2SiO3'", ":", "K2SiO3", "*", "self", ".", "DataBase", "[", "'K2SiO3'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Anorthite'", ":", "Anorthite", "*", "self", ".", "DataBase", "[", "'Anorthite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Na2SiO3'", ":", "Na2SiO3", "*", "self", ".", "DataBase", "[", "'Na2SiO3'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Acmite'", ":", "Acmite", "*", "self", ".", "DataBase", "[", "'Acmite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Diopside'", ":", "Diopside", "*", "self", ".", "DataBase", "[", "'Diopside'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Sphene'", ":", "Sphene", "*", "self", ".", "DataBase", "[", "'Sphene'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Hypersthene'", ":", "Hypersthene", "*", "self", ".", "DataBase", "[", "'Hypersthene'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Albite'", ":", "Albite", "*", "self", ".", "DataBase", "[", "'Albite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Orthoclase'", ":", "Orthoclase", "*", "self", ".", "DataBase", "[", "'Orthoclase'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Wollastonite'", ":", "Wollastonite", "*", "self", ".", "DataBase", "[", "'Wollastonite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Olivine'", ":", "Olivine", "*", "self", ".", "DataBase", "[", "'Olivine'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Perovskite'", ":", "Perovskite", "*", "self", ".", "DataBase", "[", "'Perovskite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Nepheline'", ":", "Nepheline", "*", "self", ".", "DataBase", "[", "'Nepheline'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Leucite'", ":", "Leucite", "*", "self", ".", "DataBase", "[", "'Leucite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Larnite'", ":", "Larnite", "*", "self", ".", "DataBase", "[", "'Larnite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Kalsilite'", ":", "Kalsilite", "*", "self", ".", "DataBase", "[", "'Kalsilite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Apatite'", ":", "Apatite", "*", "self", ".", "DataBase", "[", "'Apatite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Halite'", ":", "Halite", "*", "self", ".", "DataBase", "[", "'Halite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Fluorite'", ":", "Fluorite", "*", "self", ".", "DataBase", "[", "'Fluorite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Anhydrite'", ":", "Anhydrite", "*", "self", ".", "DataBase", "[", "'Anhydrite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Thenardite'", ":", "Thenardite", "*", "self", ".", "DataBase", "[", "'Thenardite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Pyrite'", ":", "Pyrite", "*", "self", ".", "DataBase", "[", "'Pyrite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Magnesiochromite'", ":", "Magnesiochromite", "*", "self", ".", "DataBase", "[", "'Magnesiochromite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Chromite'", ":", "Chromite", "*", "self", ".", "DataBase", "[", "'Chromite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Ilmenite'", ":", "Ilmenite", "*", "self", ".", "DataBase", "[", "'Ilmenite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Calcite'", ":", "Calcite", "*", "self", ".", "DataBase", "[", "'Calcite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Na2CO3'", ":", "Na2CO3", "*", "self", ".", "DataBase", "[", "'Na2CO3'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Corundum'", ":", "Corundum", "*", "self", ".", "DataBase", "[", "'Corundum'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Rutile'", ":", "Rutile", "*", "self", ".", "DataBase", "[", "'Rutile'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Magnetite'", ":", "Magnetite", "*", "self", ".", "DataBase", "[", "'Magnetite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Hematite'", ":", "Hematite", "*", "self", ".", "DataBase", "[", "'Hematite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'Q Weight'", ":", "Quartz", "*", "self", ".", "DataBase", "[", "'Quartz'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'A Weight'", ":", "Orthoclase", "*", "self", ".", "DataBase", "[", "'Orthoclase'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'P Weight'", ":", "Anorthite", "*", "self", ".", "DataBase", "[", "'Anorthite'", "]", "[", "0", "]", "+", "Albite", "*", "self", ".", "DataBase", "[", "'Albite'", "]", "[", "0", "]", "}", ")", "DataWeight", ".", "update", "(", "{", "'F Weight'", ":", "Nepheline", "*", "self", ".", "DataBase", "[", "'Nepheline'", "]", "[", "0", "]", "+", "Leucite", "*", "self", ".", "DataBase", "[", "'Leucite'", "]", "[", "0", "]", "+", "Kalsilite", "*", "self", ".", "DataBase", "[", "'Kalsilite'", "]", "[", "0", "]", "}", ")", "WholeVolume", "=", "0", "WholeMole", "=", "0", "tmpVolume", "=", "[", "]", "tmpVolume", ".", "append", "(", "Quartz", "*", "self", ".", "DataBase", "[", "'Quartz'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Quartz'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Zircon", "*", "self", ".", "DataBase", "[", "'Zircon'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Zircon'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "K2SiO3", "*", "self", ".", "DataBase", "[", "'K2SiO3'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'K2SiO3'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Anorthite", "*", "self", ".", "DataBase", "[", "'Anorthite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Anorthite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Na2SiO3", "*", "self", ".", "DataBase", "[", "'Na2SiO3'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Na2SiO3'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Acmite", "*", "self", ".", "DataBase", "[", "'Acmite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Acmite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Diopside", "*", "self", ".", "DataBase", "[", "'Diopside'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Diopside'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Sphene", "*", "self", ".", "DataBase", "[", "'Sphene'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Sphene'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Hypersthene", "*", "self", ".", "DataBase", "[", "'Hypersthene'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Hypersthene'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Albite", "*", "self", ".", "DataBase", "[", "'Albite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Albite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Orthoclase", "*", "self", ".", "DataBase", "[", "'Orthoclase'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Orthoclase'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Wollastonite", "*", "self", ".", "DataBase", "[", "'Wollastonite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Wollastonite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Olivine", "*", "self", ".", "DataBase", "[", "'Olivine'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Olivine'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Perovskite", "*", "self", ".", "DataBase", "[", "'Perovskite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Perovskite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Nepheline", "*", "self", ".", "DataBase", "[", "'Nepheline'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Nepheline'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Leucite", "*", "self", ".", "DataBase", "[", "'Leucite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Leucite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Larnite", "*", "self", ".", "DataBase", "[", "'Larnite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Larnite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Kalsilite", "*", "self", ".", "DataBase", "[", "'Kalsilite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Kalsilite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Apatite", "*", "self", ".", "DataBase", "[", "'Apatite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Apatite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Halite", "*", "self", ".", "DataBase", "[", "'Halite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Halite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Fluorite", "*", "self", ".", "DataBase", "[", "'Fluorite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Fluorite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Anhydrite", "*", "self", ".", "DataBase", "[", "'Anhydrite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Anhydrite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Thenardite", "*", "self", ".", "DataBase", "[", "'Thenardite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Thenardite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Pyrite", "*", "self", ".", "DataBase", "[", "'Pyrite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Pyrite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Magnesiochromite", "*", "self", ".", "DataBase", "[", "'Magnesiochromite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Magnesiochromite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Chromite", "*", "self", ".", "DataBase", "[", "'Chromite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Chromite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Ilmenite", "*", "self", ".", "DataBase", "[", "'Ilmenite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Ilmenite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Calcite", "*", "self", ".", "DataBase", "[", "'Calcite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Calcite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Na2CO3", "*", "self", ".", "DataBase", "[", "'Na2CO3'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Na2CO3'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Corundum", "*", "self", ".", "DataBase", "[", "'Corundum'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Corundum'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Rutile", "*", "self", ".", "DataBase", "[", "'Rutile'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Rutile'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Magnetite", "*", "self", ".", "DataBase", "[", "'Magnetite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Magnetite'", "]", "[", "1", "]", ")", "tmpVolume", ".", "append", "(", "Hematite", "*", "self", ".", "DataBase", "[", "'Hematite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Hematite'", "]", "[", "1", "]", ")", "WholeVolume", "=", "sum", "(", "tmpVolume", ")", "DataVolume", ".", "update", "(", "{", "'Quartz'", ":", "(", "Quartz", "*", "self", ".", "DataBase", "[", "'Quartz'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Quartz'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Zircon'", ":", "(", "Zircon", "*", "self", ".", "DataBase", "[", "'Zircon'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Zircon'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'K2SiO3'", ":", "(", "K2SiO3", "*", "self", ".", "DataBase", "[", "'K2SiO3'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'K2SiO3'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Anorthite'", ":", "(", "Anorthite", "*", "self", ".", "DataBase", "[", "'Anorthite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Anorthite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Na2SiO3'", ":", "(", "Na2SiO3", "*", "self", ".", "DataBase", "[", "'Na2SiO3'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Na2SiO3'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Acmite'", ":", "(", "Acmite", "*", "self", ".", "DataBase", "[", "'Acmite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Acmite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Diopside'", ":", "(", "Diopside", "*", "self", ".", "DataBase", "[", "'Diopside'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Diopside'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Sphene'", ":", "(", "Sphene", "*", "self", ".", "DataBase", "[", "'Sphene'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Sphene'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Hypersthene'", ":", "(", "Hypersthene", "*", "self", ".", "DataBase", "[", "'Hypersthene'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Hypersthene'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Albite'", ":", "(", "Albite", "*", "self", ".", "DataBase", "[", "'Albite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Albite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Orthoclase'", ":", "(", "Orthoclase", "*", "self", ".", "DataBase", "[", "'Orthoclase'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Orthoclase'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Wollastonite'", ":", "(", "Wollastonite", "*", "self", ".", "DataBase", "[", "'Wollastonite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Wollastonite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Olivine'", ":", "(", "Olivine", "*", "self", ".", "DataBase", "[", "'Olivine'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Olivine'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Perovskite'", ":", "(", "Perovskite", "*", "self", ".", "DataBase", "[", "'Perovskite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Perovskite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Nepheline'", ":", "(", "Nepheline", "*", "self", ".", "DataBase", "[", "'Nepheline'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Nepheline'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Leucite'", ":", "(", "Leucite", "*", "self", ".", "DataBase", "[", "'Leucite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Leucite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Larnite'", ":", "(", "Larnite", "*", "self", ".", "DataBase", "[", "'Larnite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Larnite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Kalsilite'", ":", "(", "Kalsilite", "*", "self", ".", "DataBase", "[", "'Kalsilite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Kalsilite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Apatite'", ":", "(", "Apatite", "*", "self", ".", "DataBase", "[", "'Apatite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Apatite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Halite'", ":", "(", "Halite", "*", "self", ".", "DataBase", "[", "'Halite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Halite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Fluorite'", ":", "(", "Fluorite", "*", "self", ".", "DataBase", "[", "'Fluorite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Fluorite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Anhydrite'", ":", "(", "Anhydrite", "*", "self", ".", "DataBase", "[", "'Anhydrite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Anhydrite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Thenardite'", ":", "(", "Thenardite", "*", "self", ".", "DataBase", "[", "'Thenardite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Thenardite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Pyrite'", ":", "(", "Pyrite", "*", "self", ".", "DataBase", "[", "'Pyrite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Pyrite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Magnesiochromite'", ":", "(", "Magnesiochromite", "*", "self", ".", "DataBase", "[", "'Magnesiochromite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Magnesiochromite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Chromite'", ":", "(", "Chromite", "*", "self", ".", "DataBase", "[", "'Chromite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Chromite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Ilmenite'", ":", "(", "Ilmenite", "*", "self", ".", "DataBase", "[", "'Ilmenite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Ilmenite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Calcite'", ":", "(", "Calcite", "*", "self", ".", "DataBase", "[", "'Calcite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Calcite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Na2CO3'", ":", "(", "Na2CO3", "*", "self", ".", "DataBase", "[", "'Na2CO3'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Na2CO3'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Corundum'", ":", "(", "Corundum", "*", "self", ".", "DataBase", "[", "'Corundum'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Corundum'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Rutile'", ":", "(", "Rutile", "*", "self", ".", "DataBase", "[", "'Rutile'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Rutile'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Magnetite'", ":", "(", "Magnetite", "*", "self", ".", "DataBase", "[", "'Magnetite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Magnetite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Hematite'", ":", "(", "Hematite", "*", "self", ".", "DataBase", "[", "'Hematite'", "]", "[", "0", "]", "/", "self", ".", "DataBase", "[", "'Hematite'", "]", "[", "1", "]", ")", "/", "WholeVolume", "*", "100", "}", ")", "DataVolume", ".", "update", "(", "{", "'Q'", ":", "DataVolume", "[", "'Quartz'", "]", "}", ")", "DataVolume", ".", "update", "(", "{", "'A'", ":", "DataVolume", "[", "'Orthoclase'", "]", "}", ")", "DataVolume", ".", "update", "(", "{", "'P'", ":", "DataVolume", "[", "'Anorthite'", "]", "+", "DataVolume", "[", "'Albite'", "]", "}", ")", "DataVolume", ".", "update", "(", "{", "'F'", ":", "DataVolume", "[", "'Nepheline'", "]", "+", "DataVolume", "[", "'Leucite'", "]", "+", "DataVolume", "[", "'Kalsilite'", "]", "}", ")", "DI", "=", "0", "# for i in ['Quartz', 'Anorthite', 'Albite', 'Orthoclase', 'Nepheline', 'Leucite', 'Kalsilite']:", "# exec('DI+=' + i + '*self.DataBase[\\'' + i + '\\'][0]')", "DI", "=", "Quartz", "+", "Anorthite", "+", "Albite", "+", "Orthoclase", "+", "Nepheline", "+", "Leucite", "+", "Kalsilite", "DiWeight", "=", "0", "DiVolume", "=", "0", "DiWeight", "=", "DataWeight", "[", "'Quartz'", "]", "+", "DataWeight", "[", "'Anorthite'", "]", "+", "DataWeight", "[", "'Albite'", "]", "+", "DataWeight", "[", "'Orthoclase'", "]", "+", "DataWeight", "[", "'Nepheline'", "]", "+", "DataWeight", "[", "'Leucite'", "]", "+", "DataWeight", "[", "'Kalsilite'", "]", "DiVolume", "=", "DataVolume", "[", "'Quartz'", "]", "+", "DataVolume", "[", "'Anorthite'", "]", "+", "DataVolume", "[", "'Albite'", "]", "+", "DataVolume", "[", "'Orthoclase'", "]", "+", "DataVolume", "[", "'Nepheline'", "]", "+", "DataVolume", "[", "'Leucite'", "]", "+", "DataVolume", "[", "'Kalsilite'", "]", "# print('\\n\\n DI is\\n',DI,'\\n\\n')", "DataCalced", ".", "update", "(", "{", "'Differentiation Index Weight'", ":", "DiWeight", "}", ")", "DataCalced", ".", "update", "(", "{", "'Differentiation Index Volume'", ":", "DiVolume", "}", ")", "return", "(", "DataResult", ",", "DataWeight", ",", "DataVolume", ",", "DataCalced", ")" ]
Seem like should be =IF(AD7>0,IF(AD12>AD7,'Anorthite','Corundum'),'None') If Al2O3 is left after alloting orthoclase and albite, then: Anorthite = Al2O3, CaO = CaO - Al2O3, SiO2 = SiO2 - 2 Al2O3, Al2O3 = 0 If Al2O3 exceeds CaO in the preceding calculation, then: Anorthite = CaO, Al2O3 = Al2O3 - CaO, SiO2 = SiO2 - 2 CaO Corundum = Al2O3, CaO =0, Al2O3 = 0 if DataCalculating['Al2O3']<=0: AorC='None' else: if DataCalculating['CaO']>DataCalculating['Al2O3']: AorC= 'Anorthite' else: Aorc='Corundum'
[ "Seem", "like", "should", "be", "=", "IF", "(", "AD7", ">", "0", "IF", "(", "AD12", ">", "AD7", "Anorthite", "Corundum", ")", "None", ")" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/NewCIPW.py#L307-L1492
GeoPyTool/GeoPyTool
geopytool/__init__.py
Ui_MainWindow.retranslateUi
def retranslateUi(self): _translate = QtCore.QCoreApplication.translate self.talk= _translate('MainWindow','You are using GeoPyTool ') + version +'\n'+ _translate('MainWindow','released on ') + date + '\n' self.menuFile.setTitle(_translate('MainWindow', u'Data File')) self.menuGeoChem.setTitle(_translate('MainWindow', u'Geochemistry')) self.menuGeoCalc.setTitle(_translate('MainWindow',u'Calculation')) self.menuStructure.setTitle(_translate('MainWindow', u'Structure')) self.menuSedimentary.setTitle(_translate('MainWindow', u'Sedimentary')) self.menuAdditional.setTitle(_translate('MainWindow', u'Additional Functions')) self.menuHelp.setTitle(_translate('MainWindow', u'Help')) self.menuLanguage.setTitle(_translate('MainWindow', u'Language')) self.actionCombine.setText(_translate('MainWindow', u'Combine')) self.actionCombine_transverse.setText(_translate('MainWindow', u'Combine_transverse')) self.actionFlatten.setText(_translate('MainWindow',u'Flatten')) self.actionTrans.setText(_translate('MainWindow',u'Trans')) self.actionReFormat.setText(_translate('MainWindow',u'ReFormat')) self.actionOpen.setText(_translate('MainWindow', u'Open Data')) self.actionClose.setText(_translate('MainWindow', u'Close Data')) self.actionSet.setText(_translate('MainWindow', u'Set Format')) self.actionSave.setText(_translate('MainWindow', u'Save Data')) self.actionQuit.setText(_translate('MainWindow', u'Quit App')) self.actionRemoveLOI.setText('1-0 '+_translate('MainWindow',u'Remove LOI')) self.actionAuto.setText('1-1 '+_translate('MainWindow', u'Auto')) self.actionTAS.setText('1-2 '+ _translate('MainWindow',u'TAS')) self.actionTrace.setText('1-3 '+_translate('MainWindow',u'Trace')) self.actionRee.setText('1-4 '+_translate('MainWindow',u'REE')) self.actionPearce.setText('1-5 '+_translate('MainWindow',u'Pearce')) self.actionHarker.setText('1-6 '+_translate('MainWindow',u'Harker')) self.actionCIPW.setText('1-7 '+_translate('MainWindow',u'CIPW')) self.actionQAPF.setText('1-8 '+_translate('MainWindow',u'QAPF')) self.actionSaccani.setText('1-9 '+_translate('MainWindow',u'Saccani Plot')) self.actionK2OSiO2.setText('1-10 '+_translate('MainWindow',u'K2O-SiO2')) self.actionRaman.setText('1-11 '+_translate('MainWindow',u'Raman Strength')) self.actionFluidInclusion.setText('1-12 '+_translate('MainWindow',u'Fluid Inclusion')) self.actionHarkerOld.setText('1-14 '+_translate('MainWindow',u'Harker Classical')) self.actionTraceNew.setText('1-15 '+_translate('MainWindow',u'TraceNew')) self.actionStereo.setText('2-1 '+_translate('MainWindow',u'Stereo')) self.actionRose.setText('2-2 '+_translate('MainWindow',u'Rose')) self.actionQFL.setText('3-1 '+_translate('MainWindow',u'QFL')) self.actionQmFLt.setText('3-2 '+_translate('MainWindow',u'QmFLt')) self.actionClastic.setText('3-3 '+_translate('MainWindow',u'Clastic')) self.actionCIA.setText('3-4 '+ _translate('MainWindow',u'CIA and ICV')) self.actionZirconCe.setText('4-1 '+ _translate('MainWindow',u'ZirconCe')) self.actionZirconCeOld.setText('4-2 '+ _translate('MainWindow', u'ZirconCeOld')) self.actionZirconTiTemp.setText('4-3 '+ _translate('MainWindow',u'ZirconTiTemp')) self.actionRutileZrTemp.setText('4-4 '+_translate('MainWindow',u'RutileZrTemp')) self.actionRbSrIsoTope.setText('4-5 '+_translate('MainWindow',u'Rb-Sr IsoTope')) self.actionSmNdIsoTope.setText('4-6 '+_translate('MainWindow',u'Sm-Nd IsoTope')) #self.actionKArIsoTope.setText(_translate('MainWindow',u'K-Ar IsoTope')) self.actionXY.setText('5-1 '+_translate('MainWindow',u'X-Y plot')) self.actionXYZ.setText('5-2 '+_translate('MainWindow',u'X-Y-Z plot')) self.actionCluster.setText('5-3 '+_translate('MainWindow',u'Cluster')) self.actionMultiDimension.setText('5-4 '+_translate('MainWindow',u'MultiDimension')) self.actionFA.setText('5-5 '+_translate('MainWindow',u'FA')) self.actionPCA.setText('5-6 '+_translate('MainWindow',u'PCA')) self.actionDist.setText('5-7 '+_translate('MainWindow',u'Distance')) self.actionStatistics.setText('5-8 '+_translate('MainWindow',u'Statistics')) self.actionThreeD.setText('5-9 '+_translate('MainWindow',u'ThreeD')) self.actionTwoD.setText('5-10 '+_translate('MainWindow',u'TwoD')) self.actionTwoD_Grey.setText('5-11 '+_translate('MainWindow',u'TwoD Grey')) self.actionMyHist.setText('5-12 '+_translate('MainWindow',u'Histogram + KDE Curve')) self.actionVersionCheck.setText(_translate('MainWindow', u'Check Update')) self.actionWeb.setText(_translate('MainWindow', u'English Forum')) self.actionGoGithub.setText(_translate('MainWindow', u'Github')) ''' self.actionCnS.setText(_translate('MainWindow',u'Simplified Chinese')) self.actionCnT.setText(_translate('MainWindow', u'Traditional Chinese')) self.actionEn.setText(_translate('MainWindow',u'English')) ''' self.actionCnS.setText(u'简体中文') self.actionCnT.setText(u'繁體中文') self.actionEn.setText(u'English') self.actionLoadLanguage.setText(_translate('MainWindow',u'Load Language'))
python
def retranslateUi(self): _translate = QtCore.QCoreApplication.translate self.talk= _translate('MainWindow','You are using GeoPyTool ') + version +'\n'+ _translate('MainWindow','released on ') + date + '\n' self.menuFile.setTitle(_translate('MainWindow', u'Data File')) self.menuGeoChem.setTitle(_translate('MainWindow', u'Geochemistry')) self.menuGeoCalc.setTitle(_translate('MainWindow',u'Calculation')) self.menuStructure.setTitle(_translate('MainWindow', u'Structure')) self.menuSedimentary.setTitle(_translate('MainWindow', u'Sedimentary')) self.menuAdditional.setTitle(_translate('MainWindow', u'Additional Functions')) self.menuHelp.setTitle(_translate('MainWindow', u'Help')) self.menuLanguage.setTitle(_translate('MainWindow', u'Language')) self.actionCombine.setText(_translate('MainWindow', u'Combine')) self.actionCombine_transverse.setText(_translate('MainWindow', u'Combine_transverse')) self.actionFlatten.setText(_translate('MainWindow',u'Flatten')) self.actionTrans.setText(_translate('MainWindow',u'Trans')) self.actionReFormat.setText(_translate('MainWindow',u'ReFormat')) self.actionOpen.setText(_translate('MainWindow', u'Open Data')) self.actionClose.setText(_translate('MainWindow', u'Close Data')) self.actionSet.setText(_translate('MainWindow', u'Set Format')) self.actionSave.setText(_translate('MainWindow', u'Save Data')) self.actionQuit.setText(_translate('MainWindow', u'Quit App')) self.actionRemoveLOI.setText('1-0 '+_translate('MainWindow',u'Remove LOI')) self.actionAuto.setText('1-1 '+_translate('MainWindow', u'Auto')) self.actionTAS.setText('1-2 '+ _translate('MainWindow',u'TAS')) self.actionTrace.setText('1-3 '+_translate('MainWindow',u'Trace')) self.actionRee.setText('1-4 '+_translate('MainWindow',u'REE')) self.actionPearce.setText('1-5 '+_translate('MainWindow',u'Pearce')) self.actionHarker.setText('1-6 '+_translate('MainWindow',u'Harker')) self.actionCIPW.setText('1-7 '+_translate('MainWindow',u'CIPW')) self.actionQAPF.setText('1-8 '+_translate('MainWindow',u'QAPF')) self.actionSaccani.setText('1-9 '+_translate('MainWindow',u'Saccani Plot')) self.actionK2OSiO2.setText('1-10 '+_translate('MainWindow',u'K2O-SiO2')) self.actionRaman.setText('1-11 '+_translate('MainWindow',u'Raman Strength')) self.actionFluidInclusion.setText('1-12 '+_translate('MainWindow',u'Fluid Inclusion')) self.actionHarkerOld.setText('1-14 '+_translate('MainWindow',u'Harker Classical')) self.actionTraceNew.setText('1-15 '+_translate('MainWindow',u'TraceNew')) self.actionStereo.setText('2-1 '+_translate('MainWindow',u'Stereo')) self.actionRose.setText('2-2 '+_translate('MainWindow',u'Rose')) self.actionQFL.setText('3-1 '+_translate('MainWindow',u'QFL')) self.actionQmFLt.setText('3-2 '+_translate('MainWindow',u'QmFLt')) self.actionClastic.setText('3-3 '+_translate('MainWindow',u'Clastic')) self.actionCIA.setText('3-4 '+ _translate('MainWindow',u'CIA and ICV')) self.actionZirconCe.setText('4-1 '+ _translate('MainWindow',u'ZirconCe')) self.actionZirconCeOld.setText('4-2 '+ _translate('MainWindow', u'ZirconCeOld')) self.actionZirconTiTemp.setText('4-3 '+ _translate('MainWindow',u'ZirconTiTemp')) self.actionRutileZrTemp.setText('4-4 '+_translate('MainWindow',u'RutileZrTemp')) self.actionRbSrIsoTope.setText('4-5 '+_translate('MainWindow',u'Rb-Sr IsoTope')) self.actionSmNdIsoTope.setText('4-6 '+_translate('MainWindow',u'Sm-Nd IsoTope')) self.actionXY.setText('5-1 '+_translate('MainWindow',u'X-Y plot')) self.actionXYZ.setText('5-2 '+_translate('MainWindow',u'X-Y-Z plot')) self.actionCluster.setText('5-3 '+_translate('MainWindow',u'Cluster')) self.actionMultiDimension.setText('5-4 '+_translate('MainWindow',u'MultiDimension')) self.actionFA.setText('5-5 '+_translate('MainWindow',u'FA')) self.actionPCA.setText('5-6 '+_translate('MainWindow',u'PCA')) self.actionDist.setText('5-7 '+_translate('MainWindow',u'Distance')) self.actionStatistics.setText('5-8 '+_translate('MainWindow',u'Statistics')) self.actionThreeD.setText('5-9 '+_translate('MainWindow',u'ThreeD')) self.actionTwoD.setText('5-10 '+_translate('MainWindow',u'TwoD')) self.actionTwoD_Grey.setText('5-11 '+_translate('MainWindow',u'TwoD Grey')) self.actionMyHist.setText('5-12 '+_translate('MainWindow',u'Histogram + KDE Curve')) self.actionVersionCheck.setText(_translate('MainWindow', u'Check Update')) self.actionWeb.setText(_translate('MainWindow', u'English Forum')) self.actionGoGithub.setText(_translate('MainWindow', u'Github')) self.actionCnS.setText(u'简体中文') self.actionCnT.setText(u'繁體中文') self.actionEn.setText(u'English') self.actionLoadLanguage.setText(_translate('MainWindow',u'Load Language'))
[ "def", "retranslateUi", "(", "self", ")", ":", "_translate", "=", "QtCore", ".", "QCoreApplication", ".", "translate", "self", ".", "talk", "=", "_translate", "(", "'MainWindow'", ",", "'You are using GeoPyTool '", ")", "+", "version", "+", "'\\n'", "+", "_translate", "(", "'MainWindow'", ",", "'released on '", ")", "+", "date", "+", "'\\n'", "self", ".", "menuFile", ".", "setTitle", "(", "_translate", "(", "'MainWindow'", ",", "u'Data File'", ")", ")", "self", ".", "menuGeoChem", ".", "setTitle", "(", "_translate", "(", "'MainWindow'", ",", "u'Geochemistry'", ")", ")", "self", ".", "menuGeoCalc", ".", "setTitle", "(", "_translate", "(", "'MainWindow'", ",", "u'Calculation'", ")", ")", "self", ".", "menuStructure", ".", "setTitle", "(", "_translate", "(", "'MainWindow'", ",", "u'Structure'", ")", ")", "self", ".", "menuSedimentary", ".", "setTitle", "(", "_translate", "(", "'MainWindow'", ",", "u'Sedimentary'", ")", ")", "self", ".", "menuAdditional", ".", "setTitle", "(", "_translate", "(", "'MainWindow'", ",", "u'Additional Functions'", ")", ")", "self", ".", "menuHelp", ".", "setTitle", "(", "_translate", "(", "'MainWindow'", ",", "u'Help'", ")", ")", "self", ".", "menuLanguage", ".", "setTitle", "(", "_translate", "(", "'MainWindow'", ",", "u'Language'", ")", ")", "self", ".", "actionCombine", ".", "setText", "(", "_translate", "(", "'MainWindow'", ",", "u'Combine'", ")", ")", "self", ".", "actionCombine_transverse", ".", "setText", "(", "_translate", "(", "'MainWindow'", ",", "u'Combine_transverse'", ")", ")", "self", ".", "actionFlatten", ".", "setText", "(", "_translate", "(", "'MainWindow'", ",", "u'Flatten'", ")", ")", "self", ".", "actionTrans", ".", "setText", "(", "_translate", "(", "'MainWindow'", ",", "u'Trans'", ")", ")", "self", ".", "actionReFormat", ".", "setText", "(", "_translate", "(", "'MainWindow'", ",", "u'ReFormat'", ")", ")", "self", ".", "actionOpen", ".", "setText", "(", "_translate", "(", "'MainWindow'", ",", "u'Open Data'", ")", ")", "self", ".", "actionClose", ".", "setText", "(", "_translate", "(", "'MainWindow'", ",", "u'Close Data'", ")", ")", "self", ".", "actionSet", ".", "setText", "(", "_translate", "(", "'MainWindow'", ",", "u'Set Format'", ")", ")", "self", ".", "actionSave", ".", "setText", "(", "_translate", "(", "'MainWindow'", ",", "u'Save Data'", ")", ")", "self", ".", "actionQuit", ".", "setText", "(", "_translate", "(", "'MainWindow'", ",", "u'Quit App'", ")", ")", "self", ".", "actionRemoveLOI", ".", "setText", "(", "'1-0 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Remove LOI'", ")", ")", "self", ".", "actionAuto", ".", "setText", "(", "'1-1 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Auto'", ")", ")", "self", ".", "actionTAS", ".", "setText", "(", "'1-2 '", "+", "_translate", "(", "'MainWindow'", ",", "u'TAS'", ")", ")", "self", ".", "actionTrace", ".", "setText", "(", "'1-3 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Trace'", ")", ")", "self", ".", "actionRee", ".", "setText", "(", "'1-4 '", "+", "_translate", "(", "'MainWindow'", ",", "u'REE'", ")", ")", "self", ".", "actionPearce", ".", "setText", "(", "'1-5 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Pearce'", ")", ")", "self", ".", "actionHarker", ".", "setText", "(", "'1-6 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Harker'", ")", ")", "self", ".", "actionCIPW", ".", "setText", "(", "'1-7 '", "+", "_translate", "(", "'MainWindow'", ",", "u'CIPW'", ")", ")", "self", ".", "actionQAPF", ".", "setText", "(", "'1-8 '", "+", "_translate", "(", "'MainWindow'", ",", "u'QAPF'", ")", ")", "self", ".", "actionSaccani", ".", "setText", "(", "'1-9 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Saccani Plot'", ")", ")", "self", ".", "actionK2OSiO2", ".", "setText", "(", "'1-10 '", "+", "_translate", "(", "'MainWindow'", ",", "u'K2O-SiO2'", ")", ")", "self", ".", "actionRaman", ".", "setText", "(", "'1-11 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Raman Strength'", ")", ")", "self", ".", "actionFluidInclusion", ".", "setText", "(", "'1-12 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Fluid Inclusion'", ")", ")", "self", ".", "actionHarkerOld", ".", "setText", "(", "'1-14 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Harker Classical'", ")", ")", "self", ".", "actionTraceNew", ".", "setText", "(", "'1-15 '", "+", "_translate", "(", "'MainWindow'", ",", "u'TraceNew'", ")", ")", "self", ".", "actionStereo", ".", "setText", "(", "'2-1 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Stereo'", ")", ")", "self", ".", "actionRose", ".", "setText", "(", "'2-2 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Rose'", ")", ")", "self", ".", "actionQFL", ".", "setText", "(", "'3-1 '", "+", "_translate", "(", "'MainWindow'", ",", "u'QFL'", ")", ")", "self", ".", "actionQmFLt", ".", "setText", "(", "'3-2 '", "+", "_translate", "(", "'MainWindow'", ",", "u'QmFLt'", ")", ")", "self", ".", "actionClastic", ".", "setText", "(", "'3-3 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Clastic'", ")", ")", "self", ".", "actionCIA", ".", "setText", "(", "'3-4 '", "+", "_translate", "(", "'MainWindow'", ",", "u'CIA and ICV'", ")", ")", "self", ".", "actionZirconCe", ".", "setText", "(", "'4-1 '", "+", "_translate", "(", "'MainWindow'", ",", "u'ZirconCe'", ")", ")", "self", ".", "actionZirconCeOld", ".", "setText", "(", "'4-2 '", "+", "_translate", "(", "'MainWindow'", ",", "u'ZirconCeOld'", ")", ")", "self", ".", "actionZirconTiTemp", ".", "setText", "(", "'4-3 '", "+", "_translate", "(", "'MainWindow'", ",", "u'ZirconTiTemp'", ")", ")", "self", ".", "actionRutileZrTemp", ".", "setText", "(", "'4-4 '", "+", "_translate", "(", "'MainWindow'", ",", "u'RutileZrTemp'", ")", ")", "self", ".", "actionRbSrIsoTope", ".", "setText", "(", "'4-5 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Rb-Sr IsoTope'", ")", ")", "self", ".", "actionSmNdIsoTope", ".", "setText", "(", "'4-6 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Sm-Nd IsoTope'", ")", ")", "#self.actionKArIsoTope.setText(_translate('MainWindow',u'K-Ar IsoTope'))", "self", ".", "actionXY", ".", "setText", "(", "'5-1 '", "+", "_translate", "(", "'MainWindow'", ",", "u'X-Y plot'", ")", ")", "self", ".", "actionXYZ", ".", "setText", "(", "'5-2 '", "+", "_translate", "(", "'MainWindow'", ",", "u'X-Y-Z plot'", ")", ")", "self", ".", "actionCluster", ".", "setText", "(", "'5-3 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Cluster'", ")", ")", "self", ".", "actionMultiDimension", ".", "setText", "(", "'5-4 '", "+", "_translate", "(", "'MainWindow'", ",", "u'MultiDimension'", ")", ")", "self", ".", "actionFA", ".", "setText", "(", "'5-5 '", "+", "_translate", "(", "'MainWindow'", ",", "u'FA'", ")", ")", "self", ".", "actionPCA", ".", "setText", "(", "'5-6 '", "+", "_translate", "(", "'MainWindow'", ",", "u'PCA'", ")", ")", "self", ".", "actionDist", ".", "setText", "(", "'5-7 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Distance'", ")", ")", "self", ".", "actionStatistics", ".", "setText", "(", "'5-8 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Statistics'", ")", ")", "self", ".", "actionThreeD", ".", "setText", "(", "'5-9 '", "+", "_translate", "(", "'MainWindow'", ",", "u'ThreeD'", ")", ")", "self", ".", "actionTwoD", ".", "setText", "(", "'5-10 '", "+", "_translate", "(", "'MainWindow'", ",", "u'TwoD'", ")", ")", "self", ".", "actionTwoD_Grey", ".", "setText", "(", "'5-11 '", "+", "_translate", "(", "'MainWindow'", ",", "u'TwoD Grey'", ")", ")", "self", ".", "actionMyHist", ".", "setText", "(", "'5-12 '", "+", "_translate", "(", "'MainWindow'", ",", "u'Histogram + KDE Curve'", ")", ")", "self", ".", "actionVersionCheck", ".", "setText", "(", "_translate", "(", "'MainWindow'", ",", "u'Check Update'", ")", ")", "self", ".", "actionWeb", ".", "setText", "(", "_translate", "(", "'MainWindow'", ",", "u'English Forum'", ")", ")", "self", ".", "actionGoGithub", ".", "setText", "(", "_translate", "(", "'MainWindow'", ",", "u'Github'", ")", ")", "self", ".", "actionCnS", ".", "setText", "(", "u'简体中文')", "", "self", ".", "actionCnT", ".", "setText", "(", "u'繁體中文')", "", "self", ".", "actionEn", ".", "setText", "(", "u'English'", ")", "self", ".", "actionLoadLanguage", ".", "setText", "(", "_translate", "(", "'MainWindow'", ",", "u'Load Language'", ")", ")" ]
self.actionCnS.setText(_translate('MainWindow',u'Simplified Chinese')) self.actionCnT.setText(_translate('MainWindow', u'Traditional Chinese')) self.actionEn.setText(_translate('MainWindow',u'English'))
[ "self", ".", "actionCnS", ".", "setText", "(", "_translate", "(", "MainWindow", "u", "Simplified", "Chinese", "))", "self", ".", "actionCnT", ".", "setText", "(", "_translate", "(", "MainWindow", "u", "Traditional", "Chinese", "))", "self", ".", "actionEn", ".", "setText", "(", "_translate", "(", "MainWindow", "u", "English", "))" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/__init__.py#L580-L675
GeoPyTool/GeoPyTool
geopytool/Rose.py
Rose.singlerose
def singlerose(self, Width=1, Color=['red']): ''' draw the rose map of single sample with different items~ ''' self.chooser_label.setText(self.ChooseItems[self.chooser.value() - 1]) self.MultipleRoseName = self.ChooseItems[self.chooser.value() - 1] self.SingleRoseName = [(self.ChooseItems[self.chooser.value() - 1])] Name = self.SingleRoseName self.axes.clear() # self.axes.set_xlim(-90, 450) # self.axes.set_ylim(0, 90) titles = list('NWSE') titles = ['N', '330', '300', 'W', '240', '210', 'S', '150', '120', 'E', '60', '30'] self.n = len(titles) self.angles = np.arange(90, 90 + 360, 360.0 / self.n) self.angles = np.array([90., 120., 150., 180., 210., 240., 270., 300., 330., 360., 30., 60.]) self.axes.set_thetagrids(self.angles, labels=titles, fontsize=14) self.raw = self._df real_max = [] for k in range(len(Name)): Data = [] S = [] R = [] for i in range(len(self.raw)): S.append(self.raw.at[i, Name[k]]) s = np.linspace(0, 360, 360 / self.Gap + 1) t = tuple(s.tolist()) count = [] for i in range(len(t)): tmp_count = 0 for j in S: if i < len(t) - 1: if t[i] < j <= t[i + 1]: tmp_count += 1 count.append(tmp_count) count_max = max(count) real_max.append(count_max) maxuse = max(real_max) for k in range(len(Name)): Data = [] S = [] R = [] for i in range(len(self.raw)): S.append(self.raw.at[i, Name[k]]) s = np.linspace(0, 360, 360 / self.Gap + 1) t = tuple(s.tolist()) count = [] for i in range(len(t)): tmp_count = 0 for j in S: if i < len(t) - 1: if t[i] < j <= t[i + 1]: tmp_count += 1 count.append(tmp_count) s = np.linspace(0, 360, 360 / self.Gap + 1) t = tuple(s.tolist()) R_factor = 90 / maxuse for i in count: TMP = 90 - i * R_factor R.append(TMP) m, n = self.Trans(t, R) self.axes.plot(m, n, color=Color[k], linewidth=1, alpha=0.6, marker='') self.axes.fill(m, n, Color=Color[k], Alpha=0.6, ) if (self.Type_cb.isChecked()): self.Type_cb.setText('Wulf') list1 = [self.eqan(x) for x in range(15, 90, 15)] else: self.Type_cb.setText('Schmidt') list1 = [self.eqar(x) for x in range(15, 90, 15)] list2= list1 print(maxuse + 1) try: list2 = [str(x) for x in range(0, int(maxuse + 1), int((maxuse + 1.0) / 7.0))] except(ValueError): pass list2.reverse() self.axes.set_rgrids(list1, list2) #self.axes.set_thetagrids(range(360 + 90, 0 + 90, -15), [str(x) for x in range(0, 360, 15)]) if (self.legend_cb.isChecked()): self.axes.legend(bbox_to_anchor=(1.5, 1), loc=2, borderaxespad=0, prop=fontprop)
python
def singlerose(self, Width=1, Color=['red']): self.chooser_label.setText(self.ChooseItems[self.chooser.value() - 1]) self.MultipleRoseName = self.ChooseItems[self.chooser.value() - 1] self.SingleRoseName = [(self.ChooseItems[self.chooser.value() - 1])] Name = self.SingleRoseName self.axes.clear() titles = list('NWSE') titles = ['N', '330', '300', 'W', '240', '210', 'S', '150', '120', 'E', '60', '30'] self.n = len(titles) self.angles = np.arange(90, 90 + 360, 360.0 / self.n) self.angles = np.array([90., 120., 150., 180., 210., 240., 270., 300., 330., 360., 30., 60.]) self.axes.set_thetagrids(self.angles, labels=titles, fontsize=14) self.raw = self._df real_max = [] for k in range(len(Name)): Data = [] S = [] R = [] for i in range(len(self.raw)): S.append(self.raw.at[i, Name[k]]) s = np.linspace(0, 360, 360 / self.Gap + 1) t = tuple(s.tolist()) count = [] for i in range(len(t)): tmp_count = 0 for j in S: if i < len(t) - 1: if t[i] < j <= t[i + 1]: tmp_count += 1 count.append(tmp_count) count_max = max(count) real_max.append(count_max) maxuse = max(real_max) for k in range(len(Name)): Data = [] S = [] R = [] for i in range(len(self.raw)): S.append(self.raw.at[i, Name[k]]) s = np.linspace(0, 360, 360 / self.Gap + 1) t = tuple(s.tolist()) count = [] for i in range(len(t)): tmp_count = 0 for j in S: if i < len(t) - 1: if t[i] < j <= t[i + 1]: tmp_count += 1 count.append(tmp_count) s = np.linspace(0, 360, 360 / self.Gap + 1) t = tuple(s.tolist()) R_factor = 90 / maxuse for i in count: TMP = 90 - i * R_factor R.append(TMP) m, n = self.Trans(t, R) self.axes.plot(m, n, color=Color[k], linewidth=1, alpha=0.6, marker='') self.axes.fill(m, n, Color=Color[k], Alpha=0.6, ) if (self.Type_cb.isChecked()): self.Type_cb.setText('Wulf') list1 = [self.eqan(x) for x in range(15, 90, 15)] else: self.Type_cb.setText('Schmidt') list1 = [self.eqar(x) for x in range(15, 90, 15)] list2= list1 print(maxuse + 1) try: list2 = [str(x) for x in range(0, int(maxuse + 1), int((maxuse + 1.0) / 7.0))] except(ValueError): pass list2.reverse() self.axes.set_rgrids(list1, list2) if (self.legend_cb.isChecked()): self.axes.legend(bbox_to_anchor=(1.5, 1), loc=2, borderaxespad=0, prop=fontprop)
[ "def", "singlerose", "(", "self", ",", "Width", "=", "1", ",", "Color", "=", "[", "'red'", "]", ")", ":", "self", ".", "chooser_label", ".", "setText", "(", "self", ".", "ChooseItems", "[", "self", ".", "chooser", ".", "value", "(", ")", "-", "1", "]", ")", "self", ".", "MultipleRoseName", "=", "self", ".", "ChooseItems", "[", "self", ".", "chooser", ".", "value", "(", ")", "-", "1", "]", "self", ".", "SingleRoseName", "=", "[", "(", "self", ".", "ChooseItems", "[", "self", ".", "chooser", ".", "value", "(", ")", "-", "1", "]", ")", "]", "Name", "=", "self", ".", "SingleRoseName", "self", ".", "axes", ".", "clear", "(", ")", "# self.axes.set_xlim(-90, 450)", "# self.axes.set_ylim(0, 90)", "titles", "=", "list", "(", "'NWSE'", ")", "titles", "=", "[", "'N'", ",", "'330'", ",", "'300'", ",", "'W'", ",", "'240'", ",", "'210'", ",", "'S'", ",", "'150'", ",", "'120'", ",", "'E'", ",", "'60'", ",", "'30'", "]", "self", ".", "n", "=", "len", "(", "titles", ")", "self", ".", "angles", "=", "np", ".", "arange", "(", "90", ",", "90", "+", "360", ",", "360.0", "/", "self", ".", "n", ")", "self", ".", "angles", "=", "np", ".", "array", "(", "[", "90.", ",", "120.", ",", "150.", ",", "180.", ",", "210.", ",", "240.", ",", "270.", ",", "300.", ",", "330.", ",", "360.", ",", "30.", ",", "60.", "]", ")", "self", ".", "axes", ".", "set_thetagrids", "(", "self", ".", "angles", ",", "labels", "=", "titles", ",", "fontsize", "=", "14", ")", "self", ".", "raw", "=", "self", ".", "_df", "real_max", "=", "[", "]", "for", "k", "in", "range", "(", "len", "(", "Name", ")", ")", ":", "Data", "=", "[", "]", "S", "=", "[", "]", "R", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "self", ".", "raw", ")", ")", ":", "S", ".", "append", "(", "self", ".", "raw", ".", "at", "[", "i", ",", "Name", "[", "k", "]", "]", ")", "s", "=", "np", ".", "linspace", "(", "0", ",", "360", ",", "360", "/", "self", ".", "Gap", "+", "1", ")", "t", "=", "tuple", "(", "s", ".", "tolist", "(", ")", ")", "count", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "t", ")", ")", ":", "tmp_count", "=", "0", "for", "j", "in", "S", ":", "if", "i", "<", "len", "(", "t", ")", "-", "1", ":", "if", "t", "[", "i", "]", "<", "j", "<=", "t", "[", "i", "+", "1", "]", ":", "tmp_count", "+=", "1", "count", ".", "append", "(", "tmp_count", ")", "count_max", "=", "max", "(", "count", ")", "real_max", ".", "append", "(", "count_max", ")", "maxuse", "=", "max", "(", "real_max", ")", "for", "k", "in", "range", "(", "len", "(", "Name", ")", ")", ":", "Data", "=", "[", "]", "S", "=", "[", "]", "R", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "self", ".", "raw", ")", ")", ":", "S", ".", "append", "(", "self", ".", "raw", ".", "at", "[", "i", ",", "Name", "[", "k", "]", "]", ")", "s", "=", "np", ".", "linspace", "(", "0", ",", "360", ",", "360", "/", "self", ".", "Gap", "+", "1", ")", "t", "=", "tuple", "(", "s", ".", "tolist", "(", ")", ")", "count", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "t", ")", ")", ":", "tmp_count", "=", "0", "for", "j", "in", "S", ":", "if", "i", "<", "len", "(", "t", ")", "-", "1", ":", "if", "t", "[", "i", "]", "<", "j", "<=", "t", "[", "i", "+", "1", "]", ":", "tmp_count", "+=", "1", "count", ".", "append", "(", "tmp_count", ")", "s", "=", "np", ".", "linspace", "(", "0", ",", "360", ",", "360", "/", "self", ".", "Gap", "+", "1", ")", "t", "=", "tuple", "(", "s", ".", "tolist", "(", ")", ")", "R_factor", "=", "90", "/", "maxuse", "for", "i", "in", "count", ":", "TMP", "=", "90", "-", "i", "*", "R_factor", "R", ".", "append", "(", "TMP", ")", "m", ",", "n", "=", "self", ".", "Trans", "(", "t", ",", "R", ")", "self", ".", "axes", ".", "plot", "(", "m", ",", "n", ",", "color", "=", "Color", "[", "k", "]", ",", "linewidth", "=", "1", ",", "alpha", "=", "0.6", ",", "marker", "=", "''", ")", "self", ".", "axes", ".", "fill", "(", "m", ",", "n", ",", "Color", "=", "Color", "[", "k", "]", ",", "Alpha", "=", "0.6", ",", ")", "if", "(", "self", ".", "Type_cb", ".", "isChecked", "(", ")", ")", ":", "self", ".", "Type_cb", ".", "setText", "(", "'Wulf'", ")", "list1", "=", "[", "self", ".", "eqan", "(", "x", ")", "for", "x", "in", "range", "(", "15", ",", "90", ",", "15", ")", "]", "else", ":", "self", ".", "Type_cb", ".", "setText", "(", "'Schmidt'", ")", "list1", "=", "[", "self", ".", "eqar", "(", "x", ")", "for", "x", "in", "range", "(", "15", ",", "90", ",", "15", ")", "]", "list2", "=", "list1", "print", "(", "maxuse", "+", "1", ")", "try", ":", "list2", "=", "[", "str", "(", "x", ")", "for", "x", "in", "range", "(", "0", ",", "int", "(", "maxuse", "+", "1", ")", ",", "int", "(", "(", "maxuse", "+", "1.0", ")", "/", "7.0", ")", ")", "]", "except", "(", "ValueError", ")", ":", "pass", "list2", ".", "reverse", "(", ")", "self", ".", "axes", ".", "set_rgrids", "(", "list1", ",", "list2", ")", "#self.axes.set_thetagrids(range(360 + 90, 0 + 90, -15), [str(x) for x in range(0, 360, 15)])", "if", "(", "self", ".", "legend_cb", ".", "isChecked", "(", ")", ")", ":", "self", ".", "axes", ".", "legend", "(", "bbox_to_anchor", "=", "(", "1.5", ",", "1", ")", ",", "loc", "=", "2", ",", "borderaxespad", "=", "0", ",", "prop", "=", "fontprop", ")" ]
draw the rose map of single sample with different items~
[ "draw", "the", "rose", "map", "of", "single", "sample", "with", "different", "items~" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/Rose.py#L154-L265
GeoPyTool/GeoPyTool
geopytool/Rose.py
Rose.multirose
def multirose(self, Width=1, Name='Dip'): ''' draw the rose map of multiple samples~ ''' Name = self.MultipleRoseName self.axes.clear() # self.axes.set_xlim(-90, 450) # self.axes.set_ylim(0, 90) titles = list('NWSE') titles = ['N', '330', '300', 'W', '240', '210', 'S', '150', '120', 'E', '60', '30'] self.n = len(titles) self.angles = np.arange(90, 90 + 360, 360.0 / self.n) self.angles = np.array([90., 120., 150., 180., 210., 240., 270., 300., 330., 360., 30., 60.]) self.axes.set_thetagrids(self.angles, labels=titles, fontsize=14) self.raw = self._df real_max = [] S = [] R = [] Color = [] Label = [] Whole = {} for i in range(len(self.raw)): S.append(self.raw.at[i, Name]) if self.raw.at[i, 'Color'] not in Color and self.raw.at[i, 'Color'] != '': Color.append(self.raw.at[i, 'Color']) if self.raw.at[i, 'Label'] not in Label and self.raw.at[i, 'Label'] != '': Label.append(self.raw.at[i, 'Label']) Whole = ({k: [] for k in Label}) WholeCount = ({k: [] for k in Label}) for i in range(len(self.raw)): for k in Label: if self.raw.at[i, 'Label'] == k: Whole[k].append(self.raw.at[i, Name]) t = tuple(np.linspace(0, 360, 360 / self.Gap + 1).tolist()) real_max = 0 for j in range(len(Label)): for i in range(len(t)): tmp_count = 0 for u in Whole[Label[j]]: if i < len(t) - 1: if t[i] < u <= t[i + 1]: tmp_count += 1 real_max = max(real_max, tmp_count) WholeCount[Label[j]].append(tmp_count) maxuse = real_max R_factor = 90 / maxuse for j in range(len(Label)): R = [] for i in WholeCount[Label[j]]: TMP = 90 - i * R_factor R.append(TMP) m, n = self.Trans(t, R) self.axes.plot(m, n, color=Color[j], linewidth=1, alpha=0.6, marker='', label=Label[j]) self.axes.fill(m, n, Color=Color[j], Alpha=0.6) if (self.Type_cb.isChecked()): self.Type_cb.setText('Wulf') list1 = [self.eqan(x) for x in range(15, 90, 15)] else: self.Type_cb.setText('Schmidt') list1 = [self.eqar(x) for x in range(15, 90, 15)] list2= list1 try: list2 = [str(x) for x in range(0, int(maxuse + 1), int((maxuse + 1) / 7))] except(ValueError): pass list2.reverse() self.axes.set_rgrids(list1, list2) #self.axes.set_thetagrids(range(360 + 90, 0 + 90, -15), [str(x) for x in range(0, 360, 15)]) if (self.legend_cb.isChecked()): self.axes.legend(bbox_to_anchor=(1.5, 1), loc=2, borderaxespad=0, prop=fontprop)
python
def multirose(self, Width=1, Name='Dip'): Name = self.MultipleRoseName self.axes.clear() titles = list('NWSE') titles = ['N', '330', '300', 'W', '240', '210', 'S', '150', '120', 'E', '60', '30'] self.n = len(titles) self.angles = np.arange(90, 90 + 360, 360.0 / self.n) self.angles = np.array([90., 120., 150., 180., 210., 240., 270., 300., 330., 360., 30., 60.]) self.axes.set_thetagrids(self.angles, labels=titles, fontsize=14) self.raw = self._df real_max = [] S = [] R = [] Color = [] Label = [] Whole = {} for i in range(len(self.raw)): S.append(self.raw.at[i, Name]) if self.raw.at[i, 'Color'] not in Color and self.raw.at[i, 'Color'] != '': Color.append(self.raw.at[i, 'Color']) if self.raw.at[i, 'Label'] not in Label and self.raw.at[i, 'Label'] != '': Label.append(self.raw.at[i, 'Label']) Whole = ({k: [] for k in Label}) WholeCount = ({k: [] for k in Label}) for i in range(len(self.raw)): for k in Label: if self.raw.at[i, 'Label'] == k: Whole[k].append(self.raw.at[i, Name]) t = tuple(np.linspace(0, 360, 360 / self.Gap + 1).tolist()) real_max = 0 for j in range(len(Label)): for i in range(len(t)): tmp_count = 0 for u in Whole[Label[j]]: if i < len(t) - 1: if t[i] < u <= t[i + 1]: tmp_count += 1 real_max = max(real_max, tmp_count) WholeCount[Label[j]].append(tmp_count) maxuse = real_max R_factor = 90 / maxuse for j in range(len(Label)): R = [] for i in WholeCount[Label[j]]: TMP = 90 - i * R_factor R.append(TMP) m, n = self.Trans(t, R) self.axes.plot(m, n, color=Color[j], linewidth=1, alpha=0.6, marker='', label=Label[j]) self.axes.fill(m, n, Color=Color[j], Alpha=0.6) if (self.Type_cb.isChecked()): self.Type_cb.setText('Wulf') list1 = [self.eqan(x) for x in range(15, 90, 15)] else: self.Type_cb.setText('Schmidt') list1 = [self.eqar(x) for x in range(15, 90, 15)] list2= list1 try: list2 = [str(x) for x in range(0, int(maxuse + 1), int((maxuse + 1) / 7))] except(ValueError): pass list2.reverse() self.axes.set_rgrids(list1, list2) if (self.legend_cb.isChecked()): self.axes.legend(bbox_to_anchor=(1.5, 1), loc=2, borderaxespad=0, prop=fontprop)
[ "def", "multirose", "(", "self", ",", "Width", "=", "1", ",", "Name", "=", "'Dip'", ")", ":", "Name", "=", "self", ".", "MultipleRoseName", "self", ".", "axes", ".", "clear", "(", ")", "# self.axes.set_xlim(-90, 450)", "# self.axes.set_ylim(0, 90)", "titles", "=", "list", "(", "'NWSE'", ")", "titles", "=", "[", "'N'", ",", "'330'", ",", "'300'", ",", "'W'", ",", "'240'", ",", "'210'", ",", "'S'", ",", "'150'", ",", "'120'", ",", "'E'", ",", "'60'", ",", "'30'", "]", "self", ".", "n", "=", "len", "(", "titles", ")", "self", ".", "angles", "=", "np", ".", "arange", "(", "90", ",", "90", "+", "360", ",", "360.0", "/", "self", ".", "n", ")", "self", ".", "angles", "=", "np", ".", "array", "(", "[", "90.", ",", "120.", ",", "150.", ",", "180.", ",", "210.", ",", "240.", ",", "270.", ",", "300.", ",", "330.", ",", "360.", ",", "30.", ",", "60.", "]", ")", "self", ".", "axes", ".", "set_thetagrids", "(", "self", ".", "angles", ",", "labels", "=", "titles", ",", "fontsize", "=", "14", ")", "self", ".", "raw", "=", "self", ".", "_df", "real_max", "=", "[", "]", "S", "=", "[", "]", "R", "=", "[", "]", "Color", "=", "[", "]", "Label", "=", "[", "]", "Whole", "=", "{", "}", "for", "i", "in", "range", "(", "len", "(", "self", ".", "raw", ")", ")", ":", "S", ".", "append", "(", "self", ".", "raw", ".", "at", "[", "i", ",", "Name", "]", ")", "if", "self", ".", "raw", ".", "at", "[", "i", ",", "'Color'", "]", "not", "in", "Color", "and", "self", ".", "raw", ".", "at", "[", "i", ",", "'Color'", "]", "!=", "''", ":", "Color", ".", "append", "(", "self", ".", "raw", ".", "at", "[", "i", ",", "'Color'", "]", ")", "if", "self", ".", "raw", ".", "at", "[", "i", ",", "'Label'", "]", "not", "in", "Label", "and", "self", ".", "raw", ".", "at", "[", "i", ",", "'Label'", "]", "!=", "''", ":", "Label", ".", "append", "(", "self", ".", "raw", ".", "at", "[", "i", ",", "'Label'", "]", ")", "Whole", "=", "(", "{", "k", ":", "[", "]", "for", "k", "in", "Label", "}", ")", "WholeCount", "=", "(", "{", "k", ":", "[", "]", "for", "k", "in", "Label", "}", ")", "for", "i", "in", "range", "(", "len", "(", "self", ".", "raw", ")", ")", ":", "for", "k", "in", "Label", ":", "if", "self", ".", "raw", ".", "at", "[", "i", ",", "'Label'", "]", "==", "k", ":", "Whole", "[", "k", "]", ".", "append", "(", "self", ".", "raw", ".", "at", "[", "i", ",", "Name", "]", ")", "t", "=", "tuple", "(", "np", ".", "linspace", "(", "0", ",", "360", ",", "360", "/", "self", ".", "Gap", "+", "1", ")", ".", "tolist", "(", ")", ")", "real_max", "=", "0", "for", "j", "in", "range", "(", "len", "(", "Label", ")", ")", ":", "for", "i", "in", "range", "(", "len", "(", "t", ")", ")", ":", "tmp_count", "=", "0", "for", "u", "in", "Whole", "[", "Label", "[", "j", "]", "]", ":", "if", "i", "<", "len", "(", "t", ")", "-", "1", ":", "if", "t", "[", "i", "]", "<", "u", "<=", "t", "[", "i", "+", "1", "]", ":", "tmp_count", "+=", "1", "real_max", "=", "max", "(", "real_max", ",", "tmp_count", ")", "WholeCount", "[", "Label", "[", "j", "]", "]", ".", "append", "(", "tmp_count", ")", "maxuse", "=", "real_max", "R_factor", "=", "90", "/", "maxuse", "for", "j", "in", "range", "(", "len", "(", "Label", ")", ")", ":", "R", "=", "[", "]", "for", "i", "in", "WholeCount", "[", "Label", "[", "j", "]", "]", ":", "TMP", "=", "90", "-", "i", "*", "R_factor", "R", ".", "append", "(", "TMP", ")", "m", ",", "n", "=", "self", ".", "Trans", "(", "t", ",", "R", ")", "self", ".", "axes", ".", "plot", "(", "m", ",", "n", ",", "color", "=", "Color", "[", "j", "]", ",", "linewidth", "=", "1", ",", "alpha", "=", "0.6", ",", "marker", "=", "''", ",", "label", "=", "Label", "[", "j", "]", ")", "self", ".", "axes", ".", "fill", "(", "m", ",", "n", ",", "Color", "=", "Color", "[", "j", "]", ",", "Alpha", "=", "0.6", ")", "if", "(", "self", ".", "Type_cb", ".", "isChecked", "(", ")", ")", ":", "self", ".", "Type_cb", ".", "setText", "(", "'Wulf'", ")", "list1", "=", "[", "self", ".", "eqan", "(", "x", ")", "for", "x", "in", "range", "(", "15", ",", "90", ",", "15", ")", "]", "else", ":", "self", ".", "Type_cb", ".", "setText", "(", "'Schmidt'", ")", "list1", "=", "[", "self", ".", "eqar", "(", "x", ")", "for", "x", "in", "range", "(", "15", ",", "90", ",", "15", ")", "]", "list2", "=", "list1", "try", ":", "list2", "=", "[", "str", "(", "x", ")", "for", "x", "in", "range", "(", "0", ",", "int", "(", "maxuse", "+", "1", ")", ",", "int", "(", "(", "maxuse", "+", "1", ")", "/", "7", ")", ")", "]", "except", "(", "ValueError", ")", ":", "pass", "list2", ".", "reverse", "(", ")", "self", ".", "axes", ".", "set_rgrids", "(", "list1", ",", "list2", ")", "#self.axes.set_thetagrids(range(360 + 90, 0 + 90, -15), [str(x) for x in range(0, 360, 15)])", "if", "(", "self", ".", "legend_cb", ".", "isChecked", "(", ")", ")", ":", "self", ".", "axes", ".", "legend", "(", "bbox_to_anchor", "=", "(", "1.5", ",", "1", ")", ",", "loc", "=", "2", ",", "borderaxespad", "=", "0", ",", "prop", "=", "fontprop", ")" ]
draw the rose map of multiple samples~
[ "draw", "the", "rose", "map", "of", "multiple", "samples~" ]
train
https://github.com/GeoPyTool/GeoPyTool/blob/8c198aa42e4fbdf62fac05d40cbf4d1086328da3/geopytool/Rose.py#L267-L365
HDI-Project/MLPrimitives
mlprimitives/adapters/pandas.py
resample
def resample(df, rule, time_index, groupby=None, aggregation='mean'): """pd.DataFrame.resample adapter. Call the `df.resample` method on the given time_index and afterwards call the indicated aggregation. Optionally group the dataframe by the indicated columns before performing the resampling. If groupby option is used, the result is a multi-index datagrame. Args: df (pandas.DataFrame): DataFrame to resample. rule (str): The offset string or object representing target conversion. groupby (list): Optional list of columns to group by. time_index (str): Name of the column to use as the time index. aggregation (str): Name of the aggregation function to use. Returns: pandas.Dataframe: resampled dataframe """ if groupby: df = df.groupby(groupby) df = df.resample(rule, on=time_index) df = getattr(df, aggregation)() for column in groupby: del df[column] return df
python
def resample(df, rule, time_index, groupby=None, aggregation='mean'): if groupby: df = df.groupby(groupby) df = df.resample(rule, on=time_index) df = getattr(df, aggregation)() for column in groupby: del df[column] return df
[ "def", "resample", "(", "df", ",", "rule", ",", "time_index", ",", "groupby", "=", "None", ",", "aggregation", "=", "'mean'", ")", ":", "if", "groupby", ":", "df", "=", "df", ".", "groupby", "(", "groupby", ")", "df", "=", "df", ".", "resample", "(", "rule", ",", "on", "=", "time_index", ")", "df", "=", "getattr", "(", "df", ",", "aggregation", ")", "(", ")", "for", "column", "in", "groupby", ":", "del", "df", "[", "column", "]", "return", "df" ]
pd.DataFrame.resample adapter. Call the `df.resample` method on the given time_index and afterwards call the indicated aggregation. Optionally group the dataframe by the indicated columns before performing the resampling. If groupby option is used, the result is a multi-index datagrame. Args: df (pandas.DataFrame): DataFrame to resample. rule (str): The offset string or object representing target conversion. groupby (list): Optional list of columns to group by. time_index (str): Name of the column to use as the time index. aggregation (str): Name of the aggregation function to use. Returns: pandas.Dataframe: resampled dataframe
[ "pd", ".", "DataFrame", ".", "resample", "adapter", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/adapters/pandas.py#L1-L30
HDI-Project/MLPrimitives
mlprimitives/adapters/pandas.py
_join_names
def _join_names(names): """Join the names of a multi-level index with an underscore.""" levels = (str(name) for name in names if name != '') return '_'.join(levels)
python
def _join_names(names): levels = (str(name) for name in names if name != '') return '_'.join(levels)
[ "def", "_join_names", "(", "names", ")", ":", "levels", "=", "(", "str", "(", "name", ")", "for", "name", "in", "names", "if", "name", "!=", "''", ")", "return", "'_'", ".", "join", "(", "levels", ")" ]
Join the names of a multi-level index with an underscore.
[ "Join", "the", "names", "of", "a", "multi", "-", "level", "index", "with", "an", "underscore", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/adapters/pandas.py#L33-L37
HDI-Project/MLPrimitives
mlprimitives/adapters/pandas.py
unstack
def unstack(df, level=-1, reset_index=True): """pd.DataFrame.unstack adapter. Call the `df.unstack` method using the indicated level and afterwards join the column names using an underscore. Args: df (pandas.DataFrame): DataFrame to unstack. level (str, int or list): Level(s) of index to unstack, can pass level name reset_index (bool): Whether to reset the index after unstacking Returns: pandas.Dataframe: unstacked dataframe """ df = df.unstack(level=level) if reset_index: df = df.reset_index() df.columns = df.columns.map(_join_names) return df
python
def unstack(df, level=-1, reset_index=True): df = df.unstack(level=level) if reset_index: df = df.reset_index() df.columns = df.columns.map(_join_names) return df
[ "def", "unstack", "(", "df", ",", "level", "=", "-", "1", ",", "reset_index", "=", "True", ")", ":", "df", "=", "df", ".", "unstack", "(", "level", "=", "level", ")", "if", "reset_index", ":", "df", "=", "df", ".", "reset_index", "(", ")", "df", ".", "columns", "=", "df", ".", "columns", ".", "map", "(", "_join_names", ")", "return", "df" ]
pd.DataFrame.unstack adapter. Call the `df.unstack` method using the indicated level and afterwards join the column names using an underscore. Args: df (pandas.DataFrame): DataFrame to unstack. level (str, int or list): Level(s) of index to unstack, can pass level name reset_index (bool): Whether to reset the index after unstacking Returns: pandas.Dataframe: unstacked dataframe
[ "pd", ".", "DataFrame", ".", "unstack", "adapter", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/adapters/pandas.py#L40-L59
HDI-Project/MLPrimitives
mlprimitives/candidates/dsp.py
next_power_of_2
def next_power_of_2(x): """Finds the next power of 2 value Args: x: Input value Returns: power_of_2: Next power of 2 value """ power_of_2 = 1 if x == 0 else 2 ** np.ceil(np.log2(x)) return power_of_2
python
def next_power_of_2(x): power_of_2 = 1 if x == 0 else 2 ** np.ceil(np.log2(x)) return power_of_2
[ "def", "next_power_of_2", "(", "x", ")", ":", "power_of_2", "=", "1", "if", "x", "==", "0", "else", "2", "**", "np", ".", "ceil", "(", "np", ".", "log2", "(", "x", ")", ")", "return", "power_of_2" ]
Finds the next power of 2 value Args: x: Input value Returns: power_of_2: Next power of 2 value
[ "Finds", "the", "next", "power", "of", "2", "value", "Args", ":", "x", ":", "Input", "value", "Returns", ":", "power_of_2", ":", "Next", "power", "of", "2", "value" ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/dsp.py#L4-L16
HDI-Project/MLPrimitives
mlprimitives/candidates/dsp.py
SpectralMask.window_design
def window_design(self, window_length, beta): """Kaiser window design Args: window_length: Length of the window in number of samples beta: Beta value for Kaiser window design Returns: window: Window designed using the beta and length provided as inputs """ self.window = np.kaiser(window_length, beta) return self.window
python
def window_design(self, window_length, beta): self.window = np.kaiser(window_length, beta) return self.window
[ "def", "window_design", "(", "self", ",", "window_length", ",", "beta", ")", ":", "self", ".", "window", "=", "np", ".", "kaiser", "(", "window_length", ",", "beta", ")", "return", "self", ".", "window" ]
Kaiser window design Args: window_length: Length of the window in number of samples beta: Beta value for Kaiser window design Returns: window: Window designed using the beta and length provided as inputs
[ "Kaiser", "window", "design", "Args", ":", "window_length", ":", "Length", "of", "the", "window", "in", "number", "of", "samples", "beta", ":", "Beta", "value", "for", "Kaiser", "window", "design", "Returns", ":", "window", ":", "Window", "designed", "using", "the", "beta", "and", "length", "provided", "as", "inputs" ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/dsp.py#L44-L58
HDI-Project/MLPrimitives
mlprimitives/candidates/dsp.py
SpectralMask.fit
def fit(self, X): """Defines a spectral mask based on training data Args: X: Training data """ training_signal = X self.window_design(self.window_length, self.beta) if self.method == 'std_dev': self.fit_freq_std_dev(training_signal) elif self.method == 'min_max': self.fit_freq_min_max(training_signal) else: raise ValueError('Unknown method: {}'.format(self.method))
python
def fit(self, X): training_signal = X self.window_design(self.window_length, self.beta) if self.method == 'std_dev': self.fit_freq_std_dev(training_signal) elif self.method == 'min_max': self.fit_freq_min_max(training_signal) else: raise ValueError('Unknown method: {}'.format(self.method))
[ "def", "fit", "(", "self", ",", "X", ")", ":", "training_signal", "=", "X", "self", ".", "window_design", "(", "self", ".", "window_length", ",", "self", ".", "beta", ")", "if", "self", ".", "method", "==", "'std_dev'", ":", "self", ".", "fit_freq_std_dev", "(", "training_signal", ")", "elif", "self", ".", "method", "==", "'min_max'", ":", "self", ".", "fit_freq_min_max", "(", "training_signal", ")", "else", ":", "raise", "ValueError", "(", "'Unknown method: {}'", ".", "format", "(", "self", ".", "method", ")", ")" ]
Defines a spectral mask based on training data Args: X: Training data
[ "Defines", "a", "spectral", "mask", "based", "on", "training", "data", "Args", ":", "X", ":", "Training", "data" ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/dsp.py#L60-L77
HDI-Project/MLPrimitives
mlprimitives/candidates/dsp.py
SpectralMask.fit_freq_min_max
def fit_freq_min_max(self, training_signal): """Defines a spectral mask based on training data using min and max values of each frequency component Args: training_signal: Training data """ window_length = len(self.window) window_weight = sum(self.window) max_mask = np.zeros(int(window_length / 2) + 1) min_mask = np.zeros(int(window_length / 2) + 1) for i in range(0, len(training_signal) - window_length - 1): rfft = np.fft.rfft(training_signal[i:i + window_length] * self.window) temp = np.abs(rfft) / window_weight max_mask = np.maximum(max_mask, temp) min_mask = np.minimum(min_mask, temp) self.mask_top = self.gain * max_mask self.mask_bottom = min_mask / self.gain
python
def fit_freq_min_max(self, training_signal): window_length = len(self.window) window_weight = sum(self.window) max_mask = np.zeros(int(window_length / 2) + 1) min_mask = np.zeros(int(window_length / 2) + 1) for i in range(0, len(training_signal) - window_length - 1): rfft = np.fft.rfft(training_signal[i:i + window_length] * self.window) temp = np.abs(rfft) / window_weight max_mask = np.maximum(max_mask, temp) min_mask = np.minimum(min_mask, temp) self.mask_top = self.gain * max_mask self.mask_bottom = min_mask / self.gain
[ "def", "fit_freq_min_max", "(", "self", ",", "training_signal", ")", ":", "window_length", "=", "len", "(", "self", ".", "window", ")", "window_weight", "=", "sum", "(", "self", ".", "window", ")", "max_mask", "=", "np", ".", "zeros", "(", "int", "(", "window_length", "/", "2", ")", "+", "1", ")", "min_mask", "=", "np", ".", "zeros", "(", "int", "(", "window_length", "/", "2", ")", "+", "1", ")", "for", "i", "in", "range", "(", "0", ",", "len", "(", "training_signal", ")", "-", "window_length", "-", "1", ")", ":", "rfft", "=", "np", ".", "fft", ".", "rfft", "(", "training_signal", "[", "i", ":", "i", "+", "window_length", "]", "*", "self", ".", "window", ")", "temp", "=", "np", ".", "abs", "(", "rfft", ")", "/", "window_weight", "max_mask", "=", "np", ".", "maximum", "(", "max_mask", ",", "temp", ")", "min_mask", "=", "np", ".", "minimum", "(", "min_mask", ",", "temp", ")", "self", ".", "mask_top", "=", "self", ".", "gain", "*", "max_mask", "self", ".", "mask_bottom", "=", "min_mask", "/", "self", ".", "gain" ]
Defines a spectral mask based on training data using min and max values of each frequency component Args: training_signal: Training data
[ "Defines", "a", "spectral", "mask", "based", "on", "training", "data", "using", "min", "and", "max", "values", "of", "each", "frequency", "component", "Args", ":", "training_signal", ":", "Training", "data" ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/dsp.py#L79-L100
HDI-Project/MLPrimitives
mlprimitives/candidates/dsp.py
SpectralMask.fit_freq_std_dev
def fit_freq_std_dev(self, training_signal): """Defines a spectral mask based on training data using the standard deviation values of each frequency component Args: training_signal: Training data """ window_length = len(self.window) window_weight = sum(self.window) num_of_windows = len(training_signal) - window_length - 1 mean = np.zeros(int(window_length / 2) + 1) pow = np.zeros(int(window_length / 2) + 1) temp = np.zeros(int(window_length / 2) + 1) rfft = np.fft.rfft(training_signal[0:0 + window_length] * self.window) max = np.abs(rfft) / window_weight min = max for i in range(0, num_of_windows): rfft = np.fft.rfft(training_signal[i:i + window_length] * self.window) temp = np.abs(rfft) / window_weight max = np.maximum(temp, max) min = np.minimum(temp, min) mean = mean + temp pow = pow + np.power(temp, 2) mean = mean / num_of_windows pow = pow / num_of_windows std_dev = np.sqrt(pow - np.power(mean, 2)) self.mask_top = mean + self.gain * std_dev self.mask_bottom = np.maximum(mean - self.gain * std_dev, np.zeros(int(window_length / 2) + 1))
python
def fit_freq_std_dev(self, training_signal): window_length = len(self.window) window_weight = sum(self.window) num_of_windows = len(training_signal) - window_length - 1 mean = np.zeros(int(window_length / 2) + 1) pow = np.zeros(int(window_length / 2) + 1) temp = np.zeros(int(window_length / 2) + 1) rfft = np.fft.rfft(training_signal[0:0 + window_length] * self.window) max = np.abs(rfft) / window_weight min = max for i in range(0, num_of_windows): rfft = np.fft.rfft(training_signal[i:i + window_length] * self.window) temp = np.abs(rfft) / window_weight max = np.maximum(temp, max) min = np.minimum(temp, min) mean = mean + temp pow = pow + np.power(temp, 2) mean = mean / num_of_windows pow = pow / num_of_windows std_dev = np.sqrt(pow - np.power(mean, 2)) self.mask_top = mean + self.gain * std_dev self.mask_bottom = np.maximum(mean - self.gain * std_dev, np.zeros(int(window_length / 2) + 1))
[ "def", "fit_freq_std_dev", "(", "self", ",", "training_signal", ")", ":", "window_length", "=", "len", "(", "self", ".", "window", ")", "window_weight", "=", "sum", "(", "self", ".", "window", ")", "num_of_windows", "=", "len", "(", "training_signal", ")", "-", "window_length", "-", "1", "mean", "=", "np", ".", "zeros", "(", "int", "(", "window_length", "/", "2", ")", "+", "1", ")", "pow", "=", "np", ".", "zeros", "(", "int", "(", "window_length", "/", "2", ")", "+", "1", ")", "temp", "=", "np", ".", "zeros", "(", "int", "(", "window_length", "/", "2", ")", "+", "1", ")", "rfft", "=", "np", ".", "fft", ".", "rfft", "(", "training_signal", "[", "0", ":", "0", "+", "window_length", "]", "*", "self", ".", "window", ")", "max", "=", "np", ".", "abs", "(", "rfft", ")", "/", "window_weight", "min", "=", "max", "for", "i", "in", "range", "(", "0", ",", "num_of_windows", ")", ":", "rfft", "=", "np", ".", "fft", ".", "rfft", "(", "training_signal", "[", "i", ":", "i", "+", "window_length", "]", "*", "self", ".", "window", ")", "temp", "=", "np", ".", "abs", "(", "rfft", ")", "/", "window_weight", "max", "=", "np", ".", "maximum", "(", "temp", ",", "max", ")", "min", "=", "np", ".", "minimum", "(", "temp", ",", "min", ")", "mean", "=", "mean", "+", "temp", "pow", "=", "pow", "+", "np", ".", "power", "(", "temp", ",", "2", ")", "mean", "=", "mean", "/", "num_of_windows", "pow", "=", "pow", "/", "num_of_windows", "std_dev", "=", "np", ".", "sqrt", "(", "pow", "-", "np", ".", "power", "(", "mean", ",", "2", ")", ")", "self", ".", "mask_top", "=", "mean", "+", "self", ".", "gain", "*", "std_dev", "self", ".", "mask_bottom", "=", "np", ".", "maximum", "(", "mean", "-", "self", ".", "gain", "*", "std_dev", ",", "np", ".", "zeros", "(", "int", "(", "window_length", "/", "2", ")", "+", "1", ")", ")" ]
Defines a spectral mask based on training data using the standard deviation values of each frequency component Args: training_signal: Training data
[ "Defines", "a", "spectral", "mask", "based", "on", "training", "data", "using", "the", "standard", "deviation", "values", "of", "each", "frequency", "component", "Args", ":", "training_signal", ":", "Training", "data" ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/dsp.py#L102-L134
HDI-Project/MLPrimitives
mlprimitives/candidates/dsp.py
SpectralMask.produce
def produce(self, X): """Detects anomalies in telemetry data based on its power spectral density Args: X: Telemetry data Returns: anomalies: Data vector consisting of the anomalies detected in the telemetry data """ signal = X window_length = len(self.window) anomalies = np.zeros(len(signal)) window_weight = sum(self.window) for i in range(0, len(signal) - window_length - 1): rfft = np.fft.rfft(signal[i:i + window_length] * self.window) sig_freq = np.abs(rfft) / window_weight anomalies[i] = 0 for m in range(0, int(window_length / 2) - 1): if ((sig_freq[m] > self.mask_top[m]) or (sig_freq[m] < self.mask_bottom[m])): anomalies[i] = 1 break return anomalies
python
def produce(self, X): signal = X window_length = len(self.window) anomalies = np.zeros(len(signal)) window_weight = sum(self.window) for i in range(0, len(signal) - window_length - 1): rfft = np.fft.rfft(signal[i:i + window_length] * self.window) sig_freq = np.abs(rfft) / window_weight anomalies[i] = 0 for m in range(0, int(window_length / 2) - 1): if ((sig_freq[m] > self.mask_top[m]) or (sig_freq[m] < self.mask_bottom[m])): anomalies[i] = 1 break return anomalies
[ "def", "produce", "(", "self", ",", "X", ")", ":", "signal", "=", "X", "window_length", "=", "len", "(", "self", ".", "window", ")", "anomalies", "=", "np", ".", "zeros", "(", "len", "(", "signal", ")", ")", "window_weight", "=", "sum", "(", "self", ".", "window", ")", "for", "i", "in", "range", "(", "0", ",", "len", "(", "signal", ")", "-", "window_length", "-", "1", ")", ":", "rfft", "=", "np", ".", "fft", ".", "rfft", "(", "signal", "[", "i", ":", "i", "+", "window_length", "]", "*", "self", ".", "window", ")", "sig_freq", "=", "np", ".", "abs", "(", "rfft", ")", "/", "window_weight", "anomalies", "[", "i", "]", "=", "0", "for", "m", "in", "range", "(", "0", ",", "int", "(", "window_length", "/", "2", ")", "-", "1", ")", ":", "if", "(", "(", "sig_freq", "[", "m", "]", ">", "self", ".", "mask_top", "[", "m", "]", ")", "or", "(", "sig_freq", "[", "m", "]", "<", "self", ".", "mask_bottom", "[", "m", "]", ")", ")", ":", "anomalies", "[", "i", "]", "=", "1", "break", "return", "anomalies" ]
Detects anomalies in telemetry data based on its power spectral density Args: X: Telemetry data Returns: anomalies: Data vector consisting of the anomalies detected in the telemetry data
[ "Detects", "anomalies", "in", "telemetry", "data", "based", "on", "its", "power", "spectral", "density", "Args", ":", "X", ":", "Telemetry", "data", "Returns", ":", "anomalies", ":", "Data", "vector", "consisting", "of", "the", "anomalies", "detected", "in", "the", "telemetry", "data" ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/dsp.py#L136-L161
HDI-Project/MLPrimitives
mlprimitives/datasets.py
load_boston_multitask
def load_boston_multitask(): """Boston House Prices Dataset with a synthetic multitask output. The multitask output is obtained by applying a linear transformation to the original y and adding it as a second output column. """ dataset = datasets.load_boston() y = dataset.target target = np.column_stack([y, 2 * y + 5]) return Dataset(load_boston.__doc__, dataset.data, target, r2_score)
python
def load_boston_multitask(): dataset = datasets.load_boston() y = dataset.target target = np.column_stack([y, 2 * y + 5]) return Dataset(load_boston.__doc__, dataset.data, target, r2_score)
[ "def", "load_boston_multitask", "(", ")", ":", "dataset", "=", "datasets", ".", "load_boston", "(", ")", "y", "=", "dataset", ".", "target", "target", "=", "np", ".", "column_stack", "(", "[", "y", ",", "2", "*", "y", "+", "5", "]", ")", "return", "Dataset", "(", "load_boston", ".", "__doc__", ",", "dataset", ".", "data", ",", "target", ",", "r2_score", ")" ]
Boston House Prices Dataset with a synthetic multitask output. The multitask output is obtained by applying a linear transformation to the original y and adding it as a second output column.
[ "Boston", "House", "Prices", "Dataset", "with", "a", "synthetic", "multitask", "output", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/datasets.py#L482-L491
HDI-Project/MLPrimitives
mlprimitives/candidates/audio_featurization.py
energy
def energy(data): """Computes signal energy of data""" data = np.mean(data, axis=1) return np.sum(data ** 2) / np.float64(len(data))
python
def energy(data): data = np.mean(data, axis=1) return np.sum(data ** 2) / np.float64(len(data))
[ "def", "energy", "(", "data", ")", ":", "data", "=", "np", ".", "mean", "(", "data", ",", "axis", "=", "1", ")", "return", "np", ".", "sum", "(", "data", "**", "2", ")", "/", "np", ".", "float64", "(", "len", "(", "data", ")", ")" ]
Computes signal energy of data
[ "Computes", "signal", "energy", "of", "data" ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/audio_featurization.py#L10-L13
HDI-Project/MLPrimitives
mlprimitives/candidates/audio_featurization.py
spectral_entropy
def spectral_entropy(data, numOfShortBlocks=10): """Computes the spectral entropy""" data = np.mean(data, axis=1) nFFT = len(data) // 2 X = FFT(data, nFFT) L = len(X) # number of frame data Eol = np.sum(X ** 2) # total spectral energy subWinLength = int(np.floor(L / numOfShortBlocks)) # length of sub-frame if L != subWinLength * numOfShortBlocks: X = X[0:subWinLength * numOfShortBlocks] # define sub-frames (using matrix reshape) subWindows = X.reshape(subWinLength, numOfShortBlocks, order='F').copy() # compute spectral sub-energies s = np.sum(subWindows ** 2, axis=0) / (Eol + EPSILON) # compute spectral entropy return -np.sum(s * np.log2(s + EPSILON))
python
def spectral_entropy(data, numOfShortBlocks=10): data = np.mean(data, axis=1) nFFT = len(data) // 2 X = FFT(data, nFFT) L = len(X) Eol = np.sum(X ** 2) subWinLength = int(np.floor(L / numOfShortBlocks)) if L != subWinLength * numOfShortBlocks: X = X[0:subWinLength * numOfShortBlocks] subWindows = X.reshape(subWinLength, numOfShortBlocks, order='F').copy() s = np.sum(subWindows ** 2, axis=0) / (Eol + EPSILON) return -np.sum(s * np.log2(s + EPSILON))
[ "def", "spectral_entropy", "(", "data", ",", "numOfShortBlocks", "=", "10", ")", ":", "data", "=", "np", ".", "mean", "(", "data", ",", "axis", "=", "1", ")", "nFFT", "=", "len", "(", "data", ")", "//", "2", "X", "=", "FFT", "(", "data", ",", "nFFT", ")", "L", "=", "len", "(", "X", ")", "# number of frame data", "Eol", "=", "np", ".", "sum", "(", "X", "**", "2", ")", "# total spectral energy", "subWinLength", "=", "int", "(", "np", ".", "floor", "(", "L", "/", "numOfShortBlocks", ")", ")", "# length of sub-frame", "if", "L", "!=", "subWinLength", "*", "numOfShortBlocks", ":", "X", "=", "X", "[", "0", ":", "subWinLength", "*", "numOfShortBlocks", "]", "# define sub-frames (using matrix reshape)", "subWindows", "=", "X", ".", "reshape", "(", "subWinLength", ",", "numOfShortBlocks", ",", "order", "=", "'F'", ")", ".", "copy", "(", ")", "# compute spectral sub-energies", "s", "=", "np", ".", "sum", "(", "subWindows", "**", "2", ",", "axis", "=", "0", ")", "/", "(", "Eol", "+", "EPSILON", ")", "# compute spectral entropy", "return", "-", "np", ".", "sum", "(", "s", "*", "np", ".", "log2", "(", "s", "+", "EPSILON", ")", ")" ]
Computes the spectral entropy
[ "Computes", "the", "spectral", "entropy" ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/audio_featurization.py#L22-L42
HDI-Project/MLPrimitives
mlprimitives/candidates/audio_featurization.py
zcr
def zcr(data): """Computes zero crossing rate of segment""" data = np.mean(data, axis=1) count = len(data) countZ = np.sum(np.abs(np.diff(np.sign(data)))) / 2 return (np.float64(countZ) / np.float64(count - 1.0))
python
def zcr(data): data = np.mean(data, axis=1) count = len(data) countZ = np.sum(np.abs(np.diff(np.sign(data)))) / 2 return (np.float64(countZ) / np.float64(count - 1.0))
[ "def", "zcr", "(", "data", ")", ":", "data", "=", "np", ".", "mean", "(", "data", ",", "axis", "=", "1", ")", "count", "=", "len", "(", "data", ")", "countZ", "=", "np", ".", "sum", "(", "np", ".", "abs", "(", "np", ".", "diff", "(", "np", ".", "sign", "(", "data", ")", ")", ")", ")", "/", "2", "return", "(", "np", ".", "float64", "(", "countZ", ")", "/", "np", ".", "float64", "(", "count", "-", "1.0", ")", ")" ]
Computes zero crossing rate of segment
[ "Computes", "zero", "crossing", "rate", "of", "segment" ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/audio_featurization.py#L51-L57
HDI-Project/MLPrimitives
mlprimitives/candidates/audio_featurization.py
spectral_flux
def spectral_flux(d0, d1): """ Computes the spectral flux feature of the current frame """ # compute the spectral flux as the sum of square distances: d0 = np.mean(d0, axis=1) d1 = np.mean(d1, axis=1) nFFT = min(len(d0) // 2, len(d1) // 2) X = FFT(d0, nFFT) Xprev = FFT(d1, nFFT) # L = min(len(X), len(Xprev)) sumX = np.sum(X + EPSILON) sumPrevX = np.sum(Xprev + EPSILON) return np.sum((X / sumX - Xprev / sumPrevX) ** 2)
python
def spectral_flux(d0, d1): d0 = np.mean(d0, axis=1) d1 = np.mean(d1, axis=1) nFFT = min(len(d0) // 2, len(d1) // 2) X = FFT(d0, nFFT) Xprev = FFT(d1, nFFT) sumX = np.sum(X + EPSILON) sumPrevX = np.sum(Xprev + EPSILON) return np.sum((X / sumX - Xprev / sumPrevX) ** 2)
[ "def", "spectral_flux", "(", "d0", ",", "d1", ")", ":", "# compute the spectral flux as the sum of square distances:", "d0", "=", "np", ".", "mean", "(", "d0", ",", "axis", "=", "1", ")", "d1", "=", "np", ".", "mean", "(", "d1", ",", "axis", "=", "1", ")", "nFFT", "=", "min", "(", "len", "(", "d0", ")", "//", "2", ",", "len", "(", "d1", ")", "//", "2", ")", "X", "=", "FFT", "(", "d0", ",", "nFFT", ")", "Xprev", "=", "FFT", "(", "d1", ",", "nFFT", ")", "# L = min(len(X), len(Xprev))", "sumX", "=", "np", ".", "sum", "(", "X", "+", "EPSILON", ")", "sumPrevX", "=", "np", ".", "sum", "(", "Xprev", "+", "EPSILON", ")", "return", "np", ".", "sum", "(", "(", "X", "/", "sumX", "-", "Xprev", "/", "sumPrevX", ")", "**", "2", ")" ]
Computes the spectral flux feature of the current frame
[ "Computes", "the", "spectral", "flux", "feature", "of", "the", "current", "frame" ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/audio_featurization.py#L60-L75
HDI-Project/MLPrimitives
mlprimitives/candidates/audio_featurization.py
energy_entropy
def energy_entropy(data, fs, numOfShortBlocks=10): """Computes entropy of energy""" data = np.mean(data, axis=1) Eol = np.sum(data ** 2) # total data energy L = len(data) subWinLength = int(np.floor(L / numOfShortBlocks)) if L != subWinLength * numOfShortBlocks: data = data[0:subWinLength * numOfShortBlocks] # subWindows is of size [numOfShortBlocks x L] subWindows = data.reshape(subWinLength, numOfShortBlocks, order='F').copy() # Compute normalized sub-data energies: s = np.sum(subWindows ** 2, axis=0) / (Eol + EPSILON) # Compute entropy of the normalized sub-data energies: Entropy = -np.sum(s * np.log2(s + EPSILON)) return Entropy
python
def energy_entropy(data, fs, numOfShortBlocks=10): data = np.mean(data, axis=1) Eol = np.sum(data ** 2) L = len(data) subWinLength = int(np.floor(L / numOfShortBlocks)) if L != subWinLength * numOfShortBlocks: data = data[0:subWinLength * numOfShortBlocks] subWindows = data.reshape(subWinLength, numOfShortBlocks, order='F').copy() s = np.sum(subWindows ** 2, axis=0) / (Eol + EPSILON) Entropy = -np.sum(s * np.log2(s + EPSILON)) return Entropy
[ "def", "energy_entropy", "(", "data", ",", "fs", ",", "numOfShortBlocks", "=", "10", ")", ":", "data", "=", "np", ".", "mean", "(", "data", ",", "axis", "=", "1", ")", "Eol", "=", "np", ".", "sum", "(", "data", "**", "2", ")", "# total data energy", "L", "=", "len", "(", "data", ")", "subWinLength", "=", "int", "(", "np", ".", "floor", "(", "L", "/", "numOfShortBlocks", ")", ")", "if", "L", "!=", "subWinLength", "*", "numOfShortBlocks", ":", "data", "=", "data", "[", "0", ":", "subWinLength", "*", "numOfShortBlocks", "]", "# subWindows is of size [numOfShortBlocks x L]", "subWindows", "=", "data", ".", "reshape", "(", "subWinLength", ",", "numOfShortBlocks", ",", "order", "=", "'F'", ")", ".", "copy", "(", ")", "# Compute normalized sub-data energies:", "s", "=", "np", ".", "sum", "(", "subWindows", "**", "2", ",", "axis", "=", "0", ")", "/", "(", "Eol", "+", "EPSILON", ")", "# Compute entropy of the normalized sub-data energies:", "Entropy", "=", "-", "np", ".", "sum", "(", "s", "*", "np", ".", "log2", "(", "s", "+", "EPSILON", ")", ")", "return", "Entropy" ]
Computes entropy of energy
[ "Computes", "entropy", "of", "energy" ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/audio_featurization.py#L78-L96
HDI-Project/MLPrimitives
mlprimitives/candidates/audio_featurization.py
spectral_centroid_and_spread
def spectral_centroid_and_spread(data, fs): """Computes spectral centroid of frame (given abs(FFT))""" data = np.mean(data, axis=1) nFFT = len(data) // 2 X = FFT(data, nFFT) ind = (np.arange(1, len(X) + 1)) * (fs / (2.0 * len(X))) Xt = X.copy() Xt = Xt / Xt.max() NUM = np.sum(ind * Xt) DEN = np.sum(Xt) + EPSILON # Centroid: C = (NUM / DEN) # Spread: S = np.sqrt(np.sum(((ind - C) ** 2) * Xt) / DEN) # Normalize: C = C / (fs / 2.0) S = S / (fs / 2.0) return (C, S)
python
def spectral_centroid_and_spread(data, fs): data = np.mean(data, axis=1) nFFT = len(data) // 2 X = FFT(data, nFFT) ind = (np.arange(1, len(X) + 1)) * (fs / (2.0 * len(X))) Xt = X.copy() Xt = Xt / Xt.max() NUM = np.sum(ind * Xt) DEN = np.sum(Xt) + EPSILON C = (NUM / DEN) S = np.sqrt(np.sum(((ind - C) ** 2) * Xt) / DEN) C = C / (fs / 2.0) S = S / (fs / 2.0) return (C, S)
[ "def", "spectral_centroid_and_spread", "(", "data", ",", "fs", ")", ":", "data", "=", "np", ".", "mean", "(", "data", ",", "axis", "=", "1", ")", "nFFT", "=", "len", "(", "data", ")", "//", "2", "X", "=", "FFT", "(", "data", ",", "nFFT", ")", "ind", "=", "(", "np", ".", "arange", "(", "1", ",", "len", "(", "X", ")", "+", "1", ")", ")", "*", "(", "fs", "/", "(", "2.0", "*", "len", "(", "X", ")", ")", ")", "Xt", "=", "X", ".", "copy", "(", ")", "Xt", "=", "Xt", "/", "Xt", ".", "max", "(", ")", "NUM", "=", "np", ".", "sum", "(", "ind", "*", "Xt", ")", "DEN", "=", "np", ".", "sum", "(", "Xt", ")", "+", "EPSILON", "# Centroid:", "C", "=", "(", "NUM", "/", "DEN", ")", "# Spread:", "S", "=", "np", ".", "sqrt", "(", "np", ".", "sum", "(", "(", "(", "ind", "-", "C", ")", "**", "2", ")", "*", "Xt", ")", "/", "DEN", ")", "# Normalize:", "C", "=", "C", "/", "(", "fs", "/", "2.0", ")", "S", "=", "S", "/", "(", "fs", "/", "2.0", ")", "return", "(", "C", ",", "S", ")" ]
Computes spectral centroid of frame (given abs(FFT))
[ "Computes", "spectral", "centroid", "of", "frame", "(", "given", "abs", "(", "FFT", "))" ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/audio_featurization.py#L99-L123
HDI-Project/MLPrimitives
mlprimitives/candidates/audio_featurization.py
spectral_rolloff
def spectral_rolloff(data, coeff): """Computes spectral roll-off""" data = np.mean(data, axis=1) nFFT = len(data) // 2 X = FFT(data, nFFT) totalEnergy = np.sum(X ** 2) fftLength = len(X) Thres = coeff * totalEnergy # Find the spectral rolloff as the frequency position where the # respective spectral energy is equal to c*totalEnergy CumSum = np.cumsum(X ** 2) + EPSILON [a, ] = np.nonzero(CumSum > Thres) if len(a) > 0: mC = np.float64(a[0]) / (float(fftLength)) else: mC = 0.0 return mC
python
def spectral_rolloff(data, coeff): data = np.mean(data, axis=1) nFFT = len(data) // 2 X = FFT(data, nFFT) totalEnergy = np.sum(X ** 2) fftLength = len(X) Thres = coeff * totalEnergy CumSum = np.cumsum(X ** 2) + EPSILON [a, ] = np.nonzero(CumSum > Thres) if len(a) > 0: mC = np.float64(a[0]) / (float(fftLength)) else: mC = 0.0 return mC
[ "def", "spectral_rolloff", "(", "data", ",", "coeff", ")", ":", "data", "=", "np", ".", "mean", "(", "data", ",", "axis", "=", "1", ")", "nFFT", "=", "len", "(", "data", ")", "//", "2", "X", "=", "FFT", "(", "data", ",", "nFFT", ")", "totalEnergy", "=", "np", ".", "sum", "(", "X", "**", "2", ")", "fftLength", "=", "len", "(", "X", ")", "Thres", "=", "coeff", "*", "totalEnergy", "# Find the spectral rolloff as the frequency position where the", "# respective spectral energy is equal to c*totalEnergy", "CumSum", "=", "np", ".", "cumsum", "(", "X", "**", "2", ")", "+", "EPSILON", "[", "a", ",", "]", "=", "np", ".", "nonzero", "(", "CumSum", ">", "Thres", ")", "if", "len", "(", "a", ")", ">", "0", ":", "mC", "=", "np", ".", "float64", "(", "a", "[", "0", "]", ")", "/", "(", "float", "(", "fftLength", ")", ")", "else", ":", "mC", "=", "0.0", "return", "mC" ]
Computes spectral roll-off
[ "Computes", "spectral", "roll", "-", "off" ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/audio_featurization.py#L126-L145
HDI-Project/MLPrimitives
mlprimitives/custom/timeseries_preprocessing.py
rolling_window_sequences
def rolling_window_sequences(X, index, window_size, target_size, target_column): """Create rolling window sequences out of timeseries data.""" out_X = list() out_y = list() X_index = list() y_index = list() target = X[:, target_column] for start in range(len(X) - window_size - target_size + 1): end = start + window_size out_X.append(X[start:end]) out_y.append(target[end:end + target_size]) X_index.append(index[start]) y_index.append(index[end]) return np.asarray(out_X), np.asarray(out_y), np.asarray(X_index), np.asarray(y_index)
python
def rolling_window_sequences(X, index, window_size, target_size, target_column): out_X = list() out_y = list() X_index = list() y_index = list() target = X[:, target_column] for start in range(len(X) - window_size - target_size + 1): end = start + window_size out_X.append(X[start:end]) out_y.append(target[end:end + target_size]) X_index.append(index[start]) y_index.append(index[end]) return np.asarray(out_X), np.asarray(out_y), np.asarray(X_index), np.asarray(y_index)
[ "def", "rolling_window_sequences", "(", "X", ",", "index", ",", "window_size", ",", "target_size", ",", "target_column", ")", ":", "out_X", "=", "list", "(", ")", "out_y", "=", "list", "(", ")", "X_index", "=", "list", "(", ")", "y_index", "=", "list", "(", ")", "target", "=", "X", "[", ":", ",", "target_column", "]", "for", "start", "in", "range", "(", "len", "(", "X", ")", "-", "window_size", "-", "target_size", "+", "1", ")", ":", "end", "=", "start", "+", "window_size", "out_X", ".", "append", "(", "X", "[", "start", ":", "end", "]", ")", "out_y", ".", "append", "(", "target", "[", "end", ":", "end", "+", "target_size", "]", ")", "X_index", ".", "append", "(", "index", "[", "start", "]", ")", "y_index", ".", "append", "(", "index", "[", "end", "]", ")", "return", "np", ".", "asarray", "(", "out_X", ")", ",", "np", ".", "asarray", "(", "out_y", ")", ",", "np", ".", "asarray", "(", "X_index", ")", ",", "np", ".", "asarray", "(", "y_index", ")" ]
Create rolling window sequences out of timeseries data.
[ "Create", "rolling", "window", "sequences", "out", "of", "timeseries", "data", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/custom/timeseries_preprocessing.py#L7-L23
HDI-Project/MLPrimitives
mlprimitives/custom/timeseries_preprocessing.py
time_segments_average
def time_segments_average(X, interval, time_column): """Compute average of values over fixed length time segments.""" warnings.warn(_TIME_SEGMENTS_AVERAGE_DEPRECATION_WARNING, DeprecationWarning) if isinstance(X, np.ndarray): X = pd.DataFrame(X) X = X.sort_values(time_column).set_index(time_column) start_ts = X.index.values[0] max_ts = X.index.values[-1] values = list() index = list() while start_ts <= max_ts: end_ts = start_ts + interval subset = X.loc[start_ts:end_ts - 1] means = subset.mean(skipna=True).values values.append(means) index.append(start_ts) start_ts = end_ts return np.asarray(values), np.asarray(index)
python
def time_segments_average(X, interval, time_column): warnings.warn(_TIME_SEGMENTS_AVERAGE_DEPRECATION_WARNING, DeprecationWarning) if isinstance(X, np.ndarray): X = pd.DataFrame(X) X = X.sort_values(time_column).set_index(time_column) start_ts = X.index.values[0] max_ts = X.index.values[-1] values = list() index = list() while start_ts <= max_ts: end_ts = start_ts + interval subset = X.loc[start_ts:end_ts - 1] means = subset.mean(skipna=True).values values.append(means) index.append(start_ts) start_ts = end_ts return np.asarray(values), np.asarray(index)
[ "def", "time_segments_average", "(", "X", ",", "interval", ",", "time_column", ")", ":", "warnings", ".", "warn", "(", "_TIME_SEGMENTS_AVERAGE_DEPRECATION_WARNING", ",", "DeprecationWarning", ")", "if", "isinstance", "(", "X", ",", "np", ".", "ndarray", ")", ":", "X", "=", "pd", ".", "DataFrame", "(", "X", ")", "X", "=", "X", ".", "sort_values", "(", "time_column", ")", ".", "set_index", "(", "time_column", ")", "start_ts", "=", "X", ".", "index", ".", "values", "[", "0", "]", "max_ts", "=", "X", ".", "index", ".", "values", "[", "-", "1", "]", "values", "=", "list", "(", ")", "index", "=", "list", "(", ")", "while", "start_ts", "<=", "max_ts", ":", "end_ts", "=", "start_ts", "+", "interval", "subset", "=", "X", ".", "loc", "[", "start_ts", ":", "end_ts", "-", "1", "]", "means", "=", "subset", ".", "mean", "(", "skipna", "=", "True", ")", ".", "values", "values", ".", "append", "(", "means", ")", "index", ".", "append", "(", "start_ts", ")", "start_ts", "=", "end_ts", "return", "np", ".", "asarray", "(", "values", ")", ",", "np", ".", "asarray", "(", "index", ")" ]
Compute average of values over fixed length time segments.
[ "Compute", "average", "of", "values", "over", "fixed", "length", "time", "segments", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/custom/timeseries_preprocessing.py#L33-L55
HDI-Project/MLPrimitives
mlprimitives/custom/timeseries_preprocessing.py
time_segments_aggregate
def time_segments_aggregate(X, interval, time_column, method=['mean']): """Aggregate values over fixed length time segments.""" if isinstance(X, np.ndarray): X = pd.DataFrame(X) X = X.sort_values(time_column).set_index(time_column) if isinstance(method, str): method = [method] start_ts = X.index.values[0] max_ts = X.index.values[-1] values = list() index = list() while start_ts <= max_ts: end_ts = start_ts + interval subset = X.loc[start_ts:end_ts - 1] aggregated = [ getattr(subset, agg)(skipna=True).values for agg in method ] values.append(np.concatenate(aggregated)) index.append(start_ts) start_ts = end_ts return np.asarray(values), np.asarray(index)
python
def time_segments_aggregate(X, interval, time_column, method=['mean']): if isinstance(X, np.ndarray): X = pd.DataFrame(X) X = X.sort_values(time_column).set_index(time_column) if isinstance(method, str): method = [method] start_ts = X.index.values[0] max_ts = X.index.values[-1] values = list() index = list() while start_ts <= max_ts: end_ts = start_ts + interval subset = X.loc[start_ts:end_ts - 1] aggregated = [ getattr(subset, agg)(skipna=True).values for agg in method ] values.append(np.concatenate(aggregated)) index.append(start_ts) start_ts = end_ts return np.asarray(values), np.asarray(index)
[ "def", "time_segments_aggregate", "(", "X", ",", "interval", ",", "time_column", ",", "method", "=", "[", "'mean'", "]", ")", ":", "if", "isinstance", "(", "X", ",", "np", ".", "ndarray", ")", ":", "X", "=", "pd", ".", "DataFrame", "(", "X", ")", "X", "=", "X", ".", "sort_values", "(", "time_column", ")", ".", "set_index", "(", "time_column", ")", "if", "isinstance", "(", "method", ",", "str", ")", ":", "method", "=", "[", "method", "]", "start_ts", "=", "X", ".", "index", ".", "values", "[", "0", "]", "max_ts", "=", "X", ".", "index", ".", "values", "[", "-", "1", "]", "values", "=", "list", "(", ")", "index", "=", "list", "(", ")", "while", "start_ts", "<=", "max_ts", ":", "end_ts", "=", "start_ts", "+", "interval", "subset", "=", "X", ".", "loc", "[", "start_ts", ":", "end_ts", "-", "1", "]", "aggregated", "=", "[", "getattr", "(", "subset", ",", "agg", ")", "(", "skipna", "=", "True", ")", ".", "values", "for", "agg", "in", "method", "]", "values", ".", "append", "(", "np", ".", "concatenate", "(", "aggregated", ")", ")", "index", ".", "append", "(", "start_ts", ")", "start_ts", "=", "end_ts", "return", "np", ".", "asarray", "(", "values", ")", ",", "np", ".", "asarray", "(", "index", ")" ]
Aggregate values over fixed length time segments.
[ "Aggregate", "values", "over", "fixed", "length", "time", "segments", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/custom/timeseries_preprocessing.py#L58-L84
HDI-Project/MLPrimitives
mlprimitives/utils.py
image_transform
def image_transform(X, function, reshape_before=False, reshape_after=False, width=None, height=None, **kwargs): """Apply a function image by image. Args: reshape_before: whether 1d array needs to be reshaped to a 2d image reshape_after: whether the returned values need to be reshaped back to a 1d array width: image width used to rebuild the 2d images. Required if the image is not square. height: image height used to rebuild the 2d images. Required if the image is not square. """ if not callable(function): function = import_object(function) elif not callable(function): raise ValueError("function must be a str or a callable") flat_image = len(X[0].shape) == 1 if reshape_before and flat_image: if not (width and height): side_length = math.sqrt(X.shape[1]) if side_length.is_integer(): side_length = int(side_length) width = side_length height = side_length else: raise ValueError("Image sizes must be given for non-square images") else: reshape_before = False new_X = [] for image in X: if reshape_before: image = image.reshape((width, height)) features = function( image, **kwargs ) if reshape_after: features = np.reshape(features, X.shape[1]) new_X.append(features) return np.array(new_X)
python
def image_transform(X, function, reshape_before=False, reshape_after=False, width=None, height=None, **kwargs): if not callable(function): function = import_object(function) elif not callable(function): raise ValueError("function must be a str or a callable") flat_image = len(X[0].shape) == 1 if reshape_before and flat_image: if not (width and height): side_length = math.sqrt(X.shape[1]) if side_length.is_integer(): side_length = int(side_length) width = side_length height = side_length else: raise ValueError("Image sizes must be given for non-square images") else: reshape_before = False new_X = [] for image in X: if reshape_before: image = image.reshape((width, height)) features = function( image, **kwargs ) if reshape_after: features = np.reshape(features, X.shape[1]) new_X.append(features) return np.array(new_X)
[ "def", "image_transform", "(", "X", ",", "function", ",", "reshape_before", "=", "False", ",", "reshape_after", "=", "False", ",", "width", "=", "None", ",", "height", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "not", "callable", "(", "function", ")", ":", "function", "=", "import_object", "(", "function", ")", "elif", "not", "callable", "(", "function", ")", ":", "raise", "ValueError", "(", "\"function must be a str or a callable\"", ")", "flat_image", "=", "len", "(", "X", "[", "0", "]", ".", "shape", ")", "==", "1", "if", "reshape_before", "and", "flat_image", ":", "if", "not", "(", "width", "and", "height", ")", ":", "side_length", "=", "math", ".", "sqrt", "(", "X", ".", "shape", "[", "1", "]", ")", "if", "side_length", ".", "is_integer", "(", ")", ":", "side_length", "=", "int", "(", "side_length", ")", "width", "=", "side_length", "height", "=", "side_length", "else", ":", "raise", "ValueError", "(", "\"Image sizes must be given for non-square images\"", ")", "else", ":", "reshape_before", "=", "False", "new_X", "=", "[", "]", "for", "image", "in", "X", ":", "if", "reshape_before", ":", "image", "=", "image", ".", "reshape", "(", "(", "width", ",", "height", ")", ")", "features", "=", "function", "(", "image", ",", "*", "*", "kwargs", ")", "if", "reshape_after", ":", "features", "=", "np", ".", "reshape", "(", "features", ",", "X", ".", "shape", "[", "1", "]", ")", "new_X", ".", "append", "(", "features", ")", "return", "np", ".", "array", "(", "new_X", ")" ]
Apply a function image by image. Args: reshape_before: whether 1d array needs to be reshaped to a 2d image reshape_after: whether the returned values need to be reshaped back to a 1d array width: image width used to rebuild the 2d images. Required if the image is not square. height: image height used to rebuild the 2d images. Required if the image is not square.
[ "Apply", "a", "function", "image", "by", "image", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/utils.py#L18-L65
HDI-Project/MLPrimitives
mlprimitives/custom/timeseries_anomalies.py
regression_errors
def regression_errors(y, y_hat, smoothing_window=0.01, smooth=True): """Compute an array of absolute errors comparing predictions and expected output. If smooth is True, apply EWMA to the resulting array of errors. Args: y (array): Ground truth. y_hat (array): Predictions array. smoothing_window (float): Size of the smoothing window, expressed as a proportion of the total length of y. smooth (bool): whether the returned errors should be smoothed with EWMA. Returns: (array): errors """ errors = np.abs(y - y_hat)[:, 0] if not smooth: return errors smoothing_window = int(smoothing_window * len(y)) return pd.Series(errors).ewm(span=smoothing_window).mean().values
python
def regression_errors(y, y_hat, smoothing_window=0.01, smooth=True): errors = np.abs(y - y_hat)[:, 0] if not smooth: return errors smoothing_window = int(smoothing_window * len(y)) return pd.Series(errors).ewm(span=smoothing_window).mean().values
[ "def", "regression_errors", "(", "y", ",", "y_hat", ",", "smoothing_window", "=", "0.01", ",", "smooth", "=", "True", ")", ":", "errors", "=", "np", ".", "abs", "(", "y", "-", "y_hat", ")", "[", ":", ",", "0", "]", "if", "not", "smooth", ":", "return", "errors", "smoothing_window", "=", "int", "(", "smoothing_window", "*", "len", "(", "y", ")", ")", "return", "pd", ".", "Series", "(", "errors", ")", ".", "ewm", "(", "span", "=", "smoothing_window", ")", ".", "mean", "(", ")", ".", "values" ]
Compute an array of absolute errors comparing predictions and expected output. If smooth is True, apply EWMA to the resulting array of errors. Args: y (array): Ground truth. y_hat (array): Predictions array. smoothing_window (float): Size of the smoothing window, expressed as a proportion of the total length of y. smooth (bool): whether the returned errors should be smoothed with EWMA. Returns: (array): errors
[ "Compute", "an", "array", "of", "absolute", "errors", "comparing", "predictions", "and", "expected", "output", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/custom/timeseries_anomalies.py#L11-L33
HDI-Project/MLPrimitives
mlprimitives/custom/timeseries_anomalies.py
deltas
def deltas(errors, epsilon, mean, std): """Compute mean and std deltas. delta_mean = mean(errors) - mean(all errors below epsilon) delta_std = std(errors) - std(all errors below epsilon) """ below = errors[errors <= epsilon] if not len(below): return 0, 0 return mean - below.mean(), std - below.std()
python
def deltas(errors, epsilon, mean, std): below = errors[errors <= epsilon] if not len(below): return 0, 0 return mean - below.mean(), std - below.std()
[ "def", "deltas", "(", "errors", ",", "epsilon", ",", "mean", ",", "std", ")", ":", "below", "=", "errors", "[", "errors", "<=", "epsilon", "]", "if", "not", "len", "(", "below", ")", ":", "return", "0", ",", "0", "return", "mean", "-", "below", ".", "mean", "(", ")", ",", "std", "-", "below", ".", "std", "(", ")" ]
Compute mean and std deltas. delta_mean = mean(errors) - mean(all errors below epsilon) delta_std = std(errors) - std(all errors below epsilon)
[ "Compute", "mean", "and", "std", "deltas", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/custom/timeseries_anomalies.py#L36-L46
HDI-Project/MLPrimitives
mlprimitives/custom/timeseries_anomalies.py
count_above
def count_above(errors, epsilon): """Count number of errors and continuous sequences above epsilon. Continuous sequences are counted by shifting and counting the number of positions where there was a change and the original value was true, which means that a sequence started at that position. """ above = errors > epsilon total_above = len(errors[above]) above = pd.Series(above) shift = above.shift(1) change = above != shift total_consecutive = sum(above & change) return total_above, total_consecutive
python
def count_above(errors, epsilon): above = errors > epsilon total_above = len(errors[above]) above = pd.Series(above) shift = above.shift(1) change = above != shift total_consecutive = sum(above & change) return total_above, total_consecutive
[ "def", "count_above", "(", "errors", ",", "epsilon", ")", ":", "above", "=", "errors", ">", "epsilon", "total_above", "=", "len", "(", "errors", "[", "above", "]", ")", "above", "=", "pd", ".", "Series", "(", "above", ")", "shift", "=", "above", ".", "shift", "(", "1", ")", "change", "=", "above", "!=", "shift", "total_consecutive", "=", "sum", "(", "above", "&", "change", ")", "return", "total_above", ",", "total_consecutive" ]
Count number of errors and continuous sequences above epsilon. Continuous sequences are counted by shifting and counting the number of positions where there was a change and the original value was true, which means that a sequence started at that position.
[ "Count", "number", "of", "errors", "and", "continuous", "sequences", "above", "epsilon", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/custom/timeseries_anomalies.py#L49-L65
HDI-Project/MLPrimitives
mlprimitives/custom/timeseries_anomalies.py
z_cost
def z_cost(z, errors, mean, std): """Compute how bad a z value is. The original formula is:: (delta_mean/mean) + (delta_std/std) ------------------------------------------------------ number of errors above + (number of sequences above)^2 which computes the "goodness" of `z`, meaning that the higher the value the better the `z`. In this case, we return this value inverted (we make it negative), to convert it into a cost function, as later on we will use scipy to minimize it. """ epsilon = mean + z * std delta_mean, delta_std = deltas(errors, epsilon, mean, std) above, consecutive = count_above(errors, epsilon) numerator = -(delta_mean / mean + delta_std / std) denominator = above + consecutive ** 2 if denominator == 0: return np.inf return numerator / denominator
python
def z_cost(z, errors, mean, std): epsilon = mean + z * std delta_mean, delta_std = deltas(errors, epsilon, mean, std) above, consecutive = count_above(errors, epsilon) numerator = -(delta_mean / mean + delta_std / std) denominator = above + consecutive ** 2 if denominator == 0: return np.inf return numerator / denominator
[ "def", "z_cost", "(", "z", ",", "errors", ",", "mean", ",", "std", ")", ":", "epsilon", "=", "mean", "+", "z", "*", "std", "delta_mean", ",", "delta_std", "=", "deltas", "(", "errors", ",", "epsilon", ",", "mean", ",", "std", ")", "above", ",", "consecutive", "=", "count_above", "(", "errors", ",", "epsilon", ")", "numerator", "=", "-", "(", "delta_mean", "/", "mean", "+", "delta_std", "/", "std", ")", "denominator", "=", "above", "+", "consecutive", "**", "2", "if", "denominator", "==", "0", ":", "return", "np", ".", "inf", "return", "numerator", "/", "denominator" ]
Compute how bad a z value is. The original formula is:: (delta_mean/mean) + (delta_std/std) ------------------------------------------------------ number of errors above + (number of sequences above)^2 which computes the "goodness" of `z`, meaning that the higher the value the better the `z`. In this case, we return this value inverted (we make it negative), to convert it into a cost function, as later on we will use scipy to minimize it.
[ "Compute", "how", "bad", "a", "z", "value", "is", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/custom/timeseries_anomalies.py#L68-L95
HDI-Project/MLPrimitives
mlprimitives/custom/timeseries_anomalies.py
find_threshold
def find_threshold(errors, z_range=(0, 10)): """Find the ideal threshold. The ideal threshold is the one that minimizes the z_cost function. """ mean = errors.mean() std = errors.std() min_z, max_z = z_range best_z = min_z best_cost = np.inf for z in range(min_z, max_z): best = fmin(z_cost, z, args=(errors, mean, std), full_output=True, disp=False) z, cost = best[0:2] if cost < best_cost: best_z = z[0] return mean + best_z * std
python
def find_threshold(errors, z_range=(0, 10)): mean = errors.mean() std = errors.std() min_z, max_z = z_range best_z = min_z best_cost = np.inf for z in range(min_z, max_z): best = fmin(z_cost, z, args=(errors, mean, std), full_output=True, disp=False) z, cost = best[0:2] if cost < best_cost: best_z = z[0] return mean + best_z * std
[ "def", "find_threshold", "(", "errors", ",", "z_range", "=", "(", "0", ",", "10", ")", ")", ":", "mean", "=", "errors", ".", "mean", "(", ")", "std", "=", "errors", ".", "std", "(", ")", "min_z", ",", "max_z", "=", "z_range", "best_z", "=", "min_z", "best_cost", "=", "np", ".", "inf", "for", "z", "in", "range", "(", "min_z", ",", "max_z", ")", ":", "best", "=", "fmin", "(", "z_cost", ",", "z", ",", "args", "=", "(", "errors", ",", "mean", ",", "std", ")", ",", "full_output", "=", "True", ",", "disp", "=", "False", ")", "z", ",", "cost", "=", "best", "[", "0", ":", "2", "]", "if", "cost", "<", "best_cost", ":", "best_z", "=", "z", "[", "0", "]", "return", "mean", "+", "best_z", "*", "std" ]
Find the ideal threshold. The ideal threshold is the one that minimizes the z_cost function.
[ "Find", "the", "ideal", "threshold", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/custom/timeseries_anomalies.py#L98-L116
HDI-Project/MLPrimitives
mlprimitives/custom/timeseries_anomalies.py
find_sequences
def find_sequences(errors, epsilon): """Find sequences of values that are above epsilon. This is done following this steps: * create a boolean mask that indicates which value are above epsilon. * shift this mask by one place, filing the empty gap with a False * compare the shifted mask with the original one to see if there are changes. * Consider a sequence start any point which was true and has changed * Consider a sequence end any point which was false and has changed """ above = pd.Series(errors > epsilon) shift = above.shift(1).fillna(False) change = above != shift index = above.index starts = index[above & change].tolist() ends = (index[~above & change] - 1).tolist() if len(ends) == len(starts) - 1: ends.append(len(above) - 1) return list(zip(starts, ends))
python
def find_sequences(errors, epsilon): above = pd.Series(errors > epsilon) shift = above.shift(1).fillna(False) change = above != shift index = above.index starts = index[above & change].tolist() ends = (index[~above & change] - 1).tolist() if len(ends) == len(starts) - 1: ends.append(len(above) - 1) return list(zip(starts, ends))
[ "def", "find_sequences", "(", "errors", ",", "epsilon", ")", ":", "above", "=", "pd", ".", "Series", "(", "errors", ">", "epsilon", ")", "shift", "=", "above", ".", "shift", "(", "1", ")", ".", "fillna", "(", "False", ")", "change", "=", "above", "!=", "shift", "index", "=", "above", ".", "index", "starts", "=", "index", "[", "above", "&", "change", "]", ".", "tolist", "(", ")", "ends", "=", "(", "index", "[", "~", "above", "&", "change", "]", "-", "1", ")", ".", "tolist", "(", ")", "if", "len", "(", "ends", ")", "==", "len", "(", "starts", ")", "-", "1", ":", "ends", ".", "append", "(", "len", "(", "above", ")", "-", "1", ")", "return", "list", "(", "zip", "(", "starts", ",", "ends", ")", ")" ]
Find sequences of values that are above epsilon. This is done following this steps: * create a boolean mask that indicates which value are above epsilon. * shift this mask by one place, filing the empty gap with a False * compare the shifted mask with the original one to see if there are changes. * Consider a sequence start any point which was true and has changed * Consider a sequence end any point which was false and has changed
[ "Find", "sequences", "of", "values", "that", "are", "above", "epsilon", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/custom/timeseries_anomalies.py#L119-L140
HDI-Project/MLPrimitives
mlprimitives/custom/timeseries_anomalies.py
find_anomalies
def find_anomalies(errors, index, z_range=(0, 10)): """Find sequences of values that are anomalous. We first find the ideal threshold for the set of errors that we have, and then find the sequences of values that are above this threshold. Lastly, we compute a score proportional to the maximum error in the sequence, and finally return the index pairs that correspond to each sequence, along with its score. """ threshold = find_threshold(errors, z_range) sequences = find_sequences(errors, threshold) anomalies = list() denominator = errors.mean() + errors.std() for start, stop in sequences: max_error = errors[start:stop + 1].max() score = (max_error - threshold) / denominator anomalies.append([index[start], index[stop], score]) return np.asarray(anomalies)
python
def find_anomalies(errors, index, z_range=(0, 10)): threshold = find_threshold(errors, z_range) sequences = find_sequences(errors, threshold) anomalies = list() denominator = errors.mean() + errors.std() for start, stop in sequences: max_error = errors[start:stop + 1].max() score = (max_error - threshold) / denominator anomalies.append([index[start], index[stop], score]) return np.asarray(anomalies)
[ "def", "find_anomalies", "(", "errors", ",", "index", ",", "z_range", "=", "(", "0", ",", "10", ")", ")", ":", "threshold", "=", "find_threshold", "(", "errors", ",", "z_range", ")", "sequences", "=", "find_sequences", "(", "errors", ",", "threshold", ")", "anomalies", "=", "list", "(", ")", "denominator", "=", "errors", ".", "mean", "(", ")", "+", "errors", ".", "std", "(", ")", "for", "start", ",", "stop", "in", "sequences", ":", "max_error", "=", "errors", "[", "start", ":", "stop", "+", "1", "]", ".", "max", "(", ")", "score", "=", "(", "max_error", "-", "threshold", ")", "/", "denominator", "anomalies", ".", "append", "(", "[", "index", "[", "start", "]", ",", "index", "[", "stop", "]", ",", "score", "]", ")", "return", "np", ".", "asarray", "(", "anomalies", ")" ]
Find sequences of values that are anomalous. We first find the ideal threshold for the set of errors that we have, and then find the sequences of values that are above this threshold. Lastly, we compute a score proportional to the maximum error in the sequence, and finally return the index pairs that correspond to each sequence, along with its score.
[ "Find", "sequences", "of", "values", "that", "are", "anomalous", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/custom/timeseries_anomalies.py#L143-L164
HDI-Project/MLPrimitives
mlprimitives/adapters/cv2.py
GaussianBlur
def GaussianBlur(X, ksize_width, ksize_height, sigma_x, sigma_y): """Apply Gaussian blur to the given data. Args: X: data to blur kernel_size: Gaussian kernel size stddev: Gaussian kernel standard deviation (in both X and Y directions) """ return image_transform( X, cv2.GaussianBlur, ksize=(ksize_width, ksize_height), sigmaX=sigma_x, sigmaY=sigma_y )
python
def GaussianBlur(X, ksize_width, ksize_height, sigma_x, sigma_y): return image_transform( X, cv2.GaussianBlur, ksize=(ksize_width, ksize_height), sigmaX=sigma_x, sigmaY=sigma_y )
[ "def", "GaussianBlur", "(", "X", ",", "ksize_width", ",", "ksize_height", ",", "sigma_x", ",", "sigma_y", ")", ":", "return", "image_transform", "(", "X", ",", "cv2", ".", "GaussianBlur", ",", "ksize", "=", "(", "ksize_width", ",", "ksize_height", ")", ",", "sigmaX", "=", "sigma_x", ",", "sigmaY", "=", "sigma_y", ")" ]
Apply Gaussian blur to the given data. Args: X: data to blur kernel_size: Gaussian kernel size stddev: Gaussian kernel standard deviation (in both X and Y directions)
[ "Apply", "Gaussian", "blur", "to", "the", "given", "data", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/adapters/cv2.py#L8-L22
HDI-Project/MLPrimitives
mlprimitives/candidates/timeseries.py
rolling_window_sequences
def rolling_window_sequences(X, window_size, target_size, value_column, time_column): """ Function that takes in a pandas.DataFrame and a window_size then creates output arrays that correspond to a timeseries sequence with window_size overlap. The output arrays can be fed into a timeseries forecasting model. Assumes the input is timeseries sorted. Args: X (pandas.DataFrame): a pandas dataframe which has 'timestamp' and 'value' columns, and is sorted based on timestamp. The timestamp column is in UNIX format (in seconds). window_size (int): number of values that overlap to create the sequence. value_column (string): name of column that has the value field. time_column (string): name of column that has the time field. Returns: (numpy.ndarray): contains the time series sequenced data with each entry having window_size rows. (numpy.ndarray): acts as the label for the forecasting problem with each entry having window_size rows. (numpy.ndarray): the corresponding timestamps series. """ output_X = [] y = [] time = [] for start in range(len(X) - window_size - target_size): end = start + window_size output_X.append(X.iloc[start:end][value_column].values.reshape([-1, 1])) y.append(X.iloc[end:end + target_size][value_column].values) time.append(X.iloc[end + 1][time_column]) return np.asarray(output_X), np.asarray(y), np.asarray(time)
python
def rolling_window_sequences(X, window_size, target_size, value_column, time_column): output_X = [] y = [] time = [] for start in range(len(X) - window_size - target_size): end = start + window_size output_X.append(X.iloc[start:end][value_column].values.reshape([-1, 1])) y.append(X.iloc[end:end + target_size][value_column].values) time.append(X.iloc[end + 1][time_column]) return np.asarray(output_X), np.asarray(y), np.asarray(time)
[ "def", "rolling_window_sequences", "(", "X", ",", "window_size", ",", "target_size", ",", "value_column", ",", "time_column", ")", ":", "output_X", "=", "[", "]", "y", "=", "[", "]", "time", "=", "[", "]", "for", "start", "in", "range", "(", "len", "(", "X", ")", "-", "window_size", "-", "target_size", ")", ":", "end", "=", "start", "+", "window_size", "output_X", ".", "append", "(", "X", ".", "iloc", "[", "start", ":", "end", "]", "[", "value_column", "]", ".", "values", ".", "reshape", "(", "[", "-", "1", ",", "1", "]", ")", ")", "y", ".", "append", "(", "X", ".", "iloc", "[", "end", ":", "end", "+", "target_size", "]", "[", "value_column", "]", ".", "values", ")", "time", ".", "append", "(", "X", ".", "iloc", "[", "end", "+", "1", "]", "[", "time_column", "]", ")", "return", "np", ".", "asarray", "(", "output_X", ")", ",", "np", ".", "asarray", "(", "y", ")", ",", "np", ".", "asarray", "(", "time", ")" ]
Function that takes in a pandas.DataFrame and a window_size then creates output arrays that correspond to a timeseries sequence with window_size overlap. The output arrays can be fed into a timeseries forecasting model. Assumes the input is timeseries sorted. Args: X (pandas.DataFrame): a pandas dataframe which has 'timestamp' and 'value' columns, and is sorted based on timestamp. The timestamp column is in UNIX format (in seconds). window_size (int): number of values that overlap to create the sequence. value_column (string): name of column that has the value field. time_column (string): name of column that has the time field. Returns: (numpy.ndarray): contains the time series sequenced data with each entry having window_size rows. (numpy.ndarray): acts as the label for the forecasting problem with each entry having window_size rows. (numpy.ndarray): the corresponding timestamps series.
[ "Function", "that", "takes", "in", "a", "pandas", ".", "DataFrame", "and", "a", "window_size", "then", "creates", "output", "arrays", "that", "correspond", "to", "a", "timeseries", "sequence", "with", "window_size", "overlap", ".", "The", "output", "arrays", "can", "be", "fed", "into", "a", "timeseries", "forecasting", "model", ".", "Assumes", "the", "input", "is", "timeseries", "sorted", ".", "Args", ":", "X", "(", "pandas", ".", "DataFrame", ")", ":", "a", "pandas", "dataframe", "which", "has", "timestamp", "and", "value", "columns", "and", "is", "sorted", "based", "on", "timestamp", ".", "The", "timestamp", "column", "is", "in", "UNIX", "format", "(", "in", "seconds", ")", ".", "window_size", "(", "int", ")", ":", "number", "of", "values", "that", "overlap", "to", "create", "the", "sequence", ".", "value_column", "(", "string", ")", ":", "name", "of", "column", "that", "has", "the", "value", "field", ".", "time_column", "(", "string", ")", ":", "name", "of", "column", "that", "has", "the", "time", "field", ".", "Returns", ":", "(", "numpy", ".", "ndarray", ")", ":", "contains", "the", "time", "series", "sequenced", "data", "with", "each", "entry", "having", "window_size", "rows", ".", "(", "numpy", ".", "ndarray", ")", ":", "acts", "as", "the", "label", "for", "the", "forecasting", "problem", "with", "each", "entry", "having", "window_size", "rows", ".", "(", "numpy", ".", "ndarray", ")", ":", "the", "corresponding", "timestamps", "series", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/timeseries.py#L5-L34
HDI-Project/MLPrimitives
mlprimitives/candidates/timeseries.py
time_segments_average
def time_segments_average(X, interval, value_column, time_column): """ function that aggregates data in a pandas dataframe by averaging over a given interval. it starts averaging from the smallest timestamp in the dataframe and ends at the largest timestamp. assumes the input is timeseries sorted. args: X (pandas.dataframe): a pandas dataframe which has 'timestamp' and 'value' columns, and is sorted based on timestamp. the timestamp column is in unix format (in seconds). interval (int): an integer denoting the number of seconds in the desired interval. value_column (string): name of column that has the value field. time_column (string): name of column that has the time field. returns: pandas.dataframe: a pandas dataframe with two colums ('timestamp' and 'value'), where each `timestamp` is the starting time of an interval and the `value` is the result of aggregation. """ start_ts = X[time_column].iloc[0] # min value end_time = X[time_column].iloc[-1] # max value in dataframe accepted_points = [] while start_ts < end_time: # average the values between start_ts, [start_ts + timedelta (e.g. 6hrs)] upper_ts = start_ts + interval mask = (X[time_column] > start_ts) & (X[time_column] <= upper_ts) average_value = X.loc[mask][value_column].mean(skipna=True) accepted_points.append([start_ts, average_value]) start_ts = upper_ts # update the timestamp return pd.DataFrame(accepted_points, columns=[time_column, value_column])
python
def time_segments_average(X, interval, value_column, time_column): start_ts = X[time_column].iloc[0] end_time = X[time_column].iloc[-1] accepted_points = [] while start_ts < end_time: upper_ts = start_ts + interval mask = (X[time_column] > start_ts) & (X[time_column] <= upper_ts) average_value = X.loc[mask][value_column].mean(skipna=True) accepted_points.append([start_ts, average_value]) start_ts = upper_ts return pd.DataFrame(accepted_points, columns=[time_column, value_column])
[ "def", "time_segments_average", "(", "X", ",", "interval", ",", "value_column", ",", "time_column", ")", ":", "start_ts", "=", "X", "[", "time_column", "]", ".", "iloc", "[", "0", "]", "# min value", "end_time", "=", "X", "[", "time_column", "]", ".", "iloc", "[", "-", "1", "]", "# max value in dataframe", "accepted_points", "=", "[", "]", "while", "start_ts", "<", "end_time", ":", "# average the values between start_ts, [start_ts + timedelta (e.g. 6hrs)]", "upper_ts", "=", "start_ts", "+", "interval", "mask", "=", "(", "X", "[", "time_column", "]", ">", "start_ts", ")", "&", "(", "X", "[", "time_column", "]", "<=", "upper_ts", ")", "average_value", "=", "X", ".", "loc", "[", "mask", "]", "[", "value_column", "]", ".", "mean", "(", "skipna", "=", "True", ")", "accepted_points", ".", "append", "(", "[", "start_ts", ",", "average_value", "]", ")", "start_ts", "=", "upper_ts", "# update the timestamp", "return", "pd", ".", "DataFrame", "(", "accepted_points", ",", "columns", "=", "[", "time_column", ",", "value_column", "]", ")" ]
function that aggregates data in a pandas dataframe by averaging over a given interval. it starts averaging from the smallest timestamp in the dataframe and ends at the largest timestamp. assumes the input is timeseries sorted. args: X (pandas.dataframe): a pandas dataframe which has 'timestamp' and 'value' columns, and is sorted based on timestamp. the timestamp column is in unix format (in seconds). interval (int): an integer denoting the number of seconds in the desired interval. value_column (string): name of column that has the value field. time_column (string): name of column that has the time field. returns: pandas.dataframe: a pandas dataframe with two colums ('timestamp' and 'value'), where each `timestamp` is the starting time of an interval and the `value` is the result of aggregation.
[ "function", "that", "aggregates", "data", "in", "a", "pandas", "dataframe", "by", "averaging", "over", "a", "given", "interval", ".", "it", "starts", "averaging", "from", "the", "smallest", "timestamp", "in", "the", "dataframe", "and", "ends", "at", "the", "largest", "timestamp", ".", "assumes", "the", "input", "is", "timeseries", "sorted", ".", "args", ":", "X", "(", "pandas", ".", "dataframe", ")", ":", "a", "pandas", "dataframe", "which", "has", "timestamp", "and", "value", "columns", "and", "is", "sorted", "based", "on", "timestamp", ".", "the", "timestamp", "column", "is", "in", "unix", "format", "(", "in", "seconds", ")", ".", "interval", "(", "int", ")", ":", "an", "integer", "denoting", "the", "number", "of", "seconds", "in", "the", "desired", "interval", ".", "value_column", "(", "string", ")", ":", "name", "of", "column", "that", "has", "the", "value", "field", ".", "time_column", "(", "string", ")", ":", "name", "of", "column", "that", "has", "the", "time", "field", ".", "returns", ":", "pandas", ".", "dataframe", ":", "a", "pandas", "dataframe", "with", "two", "colums", "(", "timestamp", "and", "value", ")", "where", "each", "timestamp", "is", "the", "starting", "time", "of", "an", "interval", "and", "the", "value", "is", "the", "result", "of", "aggregation", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/timeseries.py#L37-L67
HDI-Project/MLPrimitives
mlprimitives/candidates/timeseries_errors.py
get_forecast_errors
def get_forecast_errors(y_hat, y_true, window_size=5, batch_size=30, smoothing_percent=0.05, smoothed=True): """ Calculates the forecasting error for two arrays of data. If smoothed errors desired, runs EWMA. Args: y_hat (list): forecasted values. len(y_hat)==len(y_true). y_true (list): true values. len(y_hat)==len(y_true). window_size (int): batch_size (int): smoothing_percent (float): smoothed (bool): whether the returned errors should be smoothed with EWMA. Returns: (list): error residuals. Smoothed if specified by user. """ errors = [abs(y_h - y_t) for y_h, y_t in zip(y_hat, y_true)] if not smoothed: return errors historical_error_window = int(window_size * batch_size * smoothing_percent) moving_avg = [] for i in range(len(errors)): left_window = i - historical_error_window right_window = i + historical_error_window + 1 if left_window < 0: left_window = 0 if right_window > len(errors): right_window = len(errors) moving_avg.append(np.mean(errors[left_window:right_window])) return moving_avg
python
def get_forecast_errors(y_hat, y_true, window_size=5, batch_size=30, smoothing_percent=0.05, smoothed=True): errors = [abs(y_h - y_t) for y_h, y_t in zip(y_hat, y_true)] if not smoothed: return errors historical_error_window = int(window_size * batch_size * smoothing_percent) moving_avg = [] for i in range(len(errors)): left_window = i - historical_error_window right_window = i + historical_error_window + 1 if left_window < 0: left_window = 0 if right_window > len(errors): right_window = len(errors) moving_avg.append(np.mean(errors[left_window:right_window])) return moving_avg
[ "def", "get_forecast_errors", "(", "y_hat", ",", "y_true", ",", "window_size", "=", "5", ",", "batch_size", "=", "30", ",", "smoothing_percent", "=", "0.05", ",", "smoothed", "=", "True", ")", ":", "errors", "=", "[", "abs", "(", "y_h", "-", "y_t", ")", "for", "y_h", ",", "y_t", "in", "zip", "(", "y_hat", ",", "y_true", ")", "]", "if", "not", "smoothed", ":", "return", "errors", "historical_error_window", "=", "int", "(", "window_size", "*", "batch_size", "*", "smoothing_percent", ")", "moving_avg", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "errors", ")", ")", ":", "left_window", "=", "i", "-", "historical_error_window", "right_window", "=", "i", "+", "historical_error_window", "+", "1", "if", "left_window", "<", "0", ":", "left_window", "=", "0", "if", "right_window", ">", "len", "(", "errors", ")", ":", "right_window", "=", "len", "(", "errors", ")", "moving_avg", ".", "append", "(", "np", ".", "mean", "(", "errors", "[", "left_window", ":", "right_window", "]", ")", ")", "return", "moving_avg" ]
Calculates the forecasting error for two arrays of data. If smoothed errors desired, runs EWMA. Args: y_hat (list): forecasted values. len(y_hat)==len(y_true). y_true (list): true values. len(y_hat)==len(y_true). window_size (int): batch_size (int): smoothing_percent (float): smoothed (bool): whether the returned errors should be smoothed with EWMA. Returns: (list): error residuals. Smoothed if specified by user.
[ "Calculates", "the", "forecasting", "error", "for", "two", "arrays", "of", "data", ".", "If", "smoothed", "errors", "desired", "runs", "EWMA", ".", "Args", ":", "y_hat", "(", "list", ")", ":", "forecasted", "values", ".", "len", "(", "y_hat", ")", "==", "len", "(", "y_true", ")", ".", "y_true", "(", "list", ")", ":", "true", "values", ".", "len", "(", "y_hat", ")", "==", "len", "(", "y_true", ")", ".", "window_size", "(", "int", ")", ":", "batch_size", "(", "int", ")", ":", "smoothing_percent", "(", "float", ")", ":", "smoothed", "(", "bool", ")", ":", "whether", "the", "returned", "errors", "should", "be", "smoothed", "with", "EWMA", ".", "Returns", ":", "(", "list", ")", ":", "error", "residuals", ".", "Smoothed", "if", "specified", "by", "user", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/timeseries_errors.py#L8-L45
HDI-Project/MLPrimitives
mlprimitives/candidates/timeseries_errors.py
extract_anomalies
def extract_anomalies(y_true, smoothed_errors, window_size, batch_size, error_buffer): """ Extracts anomalies from the errors. Args: y_true (): smoothed_errors (): window_size (int): batch_size (int): error_buffer (int): Returns: """ if len(y_true) <= batch_size * window_size: raise ValueError("Window size (%s) larger than y_true (len=%s)." % (batch_size, len(y_true))) num_windows = int((len(y_true) - (batch_size * window_size)) / batch_size) anomalies_indices = [] for i in range(num_windows + 1): prev_index = i * batch_size curr_index = (window_size * batch_size) + (i * batch_size) if i == num_windows + 1: curr_index = len(y_true) window_smoothed_errors = smoothed_errors[prev_index:curr_index] window_y_true = y_true[prev_index:curr_index] epsilon, sd_threshold = compute_threshold(window_smoothed_errors, error_buffer) window_anom_indices = get_anomalies( window_smoothed_errors, window_y_true, sd_threshold, i, anomalies_indices, error_buffer ) # get anomalies from inverse of smoothed errors # This was done in the implementation of NASA paper but # wasn't referenced in the paper # we get the inverse by flipping around the mean mu = np.mean(window_smoothed_errors) smoothed_errors_inv = [mu + (mu - e) for e in window_smoothed_errors] epsilon_inv, sd_inv = compute_threshold(smoothed_errors_inv, error_buffer) inv_anom_indices = get_anomalies( smoothed_errors_inv, window_y_true, sd_inv, i, anomalies_indices, len(y_true) ) anomalies_indices = list(set(anomalies_indices + inv_anom_indices)) anomalies_indices.extend([i_a + i * batch_size for i_a in window_anom_indices]) # group anomalies anomalies_indices = sorted(list(set(anomalies_indices))) anomalies_groups = [list(group) for group in mit.consecutive_groups(anomalies_indices)] anomaly_sequences = [(g[0], g[-1]) for g in anomalies_groups if not g[0] == g[-1]] # generate "scores" for anomalies based on the max distance from epsilon for each sequence anomalies_scores = [] for e_seq in anomaly_sequences: denominator = np.mean(smoothed_errors) + np.std(smoothed_errors) score = max([ abs(smoothed_errors[x] - epsilon) / denominator for x in range(e_seq[0], e_seq[1]) ]) anomalies_scores.append(score) return anomaly_sequences, anomalies_scores
python
def extract_anomalies(y_true, smoothed_errors, window_size, batch_size, error_buffer): if len(y_true) <= batch_size * window_size: raise ValueError("Window size (%s) larger than y_true (len=%s)." % (batch_size, len(y_true))) num_windows = int((len(y_true) - (batch_size * window_size)) / batch_size) anomalies_indices = [] for i in range(num_windows + 1): prev_index = i * batch_size curr_index = (window_size * batch_size) + (i * batch_size) if i == num_windows + 1: curr_index = len(y_true) window_smoothed_errors = smoothed_errors[prev_index:curr_index] window_y_true = y_true[prev_index:curr_index] epsilon, sd_threshold = compute_threshold(window_smoothed_errors, error_buffer) window_anom_indices = get_anomalies( window_smoothed_errors, window_y_true, sd_threshold, i, anomalies_indices, error_buffer ) mu = np.mean(window_smoothed_errors) smoothed_errors_inv = [mu + (mu - e) for e in window_smoothed_errors] epsilon_inv, sd_inv = compute_threshold(smoothed_errors_inv, error_buffer) inv_anom_indices = get_anomalies( smoothed_errors_inv, window_y_true, sd_inv, i, anomalies_indices, len(y_true) ) anomalies_indices = list(set(anomalies_indices + inv_anom_indices)) anomalies_indices.extend([i_a + i * batch_size for i_a in window_anom_indices]) anomalies_indices = sorted(list(set(anomalies_indices))) anomalies_groups = [list(group) for group in mit.consecutive_groups(anomalies_indices)] anomaly_sequences = [(g[0], g[-1]) for g in anomalies_groups if not g[0] == g[-1]] anomalies_scores = [] for e_seq in anomaly_sequences: denominator = np.mean(smoothed_errors) + np.std(smoothed_errors) score = max([ abs(smoothed_errors[x] - epsilon) / denominator for x in range(e_seq[0], e_seq[1]) ]) anomalies_scores.append(score) return anomaly_sequences, anomalies_scores
[ "def", "extract_anomalies", "(", "y_true", ",", "smoothed_errors", ",", "window_size", ",", "batch_size", ",", "error_buffer", ")", ":", "if", "len", "(", "y_true", ")", "<=", "batch_size", "*", "window_size", ":", "raise", "ValueError", "(", "\"Window size (%s) larger than y_true (len=%s).\"", "%", "(", "batch_size", ",", "len", "(", "y_true", ")", ")", ")", "num_windows", "=", "int", "(", "(", "len", "(", "y_true", ")", "-", "(", "batch_size", "*", "window_size", ")", ")", "/", "batch_size", ")", "anomalies_indices", "=", "[", "]", "for", "i", "in", "range", "(", "num_windows", "+", "1", ")", ":", "prev_index", "=", "i", "*", "batch_size", "curr_index", "=", "(", "window_size", "*", "batch_size", ")", "+", "(", "i", "*", "batch_size", ")", "if", "i", "==", "num_windows", "+", "1", ":", "curr_index", "=", "len", "(", "y_true", ")", "window_smoothed_errors", "=", "smoothed_errors", "[", "prev_index", ":", "curr_index", "]", "window_y_true", "=", "y_true", "[", "prev_index", ":", "curr_index", "]", "epsilon", ",", "sd_threshold", "=", "compute_threshold", "(", "window_smoothed_errors", ",", "error_buffer", ")", "window_anom_indices", "=", "get_anomalies", "(", "window_smoothed_errors", ",", "window_y_true", ",", "sd_threshold", ",", "i", ",", "anomalies_indices", ",", "error_buffer", ")", "# get anomalies from inverse of smoothed errors", "# This was done in the implementation of NASA paper but", "# wasn't referenced in the paper", "# we get the inverse by flipping around the mean", "mu", "=", "np", ".", "mean", "(", "window_smoothed_errors", ")", "smoothed_errors_inv", "=", "[", "mu", "+", "(", "mu", "-", "e", ")", "for", "e", "in", "window_smoothed_errors", "]", "epsilon_inv", ",", "sd_inv", "=", "compute_threshold", "(", "smoothed_errors_inv", ",", "error_buffer", ")", "inv_anom_indices", "=", "get_anomalies", "(", "smoothed_errors_inv", ",", "window_y_true", ",", "sd_inv", ",", "i", ",", "anomalies_indices", ",", "len", "(", "y_true", ")", ")", "anomalies_indices", "=", "list", "(", "set", "(", "anomalies_indices", "+", "inv_anom_indices", ")", ")", "anomalies_indices", ".", "extend", "(", "[", "i_a", "+", "i", "*", "batch_size", "for", "i_a", "in", "window_anom_indices", "]", ")", "# group anomalies", "anomalies_indices", "=", "sorted", "(", "list", "(", "set", "(", "anomalies_indices", ")", ")", ")", "anomalies_groups", "=", "[", "list", "(", "group", ")", "for", "group", "in", "mit", ".", "consecutive_groups", "(", "anomalies_indices", ")", "]", "anomaly_sequences", "=", "[", "(", "g", "[", "0", "]", ",", "g", "[", "-", "1", "]", ")", "for", "g", "in", "anomalies_groups", "if", "not", "g", "[", "0", "]", "==", "g", "[", "-", "1", "]", "]", "# generate \"scores\" for anomalies based on the max distance from epsilon for each sequence", "anomalies_scores", "=", "[", "]", "for", "e_seq", "in", "anomaly_sequences", ":", "denominator", "=", "np", ".", "mean", "(", "smoothed_errors", ")", "+", "np", ".", "std", "(", "smoothed_errors", ")", "score", "=", "max", "(", "[", "abs", "(", "smoothed_errors", "[", "x", "]", "-", "epsilon", ")", "/", "denominator", "for", "x", "in", "range", "(", "e_seq", "[", "0", "]", ",", "e_seq", "[", "1", "]", ")", "]", ")", "anomalies_scores", ".", "append", "(", "score", ")", "return", "anomaly_sequences", ",", "anomalies_scores" ]
Extracts anomalies from the errors. Args: y_true (): smoothed_errors (): window_size (int): batch_size (int): error_buffer (int): Returns:
[ "Extracts", "anomalies", "from", "the", "errors", ".", "Args", ":", "y_true", "()", ":", "smoothed_errors", "()", ":", "window_size", "(", "int", ")", ":", "batch_size", "(", "int", ")", ":", "error_buffer", "(", "int", ")", ":", "Returns", ":" ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/timeseries_errors.py#L48-L125
HDI-Project/MLPrimitives
mlprimitives/candidates/timeseries_errors.py
compute_threshold
def compute_threshold(smoothed_errors, error_buffer, sd_limit=12.0): """Helper method for `extract_anomalies` method. Calculates the epsilon (threshold) for anomalies. """ mu = np.mean(smoothed_errors) sigma = np.std(smoothed_errors) max_epsilon = 0 sd_threshold = sd_limit # The treshold is determined dynamically by testing multiple Zs. # z is drawn from an ordered set of positive values representing the # number of standard deviations above mean(smoothed_errors) # here we iterate in increments of 0.5 on the range that the NASA paper found to be good for z in np.arange(2.5, sd_limit, 0.5): epsilon = mu + (sigma * z) below_epsilon, below_indices, above_epsilon = [], [], [] for i in range(len(smoothed_errors)): e = smoothed_errors[i] if e < epsilon: # save to compute delta mean and delta std # these are important for epsilon calculation below_epsilon.append(e) below_indices.append(i) if e > epsilon: # above_epsilon values are anomalies for j in range(0, error_buffer): if (i + j) not in above_epsilon and (i + j) < len(smoothed_errors): above_epsilon.append(i + j) if (i - j) not in above_epsilon and (i - j) >= 0: above_epsilon.append(i - j) if len(above_epsilon) == 0: continue # generate sequences above_epsilon = sorted(list(set(above_epsilon))) groups = [list(group) for group in mit.consecutive_groups(above_epsilon)] above_sequences = [(g[0], g[-1]) for g in groups if not g[0] == g[-1]] mean_perc_decrease = (mu - np.mean(below_epsilon)) / mu sd_perc_decrease = (sigma - np.std(below_epsilon)) / sigma epsilon = (mean_perc_decrease + sd_perc_decrease) /\ (len(above_sequences)**2 + len(above_epsilon)) # update the largest epsilon we've seen so far if epsilon > max_epsilon: sd_threshold = z max_epsilon = epsilon # sd_threshold can be multiplied by sigma to get epsilon return max_epsilon, sd_threshold
python
def compute_threshold(smoothed_errors, error_buffer, sd_limit=12.0): mu = np.mean(smoothed_errors) sigma = np.std(smoothed_errors) max_epsilon = 0 sd_threshold = sd_limit for z in np.arange(2.5, sd_limit, 0.5): epsilon = mu + (sigma * z) below_epsilon, below_indices, above_epsilon = [], [], [] for i in range(len(smoothed_errors)): e = smoothed_errors[i] if e < epsilon: below_epsilon.append(e) below_indices.append(i) if e > epsilon: for j in range(0, error_buffer): if (i + j) not in above_epsilon and (i + j) < len(smoothed_errors): above_epsilon.append(i + j) if (i - j) not in above_epsilon and (i - j) >= 0: above_epsilon.append(i - j) if len(above_epsilon) == 0: continue above_epsilon = sorted(list(set(above_epsilon))) groups = [list(group) for group in mit.consecutive_groups(above_epsilon)] above_sequences = [(g[0], g[-1]) for g in groups if not g[0] == g[-1]] mean_perc_decrease = (mu - np.mean(below_epsilon)) / mu sd_perc_decrease = (sigma - np.std(below_epsilon)) / sigma epsilon = (mean_perc_decrease + sd_perc_decrease) /\ (len(above_sequences)**2 + len(above_epsilon)) if epsilon > max_epsilon: sd_threshold = z max_epsilon = epsilon return max_epsilon, sd_threshold
[ "def", "compute_threshold", "(", "smoothed_errors", ",", "error_buffer", ",", "sd_limit", "=", "12.0", ")", ":", "mu", "=", "np", ".", "mean", "(", "smoothed_errors", ")", "sigma", "=", "np", ".", "std", "(", "smoothed_errors", ")", "max_epsilon", "=", "0", "sd_threshold", "=", "sd_limit", "# The treshold is determined dynamically by testing multiple Zs.", "# z is drawn from an ordered set of positive values representing the", "# number of standard deviations above mean(smoothed_errors)", "# here we iterate in increments of 0.5 on the range that the NASA paper found to be good", "for", "z", "in", "np", ".", "arange", "(", "2.5", ",", "sd_limit", ",", "0.5", ")", ":", "epsilon", "=", "mu", "+", "(", "sigma", "*", "z", ")", "below_epsilon", ",", "below_indices", ",", "above_epsilon", "=", "[", "]", ",", "[", "]", ",", "[", "]", "for", "i", "in", "range", "(", "len", "(", "smoothed_errors", ")", ")", ":", "e", "=", "smoothed_errors", "[", "i", "]", "if", "e", "<", "epsilon", ":", "# save to compute delta mean and delta std", "# these are important for epsilon calculation", "below_epsilon", ".", "append", "(", "e", ")", "below_indices", ".", "append", "(", "i", ")", "if", "e", ">", "epsilon", ":", "# above_epsilon values are anomalies", "for", "j", "in", "range", "(", "0", ",", "error_buffer", ")", ":", "if", "(", "i", "+", "j", ")", "not", "in", "above_epsilon", "and", "(", "i", "+", "j", ")", "<", "len", "(", "smoothed_errors", ")", ":", "above_epsilon", ".", "append", "(", "i", "+", "j", ")", "if", "(", "i", "-", "j", ")", "not", "in", "above_epsilon", "and", "(", "i", "-", "j", ")", ">=", "0", ":", "above_epsilon", ".", "append", "(", "i", "-", "j", ")", "if", "len", "(", "above_epsilon", ")", "==", "0", ":", "continue", "# generate sequences", "above_epsilon", "=", "sorted", "(", "list", "(", "set", "(", "above_epsilon", ")", ")", ")", "groups", "=", "[", "list", "(", "group", ")", "for", "group", "in", "mit", ".", "consecutive_groups", "(", "above_epsilon", ")", "]", "above_sequences", "=", "[", "(", "g", "[", "0", "]", ",", "g", "[", "-", "1", "]", ")", "for", "g", "in", "groups", "if", "not", "g", "[", "0", "]", "==", "g", "[", "-", "1", "]", "]", "mean_perc_decrease", "=", "(", "mu", "-", "np", ".", "mean", "(", "below_epsilon", ")", ")", "/", "mu", "sd_perc_decrease", "=", "(", "sigma", "-", "np", ".", "std", "(", "below_epsilon", ")", ")", "/", "sigma", "epsilon", "=", "(", "mean_perc_decrease", "+", "sd_perc_decrease", ")", "/", "(", "len", "(", "above_sequences", ")", "**", "2", "+", "len", "(", "above_epsilon", ")", ")", "# update the largest epsilon we've seen so far", "if", "epsilon", ">", "max_epsilon", ":", "sd_threshold", "=", "z", "max_epsilon", "=", "epsilon", "# sd_threshold can be multiplied by sigma to get epsilon", "return", "max_epsilon", ",", "sd_threshold" ]
Helper method for `extract_anomalies` method. Calculates the epsilon (threshold) for anomalies.
[ "Helper", "method", "for", "extract_anomalies", "method", ".", "Calculates", "the", "epsilon", "(", "threshold", ")", "for", "anomalies", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/timeseries_errors.py#L128-L183
HDI-Project/MLPrimitives
mlprimitives/candidates/timeseries_errors.py
get_anomalies
def get_anomalies(smoothed_errors, y_true, z, window, all_anomalies, error_buffer): """ Helper method to get anomalies. """ mu = np.mean(smoothed_errors) sigma = np.std(smoothed_errors) epsilon = mu + (z * sigma) # compare to epsilon errors_seq, anomaly_indices, max_error_below_e = group_consecutive_anomalies( smoothed_errors, epsilon, y_true, error_buffer, window, all_anomalies ) if len(errors_seq) > 0: anomaly_indices = prune_anomalies( errors_seq, smoothed_errors, max_error_below_e, anomaly_indices ) return anomaly_indices
python
def get_anomalies(smoothed_errors, y_true, z, window, all_anomalies, error_buffer): mu = np.mean(smoothed_errors) sigma = np.std(smoothed_errors) epsilon = mu + (z * sigma) errors_seq, anomaly_indices, max_error_below_e = group_consecutive_anomalies( smoothed_errors, epsilon, y_true, error_buffer, window, all_anomalies ) if len(errors_seq) > 0: anomaly_indices = prune_anomalies( errors_seq, smoothed_errors, max_error_below_e, anomaly_indices ) return anomaly_indices
[ "def", "get_anomalies", "(", "smoothed_errors", ",", "y_true", ",", "z", ",", "window", ",", "all_anomalies", ",", "error_buffer", ")", ":", "mu", "=", "np", ".", "mean", "(", "smoothed_errors", ")", "sigma", "=", "np", ".", "std", "(", "smoothed_errors", ")", "epsilon", "=", "mu", "+", "(", "z", "*", "sigma", ")", "# compare to epsilon", "errors_seq", ",", "anomaly_indices", ",", "max_error_below_e", "=", "group_consecutive_anomalies", "(", "smoothed_errors", ",", "epsilon", ",", "y_true", ",", "error_buffer", ",", "window", ",", "all_anomalies", ")", "if", "len", "(", "errors_seq", ")", ">", "0", ":", "anomaly_indices", "=", "prune_anomalies", "(", "errors_seq", ",", "smoothed_errors", ",", "max_error_below_e", ",", "anomaly_indices", ")", "return", "anomaly_indices" ]
Helper method to get anomalies.
[ "Helper", "method", "to", "get", "anomalies", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/timeseries_errors.py#L186-L214
HDI-Project/MLPrimitives
mlprimitives/candidates/timeseries_errors.py
prune_anomalies
def prune_anomalies(e_seq, smoothed_errors, max_error_below_e, anomaly_indices): """ Helper method that removes anomalies which don't meet a minimum separation from next anomaly. """ # min accepted perc decrease btwn max errors in anomalous sequences MIN_PERCENT_DECREASE = 0.05 e_seq_max, smoothed_errors_max = [], [] for error_seq in e_seq: if len(smoothed_errors[error_seq[0]:error_seq[1]]) > 0: sliced_errors = smoothed_errors[error_seq[0]:error_seq[1]] e_seq_max.append(max(sliced_errors)) smoothed_errors_max.append(max(sliced_errors)) smoothed_errors_max.sort(reverse=True) if max_error_below_e > 0: smoothed_errors_max.append(max_error_below_e) indices_remove = [] for i in range(len(smoothed_errors_max)): if i < len(smoothed_errors_max) - 1: delta = smoothed_errors_max[i] - smoothed_errors_max[i + 1] perc_change = delta / smoothed_errors_max[i] if perc_change < MIN_PERCENT_DECREASE: indices_remove.append(e_seq_max.index(smoothed_errors_max[i])) for index in sorted(indices_remove, reverse=True): del e_seq[index] pruned_indices = [] for i in anomaly_indices: for error_seq in e_seq: if i >= error_seq[0] and i <= error_seq[1]: pruned_indices.append(i) return pruned_indices
python
def prune_anomalies(e_seq, smoothed_errors, max_error_below_e, anomaly_indices): MIN_PERCENT_DECREASE = 0.05 e_seq_max, smoothed_errors_max = [], [] for error_seq in e_seq: if len(smoothed_errors[error_seq[0]:error_seq[1]]) > 0: sliced_errors = smoothed_errors[error_seq[0]:error_seq[1]] e_seq_max.append(max(sliced_errors)) smoothed_errors_max.append(max(sliced_errors)) smoothed_errors_max.sort(reverse=True) if max_error_below_e > 0: smoothed_errors_max.append(max_error_below_e) indices_remove = [] for i in range(len(smoothed_errors_max)): if i < len(smoothed_errors_max) - 1: delta = smoothed_errors_max[i] - smoothed_errors_max[i + 1] perc_change = delta / smoothed_errors_max[i] if perc_change < MIN_PERCENT_DECREASE: indices_remove.append(e_seq_max.index(smoothed_errors_max[i])) for index in sorted(indices_remove, reverse=True): del e_seq[index] pruned_indices = [] for i in anomaly_indices: for error_seq in e_seq: if i >= error_seq[0] and i <= error_seq[1]: pruned_indices.append(i) return pruned_indices
[ "def", "prune_anomalies", "(", "e_seq", ",", "smoothed_errors", ",", "max_error_below_e", ",", "anomaly_indices", ")", ":", "# min accepted perc decrease btwn max errors in anomalous sequences", "MIN_PERCENT_DECREASE", "=", "0.05", "e_seq_max", ",", "smoothed_errors_max", "=", "[", "]", ",", "[", "]", "for", "error_seq", "in", "e_seq", ":", "if", "len", "(", "smoothed_errors", "[", "error_seq", "[", "0", "]", ":", "error_seq", "[", "1", "]", "]", ")", ">", "0", ":", "sliced_errors", "=", "smoothed_errors", "[", "error_seq", "[", "0", "]", ":", "error_seq", "[", "1", "]", "]", "e_seq_max", ".", "append", "(", "max", "(", "sliced_errors", ")", ")", "smoothed_errors_max", ".", "append", "(", "max", "(", "sliced_errors", ")", ")", "smoothed_errors_max", ".", "sort", "(", "reverse", "=", "True", ")", "if", "max_error_below_e", ">", "0", ":", "smoothed_errors_max", ".", "append", "(", "max_error_below_e", ")", "indices_remove", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "smoothed_errors_max", ")", ")", ":", "if", "i", "<", "len", "(", "smoothed_errors_max", ")", "-", "1", ":", "delta", "=", "smoothed_errors_max", "[", "i", "]", "-", "smoothed_errors_max", "[", "i", "+", "1", "]", "perc_change", "=", "delta", "/", "smoothed_errors_max", "[", "i", "]", "if", "perc_change", "<", "MIN_PERCENT_DECREASE", ":", "indices_remove", ".", "append", "(", "e_seq_max", ".", "index", "(", "smoothed_errors_max", "[", "i", "]", ")", ")", "for", "index", "in", "sorted", "(", "indices_remove", ",", "reverse", "=", "True", ")", ":", "del", "e_seq", "[", "index", "]", "pruned_indices", "=", "[", "]", "for", "i", "in", "anomaly_indices", ":", "for", "error_seq", "in", "e_seq", ":", "if", "i", ">=", "error_seq", "[", "0", "]", "and", "i", "<=", "error_seq", "[", "1", "]", ":", "pruned_indices", ".", "append", "(", "i", ")", "return", "pruned_indices" ]
Helper method that removes anomalies which don't meet a minimum separation from next anomaly.
[ "Helper", "method", "that", "removes", "anomalies", "which", "don", "t", "meet", "a", "minimum", "separation", "from", "next", "anomaly", "." ]
train
https://github.com/HDI-Project/MLPrimitives/blob/bf415f9f751724ff545a1156ddfd7524e320f469/mlprimitives/candidates/timeseries_errors.py#L262-L299
ultrabug/uhashring
uhashring/ring.py
HashRing._configure_nodes
def _configure_nodes(self, nodes): """Parse and set up the given nodes. :param nodes: nodes used to create the continuum (see doc for format). """ if isinstance(nodes, str): nodes = [nodes] elif not isinstance(nodes, (dict, list)): raise ValueError( 'nodes configuration should be a list or a dict,' ' got {}'.format(type(nodes))) conf_changed = False for node in nodes: conf = { 'hostname': node, 'instance': None, 'nodename': node, 'port': None, 'vnodes': self._default_vnodes, 'weight': 1 } current_conf = self.runtime._nodes.get(node, {}) nodename = node # new node, trigger a ring update if not current_conf: conf_changed = True # complex config if isinstance(nodes, dict): node_conf = nodes[node] if isinstance(node_conf, int): conf['weight'] = node_conf elif isinstance(node_conf, dict): for k, v in node_conf.items(): if k in conf: conf[k] = v # changing those config trigger a ring update if k in ['nodename', 'vnodes', 'weight']: if current_conf.get(k) != v: conf_changed = True else: raise ValueError( 'node configuration should be a dict or an int,' ' got {}'.format(type(node_conf))) if self._weight_fn: conf['weight'] = self._weight_fn(**conf) # changing the weight of a node trigger a ring update if current_conf.get('weight') != conf['weight']: conf_changed = True self.runtime._nodes[nodename] = conf return conf_changed
python
def _configure_nodes(self, nodes): if isinstance(nodes, str): nodes = [nodes] elif not isinstance(nodes, (dict, list)): raise ValueError( 'nodes configuration should be a list or a dict,' ' got {}'.format(type(nodes))) conf_changed = False for node in nodes: conf = { 'hostname': node, 'instance': None, 'nodename': node, 'port': None, 'vnodes': self._default_vnodes, 'weight': 1 } current_conf = self.runtime._nodes.get(node, {}) nodename = node if not current_conf: conf_changed = True if isinstance(nodes, dict): node_conf = nodes[node] if isinstance(node_conf, int): conf['weight'] = node_conf elif isinstance(node_conf, dict): for k, v in node_conf.items(): if k in conf: conf[k] = v if k in ['nodename', 'vnodes', 'weight']: if current_conf.get(k) != v: conf_changed = True else: raise ValueError( 'node configuration should be a dict or an int,' ' got {}'.format(type(node_conf))) if self._weight_fn: conf['weight'] = self._weight_fn(**conf) if current_conf.get('weight') != conf['weight']: conf_changed = True self.runtime._nodes[nodename] = conf return conf_changed
[ "def", "_configure_nodes", "(", "self", ",", "nodes", ")", ":", "if", "isinstance", "(", "nodes", ",", "str", ")", ":", "nodes", "=", "[", "nodes", "]", "elif", "not", "isinstance", "(", "nodes", ",", "(", "dict", ",", "list", ")", ")", ":", "raise", "ValueError", "(", "'nodes configuration should be a list or a dict,'", "' got {}'", ".", "format", "(", "type", "(", "nodes", ")", ")", ")", "conf_changed", "=", "False", "for", "node", "in", "nodes", ":", "conf", "=", "{", "'hostname'", ":", "node", ",", "'instance'", ":", "None", ",", "'nodename'", ":", "node", ",", "'port'", ":", "None", ",", "'vnodes'", ":", "self", ".", "_default_vnodes", ",", "'weight'", ":", "1", "}", "current_conf", "=", "self", ".", "runtime", ".", "_nodes", ".", "get", "(", "node", ",", "{", "}", ")", "nodename", "=", "node", "# new node, trigger a ring update", "if", "not", "current_conf", ":", "conf_changed", "=", "True", "# complex config", "if", "isinstance", "(", "nodes", ",", "dict", ")", ":", "node_conf", "=", "nodes", "[", "node", "]", "if", "isinstance", "(", "node_conf", ",", "int", ")", ":", "conf", "[", "'weight'", "]", "=", "node_conf", "elif", "isinstance", "(", "node_conf", ",", "dict", ")", ":", "for", "k", ",", "v", "in", "node_conf", ".", "items", "(", ")", ":", "if", "k", "in", "conf", ":", "conf", "[", "k", "]", "=", "v", "# changing those config trigger a ring update", "if", "k", "in", "[", "'nodename'", ",", "'vnodes'", ",", "'weight'", "]", ":", "if", "current_conf", ".", "get", "(", "k", ")", "!=", "v", ":", "conf_changed", "=", "True", "else", ":", "raise", "ValueError", "(", "'node configuration should be a dict or an int,'", "' got {}'", ".", "format", "(", "type", "(", "node_conf", ")", ")", ")", "if", "self", ".", "_weight_fn", ":", "conf", "[", "'weight'", "]", "=", "self", ".", "_weight_fn", "(", "*", "*", "conf", ")", "# changing the weight of a node trigger a ring update", "if", "current_conf", ".", "get", "(", "'weight'", ")", "!=", "conf", "[", "'weight'", "]", ":", "conf_changed", "=", "True", "self", ".", "runtime", ".", "_nodes", "[", "nodename", "]", "=", "conf", "return", "conf_changed" ]
Parse and set up the given nodes. :param nodes: nodes used to create the continuum (see doc for format).
[ "Parse", "and", "set", "up", "the", "given", "nodes", "." ]
train
https://github.com/ultrabug/uhashring/blob/2297471a392e28ed913b3276c2f48d0c01523375/uhashring/ring.py#L44-L94
ultrabug/uhashring
uhashring/ring.py
HashRing._get_pos
def _get_pos(self, key): """Get the index of the given key in the sorted key list. We return the position with the nearest hash based on the provided key unless we reach the end of the continuum/ring in which case we return the 0 (beginning) index position. :param key: the key to hash and look for. """ p = bisect(self.runtime._keys, self.hashi(key)) if p == len(self.runtime._keys): return 0 else: return p
python
def _get_pos(self, key): p = bisect(self.runtime._keys, self.hashi(key)) if p == len(self.runtime._keys): return 0 else: return p
[ "def", "_get_pos", "(", "self", ",", "key", ")", ":", "p", "=", "bisect", "(", "self", ".", "runtime", ".", "_keys", ",", "self", ".", "hashi", "(", "key", ")", ")", "if", "p", "==", "len", "(", "self", ".", "runtime", ".", "_keys", ")", ":", "return", "0", "else", ":", "return", "p" ]
Get the index of the given key in the sorted key list. We return the position with the nearest hash based on the provided key unless we reach the end of the continuum/ring in which case we return the 0 (beginning) index position. :param key: the key to hash and look for.
[ "Get", "the", "index", "of", "the", "given", "key", "in", "the", "sorted", "key", "list", "." ]
train
https://github.com/ultrabug/uhashring/blob/2297471a392e28ed913b3276c2f48d0c01523375/uhashring/ring.py#L125-L138
ultrabug/uhashring
uhashring/ring.py
HashRing._get
def _get(self, key, what): """Generic getter magic method. The node with the nearest but not less hash value is returned. :param key: the key to look for. :param what: the information to look for in, allowed values: - instance (default): associated node instance - nodename: node name - pos: index of the given key in the ring - tuple: ketama compatible (pos, name) tuple - weight: node weight """ if not self.runtime._ring: return None pos = self._get_pos(key) if what == 'pos': return pos nodename = self.runtime._ring[self.runtime._keys[pos]] if what in ['hostname', 'instance', 'port', 'weight']: return self.runtime._nodes[nodename][what] elif what == 'dict': return self.runtime._nodes[nodename] elif what == 'nodename': return nodename elif what == 'tuple': return (self.runtime._keys[pos], nodename)
python
def _get(self, key, what): if not self.runtime._ring: return None pos = self._get_pos(key) if what == 'pos': return pos nodename = self.runtime._ring[self.runtime._keys[pos]] if what in ['hostname', 'instance', 'port', 'weight']: return self.runtime._nodes[nodename][what] elif what == 'dict': return self.runtime._nodes[nodename] elif what == 'nodename': return nodename elif what == 'tuple': return (self.runtime._keys[pos], nodename)
[ "def", "_get", "(", "self", ",", "key", ",", "what", ")", ":", "if", "not", "self", ".", "runtime", ".", "_ring", ":", "return", "None", "pos", "=", "self", ".", "_get_pos", "(", "key", ")", "if", "what", "==", "'pos'", ":", "return", "pos", "nodename", "=", "self", ".", "runtime", ".", "_ring", "[", "self", ".", "runtime", ".", "_keys", "[", "pos", "]", "]", "if", "what", "in", "[", "'hostname'", ",", "'instance'", ",", "'port'", ",", "'weight'", "]", ":", "return", "self", ".", "runtime", ".", "_nodes", "[", "nodename", "]", "[", "what", "]", "elif", "what", "==", "'dict'", ":", "return", "self", ".", "runtime", ".", "_nodes", "[", "nodename", "]", "elif", "what", "==", "'nodename'", ":", "return", "nodename", "elif", "what", "==", "'tuple'", ":", "return", "(", "self", ".", "runtime", ".", "_keys", "[", "pos", "]", ",", "nodename", ")" ]
Generic getter magic method. The node with the nearest but not less hash value is returned. :param key: the key to look for. :param what: the information to look for in, allowed values: - instance (default): associated node instance - nodename: node name - pos: index of the given key in the ring - tuple: ketama compatible (pos, name) tuple - weight: node weight
[ "Generic", "getter", "magic", "method", "." ]
train
https://github.com/ultrabug/uhashring/blob/2297471a392e28ed913b3276c2f48d0c01523375/uhashring/ring.py#L140-L168
ultrabug/uhashring
uhashring/ring.py
HashRing.get_instances
def get_instances(self): """Returns a list of the instances of all the configured nodes. """ return [c.get('instance') for c in self.runtime._nodes.values() if c.get('instance')]
python
def get_instances(self): return [c.get('instance') for c in self.runtime._nodes.values() if c.get('instance')]
[ "def", "get_instances", "(", "self", ")", ":", "return", "[", "c", ".", "get", "(", "'instance'", ")", "for", "c", "in", "self", ".", "runtime", ".", "_nodes", ".", "values", "(", ")", "if", "c", ".", "get", "(", "'instance'", ")", "]" ]
Returns a list of the instances of all the configured nodes.
[ "Returns", "a", "list", "of", "the", "instances", "of", "all", "the", "configured", "nodes", "." ]
train
https://github.com/ultrabug/uhashring/blob/2297471a392e28ed913b3276c2f48d0c01523375/uhashring/ring.py#L177-L181
ultrabug/uhashring
uhashring/ring.py
HashRing.get_points
def get_points(self): """Returns a ketama compatible list of (position, nodename) tuples. """ return [(k, self.runtime._ring[k]) for k in self.runtime._keys]
python
def get_points(self): return [(k, self.runtime._ring[k]) for k in self.runtime._keys]
[ "def", "get_points", "(", "self", ")", ":", "return", "[", "(", "k", ",", "self", ".", "runtime", ".", "_ring", "[", "k", "]", ")", "for", "k", "in", "self", ".", "runtime", ".", "_keys", "]" ]
Returns a ketama compatible list of (position, nodename) tuples.
[ "Returns", "a", "ketama", "compatible", "list", "of", "(", "position", "nodename", ")", "tuples", "." ]
train
https://github.com/ultrabug/uhashring/blob/2297471a392e28ed913b3276c2f48d0c01523375/uhashring/ring.py#L232-L235
ultrabug/uhashring
uhashring/ring.py
HashRing.iterate_nodes
def iterate_nodes(self, key, distinct=True): """hash_ring compatibility implementation. Given a string key it returns the nodes as a generator that can hold the key. The generator iterates one time through the ring starting at the correct position. if `distinct` is set, then the nodes returned will be unique, i.e. no virtual copies will be returned. """ if not self.runtime._ring: yield None else: for node in self.range(key, unique=distinct): yield node['nodename']
python
def iterate_nodes(self, key, distinct=True): if not self.runtime._ring: yield None else: for node in self.range(key, unique=distinct): yield node['nodename']
[ "def", "iterate_nodes", "(", "self", ",", "key", ",", "distinct", "=", "True", ")", ":", "if", "not", "self", ".", "runtime", ".", "_ring", ":", "yield", "None", "else", ":", "for", "node", "in", "self", ".", "range", "(", "key", ",", "unique", "=", "distinct", ")", ":", "yield", "node", "[", "'nodename'", "]" ]
hash_ring compatibility implementation. Given a string key it returns the nodes as a generator that can hold the key. The generator iterates one time through the ring starting at the correct position. if `distinct` is set, then the nodes returned will be unique, i.e. no virtual copies will be returned.
[ "hash_ring", "compatibility", "implementation", "." ]
train
https://github.com/ultrabug/uhashring/blob/2297471a392e28ed913b3276c2f48d0c01523375/uhashring/ring.py#L244-L258
ultrabug/uhashring
uhashring/ring.py
HashRing.print_continuum
def print_continuum(self): """Prints a ketama compatible continuum report. """ numpoints = len(self.runtime._keys) if numpoints: print('Numpoints in continuum: {}'.format(numpoints)) else: print('Continuum empty') for p in self.get_points(): point, node = p print('{} ({})'.format(node, point))
python
def print_continuum(self): numpoints = len(self.runtime._keys) if numpoints: print('Numpoints in continuum: {}'.format(numpoints)) else: print('Continuum empty') for p in self.get_points(): point, node = p print('{} ({})'.format(node, point))
[ "def", "print_continuum", "(", "self", ")", ":", "numpoints", "=", "len", "(", "self", ".", "runtime", ".", "_keys", ")", "if", "numpoints", ":", "print", "(", "'Numpoints in continuum: {}'", ".", "format", "(", "numpoints", ")", ")", "else", ":", "print", "(", "'Continuum empty'", ")", "for", "p", "in", "self", ".", "get_points", "(", ")", ":", "point", ",", "node", "=", "p", "print", "(", "'{} ({})'", ".", "format", "(", "node", ",", "point", ")", ")" ]
Prints a ketama compatible continuum report.
[ "Prints", "a", "ketama", "compatible", "continuum", "report", "." ]
train
https://github.com/ultrabug/uhashring/blob/2297471a392e28ed913b3276c2f48d0c01523375/uhashring/ring.py#L260-L270