Пример #1
0
# -*- coding: utf-8 -*-
"""
Financial Time Series Collection similar to R datasets

For while there is only Brazilian financial time series.

"""
import m2py.utils as __utils__
import os as __os__

from m2py.finance.timeserie import plot_against

from . import ipea

__thisdir = __utils__.this_dir()
datadir = datasets_dir = __utils__.resource_path("datasets")
datafiles = __os__.listdir(datadir)
datasets = [d.split(".")[0] for d in datafiles]


def __dataset_path(dataset):
    return __os__.path.join(__os__.path.join(__thisdir, "datasets", dataset))


def metadata(serie):
    filename = serie + ".csv"
    fp = open(filename, 'r')

    name = fp.readline().split(":")[1].strip()
    dataprovider = fp.readline().split(":")[1].strip()
    url = fp.readline().strip().split(":")[1].strip()
Пример #2
0
import os
import sys

__all__ = [
    "__stable__", "mixture_volume", "vapor_quality", "phase", "p_satT",
    "vf_satT", "Vg_sat", "T_sat"
]

this = os.path.dirname(os.path.abspath(__file__))
path_dir = os.path.join(this, "../..")
sys.path.append(path_dir)

from m2py.numerical.numerical import interpol, read_table
from m2py.utils import resource_path

__saturation_table__ = resource_path("saturated_steam.txt")
__saturation__ = read_table(__saturation_table__)

tol = 1e-1


def __stable__(value, _input, params):
    """
    Calculate the Saturated water thermodynamic properties 
    table from Steam table properties, given the temperature T.
    
    Source:          
        Apendix B, Page 775 - Table B1.1
        Fundamentals of Thermodynamics, 
        SI Units Thermodynamic Tables. 8th edition
        BORGNAKKE and SONNTAG
Пример #3
0
#
# http://www.wsp.ru/en/..%5Cdownload%5Cdocs%5Carticles%5Cen%5CTENG221.pdf
# http://www.wsp.ru/en/test/wspgGCGS.asp?gas_specification=air
#import sys
#sys.path.append("/home/tux/PycharmProjects/m2py")

from math import (log, exp)
from m2py import units
from m2py.utils import resource_path
from m2py import utils

#import shelve
import json

#data = shelve.open(resource_path("thermo_nasa_poly7.dat"))
data = utils.load_json_file((resource_path("data/gas_nasa_poly7.json")))

nasapoly7coefs = data['coefficients']
molarmass = data['molarmass']
substances = data['substances']

# Unity conversion factors
cal2J = units.factor("cal/J")
J2cal = units.factor("J/cal")

R_ = 1.987204118  # cal/(mol.K)

p0 = 0.1  # MPa
R = 8.31451 * 1e-3  # KJ/(mol.K)
Tr = 1000  # K
Пример #4
0
import sys
import os
import re
import json

from m2py.utils import resource_path
from m2py.thermo.scrap_mollar_mass import get_molar_mass

dat = open(resource_path("data/nasa_poly7gas.txt")).read()
data = "\n".join(dat.splitlines()[4:-2])
data = re.findall("(\S+).*1\n(.*)2\n(.*)3\n(.*)4", data, re.M)

print(data)

README = """
NASA POLYNOMIALS COEFFICIENTS


Temperatures   300.000  1000.000  5000.000
! GRI-Mech Version 3.0 Thermodynamics released 7/30/99
! NASA Polynomial format for CHEMKIN-II
! see README file for disclaimer

http://combustion.berkeley.edu/gri-mech/data/nasa_plnm.html

NASA polynomials you can consult the report by Alex Burcat 
'Thermochemical Data for Combustion Calculations'

The NASA polynomials have the form:
Пример #5
0
from m2py.thermo.marktable import read_data_tables
from m2py.thermo import gas as g
from pprint import pprint
from m2py.utils import resource_path

tables = read_data_tables(resource_path("../data/gas_test_data.txt"))

gases = list(tables.keys())


def test_fuction(function, gas, _input, _output):

    _function = lambda t: function(t, gas)
    _error = lambda x: 100 * abs(x[1] - x[0]) / x[0]

    output = list(map(_function, _input))
    error = list(map(_error, list(zip(output, _output))))

    print("GAS : ", gas)
    print("Testing : ", function.__name__)
    print("\nMax error %", max(error))

    print("x f(x) f'(x) %%error)")
    pprint(list(zip(_input, output, _output, error)))

    print("\n\n")


test_gas = lambda gas, func, output: test_fuction(func, gas, tables[gas].T,
                                                  tables[gas][output])
Пример #6
0
        datestr = param[0]

        if not dtime.flag:
            return parse_date(datestr)
        else:
            return parse_date2(datestr)

    if len(param) >= 3:
        return datetime(*param)


dtime.flag = False

#Date = lambda datestr: datetime.datetime.strptime(datestr, "%d-%m-%Y")

__brazil_holydays_database = utils.resource_path("data/brazil_holydays.csv")
#sh = shelve.open(__brazil_holydays_database, protocol=2)
sh = utils.read_file(__brazil_holydays_database)
brazil_holydays = json.loads(sh)
brazil_holydays = brazil_holydays["brholydays"]
brazil_holydays = map(lambda x: data_ymd(x, "-"), brazil_holydays)

#sh.close()


def is_leap_year(date):
    import calendar

    return calendar.isleap(date.year)