Geographic Information Systems Asked on November 29, 2021
I have external scripts in the JavaScript API for the purpose of keeping the functions needed for a mass export of data separate. For example, when I would like to reference these functions in other scripts in the main script, I would use something like:
var codes = require('users/mincej20/path:To/Script');
var cloud = require('users/mincej20/path:To/CloudScript);
The problem is that the JavaScript API is not well managed when it comes to exporting many different data tables. I have about 100,000 lakes that I need to create a .csv for, and it seems that the Python API method ee.batch.export
in a loop would suit this much better.
Am I able to reference my already-made function scripts in a Python Google Earth Engine API script similar to referencing an asset? If so, how would I do this? Or will I need to re-create these scripts locally in Python scripts?
Following @Kevin Reid accepted answer above,
gee-comunity tool is likely the tool to convert EE-Javascript to Python source code.
That gee-comunity tool mentioned Jiphy and stated that Jiphy is no longer supported. But Timothy ( creator of Jiphy ) has recently been pushing some commits to it.
just tried out Jiphy, it doesn't convert a .js to a syntax-correct .py file right away, we would definitely have to do some manual fix ( or make PRs to Jiphy ). In my case, the "var" keyword is still in the python file after conversion.
Answered by Ken Nguyen on November 29, 2021
You will need to translate the code into Python, yes.
Theoretically, if you have a function that meets the same kind of requirements as a function used in an ImageCollection.map
(no print
s or other side effects or client-side computation) then it would be possible to ask the Earth Engine API to transform ('encode'/'serialize') it into the form that it would be sent to the Earth Engine service as, and then load that data into your Python script so that it can use the same function in its own requests. However, the details of this serialization process are currently in flux and, as far as I am aware, there isn't actually a clean way to ask the Python client to use such a stored function expression as part of a larger operation written in Python.
If you feel like tinkering with the innards of the Earth Engine client code then you could certainly make it work, but that is probably not the fastest route to getting your job done unless you have a lot of JS you're starting with.
I also seem to recall hearing that another user wrote a tool to automatically translate EE JavaScript source code into Python source code, but I can't find a link to that easily.
Answered by Kevin Reid on November 29, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP