What is the full command for gdal_calc in ipython? - ipython

I've been trying to use raster calculation in ipython for a tif file I have uploaded, but I'm unable to find the whole code for the function. I keep finding examples such as below, but am unsure how to use this.
gdal_calc.py -A input.tif --outfile=result.tif --calc="A*(A>0)" --NoDataValue=0
I then tried another process by assigning sections, however this still doesn't work (code below)
a = '/iPythonData/cstone/prec_7.tif'
outfile = '/iPythonData/cstone/prec_result.tif'
expr = 'A<125'
gdal_calc.py -A=a --outfile=outfile --calc='expr' --NoDataValue=0
It keeps coming up with can't assign to operator. Can someone please help with the whole code.

Looking at the source code for gdal_calc.py, the file is only about 300 lines. Here is a link to that file.
https://raw.githubusercontent.com/OSGeo/gdal/trunk/gdal/swig/python/scripts/gdal_calc.py
The punchline is that they just create an OptionParser object in main and pass it to the doit() method (Line 63). You could generate the same OptionParser instance based on the same arguments you pass to it via the command-line and call their doit method directly.
That said, a system call is perfectly valid per #thomas-k. This is only if you really want to stay in the Python environment.

Related

How to Load PowerShell Functions On-Demand?

In my personal PowerShell profile that loads whenever I start PowerShell, I want to include a set of functions by calling a function.
So I want to do something like this:
function loadMyFunctions{
. \MyFunctions.ps1
}
Now, in MyFunctions.ps1 I have a function:
function bobtest{
write-host "My name is Bob Newhart."
}
I am able to load the script MyFunctions.ps1, but after that is loaded I am not able to call bobtest in the console - I get the error message The term bobtest is not recognized...
However, if I just load the script outside the function then that script is loaded and I can call bobtest normally - but that means that I can't just not load MyFunctions when the profile is loaded - I have to load MyFunctions and cannot choose.
You see, I want to load the other functions on demand and not have them available until I choose.
Is there another way to do this or can it even be done?
Have a look at this page, How to Create PowerShell Modules and Manifests.
This will enable you to create a module which will have all your custom functions! Then inside of your loadMyFunctions cmdlet add Import-Module NewModuleName.
This will enable you to use your cmdlets.
Hope this Helps,
Lachlan
Best way is to use modules. But still if you want to get in some different ways , then you can try with your approach.
See the below screenshots which I have performed.
I have a function addition which simply does addition and I saved it as funct1.ps1
Now I am calling the same function from another function of the other script just using dot source without using as module and it results me properly.
Funct1.ps1
Triggered the function from another function in another script .
Hope it helps...!!!

Ida pro gragh output batch mode

Can anyone let me know how we are going to output all the subroutine's graphs in batch mode suing IDC. i.e. I have 447 subroutine's and wanna be output them all and I would like to make sure I first retrieve all the routines address automatically, cuz by knowing the address I can simply use GenFuncCall.
P.S: Is this the only cfg that I can get from Ida Pro given a binary dis-assembled file?
I needed a CFG of my whole program,the base example I started from was:
https://code.google.com/p/idapython/source/browse/trunk/examples/ex_gdl_qflow_chart.py
It uses the flow chart class:
https://www.hex-rays.com/products/ida/support/idapython_docs/idaapi.FlowChart-class.html
also worth noting to trigger in batch mode, you'll want something like this
idal64 -A -S{yourscriptname}.py {yourbinary}
Tips:
Prototype the script in the IDAPro gui first
Opening of the graph processor can cause timing issues, its hacky, but something like delaying execution of the script seemed to help, e.g.
idaapi.autoWait()
Timer(2, idacfg).start()
where idacfg is your python function from the example
print to stdout doesn't seem to work in batch mode, so you'll want to set stdout to a file for your debugging.
Closing the GUI in batch mode is still an issue for me.
Hope that helps.
If you just want the address of all known functions in the IDB, you could use something like this using IDAPython (just an example):
def main():
for count, func_ea in enumerate(Functions()):
if func_ea == BADADDR:
break
func_name = GetFunctionName(funcea)
func_start = func_ea
print("[{:4}] name: {}; start address: {:#x}".format(count, func_name, func_start))
if __name__ == "__main__":
main()

Issue with a topjson object in a Meteor app built with coffeescript

