new step on abaqus using python script - python

I'm trying to create a new step using Python.
I have already created a 'Step1' step which results a deformed structure, and now I'm trying to add new results of a new step 'Step2', which should be inserted after 'step1'.
Using this script:
odb = openOdb(path='my_odb_path')
newStep= odb.Step(name='Step2', previous='Step1',domain=TIME)
newFrame = newStep.Frame(incrementNumber=0, frameValue=0.0)
newField = newFrame.FieldOutput(name='...',description='..', type=SCALAR)
newField.addData(position=...,instance=...,labels=...,data=...)
odb.save()
The problem is in the statement "previous", the error message is : (keyword error on previous)
Does anyone knows how to solve this problem
thank you

I suppose the error message clearly states the issue, keyword error on previous because the correct keyword is previousStepName not previous. Refer to 34.25 in scripting reference guide for more info.

Related

Zipline-trader: Unknown syntax [{'sid': Equity(1576 [JPM])} -

I am relatively new to Python and am working my way through the zipline-trader library. I came across a data structure that I am unfamiliar with and was wondering if you could help me access a certain element out of it.
I ran a backtest on zipline-trader and have the results-DataFrame that has a column "positions" which includes the portfolio positions for a given day.
Here is an example of the content of that column:
[{'sid': Equity(1576 [JPM]), 'amount': 39, 'cost_basis': 25.95397, 'last_sale_price': 25.94}, {'sid': Equity(2942 [UNH]), 'amount': 11, 'cost_basis': 86.62428999999999, 'last_sale_price': 86.58}]
The syntax I am unfamiliar with is the part "Equity (1576 [JPM])" - can anybody explain to me what this is? Also, can you please let me know how to access the "[JPM]"-part of it? Ultimately, what I am trying to do is access that cell of the DataFrame using a loc-function and producing the result "{JPM: 1576, UNH: 2942}"
Thank you!
That is (likely to be) an object of type Equity. If the structure you showed us was stored in a variable data then the object can be fetched using
eq = data[0]['sid']
The text when it's printed will be coming from the __str__ method defined in the Equity class, so it doesn't really tell us anything about how to access it. You would have to look up the documentation.
If you are able to access the object in an interactive session then you could run the help command against it and that might contain something useful. Again, if the structure you showed us was stored in a variable data then you could do:
help(data[0]['sid'])

How to solve "ECitMatch() got multiple values for argument 'bdata'"?

I am new to use bioservices Python package. Now I am going to use that to retrieve PMIDs for two citations, given the specified information and this is the code I have tried:
from bioservices import EUtils
s = EUtils()
print(s.ECitMatch("pubmed",retmode="xml", bdata="proc+natl+acad+sci+u+s+a|1991|88|3248|mann+bj|Art1|%0Dscience|1987|235|182|palmenberg+ac|Art2|"))
But it occurs an error:
"TypeError: ECitMatch() got multiple values for argument 'bdata'".
Could anyone help me to solve that problem?
I think the issue is that you have an unnamed argument (pubmed); if you look at the source code, you can see that the first argument should be bdata; if you provide the arguments like you do, it is, however, unclear whether bdata is "pubmed" or the named argument bdata, therefore the error you obtain.
You can reproduce it with this minimal example:
def dummy(a, b):
return a, b
dummy(10, a=3)
will return
TypeError: dummy() got multiple values for argument 'a'
If you remove "pubmed", the error disappears, however, the output is still incomplete:
from bioservices import EUtils
s = EUtils()
print(s.ECitMatch("proc+natl+acad+sci+u+s+a|1991|88|3248|mann+bj|Art1|%0Dscience|1987|235|182|palmenberg+ac|Art2|"))
returns
'proc+natl+acad+sci+u+s+a|1991|88|3248|mann+bj|Art1|2014248\n'
so only the first publication is taken into account. You can get the results for both by using the correct carriage return character \r:
print(s.ECitMatch(bdata="proc+natl+acad+sci+u+s+a|1991|88|3248|mann+bj|Art1|\rscience|1987|235|182|palmenberg+ac|Art2|"))
will return
proc+natl+acad+sci+u+s+a|1991|88|3248|mann+bj|Art1|2014248
science|1987|235|182|palmenberg+ac|Art2|3026048
I think you neither have to specify retmod nor the database (pubmed); if you look at the source code I linked above you can see:
query = "ecitmatch.cgi?db=pubmed&retmode=xml"
so seems it always uses pubmed and xml.
Two issues here: syntaxic and a bug.
The correct syntax is:
from bioservices import EUtils
s = EUtils()
query = "proc+natl+acad+sci+u+s+a|1991|88|3248|mann+bj|Art1|%0Dscience|1987|235|182|palmenberg+ac|Art2|"
print(s.ECitMatch(query))
Indeed, the underlying service related to ICitMatch has only one database (pubmed) and one format (xml) hence, those 2 parameters are not available : there are hard-coded. Therefore, only one argument is required: your query.
As for the second issue, as pointed above and reported on the bioservices issues page, your query would return only one publication. This was an issue with the special character %0D (in place of a return carriage) not being interpreted corectly by the URL request. This carriage character (either \n, \r or %0d) is now taken into account in the latest version on github or from pypi website if you use version 1.7.5
Thanks to willigot for filling the issue on bioservices page and bringing it to my attention.
disclaimer: i'm the main author of bioservices

How to clear a range in google sheet via gspread

Hi I would like to clear a range of A3:J10000 in google sheet by using gspread.
Doing a loop like this takes too much time:
for cell in range_to_clear:
cell.value=''
sh.worksheet('WorksheetX').update_cells(range_to_clear,value_input_option='USER_ENTERED')
I found the values_clear() method but wasn't able to make it working:
range_2_delete = sh.worksheet("WorksheetX").range("A3:J10000")
sh.values_clear(range_2_delete)
The above code giving this error: AttributeError: 'list' object has no attribute 'encode'
You want to clear the values of range on Google Spreadsheet.
You want to achieve this using gspread with python.
You have already been able to put and get values for Spreadsheet using Sheets API.
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
I think that the method of values_clear() can be used for your situation.
Modified script:
Please modify your script as follows.
From:
range_2_delete = sh.worksheet("WorksheetX").range("A3:J10000")
sh.values_clear(range_2_delete)
To:
sh.values_clear("WorksheetX!A3:J10000")
or
sh.values_clear("'WorksheetX'!A3:J10000")
Note:
This answer supposes as follows.
The latest version (v3.1.0) of gspread is used.
sh is declared. If sh is not declared, please use sh = gc.open('My poor gym results') and sh = client.open_by_key(spreadsheetId). Ref
Reference:
values_clear(range)
If this was not the result you want, I apologize.
You should try re-writing the code as follows:
range_2_delete = sh.worksheet("WorksheetX").range("A3:J10000")
values_clear(range_2_delete)

How to select only ikHandle and not it's effector using python in Maya?

I'm trying to automate the foot rig process in maya using python. When I try to group the ikHandles using this line of code, ankle_grp=cmds.group( ankle_ik, ball_ik,n='ankle_grp'), the effectors of the ikHandles are also coming into the ankle_grp. I do not want that. I want the ankle_grp to have only the ik Handles and not it's effectors. How do i do that?
Thanks in advance.
It worked when I gave the name of the ik_handle instead of a custom defined variable for ik_handle.
ankle_grp=cmds.group( 'ankle_ik', 'ball_ik',n='ankle_grp')
This is because the Maya's command cmds.ikHandle returns an array of two values, the ikHandle itself and the effector ;
cmds.ikHandle(sj='joint1', ee='joint2')
# Result: [u'ikHandle1', u'effector1'] #
I suggest you to keep you're variable, in order to keep your code dynamic, but you can 'explode' what Maya returns like this ;
ankle_ik, ankle_effector = cmds.ikHandle(sj='joint1', ee='joint2')
Then you can execute without error
ankle_grp=cmds.group( ankle_ik, ball_ik,n='ankle_grp')

Access specific information within worklogs in jira-python

How can I get the minutes spent from a worklog from an issue using the jira-python library?
Using the jirashell I see that the issue has the attribute issue.fields.worklog, however when I try to access that in my python code I get the error: AttributeError: type object 'PropertyHolder' has no attribute 'worklog'.
If I create a jira client and do jira_client.worklogs(ticket.key) in my python code, it returns a list of Worklogs and their ids but I don't know what to do with that. I see in the documentation there's a worklog() function that takes in the issue id, and the worklog id, but I don't understand what it returns and how I would use that/if it is what I'm looking for.
I found a roundabout way of doing it through the client.
As I iterate through each issue I get the list of worklogs per ticket by doing worklogs = jira_client.worklogs(issue.key) and then i iterate through all of the worklog items in the worklogs list (a nested for loop):
for worklog in worklogs:
totaltime += readtime(worklog.timeSpent)
Using the jirashell I accessed a specific worklog of a specific ticket: wl = jira_client.worklog(<issue key>, <worklog id>) then I typed in wl. and pressed TAB, it listed the following:
wl.author, wl.comment, wl.created, wl.delete, wl.find, wl.id, wl.raw, wl.self, wl.started,
wl.timeSpent, wl.timeSpentSeconds, wl.update, wl.updateAuthor, wl.updated
(Note: you need to include the period at the end of wl before pressing tab)
Running wl.timespent in the jirashell gave me gave me a unicode string with the number and then h or m for hour or minute (for example: u'6h'). Then I new that once I generated the worklog object in my loop above, I could access the time by using the timepsent attribute.
(Note: My readtime function turns the string into an integer and converts hours to minutes, and is not shown here)
The jirashell really helps with trying to find the attributes of the fields, etc. (Note: you need to install jira-python in addition to jira in order to run jirashell. Also if you installed jira-python in your virtualenv you need to run env/bin/jirashell from your command line once you are in your project's directory.)

Categories