Use Cartopy Maps Offline - offline

I am trying to plot maps using Cartopy offline. I've found this post:
Location of stored offline data for cartopy
However, after changing cartopy.config['data_dir'] to 'C:/...' where the downloaded files are located, when I try to draw coastlines, it still wants to download the map.
cartopy.config['data_dir'] = '.../CartopyMaps'
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
The console says :
Downloading:
http://naciscdn.org/naturalearth/110m/physical/ne_110m_coastline.zip
However, I have ne_110m_coastline dbf, shp, and shx files in .../CartopyMaps/shapefiles/natural_earth/physical/
Why does Cartopy not see my local maps and how can I help it?

Try using the "pre_existing_data_dir" path instead of the "data_dir".
from os.path import expanduser
import cartopy
cartopy.config['pre_existing_data_dir'] = expanduser('~/cartopy-data/')

i had the similar problem and was confused for quite a while. after i downloaded the whole offline dataset and put them in the right dir, after runing the code
...
states = NaturalEarthFeature(category="cultural", scale="50m",
facecolor="none",
name="admin_1_states_provinces_shp")
...
the console still says:
Downloading:
...50m/cultural/ne_50m_admin_1_states_provinces_lines_shp.zip
however, i found there is a slight difference between the file ne_50m_admin_1_states_provinces_lines.shp i downloaded and the file ne_50m_admin_1_states_provinces_lines_shp.zip cartopy tries to acquire ('_shp').
therefore i changed the command into this and it worked:
states = NaturalEarthFeature(category="cultural", scale="50m",
facecolor="none",
name="admin_1_states_provinces")

Related

Gtk2 gui looks different after compiling with py2exe to make a exe file [duplicate]

