Python returning image to NetLogo for "import-drawing" or "import-pcolors"

14 views
Skip to first unread message

Brady, Corey

unread,
May 5, 2024, 4:19:01 PMMay 5
to netlogo-devel

Hello !

I was wondering if anyone has solved the problem of getting an image created in python to NetLogo’s import-xx primitives.

I imagine there are several possible approaches, but it seems like a common enough need that someone might have solved the problem already.

Any word of solutions?

Thanks!
-Corey

 

Corey Brady

Associate Professor, Mathematics Education and the Learning Sciences

corey...@smu.edu

Department of Teaching and Learning

Simmons School of Education and Human Development

A blue and red logo

Description automatically generated

jeremy...@northwestern.edu

unread,
May 6, 2024, 12:00:22 PMMay 6
to netlogo-devel
Hey Corey,

Do you have more details on what the problem you're having is?  What isn't working about just using the import primitives as-is?  Do you mean importing image data that's generated in the Python extension in a NetLogo model, or just generally from Python?  

Thanks.

-Jeremy

Brady, Corey

unread,
May 6, 2024, 1:13:18 PMMay 6
to jeremy...@northwestern.edu, netlogo-devel

Hi Jeremy –

 

Thanks for your note!  Clarification below…


In the py extension, there is only the py:runresult  primitive for getting information back from python processes.

 

In the scenario I’m working with, I have created an image (actually, it’ll be many frames)..  that I want to bring into netlogo via import-drawing and/or import-pcolors.

 

If I use py:runresult, I get an error that the image is not JSON serializable.


Have others run into this or similar problem & solved it?

 

Thanks!
-Corey

 

 

Corey Brady

Associate Professor, Mathematics Education and the Learning Sciences

corey...@smu.edu

Department of Teaching and Learning

Simmons School of Education and Human Development

A blue and red logo

Description automatically generated

 

From: <netlog...@googlegroups.com> on behalf of "jeremy...@northwestern.edu" <jeremy...@northwestern.edu>
Date: Monday, May 6, 2024 at 11:00 AM
To: netlogo-devel <netlog...@googlegroups.com>
Subject: [netlogo-devel] Re: Python returning image to NetLogo for "import-drawing" or "import-pcolors"

 

Image removed by sender. A blue and red logo

Description automatically generated

--
You received this message because you are subscribed to the Google Groups "netlogo-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-devel/573498f5-65f4-4312-81f8-41013412f1dbn%40googlegroups.com.

Aaron Andre Brandes

unread,
May 6, 2024, 1:39:39 PMMay 6
to Brady, Corey, Jeremy Baker, netlogo-devel

Hi Corey,

This is just a shot in the dark, as I don’t know the py extension code, but how about having your procedure return the file name of the image rather than the image itself.

  • Aaron

 

-- 

Aaron Brandes, Software Developer

Center for Connected Learning and Computer-Based Modeling

 

 

jeremy...@northwestern.edu

unread,
May 6, 2024, 1:47:01 PMMay 6
to netlogo-devel
Okay, so if you have the image data available in the Python environment in the extension, then you can get it back to the NetLogo side by converting it to a base64 string, then using the ImportA Extension to put that data where you need it.  The process for encoding it in base64 will vary depending on the format, but it should be an option as it's a common operation.

I hope that helps, let me know if you need more details.

-Jeremy

Brady, Corey

unread,
May 6, 2024, 2:00:36 PMMay 6
to jeremy...@northwestern.edu, netlogo-devel

That’s great:  I’ll give that a try. Thanks! -Corey

 

Corey Brady

Associate Professor, Mathematics Education and the Learning Sciences

corey...@smu.edu

Department of Teaching and Learning

Simmons School of Education and Human Development

A blue and red logo

Description automatically generated

 

From: <netlog...@googlegroups.com> on behalf of "jeremy...@northwestern.edu" <jeremy...@northwestern.edu>
Date: Monday, May 6, 2024 at 12:47 PM
To: netlogo-devel <netlog...@googlegroups.com>
Subject: Re: [netlogo-devel] Re: Python returning image to NetLogo for "import-drawing" or "import-pcolors"

 

Okay, so if you have the image data available in the Python environment in the extension, then you can get it back to the NetLogo side by converting it to a base64 string, then using the ImportA Extension to put that data where you need it.  The process for encoding it in base64 will vary depending on the format, but it should be an option as it's a common operation.

 

I hope that helps, let me know if you need more details.

 

-Jeremy

 

On Monday, May 6, 2024 at 12:13:18PM UTC-5 Brady, Corey wrote:

Hi Jeremy –

 

Thanks for your note!  Clarification below…


In the py extension, there is only the py:runresult  primitive for getting information back from python processes.

 

In the scenario I’m working with, I have created an image (actually, it’ll be many frames)..  that I want to bring into netlogo via import-drawing and/or import-pcolors.

 

If I use py:runresult, I get an error that the image is not JSON serializable.


Have others run into this or similar problem & solved it?

 

Thanks!
-Corey

 

 

Corey Brady

Associate Professor, Mathematics Education and the Learning Sciences

corey...@smu.edu

Department of Teaching and Learning

Simmons School of Education and Human Development

Image removed by sender. A blue and red logo

Description automatically generated

 

From: <netlog...@googlegroups.com> on behalf of "jeremy...@northwestern.edu" <jeremy...@northwestern.edu>
Date: Monday, May 6, 2024 at 11:00 AM
To: netlogo-devel <netlog...@googlegroups.com>
Subject: [netlogo-devel] Re: Python returning image to NetLogo for "import-drawing" or "import-pcolors"

 

Hey Corey,

 

Do you have more details on what the problem you're having is?  What isn't working about just using the import primitives as-is?  Do you mean importing image data that's generated in the Python extension in a NetLogo model, or just generally from Python?  

 

Thanks.

 

-Jeremy

On Sunday, May 5, 2024 at 3:19:01PM UTC-5 Brady, Corey wrote:

Hello !

I was wondering if anyone has solved the problem of getting an image created in python to NetLogo’s import-xx primitives.

I imagine there are several possible approaches, but it seems like a common enough need that someone might have solved the problem already.

Any word of solutions?

Thanks!
-Corey

 

Corey Brady

Associate Professor, Mathematics Education and the Learning Sciences

corey...@smu.edu

Department of Teaching and Learning

Simmons School of Education and Human Development

Error! Filename not specified.

--
You received this message because you are subscribed to the Google Groups "netlogo-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-devel/573498f5-65f4-4312-81f8-41013412f1dbn%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "netlogo-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-deve...@googlegroups.com.

Brady, Corey

unread,
May 6, 2024, 2:01:43 PMMay 6
to Aaron Andre Brandes, Jeremy Baker, netlogo-devel

Hi Aaron –  Thanks for your reply!  I think/hope that the base64 option will be more performant, since I can avoid writing/reading to disk.  Thanks! -Corey

 

Corey Brady

Associate Professor, Mathematics Education and the Learning Sciences

corey...@smu.edu

Department of Teaching and Learning

Simmons School of Education and Human Development

A blue and red logo

Description automatically generated

 

Reply all
Reply to author
Forward
0 new messages