How to import EF 3.0 method in Brightway2? - jupyter-notebook

My colleague, after the recent update of Brightway2, can see EF3.0 method within the availeable.
I tried to do the same but it's not working (I have some new methods, but not EF3.0).
This is what I have done:
Conda update conda
Conda update brightway2
In Brightway
import brightway2 as bw
bw.Database('biosphere3').delete()
bw.Database('biosphere3').deregister()
bw.projects
bw.projects.delete_project('Name of my project',delete_dir=True)
bw.projects.report()
bw.databases
bw.databases.clear()
bw.bw2setup() #Import of biosphere3
# Import ecoinvent 3.7
ei37dir ="*my directory*"
if 'ecoinvent 3.7_cutoff' in bw.databases:
print("Database has already been imported")
else:
ei37 = bw.SingleOutputEcospold2Importer(ei37dir, 'ecoinvent 3.7_cutoff')
ei37.apply_strategies()
ei37.statistics()
ei37.drop_unlinked(True)
ei37.write_database()
list(bw.methods)
How can I implement EF3.0?
Thank you in advance
Kevin

The EF method was added in bw2io version 0.8.6. You would need to update to this library version, and then reinstall the LCIA methods (doesn't have anything to do with which version of ecoinvent you have, LCIA methods are separate).
In a new project, just calling bw2setup() should be fine. In an older project, you will need to rewrite both biosphere flow list and the LCIA methods:
import bw2io as bi
bi.create_default_biosphere3(overwrite=True)
bi.create_default_lcia_methods(overwrite=True)

Related

rpmUtils.miscutils in python3.6

I am refactoring code from python2(RHEL 7.6) to python3(RHEL 8.2) and I have problem with missing library in python3.6.
Problem:
from rpmUtils.miscutils import splitFilename ModuleNotFoundError: No module named 'rpmUtils'
I've tried to install python3-dnf and python3-rpm packages to RHEL8, but still not working. Is there any solution how to use this library in python3.6 and RHEL8 or should I write some custom function by myself?
Thank you for your answer.
This library was indeed removed, but you have several other options you can use.
Please note that these other functions expect to receive a string in the NEVRA (name, epoch, version, release, architecture) format as an input, not a filename. Thus you must remove the '.rpm' extension of the filename, in order to get a NVRA string (epoch normally is not included in the filename of the RPM package).
So basically you have 2 options:
to use dnf as suggested in i.e. https://bugzilla.redhat.com/show_bug.cgi?id=1364504
to use hawkey i.e. :
import hawkey
rpm_base_filename = os.path.basename(rpm_file)
nevra = hawkey.split_nevra(rpm_base_filename[:-len(".rpm")])
name = nevra.name
version = nevra.version
release = str(nevra.release)
epoch = str(nevra.epoch)
arch = nevra.arch
For example here is a patch for such modification that I made for one of the tools we use as part of the oVirt release process:
https://github.com/oVirt/releng-tools/commit/823405e6b261f7ff27ddbba0e8fa2b86dd2a8698

Importing packages in Python3

How do I import packages in Python3?
-Package1
|
--InnerPackage1
||
| ---InnerInnerPackage1
| ---InnerInnerPackage2
| ---InnerInnerPackage3
--InnerPackage2
||---InnerInnerPackage4
||---InnerInnerPackage5
||---InnerInnerPackage6
||---InnerInnerPackage7
--InnerPackage3
||---InnerInnerPackage8
||---InnerInnerPackage9
|||
|| ----InnerInnerInnerPackage10
|| ----InnerInnerInnerPackage11
||---InnerInnerPackage12
|||----InnerInnerInnerPackage12
|||----InnerInnerInnerPackage13
|||----InnerInnerInnerPackage14
||---InnerInnerPackge13
Now, let my directory structure be similar to what I've mentioned above, how do I import a package, when my current directory is suppose InnerInnerInnerPackage12, and I have to import InnerInnerPackage6.
Though, when I import, while traversing above using this syntax,
from InnerPackage2 import InnerInnerPackage6
Else, one can also imply importing from the root package
Package1.InnerPackage2.InnerInnerPackage6
Another logic says,
import sys.path
sys.path.insert(0, '%package_directory%\\Package1\\InnerPackage2\\InnerInnerPackage6')
That works in cmd.
Still what would be the correct way to import a module.
It gives an error on running the code in CMD, but when I run the code in JetBrains PyCharm, it works.
Can someone help me out with this problem? Would be grateful! :)
Maybe this is because what we export from python is modules not packages.
I think this issue arises due to that.
Also, to run the same in cmd, one can follow this syntax:
from InnerPackage2.InnerInnerPackage6 import InnerInnerPackage6
This might be the reason, the difficulty arises when we run the same program in both JetBrains PyCharm and on cmd.