I'm using Python 2.6 and PyGTK 2.22.6 from the all-in-one installer on Windows XP, trying to build a single-file executable (via py2exe) for my app.
My problem is that when I run my app as a script (ie. not built into an .exe file, just as a loose collection of .py files), it uses the native-looking Windows theme, but when I run the built exe I see the default GTK theme.
I know that this problem can be fixed by copying a bunch of files into the dist directory created by py2exe, but everything I've read involves manually copying the data, whereas I want this to be an automatic part of the build process. Furthermore, everything on the topic (including the FAQ) is out of date - PyGTK now keeps its files in C:\Python2x\Lib\site-packages\gtk-2.0\runtime\..., and just copying the lib and etc directories doesn't fix the problem.
My questions are:
I'd like to be able to programmatically find the GTK runtime data in setup.py rather than hard coding paths. How do I do this?
What are the minimal resources I need to include?
Update: I may have almost answered #2 by trial-and-error. For the "wimp" (ie. MS Windows) theme to work, I need the files from:
runtime\lib\gtk-2.0\2.10.0\engines\libwimp.dll
runtime\etc\gtk-2.0\gtkrc
runtime\share\icons\*
runtime\share\themes\MS-Windows
...without the runtime prefix, but otherwise with the same directory structure, sitting directly in the dist directory produced by py2exe. But where does the 2.10.0 come from, given that gtk.gtk_version is (2,22,0)?
Answering my own question here, but if anyone knows better feel free to answer too. Some of it seems quite fragile (eg. version numbers in paths), so comment or edit if you know a better way.
1. Finding the files
Firstly, I use this code to actually find the root of the GTK runtime. This is very specific to how you install the runtime, though, and could probably be improved with a number of checks for common locations:
#gtk file inclusion
import gtk
# The runtime dir is in the same directory as the module:
GTK_RUNTIME_DIR = os.path.join(
os.path.split(os.path.dirname(gtk.__file__))[0], "runtime")
assert os.path.exists(GTK_RUNTIME_DIR), "Cannot find GTK runtime data"
2. What files to include
This depends on (a) how much of a concern size is, and (b) the context of your application's deployment. By that I mean, are you deploying it to the whole wide world where anyone can have an arbitrary locale setting, or is it just for internal corporate use where you don't need translated stock strings?
If you want Windows theming, you'll need to include:
GTK_THEME_DEFAULT = os.path.join("share", "themes", "Default")
GTK_THEME_WINDOWS = os.path.join("share", "themes", "MS-Windows")
GTK_GTKRC_DIR = os.path.join("etc", "gtk-2.0")
GTK_GTKRC = "gtkrc"
GTK_WIMP_DIR = os.path.join("lib", "gtk-2.0", "2.10.0", "engines")
GTK_WIMP_DLL = "libwimp.dll"
If you want the Tango icons:
GTK_ICONS = os.path.join("share", "icons")
There is also localisation data (which I omit, but you might not want to):
GTK_LOCALE_DATA = os.path.join("share", "locale")
3. Piecing it together
Firstly, here's a function that walks the filesystem tree at a given point and produces output suitable for the data_files option.
def generate_data_files(prefix, tree, file_filter=None):
"""
Walk the filesystem starting at "prefix" + "tree", producing a list of files
suitable for the data_files option to setup(). The prefix will be omitted
from the path given to setup(). For example, if you have
C:\Python26\Lib\site-packages\gtk-2.0\runtime\etc\...
...and you want your "dist\" dir to contain "etc\..." as a subdirectory,
invoke the function as
generate_data_files(
r"C:\Python26\Lib\site-packages\gtk-2.0\runtime",
r"etc")
If, instead, you want it to contain "runtime\etc\..." use:
generate_data_files(
r"C:\Python26\Lib\site-packages\gtk-2.0",
r"runtime\etc")
Empty directories are omitted.
file_filter(root, fl) is an optional function called with a containing
directory and filename of each file. If it returns False, the file is
omitted from the results.
"""
data_files = []
for root, dirs, files in os.walk(os.path.join(prefix, tree)):
to_dir = os.path.relpath(root, prefix)
if file_filter is not None:
file_iter = (fl for fl in files if file_filter(root, fl))
else:
file_iter = files
data_files.append((to_dir, [os.path.join(root, fl) for fl in file_iter]))
non_empties = [(to, fro) for (to, fro) in data_files if fro]
return non_empties
So now you can call setup() like so:
setup(
# Other setup args here...
data_files = (
# Use the function above...
generate_data_files(GTK_RUNTIME_DIR, GTK_THEME_DEFAULT) +
generate_data_files(GTK_RUNTIME_DIR, GTK_THEME_WINDOWS) +
generate_data_files(GTK_RUNTIME_DIR, GTK_ICONS) +
# ...or include single files manually
[
(GTK_GTKRC_DIR, [
os.path.join(GTK_RUNTIME_DIR,
GTK_GTKRC_DIR,
GTK_GTKRC)
]),
(GTK_WIMP_DIR, [
os.path.join(
GTK_RUNTIME_DIR,
GTK_WIMP_DIR,
GTK_WIMP_DLL)
])
]
)
)

Save a downloaded file to storage folder on android

I've made an app that sends a file from my pc to my phone but I can't figure out how to save it to Internal storage or to a folder I can access. Can someone please help?
Looks like you need to use the FileSystem API. According to the documentation here, you need to first install it:
expo install expo-file-system
And of course, import it where needed:
import * as FileSystem from 'expo-file-system';
After which you should be able to use the method FileSystem.writeAsStringAsync and save the file to the FileSystem.documentDirectory:
FileSystem.writeAsStringAsync(
FileSystem.documentDirectory + 'filename.ext',
"some file contents or variable");
Look around the documentation about FileSystem - there are many useful methods and some examples that should help you.

RDKit drawing problem: fingerprint graph didn't show up using Draw.DrawRDKitBit command

