« first day (1090 days earlier)      last day (2362 days later) » 

10:41
@LuisMendo REPENT! THE END IS NEAR
@LuisMendo reminds me of this classic poem: youtube.com/watch?v=DPiKI8xpt4w
11:02
0
Q: Draw line between specific points by having their length of line (distance)

RozannaI have in total 360 points. I want to draw line between specific points based on my data by having their length. For example, based on my Excel sheet all points from column A connect to column B and column C is their length (distance between these points). How can I plot these lines? Thanks in ...

its the secodn time I see this
is the other question deleted?
@AnderBiguri cross-posted on MATLAB Answers with an accepted answer
Today I have seen another one in SO
In fact the question I saw is the longer comment on that MATLAB page
> No I dont have just 2 points. Actually, these are data of a pipe network. I know the length of pipe and nodes id (upstream and downstream point). That means, I have not connection between all of points.
Below is example of 3 point from total 360 points. us_node_id (coloum A in matlab data file) : [point 1,point 5, point 6]
ds_node_id (colom B in matlab data file) :[point 5, point 6, point10]
Length of line (coloum C in matlab data file):[ 12,24,22]
@AnderBiguri You're right. I have also seen that question on SO
Greetings from a volcano
where the prof told me to learn Python
heh
watch your step
11:14
'tis difficult
python's a ssssllipery slope B-)
@Adriaan numpy+matplotlib+spyder ≃ MATLAB ‍‍‍‍‍‍ ‍‍ ‍‍‍‍‍‍ ‍‍ ‍‍‍‍‍‍ ‍‍ ‍‍‍‍‍‍ ‍‍ ‍‍‍‍‍‍ ‍‍ ‍‍‍‍‍‍ ‍‍ ‍‍‍‍‍‍ ‍‍ ‍‍‍‍‍‍ ‍‍ ‍‍‍‍‍‍ ‍‍ ‍‍‍‍‍‍ ‍‍ ‍‍‍‍‍‍ ‍‍ ‍‍‍‍‍‍ ‍‍ ‍‍‍‍‍‍ ‍‍(Andras hates this, I m sure)
@Adriaan wow volcano man!
'tis true nonetheless @SardarUsama
it took me 90 minutes to get a matrix with integers [0:5] to binary A>2 :P
I found a paper on CNNs on reconstruction of time-of-flight tomography (and similar tomographies), which I believe is something like you are doing @Adriaan. When you are back from fighting lava monsters, let me know if you are interested on it ;)
11:19
@AnderBiguri if I remember ;) sounds cool, mind sending me the paper/link to it by email? Then I won't forget
hum, not sure if I have your email
I do
Yes you do, I was sad and unexperienced back in the day :P
we all were
sent you the paper
Eskarrikasko!
(?)
Eskerrikasko, but in fact, Eskarrikasko works as a dialect way
so yay!
11:31
@SardarUsama no, that's pretty much true
spyder was designed to be MATLAB
I mean, my main objections to MATLAB are the stiffness of the language and the proprietary nature. I don't mind if people can use their python as if it were MATLAB (as long as they remember that it isn't, and use it accordingly :P)
what I mean is that different things are idiomatic in different languages
in MATLAB f = @(x,y) x.^2 .* y is perfectly fine, but in python that's a paddlin'
And there are a lot of built-in constructs that don't exist in matlab and make life easier, such as list comprehensions. Or even lists, for that matter.
11:47
I have an xarray thing with lat,lon coordinates and a list of station names. The datamat.Lat and Lon work to generate the plot, but I can't use plt.text(Lat,Lon,datamat.ID) to also label the points
what's type(datamat.ID)?
object
oh, you have an array of IDs?
Yes, within an xarray thing
str(datamat.ID) didn't work either
and you'd want a bunch of labels in a single text call?
or just a single label?
11:50
bunch; I have a plot with red dots, and I;d like to label each dot with its correct name
Ah, OK. Yeah, I think you can only do that with a loop
plt.text explicitly only accepts scalars
uhoh
goes in search for loop documentation
for lat,lon,ID in zip(datamat.Lat,datamat.Lon,datamat.ID):
    plt.text(lat,lon,ID)
