drawing a circular arc using arcpy - arcgis

I would like to draw a circular arc between two angles and of certain radius using arcpy.Just to clarify it is not the blade but rather only the arc part.
I have thousands of such points so need some script to automate the process.
Any help highly appreciated.

You can create an arc between two points using the great circle method. Use XY To Line (Data Management) to accomplish this.
# Import system modules
import arcpy
from arcpy import env
# Set local variables
input_table = r"c:\workspace\city2city.dbf"
out_lines = r"c:\workspace\flt4421.gdb\routing001"
#XY To Line
arcpy.XYToLine_management(input_table,out_lines,
"LOND1","LATD1","LOND2",
"LATD2","GREAT_CIRCLE","idnum")

Related

save pyplot figure "as figure" (not as image)

How can I save a figure using PyPlot in Julia, so that the figure can be reloaded as a figure later in Julia? (not as an image)
You can use serialize to store any Julia object. This beautifully works for plots as well.
Let us start by generating a plot:
using Plots
pyplot()
p = plot(rand(10));
using Serialization
Serialization.serialize("myfile.jld", p);
Note that you need a semicolon after plot command so it does not appear on the screen.
Let us now read the plot (to have a full test I ended the previous Julia session and started a new one):
using Plots
pyplot();
using Serialization
p2 = Serialization.deserialize("myfile.jld");
In order to display it now it is enough to type in REPL:
julia> p2
You might want also want to use plain PyPlot (I strongly recommend Plots for flexibility). In that case your best bet is to follow rules described in object-oriented API of Matplotlib:
using PyPlot
ioff()
fig = subplot()
fig.plot(rand(10))
fig.set_title("Hello world")
using Serialization
serialize("pp.jld", fig)
In order to plot de-serialize back the object:
using PyPlot
ioff()
using Serialization
fig = deserialize("pp.jld")
show()
Finally, note that the serialization is good only for short term storage. If anything changes (e.g. you update Julia packages) you might not be able to de-serialize the plot.
Hence another good alternative for processable plots are saving them to LaTeX or SVG format - both is possible in Julia.

Add Compose context to pyplot axis or figure in julia

I have two different visualizations: a big plot (as PyPlot figure) and a worldmap (Compose context). Is there any possibility to combine those? (out of julia, without exporting both and then fiddling with some software).
I would like to do something like:
import PyPlot
using Compose
(fig, ax) = PyPlot.subplots(2,1)
ax[1][:plot]([1,2,3],[1,2,3])
composition = compose(compose(context(), circle()), fill("tomato"))
### magic command to add composition to ax[2]
In case there is no way to do it like this I will be greatefull for any other suggestions.
Thanks in advance!

matplotlib get rid of max_open_warning output