I simply copied and pasted these code from rdkit (https://www.rdkit.org/docs/GettingStartedInPython.html#generating-images-of-fingerprint-bits)
I was expecting to generate graphs.
However, I got a long string.
from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem import Draw
mol = Chem.MolFromSmiles('c1ccccc1CC1CC1')
bi = {}
fp = AllChem.GetMorganFingerprintAsBitVect(mol, radius=2, bitInfo=bi)
mfp2_svg = Draw.DrawMorganBit(mol, 872, bi)
rdkbi = {}
rdkfp = Chem.RDKFingerprint(mol, maxPath=5, bitInfo=rdkbi)
rdk_svg = Draw.DrawRDKitBit(mol, 1553, rdkbi)
Does anyone know how to solve this problem?
Thanks a lot in advanced.
I am now using python 3.6 and latest rdkit version (2018.09.1.0) on Windows
To see depiction in IPython or Jupyter notebooks just add
from rdkit.Chem.Draw import IPythonConsole
The RDKit 'GettingStarted' did not use Ipython for the sample scripts, so the import of the IPythonConsole is never declared, allthough it is not new.
Look in the RDKit Blog or search for notebooks the web and you see it is a standard.

Modify how a tf.estimator.Estimator creates summaries for Tensorboard

I'm trying to find out how I can modify the way a custom TensorFlow estimator creates event files for Tensorboard. Currently, I have the impression that, by default, a summary (containing the values of all the things (like typically accuracy) I'm following with tf.summary.scalar(...) ) is created every 100 steps in my model directory. The names of the event files later used by tensorboard look like
events.out.tfevents.1531418661.nameofmycomputer.
I found a routine online to change this behaviour and create directories for each run with the date and time of the computation, but it uses TensorFlow basic APIs:
logdir = "tensorboard/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") + "/"
writer = tf.summary.FileWriter(logdir, sess.graph)
Is it possible to do something similar with a TF custom estimator?
It is possible to specify a directory for each evaluation run using name argument of the evaluate method of tf.estimator.Estimator e.g.:
estimator = tf.estimator.Estimator(
model_fn=model_fn,
model_dir=model_dir
)
eval_results = estimator.evaluate(
input_fn=eval_input_fn,
name=eval_name
)
The event files for this evaluation will be saved in the directory inside model_dir named "eval_" + eval_name.
Summary Writers are not needed for TensorFlow Estimators. The summary log of the model is written to the designated folder location using the model_dir attribute of tf.Estimator function when the tf.Estimator.fit() method is called.
In the example below, the selected directory to store the training logs is './my_model'.
tf.estimator.DNNClassifier(
model_fn,
model_dir='./my_model',
config=None,
params=None,
warm_start_from=None
)
Launch TensorBoard by running tensorboard --logdir=./my_model from the terminal.

Changes to django-appengine-toolkit for Windows

I want to use django-appengine-toolkit to provide symlinks needed by Appengine to include dependencies in the production runtime environment as discussed here. Unfortunately, I ran into an "AttributeError: 'module' object has no attribute 'symlink' " problem. A bit of research took me to this solution for apptrace, which indicated it was due to running the code on Windows. Adding this change with the arguments for
kdll.CreateSymbolicLinkA(srcname, dstname, 0)
changed to
kdll.CreateSymbolicLinkA(path, dest, 0)
at _utils.py at line 62 (as shown here) fixed the AttributeError and allowed the code to complete and autogenerate appengine_config.py with the necessary sys.path information.
Unfortunately, the dependencies were not populated under the 'libs' directory and I fear that my Python skills failed me at that point.
Can anyone identify what further code changes are needed to populate the dependencies?
since I really needed this ASAP, I ended up modifying the _utils.py file on appengine_toolkit:
def make_simlinks(dest_dir, paths_list):
"""
TODO docstrings
"""
for path in paths_list:
dest = os.path.join(dest_dir, os.path.split(path)[-1])
if os.path.exists(dest):
if os.path.islink(dest):
os.remove(dest)
else:
sys.stderr.write('A file or dir named {} already exists, skipping...\n'.format(dest))
continue
try:
os.symlink(path, dest)
except:
import shutil
sys.stdout.write('Couldn\'t create symlink copying files instead ...\n')
shutil.copytree(path, dest)
Basically if symlinking fails, I just copy everything. Not the cleanest hack but it works