this would assume that you have 1d arrays and that datamat.ID can be iterated over ^
I've never used xarray, unfortunately
but there may be a better way
I'll try to adapt, köszönöm
(or Takk Fyrir as they say here)
there probably isn't a better way stackoverflow.com/a/5147430/5067311
plt.annotate is just a fancy way to put text and arrows and whatnot; same mechanics
11:59
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-28-fd932acab6a6> in <module>()
      3 _plt.xlabel('Longitude')
      4 _plt.title('Locations of gravimetry measurements')
----> 5 for lat,lon,ID in range(len(datamat)):
      6     _plt.text(datamat.Lon[lon],datamat.Lat[lat],datamat.ID[ID])
      7 #_plt.text(datamat.Lon,datamat.Lat,str(datamat.ID))

TypeError: 'int' object is not iterable
range(len(datamat)) is a 1d thing, you can't unpack it into 3 variables :)
ew, why is there a _plt?
Adriaan said so :P
Adriaan's the other student working here
yeah, the one with the silly shirt
"Not my package, so to indicate that I use underscores" he said
if you can index those arrays like that with 1 index, do what I did
12:01
@AndrasDeak says the one in hedgehog shirts ;)
I haven't worn that one for weeks :P
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-29-7d4c3e253b69> in <module>()
      4 _plt.title('Locations of gravimetry measurements')
      5 for lat,lon,ID in zip(datamat.Lat, datamat.Lon, datamat.ID):
----> 6     _plt.text(datamat.Lon[lon],datamat.Lat[lat],datamat.ID[ID])
      7 #_plt.text(datamat.Lon,datamat.Lat,str(datamat.ID))
      8 _plt.grid(True)
continuing for lots more errors
yes, do what I did :P
you only need to change plt to _plt
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/opt/miniconda3/envs/iceland/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--> 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

~/opt/miniconda3/envs/iceland/lib/python3.6/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
and so on in the traceback
That seems mildly unrelated, Something from ipython internals. Tangentially related: are you guys using pylab?
12:07
jupyter
jupyter is the environment, same category as ipython. Pylab is a module, which you import.
is there an import pylab or from pylab import anywhere?
cool, there shouldn't be, it's deprecated
and do you have an __all__ near the beginning or the end?
import pandas as _pd
import numpy as _np
import xarray as _xr
from itertools import permutations as _permutations
from matplotlib import pyplot as _plt;
import seaborn as _sns
%matplotlib inline
that's it
@Adriaan could you post the full traceback in a pastebin or gist or something? Perhaps there's some more substantial info in there
12:16
_plt.plot(datamat.Lon,datamat.Lat,'ro')
_plt.ylabel('Latitude')
_plt.xlabel('Longitude')
_plt.title('Locations of gravimetry measurements')
for lat,lon,ID in zip(datamat.Lat, datamat.Lon, datamat.ID):
    _plt.text(datamat.Lon,datamat.Lat,datamat.ID)
#_plt.text(datamat.Lon,datamat.Lat,str(datamat.ID))
_plt.grid(True)
_plt.show()

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/opt/miniconda3/envs/iceland/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
OK, I'll copy it into a pastebin myself :P
> TypeError: cannot convert the series to <class 'float'>
that may be relevant
what I don't get is how there's no error line that shows your line of code that caused this to begin with
probably .show() anyway
OK, most important question: does it work without the annotations?
Yes
I'd like the map of the local area behind it as well, but that's for later
then what's [(type(val),repr(val)) for val in [datamat.Lon[0],datamat.Lat[0],datamat.ID[0]]]?
@Adriaan matplotlib.basemap will do that really easily for you
12:32
thanks
[(type(val),repr(val)) for val in [datamat.Lon[0],datamat.Lat[0],datamat.ID[0]]]