Apologies for the lack of precision in the question, but I'm not completely sure which of possibly many things I'm doing wrong here.
I'm relatively new to Coffeescript and also geo applications in general, but here goes:
I've got a working (simple) Meteor (.7.0.1) application utilizing coffeescript in both client and server. The issue I'm having occurs when attempting to utilize TopoJSON encoded files to create a layer of US congressional districts. (the purpose of the app is to help highlight voter suppression in the US)
So, a few things: Typically in a non-Meteor app, I would just load the topoJSON file like so:
$.getJSON('./data/us-congress-113.json', function (data) {
var congress_geojson = topojson.feature(data, data.objects.districts);
congress_layer.addData(congress_geojson);
});
Now of course this won't work in Meteor because its not asynchronous.
One of the things that was recommended here on SO was to not worry about reading the file, and to instead change the json file to .js, and then set the contents (which are of course just an object) equal to a variable.
Here's what I did:
First, I changed the .json file to a .js file in the server directory, and added the "congress =" to the beginning of the file. It's a huge file so forgive me for omitting the whole object.
congress = {"type":"Topology",
"objects":
{"districts":
{"type":"GeometryCollection","geometries":[{"type":"Polygon"
Now here's where everything starts to give me issues:
In the server.coffee, I've created a variable like so to reference the congress object:
#congress_geojson = topojson.feature(congress, congress.objects.districts)
Notice how I'm putting the # symbol there? I've been told this allows a variable in Coffeescript to be globally scoped? I tried to also use a Meteor feature called "share" where I declare the variable as "share.congress_geojson". That led to the same issues which I will describe below.
Now in the client.coffee file, I'm trying to call this variable to load into a Leaflet map.
congress_layer = L.geoJson(null,
style:
color: "#DE0404"
weight: 2
opacity: 0.4
fillOpacity: 0.1
)
congress_layer.addData(#congress_geojson)
This isn't working, and specifically (despite attempts to find other ways, the errors I'm getting in the console are:
Exception from Deps afterFlush function: TypeError: Cannot read property 'features' of undefined
at o.GeoJSON.o.FeatureGroup.extend.addData (http://localhost:3000/packages/leaflet.js?ad7b569067d1f68c7403ea1c89a172b4cfd68d85:39:16471)
at Object.Template.map.rendered (http://localhost:3000/client/client.coffee.js?37b1cdc5945f3407f2726a5719e1459f44d1db2d:213:18)
I have no doubt that I'm missing something stupidly obvious here. Any suggestions or tips for what I'm doing completely wrong would be appreciated. Is it a case where an object globally declared in a .js file isn't available to code in a .coffee file? Maybe I'm doing something wrong on the Meteor side?
Thanks!
Edit:
So I was able to get things working by putting the .js file containing the congress object in a root /lib folder, causing the object to load first, and then calling the congress object from the client. However, I'm still wanting to know how I could simply share this object from the server? What is the "Meteor way" here?
If you are looking for the Meteor way to order the loading of files, use the Meteor.startup function and put the initialization code there. That function is the $.ready of the Meteor world, i.e., it will execute only after all your files have been successfully loaded on the client.
So in your case:
Meter.startup ->
congress_layer.addData(#congress_geojson)

MATLAB: force doc command to open a specified reference HTML page

Say I've written a class in a package, called mypackage.myclass. I've written my own HTML documentation for the package and the class, and have included this within the MATLAB help browser as described in the MATLAB documentation.
I can display this HTML documentation by using the help browser to navigate directly to it, but typing doc mypackage.myclass does not display it; instead it displays some HTML documentation that is auto-generated by helpwin (which is a nice feature, but not what I want - the auto-generated documentation is too techy for my users).
How can I force doc to display my documentation, rather than the auto-generated documentation?
Equivalently:
When you run doc docTopic, inside the doc command the Java class com.mathworks.mlservices.MLHelpServices.showReferencePage(docTopic) gets called. If a reference page for docTopic exists, it displays it and returns a success value. If a reference page doesn't exist, it returns a failure value, which then causes helpwin(docTopic) to get called. Somewhere there must be some catalog that connects values of docTopic with individual reference HTML files. How can I fiddle with that catalog - or can I create one for my package?
MathWorkers and #Yair, please give me enough undocumented rope to hang myself with :)
As far as I know this is not possible and not intended by MathWorks. I don't know of an undocumented way of doing this either. As far as I remember the keywords for doc are hard-coded somewhere.
Depending on your setup you can try the following: Prepare your own doc command that uses web(..., '-helpbrowser') to display HTML pages in MATLAB's help browser:
function doc(topic)
my_topics = {
'foo', 'foo.html'
'bar', 'bar/help/intro.html'
};
for i = 1 : size(my_topics, 1)
if strcmpi(topic, my_topics{i, 1})
web(my_topics{i, 2}, '-helpbrowser');
return;
end
end
% Fall back to MATLAB's doc. Note that our doc shadows MATLAB's doc.
docs = which('doc', '-all');
old_dir = cd();
c = onCleanup(#() cd(old_dir));
cd(fileparts(docs{2}));
doc(topic);
end
If you put that function in a file doc.m and put the corresponding directory at the beginning of the MATLAB path (see help addpath) then it will be called instead of the built-in doc.
Of course you could use some other place to store your custom doc mapping (a file, for instance) or use some kind of dynamic lookup scheme.
UPDATE: As of MATLAB R2012b, the '-helpbrowser' option of web is undocumented. This is probably related to the GUI changes in that MATLAB version, which also include the help browser. web(..., '-helpbrowser') still works as intended, but that may change in future versions of MATLAB. As far as I know, there is no documented way of opening any HTML page in the help browser in R2012b.

Windbg: Creating log of function entry and exit

I wish to create log of function entry and exit for my code. I am using the following command in WinDbg-
Function name and the return value
bm <module_name>!* "kcL1;.echotime;gu;r eax;.echotime;gc;"
Now I wish to do this for all the modules of the function but I don't want to write the code again for each module. Is there some way to specify bm to read module names from a file which I create using "lm" and set breakpoint for each module or something even more simple.
Also, how can I specify bm to not print the output on the screen? I am using a log file.
Sometimes I don't see the time for call exit. What can be the reason for this? How can I correct it?
you can use !for_each_module
You will not see call exit time if another breakpoint is hit (in another thread, or if the funciton calls other functions that have breakpoints)