I wrote a script that calls functions from QIIME to build a bunch of plots among other things. Everything runs fine to completion, but matplotlib always throws the following feedback for every plot it creates (super annoying):
/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py:412: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (matplotlib.pyplot.figure) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam figure.max_num_figures).
max_open_warning, RuntimeWarning)
I found this page which seems to explain how to fix this problem , but after I follow directions, nothing changes:
import matplotlib as mpl
mpl.rcParams[figure.max_open_warning'] = 0
I went into the file after calling matplotlib directly from python to see which rcparams file I should be investigating and manually changed the 20 to 0. Still no change. In case the documentation was incorrect, I also changed it to 1000, and still am getting the same warning messages.
I understand that this could be a problem for people running on computers with limited power, but that isn't a problem in my case. How can I make this feedback go away permanently?
Try setting it this way:
import matplotlib as plt
plt.rcParams.update({'figure.max_open_warning': 0})
Not sure exactly why this works, but it mirrors the way I have changed the font size in the past and seems to fix the warnings for me.
Another way I just tried and it worked:
import matplotlib as mpl
mpl.rc('figure', max_open_warning = 0)
When using Seaborn you can do it like this
import seaborn as sns
sns.set_theme(rc={'figure.max_open_warning': 0})
Check out this article which basically says to plt.close(fig1) after you're done with fig1. This way you don't have too many figs floating around in memory.
In Matplotlib, figure.max_open_warning is a configuration parameter that determines the maximum number of figures that can be opened before a warning is issued. By default, the value of this parameter is 20. This means that if you open more than 20 figures in a single Matplotlib session, you will see a warning message. You can change the value of this parameter by using the matplotlib.rcParams function. For example:
import matplotlib.pyplot as plt
plt.rcParams['figure.max_open_warning'] = 50
This will set the value of figure.max_open_warning to 50, so that you will see a warning message if you open more than 50 figures in a single Matplotlib session.

PathPatch object in julia with PyPlot

I was trying to reproduce this example from the matplotlib website using the PyPlot package for Julia. As far as I know, the PyPlot is essentialy the matplotlib.pyplot module, so I imported the other modules of matplotlib that I needed (with the #pyimport macro):
using PyCall
#pyimport matplotlib.path as mpath
#pyimport matplotlib.patches as mpatches
Then I proceed to define the path object:
Path = mpath.Path
but then I get:
fn (generic function with 1 method) .
As if I had defined a function. Moreover, when I assign the path_data I get the following error:
ERROR: type Function has no field MOVETO
Of course, that's due to Path, which Julia tries as a function and not as a type or something like that. As you might guess the same happens when I try to define the variable patch .
So, there are incompatibilities of modules from matplotlib different to pyplot for Julia since the expected objects (types) are taken as functions. This behaviour can be expected if it were different the PyPlot.jl file wouldn't be needed.
My questions are:
-Am I doing something wrong?
-Is there a simple way to make it works?
-Do you know another package for Julia in which I can define patches and work in a similar way to matplotlib?
I have in mind to do this kind of animations.
Thanks for your ideas.
You need to get the "raw" Python object for Path. By default, PyCall converts Python type objects into functions (which call the corresponding constructor), but then you cannot access static members of the class.
Instead, do e.g. Path = mpath.pymember("Path") to get the "raw" PyObject, and then you can do Path["MOVETO"] or Path[:MOVETO] to access the MOVETO member.
(This difficulty will hopefully go away in Julia 0.4 once something like https://github.com/JuliaLang/julia/pull/8008 gets merged (so that we can make PyObjects callable directly.)

Save a figure with multiple extensions?

In matplotlib, is there any (especially clever) way to save a figure with multiple extensions?
Use case: I generally want .png's for quick-look examination, uploading to the web, etc. But for publication-quality figures, I want .pdf or .eps files. Often, I want all 3.
It's not hard to do:
for suffix in 'png eps pdf'.split():
pl.savefig(figname+"."+suffix)
but it does involve a lot of rewriting code (since I generally just have savefig(figname+'.png') everywhere right now), and this seems like an easy case for a convenient wrapper function.
If you always do
from matplotlib import pyplot as pl
...
pl.savefig
then you could concievably reassign pl.savefig in one place and it would affect all places.
from matplotlib import pyplot as pl
def save_figs(fn,types=('.pdf',)):
fig = pl.gcf()
for t in types:
fig.savefig(fn+t)
pl.savefig = save_figs
If you usually do
fig=pl.figure()
fig.savefig(...)
then that will require more effort.
You can specify the file type as shown in the documentation for savefig by using format. But as far as I know you can only specify a single format.
While not especially clever, to minimised rewriting code you should write a save_fig function. This can then handle automatically creating appropriate file names and a quality.
def save_fig(fig_name, quality="quick-look"):
if "quick-look" in quality:
# save fig with .png etc
if "pub-qual" in quality:
# save fig with increased dpi etc etc.
Probably not the answer you're looking for as it will require you to rewrite every savefig however I feel this kind of thing can help reduce the amount of repeated code overall.