[(numpy.float64, '-16.81598'), (numpy.float64, '65.62167'), (str, "'BF18'")]
Hmm, seems sane enough... I don't really know where that error is coming from, then :/
any chance that some of the lat/lon values are wrong? I.e. not floats?
OK, one more: {(type(lon),type(lat),type(ID)) for lon,lat,ID in zip(datamat.Lon,datamat.Lat,datamat.ID)}
(edited x2, sorry)
float float str
just the one tuple, right?
if {(float, float, str)} is a tuple, then yes
a single 3-element tuple inside a set, yes :)
sets contain any item at most once, so that set comprehension reduced your many 3-tuples to 1 unique one
So...perhaps something completely different is wrong. Comment out your loop, and put a single text by hand, like _plt.text(-16.85, 65.68, 'foo'). I'd hope that it breaks similarly
12:41
_plt.plot(datamat.Lon,datamat.Lat,'ro')
_plt.ylabel('Latitude')
_plt.xlabel('Longitude')
_plt.title('Locations of gravimetry measurements')
#for lat,lon,ID in zip(datamat.Lat, datamat.Lon, datamat.ID):
#    _plt.text(datamat.Lon,datamat.Lat,datamat.ID)
#_plt.text(datamat.Lon,datamat.Lat,str(datamat.ID))
_plt.text(0.5,0.5,'foo')
_plt.grid(True)
_plt.show()

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
delightful :D
did you ask for an image that large?
this all may be a jupyter thing...
Image size of 27489x127888 pixels is too large. I agree python, I agree....
Hold on, do you keep creating new figures? You can easily end up in a stale state if you don't. So: have you tried restarting jupyter?
I restarted
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/opt/miniconda3/envs/iceland/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--> 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

~/opt/miniconda3/envs/iceland/lib/python3.6/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
changing the texst to be within lat,lon of my area didn't help either
12:45
(except that you now know approximately where I am)
I didn't ask for a thing
just that code
well it can't be "just that code" since you're missing the input array definitions etc ;)
nothing else with _plt or _sns?
Is this jupyter or jupyter-notebook? I suspect the latter, because %matplotlib inline
_sns creates another, working, plot
plotting both with plt and sns is...weird
Removed everything cotaining sns, still errors
with the single text that is
oh, yeah, I'm sure it's unrelated. Just noting :)
I also thought about the underscore thing, and I think your Adriaan is wrong. Underscores usually signal "private" attributes (not that such a thing truly exists in python), so you use _module exactly for your own internal stuff. I asked around in the python room to be sure about best practices
12:55
I'll tell my Adriaan :P
Lunchtime on Iceland, finally!
brb
He should document his API well, and he can define an __all__ after which star imports will only import what he wants to.
have a steamy lunch ;)
 
4 hours later…
17:26
posted on June 25, 2018 by Cleve Moler

If you follow this blog regularly, you know that I love fractals. I recently spent a pleasant afternoon in Nashua, New Hampshire, where my daughter Teresa introduced me to Gregory Searle, a fractal artist and computer geek. Here is his logo.... read more >>

 
2 hours later…
19:21
Is it true that global variables "overwrite" local variables without explicitly stating you want to access a global variable?
0
Q: How to find out which variable is triggering Matlab warning about global variables

Robert DodierI'm working with Matlab R2018a on Linux. I am getting the warning message: "Warning: The value of local variables may have been changed to match the globals. Future versions of MATLAB will require that you declare a variable to be global before you use that variable." The warning is accompanie...

This sounds incredibly stupid. This makes global variables dangerous, not just difficult to debug.
Well, there is a reason why there are very few langauges that have global variables or goto (or eval for that matter) :)
19:44
@flawr goto is the best thing since sliced bread! What are you talking about??? :p
...though I'm not sure what is so good about sliced bread, that saying makes no sense to me at all.
goto has its place in very low-level routines where you need to do cleanup, like the cpython implementation
@CrisLuengo ah, yes, the magical "say it's global once, *poof*" mechanics
Even global variables have their use. I don't believe in black/white.
yeah, but same as goto you need to be really careful not to end up with unmaintainable/undebuggable code
I'd say globals come even before gotos, at least as conventions go
@AndrasDeak So three years later, after typing "global" on a different computer, you're still being haunted by weird errors caused by untraceable global variables...
Can you read variables from someone else's computer by declaring them global?
sure, it's all yours then
global === dibs
19:51
"What are we going to do to day, Brain?" - "The same thing we do every day, Pinky. Take over the world using global variables."
I don't want to be that guy but in python you need to say global inside the function rather than outside
@AndrasDeak That is the sane way to do it.
Real men use Haskell.
19:56
but you always see variables in enclosing scopes, and you can even mutate them :P
In C and C++, declaring a local variable hides any variables with the same name in an enclosing scope. That makes globals a lot safer (though not necessarily saner).
20:26
I am not sure if I understand that.

Does it mean if:

function foo = foobar(baz)
foo = sum(baz);
end

and if baz is also some global variable then that global baz will be used in the above foobar function?
@SardarUsama That is how I understood it. I don't have MATLAB here to test it, but it certainly sounds crazy.
that's horrible
Aye.
I felt like I needed to take a shower after reading that... :)
I guess I've never used global variables, I'm sure I would have run into this issue otherwise.
@SardarUsama doesn't work in 2017b
but in future versions we will need to declare the global variables according to that post. So that horrible thing if true is in just R2018a for now
20:32
the docs of global also say that you have to declar a variable as global in every scope you want to use it
@flawr thanks for testing
@flawr but if you don't declare it as global then the value of local variable is changing to match with that of global according to that post
@SardarUsama I also get that warning in 2017b when adding the globl baz line in foobar()
@SardarUsama that does not seem to be the case
so what does that warning mean?
Oh, so the warning happens if

`baz = 3;`
`global baz`
`disp(baz) % shows value of global baz`
Is that right, @flawr?
@flawr the exact wording is "may have been changed" which indicates that there would be some cases when it would change and some cases when it would not
20:35
@SardarUsama right, that is somehow confusing
Damn, is there no way to format code in chat?
multiline? nope
@CrisLuengo just line you fix in SO main. four spaces but it should be a separate message
I tried that, but didn't get monspaced font.
@CrisLuengo no, doesn't produce any warning
20:37
Ah, separate message. Right. Thanks!
function foo = todel(baz)
baz = baz*100; % local baz is used
global baz;
foo = sum(baz); % global baz is used
end
here the warning makes sense
Is that where you get the warning?
It would indeed make sense to get a warning there.
yes
but i also get it when it doesn't make any sense
ah no
it does make sense
in function foo = todel(baz);global baz;foo = sum(baz);end
I get the warning
but just because the argument baz is defined before global baz is "executed"
Yes, there you're overwriting the input argument, that's a good warning to give.
so it only seems to warn when it actually makes sense
20:43
Oh, and so "Future versions of MATLAB will require that you declare a variable to be global before you use that variable." means that you will get an error in this case in the future.
You won't be able to do baz=3; global baz. You'll have to do global baz; baz=3.
I think I understand the message now.
right!
maybe add that as an answer!
if you use a global baz as an input of some function and you don't write global baz in that function and if that function changes the value of baz, will the global baz change as well?
@SardarUsama : Good question.
@flawr I saw you added this as a comment, why don't you make it into an answer? You did all the testing after all... :)
@CrisLuengo it doesn't change the global baz (R2018a)
@SardarUsama Thanks for testing, that makes me feel a lot better. At first I thought that global variables would be changed if in a function you use a local variable with the same name.
21:02
that's a relief indeed
@CrisLuengo sopython.com/wiki/… cc @flawr
by the way I'm also glad you figured out that the situation is not as bad as it should be ;)
2
@AndrasDeak LOL "not as bad as it should be" That's either the best typo ever or a really clever joke.
@CrisLuengo Hint: his main tag is python :/
@SardarUsama Ah, so it's an underhanded compliment...
haha, I'm afraid that's a mere typo rather than brilliance :D
21:53
@AnderBiguri Hahaha. Short and to the point

« first day (1090 days earlier)      last day (2362 days later) »