ExecComp - Vectorize Bug? 2.4.0

Sample code from the manual is below.
If the vectorize=True is there I get an error :
comp: arg 'vectorize' in call to ExecComp() does not refer to any variable in the expressions ['y=3.0*x + 2.5']
i assume the newest version does not have this flag?
and can i use np.diff in the execcomp
import numpy as np
from openmdao.api import IndepVarComp, Group, Problem, ExecComp
p = Problem()
model = p.model
model.add_subsystem('indep', IndepVarComp('x', val=np.ones(5)))
model.add_subsystem('comp', ExecComp('y=3.0*x + 2.5', vectorize=True, x=np.ones(5), y=np.ones(5)))
model.connect('indep.x', 'comp.x')
p.setup()
p.run_model()
J = p.compute_totals(of=['comp.y'], wrt=['indep.x'], return_format='array')
print(J)
The vectorize option was added after the latest OpenMDAO version was released, so in order to use it you'll have to either wait until the next release, or install using the latest commit to the OpenMDAO github repository.
To answer your second question, the np.diff command is not currently available in ExecComp. You can submit an issue to the OpenMDAO github repository at (https://github.com/OpenMDAO/OpenMDAO/issues) if you'd like it to be made available.

how to give ctrl+c command in robot framework

In Robot Framework how do I give the ctrl+c command?
I have tried this line but it does not work
${crtl_c} Evaluate chr(int(3)) SSHLibrary.Write Bare ${crtl_c}
Use imagehorizon as a library :
Press Combination KEY.CTRL C
Use PyAutoGUI
PyAutoGUI works on Windows/Mac/Linux on Python 2 & 3. Install from PyPI with
pip install pyautogui
import pyautogui
def CntrlC():
pyautogui.hotkey('ctrl', 'c') #Performs ctrl+c
Now just import the py file and use CntrlC as the Keyword
${ctrl_c} evaluate chr(int(3))
SSHLibrary.Write Bare ${crtl_c}
Or else you can give the line in variables section:
***variable***
${ctrl_c} evaluate chr(int(3))
Just got this working. The problem with the answers above is that you need an equal sign.
${ctrl-c}= evaluate chr(int(3))
Write Bare ${ctrl-c}
Refering to a previous answer on an SO question where if you're on windows, the SendKeys python library is used to send actual key presses to the system. In case you're on a linux based system it pretty much depends on the GUI you're using and a few other factors. This SO Question has some good content that might help you.

getMethodASTEclipse() returns undeclared variable

I am completely new to Rascal and am trying to create ASTs from an eclipse project using the following code
Module FirstTryAST
import lang::java::m3::Core;
import lang::java::jdt::m3::Core;
import Set;
import Relation;
import IO;
import List;
import Map;
import Exception;
import ParseTree;
void test(){
M3 myModel = createM3FromEclipseProject(|project://MyProject/|);
println("Loaded M3 model, looping through methods..");
for(m <- methods(model)) mAST = getMethodASTEclipse(m);
println("Success");
}
When the program (run in eclipse Rascal Console) tries to execute
getMethodASTEclipse(m);
it returns:
|plugin://rascal_eclipse/src/org/rascalmpl/eclipse/library/lang/java/jdt/m3/Core.rsc|(1238,18,<40,12>,<40,30>):
Undeclared variable: getModelContaining
How do I get around this / what did I do wrong ?
I am using Eclipse Mars on Ubuntu 15.04 (Cinnamon).
If you need more information, please let me know.
Update:
When I use getMethodASTEclipse(m, model = myModel) it works fine.
Although this workaround works for me, I still would like to know the answer on why I get this undeclared variable message.
This has been translated into an issue on github. This was a bit of an unused function, and I think we will delete it.
To get the AST use either lang::java::jdt::m3::AST::createAstsFromEclipseProject or lang::java::jdt::m3::AST::createAstsFromEclipseFile. With rascal pattern matching you can find the methods inside.

Resources