[yt-svn] commit/yt: 16 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Mar 14 08:43:50 PDT 2018
16 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/d52d38dfc265/
Changeset: d52d38dfc265
User: Corentin Cadiou
Date: 2017-12-20 15:34:39+00:00
Summary: add scale
Affected #: 1 file
diff -r 5d32ce66cd07c8ef6a6506cc13e2f3d02f9335a7 -r d52d38dfc2654325aba84a02bd56bf25e01605c5 yt/visualization/mapserver/html/map_index.html
--- a/yt/visualization/mapserver/html/map_index.html
+++ b/yt/visualization/mapserver/html/map_index.html
@@ -49,6 +49,7 @@
});
L.control.layers(layer_group).addTo(map);
+ L.control.scale().addTo(map);
});
})
https://bitbucket.org/yt_analysis/yt/commits/dee8a398e2bd/
Changeset: dee8a398e2bd
User: Corentin Cadiou
Date: 2017-12-09 09:39:21+00:00
Summary: possibility to add custom definitions
Affected #: 1 file
diff -r d52d38dfc2654325aba84a02bd56bf25e01605c5 -r dee8a398e2bd66f09c7959b359b7a6eaf0343621 yt/frontends/ramses/definitions.py
--- a/yt/frontends/ramses/definitions.py
+++ b/yt/frontends/ramses/definitions.py
@@ -15,6 +15,8 @@
#-----------------------------------------------------------------------------
# These functions are RAMSES-specific
+from yt.config import ytcfg
+from yt.funcs import mylog
def ramses_header(hvals):
header = ( ('ncpu', 1, 'i'),
@@ -72,3 +74,10 @@
'dust_tracer': -4,
'gas_tracer': 0
}
+
+if ytcfg.has_section('ramses-families'):
+ for key in particle_families.keys():
+ val = ytcfg.getint('ramses-families', key, fallback=None)
+ if val is not None:
+ mylog.info('Changing family %s from %s to %s' % (key, particle_families[key], val))
+ particle_families[key] = val
https://bitbucket.org/yt_analysis/yt/commits/5ac19f5248d7/
Changeset: 5ac19f5248d7
User: Corentin Cadiou
Date: 2017-12-20 16:09:09+00:00
Summary: support for cmap
Affected #: 2 files
diff -r dee8a398e2bd66f09c7959b359b7a6eaf0343621 -r 5ac19f5248d77af2160f6c1c5956fe2a976cb0de yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -130,7 +130,7 @@
print("Changeset = %s" % vstring.strip())
print("---")
return vstring
-
+
def _get_girder_client():
try:
@@ -192,7 +192,7 @@
title=cls.subparser, dest=cls.subparser)
sp = _subparsers[cls.subparser]
for name in names:
- sc = sp.add_parser(name, description=cls.description,
+ sc = sp.add_parser(name, description=cls.description,
help=cls.description)
sc.set_defaults(func=cls.run)
for arg in cls.args:
@@ -637,7 +637,7 @@
password=password1, lastName=last_name, admin=False)
hub_url = ytcfg.get("yt", "hub_url")
req = requests.post(hub_url + "/user", data=data)
-
+
if req.ok:
headers = {'Girder-Token': req.json()['authToken']['token']}
else:
@@ -653,7 +653,7 @@
print("Storing API key in configuration file")
set_config("yt", "hub_api_key", apiKey)
-
+
print()
print("SUCCESS!")
print()
@@ -725,7 +725,7 @@
IPython.embed(config=cfg,user_ns=local_ns)
class YTMapserverCmd(YTCommand):
- args = ("proj", "field", "weight", "linear", "center", "width",
+ args = ("proj", "field", "weight", "linear", "center", "width", "cmap",
dict(short="-a", longname="--axis", action="store", type=int,
dest="axis", default=0, help="Axis"),
dict(short ="-o", longname="--host", action="store", type=str,
@@ -768,13 +768,13 @@
if args.projection:
p = ProjectionPlot(ds, args.axis, args.field, weight_field=args.weight, data_source=ad,
center=center, width=width)
- p.set_log(args.field, args.takelog)
else:
p = SlicePlot(ds, args.axis, args.field, data_source=ad,
center=center, width=width)
- p.set_log(args.field, args.takelog)
+ p.set_log('all', args.takelog)
+ p.set_cmap('all', args.cmap)
- PannableMapServer(p.data_source, args.field, args.takelog)
+ PannableMapServer(p.data_source, args.field, args.takelog, args.cmap)
try:
import bottle
except ImportError:
@@ -847,7 +847,7 @@
class YTHubStartNotebook(YTCommand):
args = (
dict(dest="folderId", default=ytcfg.get("yt", "hub_sandbox"),
- nargs="?",
+ nargs="?",
help="(Optional) Hub folder to mount inside the Notebook"),
)
description = \
@@ -1012,7 +1012,7 @@
)
description = \
"""
- Start the Jupyter Notebook locally.
+ Start the Jupyter Notebook locally.
"""
def __call__(self, args):
kwargs = {}
@@ -1334,7 +1334,7 @@
args = (
dict(short="filename", action="store", type=str,
help="The name of the file to download", nargs='?',
- default=''),
+ default=''),
dict(short="location", action="store", type=str, nargs='?',
help="The location in which to place the file, can be "
"\"supp_data_dir\", \"test_data_dir\", or any valid "
@@ -1348,8 +1348,8 @@
)
description = \
"""
- Download a file from http://yt-project.org/data and save it to a
- particular location. Files can be saved to the locations provided
+ Download a file from http://yt-project.org/data and save it to a
+ particular location. Files can be saved to the locations provided
by the "test_data_dir" or "supp_data_dir" configuration entries, or
any valid path to a location on disk.
"""
diff -r dee8a398e2bd66f09c7959b359b7a6eaf0343621 -r 5ac19f5248d77af2160f6c1c5956fe2a976cb0de yt/visualization/mapserver/pannable_map.py
--- a/yt/visualization/mapserver/pannable_map.py
+++ b/yt/visualization/mapserver/pannable_map.py
@@ -40,10 +40,11 @@
class PannableMapServer(object):
_widget_name = "pannable_map"
- def __init__(self, data, field, takelog, route_prefix = ""):
+ def __init__(self, data, field, takelog, cmap, route_prefix = ""):
self.data = data
self.ds = data.ds
self.field = field
+ self.cmap = cmap
bottle.route("%s/map/:field/:L/:x/:y.png" % route_prefix)(self.map)
bottle.route("%s/map/:field/:L/:x/:y.png" % route_prefix)(self.map)
@@ -70,6 +71,7 @@
def map(self, field, L, x, y):
if ',' in field:
field = tuple(field.split(','))
+ cmap = self.cmap
dd = 1.0 / (2.0**(int(L)))
relx = int(x) * dd
rely = int(y) * dd
@@ -97,9 +99,11 @@
if self.takelog:
cmi = np.log10(cmi)
cma = np.log10(cma)
- to_plot = apply_colormap(np.log10(frb[field]), color_bounds = (cmi, cma))
+ to_plot = apply_colormap(np.log10(frb[field]), color_bounds = (cmi, cma),
+ cmap_name=cmap)
else:
- to_plot = apply_colormap(frb[field], color_bounds = (cmi, cma))
+ to_plot = apply_colormap(frb[field], color_bounds = (cmi, cma),
+ cmap_name=cmap)
rv = write_png_to_string(to_plot)
return rv
https://bitbucket.org/yt_analysis/yt/commits/5ec0eb71d9cd/
Changeset: 5ec0eb71d9cd
User: Corentin Cadiou
Date: 2017-12-20 16:13:39+00:00
Summary: add possibility to query specific field via URL
Affected #: 1 file
diff -r 5ac19f5248d77af2160f6c1c5956fe2a976cb0de -r 5ec0eb71d9cdf9102633b79a292d9fc84de25cea yt/visualization/mapserver/pannable_map.py
--- a/yt/visualization/mapserver/pannable_map.py
+++ b/yt/visualization/mapserver/pannable_map.py
@@ -49,6 +49,7 @@
bottle.route("%s/map/:field/:L/:x/:y.png" % route_prefix)(self.map)
bottle.route("%s/map/:field/:L/:x/:y.png" % route_prefix)(self.map)
bottle.route("%s/" % route_prefix)(self.index)
+ bottle.route("%s/:field" % route_prefix)(self.index)
bottle.route("%s/index.html" % route_prefix)(self.index)
bottle.route("%s/list" % route_prefix, "GET")(self.list_fields)
# This is a double-check, since we do not always mandate this for
@@ -108,7 +109,9 @@
rv = write_png_to_string(to_plot)
return rv
- def index(self):
+ def index(self, field=None):
+ if field is not None:
+ self.field = field
return bottle.static_file("map_index.html",
root=os.path.join(local_dir, "html"))
https://bitbucket.org/yt_analysis/yt/commits/02f7d6388d97/
Changeset: 02f7d6388d97
User: Corentin Cadiou
Date: 2018-01-13 13:13:22+00:00
Summary: full screen by default
Affected #: 1 file
diff -r 5ec0eb71d9cdf9102633b79a292d9fc84de25cea -r 02f7d6388d976e581b5072392881d598d7014164 yt/visualization/mapserver/html/map_index.html
--- a/yt/visualization/mapserver/html/map_index.html
+++ b/yt/visualization/mapserver/html/map_index.html
@@ -54,8 +54,13 @@
})
</script>
-</HEAD>
-<BODY>
- <DIV id="map" style="height: 512px; width: 512px;"></div>
-</BODY>
-</HTML>
+<style>
+body {
+ margin: 0;
+}
+</style>
+</head>
+<body>
+ <div id="map" style="height: 500px; width: 500px;"></div>
+</body>
+</html>
https://bitbucket.org/yt_analysis/yt/commits/c89a571a7057/
Changeset: c89a571a7057
User: Corentin Cadiou
Date: 2018-01-13 13:14:00+00:00
Summary: Improve map
Affected #: 2 files
diff -r 02f7d6388d976e581b5072392881d598d7014164 -r c89a571a705750174fc53446b92e20090bdade7a yt/visualization/mapserver/html/map_index.html
--- a/yt/visualization/mapserver/html/map_index.html
+++ b/yt/visualization/mapserver/html/map_index.html
@@ -6,52 +6,57 @@
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.2.0/leaflet.css" /><script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script><script type="text/javascript">
- $(document).ready(function() {
- // initialize the map on the "map" div with a given center and zoom
+function setFullScreen () {
$("#map").width($(window).width());
$("#map").height($(window).height());
-
- $.getJSON('/list', function(data) {
- var layers = [],
- layer_groups = [],
- default_layer = [null];
- var layer_group = {};
+}
- // Loop over field types
- for (var type in data['data']) {
- var dtype = data['data'][type];
+$(document).ready(function() {
+ // Initialize to full screen
+ setFullScreen();
+ // initialize the map on the "map" div with a given center and zoom
+ $.getJSON('/list', function(data) {
+ var layers = [],
+ layer_groups = [],
+ default_layer = [null];
+ var layer_group = {};
- // Loop over fields of given type
- for (var field in dtype) {
- var loc = dtype[field]
- var field = loc[0],
- active = loc[1],
- url = 'map/' + field[0] + ',' + field[1] + '/{z}/{x}/{y}.png';
+ // Loop over field types
+ for (var type in data['data']) {
+ var dtype = data['data'][type];
- // Create new layer
- var layer = new L.TileLayer(url, {id: 'MapID', maxzoom: 18});
+ // Loop over fields of given type
+ for (var field in dtype) {
+ var loc = dtype[field]
+ var field = loc[0],
+ active = loc[1],
+ url = 'map/' + field[0] + ',' + field[1] + '/{z}/{x}/{y}.png';
- // Create readable name
- human_name = field.join(' ');
+ // Create new layer
+ var layer = new L.TileLayer(url, {id: 'MapID', maxzoom: 18});
+
+ // Create readable name
+ human_name = field.join(' ');
- // Store it
- layers.push(layer);
- layer_group[human_name] = layer;
- if (active) {
- default_layer[0] = layer;
- }
- }
+ // Store it
+ layers.push(layer);
+ layer_group[human_name] = layer;
+ if (active) {
+ default_layer[0] = layer;
}
- var map = new L.Map('map', {
- center: new L.LatLng(0.0, 0.0),
- zoom: 2,
- layers: default_layer
- });
+ }
+ }
+ var map = new L.Map('map', {
+ center: new L.LatLng(0., 0.),
+ zoom: 2,
+ layers: default_layer,
+ crs: L.CRS.Simple
+ });
+ L.control.layers(layer_group).addTo(map);
+ });
- L.control.layers(layer_group).addTo(map);
- L.control.scale().addTo(map);
- });
-
+ // Resize map automatically
+ $(window).resize(setFullScreen);
})
</script><style>
diff -r 02f7d6388d976e581b5072392881d598d7014164 -r c89a571a705750174fc53446b92e20090bdade7a yt/visualization/mapserver/pannable_map.py
--- a/yt/visualization/mapserver/pannable_map.py
+++ b/yt/visualization/mapserver/pannable_map.py
@@ -143,4 +143,7 @@
active = f[1] == self.field
d[ftype].append((f, active))
- return dict(data=d, active=self.field)
+ # TODO: get projection domain instead of dataset width
+ w = self.ds.domain_width.in_units('kpc').value[0]
+
+ return dict(data=d, width=w, active=self.field)
https://bitbucket.org/yt_analysis/yt/commits/7f7dc0a768dc/
Changeset: 7f7dc0a768dc
User: Corentin Cadiou
Date: 2018-01-13 14:22:35+00:00
Summary: Add seach widget
This helps filtering out when there are two many layers
Affected #: 1 file
diff -r c89a571a705750174fc53446b92e20090bdade7a -r 7f7dc0a768dc21b63c7c46bff894febc80e7adea yt/visualization/mapserver/html/map_index.html
--- a/yt/visualization/mapserver/html/map_index.html
+++ b/yt/visualization/mapserver/html/map_index.html
@@ -11,14 +11,52 @@
$("#map").height($(window).height());
}
+var SearchWidget = function () {
+ var obj = {
+ filter: function (searchStrs) {
+ console.log("filtering on " + searchStrs);
+ this._selector.each(function(i, el) {
+ var val = $(el).text();
+ // Search
+ var matched = searchStrs.map((str) => {
+ return val.indexOf(str) !== -1;
+ }).reduce((reduced, result) => {
+ return reduced && result;
+ }, true);
+ if (matched) {
+ $(el).show();
+ } else {
+ $(el).hide();
+ }
+ });
+ },
+ init: function () {
+ var self = this;
+
+ this._selector = $('.leaflet-control-layers-list label');
+
+ $('#filter input').keyup(function(ev) {
+ const val = $(this).val();
+ self.filter(val.split(" "));
+ });
+
+ // Move search input in the DOM
+ $('leaflet-control-layers-base').prepend($('#filter'));
+ $('#filter').show();
+ },
+ _selector: null
+ };
+ obj.init();
+ return obj;
+};
$(document).ready(function() {
// Initialize to full screen
setFullScreen();
// initialize the map on the "map" div with a given center and zoom
$.getJSON('/list', function(data) {
var layers = [],
- layer_groups = [],
- default_layer = [null];
+ layer_groups = [],
+ default_layer = [null];
var layer_group = {};
// Loop over field types
@@ -27,23 +65,23 @@
// Loop over fields of given type
for (var field in dtype) {
- var loc = dtype[field]
- var field = loc[0],
- active = loc[1],
- url = 'map/' + field[0] + ',' + field[1] + '/{z}/{x}/{y}.png';
+ var loc = dtype[field]
+ var field = loc[0],
+ active = loc[1],
+ url = 'map/' + field[0] + ',' + field[1] + '/{z}/{x}/{y}.png';
- // Create new layer
- var layer = new L.TileLayer(url, {id: 'MapID', maxzoom: 18});
+ // Create new layer
+ var layer = new L.TileLayer(url, {id: 'MapID', maxzoom: 18});
- // Create readable name
- human_name = field.join(' ');
+ // Create readable name
+ human_name = field.join(' ');
- // Store it
- layers.push(layer);
- layer_group[human_name] = layer;
- if (active) {
- default_layer[0] = layer;
- }
+ // Store it
+ layers.push(layer);
+ layer_group[human_name] = layer;
+ if (active) {
+ default_layer[0] = layer;
+ }
}
}
var map = new L.Map('map', {
@@ -53,19 +91,31 @@
crs: L.CRS.Simple
});
L.control.layers(layer_group).addTo(map);
+
+ // Search widget
+ var search = SearchWidget();
});
// Resize map automatically
$(window).resize(setFullScreen);
-})
+});
+
</script><style>
body {
margin: 0;
}
+#filter {
+ position: absolute;
+ bottom: 0;
+ left:0;
+ z-index: 1000;
+ display: none;
+}
</style></head><body><div id="map" style="height: 500px; width: 500px;"></div>
+ <div id="filter""><input type="text" placeholder="Filter out..."></div></body></html>
https://bitbucket.org/yt_analysis/yt/commits/3d5a89bd43d3/
Changeset: 3d5a89bd43d3
User: Corentin Cadiou
Date: 2018-01-13 15:56:54+00:00
Summary: automatic generation of search field
Affected #: 1 file
diff -r 7f7dc0a768dc21b63c7c46bff894febc80e7adea -r 3d5a89bd43d3ca7e2ed28f4f0475f9019e3f7f92 yt/visualization/mapserver/html/map_index.html
--- a/yt/visualization/mapserver/html/map_index.html
+++ b/yt/visualization/mapserver/html/map_index.html
@@ -33,16 +33,20 @@
init: function () {
var self = this;
- this._selector = $('.leaflet-control-layers-list label');
+ var searchElement = $('<div id="filter"><input type="text" placeholder="Filter layers"></div>');
+ var selector = $('.leaflet-control-layers-list label');
+
+ this._selector = selector;
+ // Add input in the DOM
+ selector.first().parent().prepend(searchElement);
+
+ // Listen to keyboard input
$('#filter input').keyup(function(ev) {
const val = $(this).val();
self.filter(val.split(" "));
});
- // Move search input in the DOM
- $('leaflet-control-layers-base').prepend($('#filter'));
- $('#filter').show();
},
_selector: null
};
@@ -105,17 +109,9 @@
body {
margin: 0;
}
-#filter {
- position: absolute;
- bottom: 0;
- left:0;
- z-index: 1000;
- display: none;
-}
</style></head><body><div id="map" style="height: 500px; width: 500px;"></div>
- <div id="filter""><input type="text" placeholder="Filter out..."></div></body></html>
https://bitbucket.org/yt_analysis/yt/commits/7c08d478ca73/
Changeset: 7c08d478ca73
User: Corentin Cadiou
Date: 2018-01-13 15:59:29+00:00
Summary: go back to default CRS
Affected #: 1 file
diff -r 3d5a89bd43d3ca7e2ed28f4f0475f9019e3f7f92 -r 7c08d478ca73ed37cd95518a5fb3bac59f694d3c yt/visualization/mapserver/html/map_index.html
--- a/yt/visualization/mapserver/html/map_index.html
+++ b/yt/visualization/mapserver/html/map_index.html
@@ -92,7 +92,6 @@
center: new L.LatLng(0., 0.),
zoom: 2,
layers: default_layer,
- crs: L.CRS.Simple
});
L.control.layers(layer_group).addTo(map);
https://bitbucket.org/yt_analysis/yt/commits/e8dd7b3c7ca2/
Changeset: e8dd7b3c7ca2
User: Corentin Cadiou
Date: 2018-01-13 16:05:16+00:00
Summary: Revert "possibility to add custom definitions"
This reverts commit fcff17fa4fe0a8ba3faaa42ca4c2a63c4e248339.
Affected #: 1 file
diff -r 7c08d478ca73ed37cd95518a5fb3bac59f694d3c -r e8dd7b3c7ca250fc116aa0b3b9526c6573d5c40c yt/frontends/ramses/definitions.py
--- a/yt/frontends/ramses/definitions.py
+++ b/yt/frontends/ramses/definitions.py
@@ -15,8 +15,6 @@
#-----------------------------------------------------------------------------
# These functions are RAMSES-specific
-from yt.config import ytcfg
-from yt.funcs import mylog
def ramses_header(hvals):
header = ( ('ncpu', 1, 'i'),
@@ -74,10 +72,3 @@
'dust_tracer': -4,
'gas_tracer': 0
}
-
-if ytcfg.has_section('ramses-families'):
- for key in particle_families.keys():
- val = ytcfg.getint('ramses-families', key, fallback=None)
- if val is not None:
- mylog.info('Changing family %s from %s to %s' % (key, particle_families[key], val))
- particle_families[key] = val
https://bitbucket.org/yt_analysis/yt/commits/77864ac346a5/
Changeset: 77864ac346a5
User: Corentin Cadiou
Date: 2018-01-13 16:09:01+00:00
Summary: remove useless lines
Affected #: 1 file
diff -r e8dd7b3c7ca250fc116aa0b3b9526c6573d5c40c -r 77864ac346a53ec210546984480a230090e41964 yt/visualization/mapserver/pannable_map.py
--- a/yt/visualization/mapserver/pannable_map.py
+++ b/yt/visualization/mapserver/pannable_map.py
@@ -143,7 +143,4 @@
active = f[1] == self.field
d[ftype].append((f, active))
- # TODO: get projection domain instead of dataset width
- w = self.ds.domain_width.in_units('kpc').value[0]
-
- return dict(data=d, width=w, active=self.field)
+ return dict(data=d, active=self.field)
https://bitbucket.org/yt_analysis/yt/commits/4a90e430efc3/
Changeset: 4a90e430efc3
User: Corentin Cadiou
Date: 2018-01-18 17:07:11+00:00
Summary: Add support for domain width
Affected #: 4 files
diff -r 77864ac346a53ec210546984480a230090e41964 -r 4a90e430efc3ee4e7ad6779cfc20364521a1ceb5 yt/visualization/mapserver/html/Leaflet.Coordinates-0.1.5.css
--- /dev/null
+++ b/yt/visualization/mapserver/html/Leaflet.Coordinates-0.1.5.css
@@ -0,0 +1,1 @@
+.leaflet-control-coordinates{background-color:#D8D8D8;background-color:rgba(255,255,255,.8);cursor:pointer}.leaflet-control-coordinates,.leaflet-control-coordinates .uiElement input{-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}.leaflet-control-coordinates .uiElement{margin:4px}.leaflet-control-coordinates .uiElement .labelFirst{margin-right:4px}.leaflet-control-coordinates .uiHidden{display:none}.leaflet-control-coordinates .uiElement.label{color:inherit;font-weight:inherit;font-size:inherit;padding:0;display:inherit}
\ No newline at end of file
diff -r 77864ac346a53ec210546984480a230090e41964 -r 4a90e430efc3ee4e7ad6779cfc20364521a1ceb5 yt/visualization/mapserver/html/Leaflet.Coordinates-0.1.5.src.js
--- /dev/null
+++ b/yt/visualization/mapserver/html/Leaflet.Coordinates-0.1.5.src.js
@@ -0,0 +1,350 @@
+
+
+/*
+ * L.Control.Coordinates is used for displaying current mouse coordinates on the map.
+ */
+
+L.Control.Coordinates = L.Control.extend({
+ options: {
+ position: 'bottomright',
+ //decimals used if not using DMS or labelFormatter functions
+ decimals: 4,
+ //decimalseperator used if not using DMS or labelFormatter functions
+ decimalSeperator: ".",
+ //label templates for usage if no labelFormatter function is defined
+ labelTemplateLat: "Lat: {y}",
+ labelTemplateLng: "Lng: {x}",
+ //label formatter functions
+ labelFormatterLat: undefined,
+ labelFormatterLng: undefined,
+ //switch on/off input fields on click
+ enableUserInput: true,
+ //use Degree-Minute-Second
+ useDMS: false,
+ //if true lat-lng instead of lng-lat label ordering is used
+ useLatLngOrder: false,
+ //if true user given coordinates are centered directly
+ centerUserCoordinates: false,
+ //leaflet marker type
+ markerType: L.marker,
+ //leaflet marker properties
+ markerProps: {}
+ },
+
+ onAdd: function(map) {
+ this._map = map;
+
+ var className = 'leaflet-control-coordinates',
+ container = this._container = L.DomUtil.create('div', className),
+ options = this.options;
+
+ //label containers
+ this._labelcontainer = L.DomUtil.create("div", "uiElement label", container);
+ this._label = L.DomUtil.create("span", "labelFirst", this._labelcontainer);
+
+
+ //input containers
+ this._inputcontainer = L.DomUtil.create("div", "uiElement input uiHidden", container);
+ var xSpan, ySpan;
+ if (options.useLatLngOrder) {
+ ySpan = L.DomUtil.create("span", "", this._inputcontainer);
+ this._inputY = this._createInput("inputY", this._inputcontainer);
+ xSpan = L.DomUtil.create("span", "", this._inputcontainer);
+ this._inputX = this._createInput("inputX", this._inputcontainer);
+ } else {
+ xSpan = L.DomUtil.create("span", "", this._inputcontainer);
+ this._inputX = this._createInput("inputX", this._inputcontainer);
+ ySpan = L.DomUtil.create("span", "", this._inputcontainer);
+ this._inputY = this._createInput("inputY", this._inputcontainer);
+ }
+ xSpan.innerHTML = options.labelTemplateLng.replace("{x}", "");
+ ySpan.innerHTML = options.labelTemplateLat.replace("{y}", "");
+
+ L.DomEvent.on(this._inputX, 'keyup', this._handleKeypress, this);
+ L.DomEvent.on(this._inputY, 'keyup', this._handleKeypress, this);
+
+ //connect to mouseevents
+ map.on("mousemove", this._update, this);
+ map.on('dragstart', this.collapse, this);
+
+ map.whenReady(this._update, this);
+
+ this._showsCoordinates = true;
+ //wether or not to show inputs on click
+ if (options.enableUserInput) {
+ L.DomEvent.addListener(this._container, "click", this._switchUI, this);
+ }
+
+ return container;
+ },
+
+ /**
+ * Creates an input HTML element in given container with given classname
+ */
+ _createInput: function(classname, container) {
+ var input = L.DomUtil.create("input", classname, container);
+ input.type = "text";
+ L.DomEvent.disableClickPropagation(input);
+ return input;
+ },
+
+ _clearMarker: function() {
+ this._map.removeLayer(this._marker);
+ },
+
+ /**
+ * Called onkeyup of input fields
+ */
+ _handleKeypress: function(e) {
+ switch (e.keyCode) {
+ case 27: //Esc
+ this.collapse();
+ break;
+ case 13: //Enter
+ this._handleSubmit();
+ this.collapse();
+ break;
+ default: //All keys
+ this._handleSubmit();
+ break;
+ }
+ },
+
+ /**
+ * Called on each keyup except ESC
+ */
+ _handleSubmit: function() {
+ var x = L.NumberFormatter.createValidNumber(this._inputX.value, this.options.decimalSeperator);
+ var y = L.NumberFormatter.createValidNumber(this._inputY.value, this.options.decimalSeperator);
+ if (x !== undefined && y !== undefined) {
+ var marker = this._marker;
+ if (!marker) {
+ marker = this._marker = this._createNewMarker();
+ marker.on("click", this._clearMarker, this);
+ }
+ var ll = new L.LatLng(y, x);
+ marker.setLatLng(ll);
+ marker.addTo(this._map);
+ if (this.options.centerUserCoordinates) {
+ this._map.setView(ll, this._map.getZoom());
+ }
+ }
+ },
+
+ /**
+ * Shows inputs fields
+ */
+ expand: function() {
+ this._showsCoordinates = false;
+
+ this._map.off("mousemove", this._update, this);
+
+ L.DomEvent.addListener(this._container, "mousemove", L.DomEvent.stop);
+ L.DomEvent.removeListener(this._container, "click", this._switchUI, this);
+
+ L.DomUtil.addClass(this._labelcontainer, "uiHidden");
+ L.DomUtil.removeClass(this._inputcontainer, "uiHidden");
+ },
+
+ /**
+ * Creates the label according to given options and formatters
+ */
+ _createCoordinateLabel: function(ll) {
+ var opts = this.options,
+ x, y;
+ if (opts.customLabelFcn) {
+ return opts.customLabelFcn(ll, opts);
+ }
+ if (opts.labelFormatterLng) {
+ x = opts.labelFormatterLng(ll.lng);
+ } else {
+ x = L.Util.template(opts.labelTemplateLng, {
+ x: this._getNumber(ll.lng, opts)
+ });
+ }
+ if (opts.labelFormatterLat) {
+ y = opts.labelFormatterLat(ll.lat);
+ } else {
+ y = L.Util.template(opts.labelTemplateLat, {
+ y: this._getNumber(ll.lat, opts)
+ });
+ }
+ if (opts.useLatLngOrder) {
+ return y + " " + x;
+ }
+ return x + " " + y;
+ },
+
+ /**
+ * Returns a Number according to options (DMS or decimal)
+ */
+ _getNumber: function(n, opts) {
+ var res;
+ if (opts.useDMS) {
+ res = L.NumberFormatter.toDMS(n);
+ } else {
+ res = L.NumberFormatter.round(n, opts.decimals, opts.decimalSeperator);
+ }
+ return res;
+ },
+
+ /**
+ * Shows coordinate labels after user input has ended. Also
+ * displays a marker with popup at the last input position.
+ */
+ collapse: function() {
+ if (!this._showsCoordinates) {
+ this._map.on("mousemove", this._update, this);
+ this._showsCoordinates = true;
+ var opts = this.options;
+ L.DomEvent.addListener(this._container, "click", this._switchUI, this);
+ L.DomEvent.removeListener(this._container, "mousemove", L.DomEvent.stop);
+
+ L.DomUtil.addClass(this._inputcontainer, "uiHidden");
+ L.DomUtil.removeClass(this._labelcontainer, "uiHidden");
+
+ if (this._marker) {
+ var m = this._createNewMarker(),
+ ll = this._marker.getLatLng();
+ m.setLatLng(ll);
+
+ var container = L.DomUtil.create("div", "");
+ var label = L.DomUtil.create("div", "", container);
+ label.innerHTML = this._ordinateLabel(ll);
+
+ var close = L.DomUtil.create("a", "", container);
+ close.innerHTML = "Remove";
+ close.href = "#";
+ var stop = L.DomEvent.stopPropagation;
+
+ L.DomEvent
+ .on(close, 'click', stop)
+ .on(close, 'mousedown', stop)
+ .on(close, 'dblclick', stop)
+ .on(close, 'click', L.DomEvent.preventDefault)
+ .on(close, 'click', function() {
+ this._map.removeLayer(m);
+ }, this);
+
+ m.bindPopup(container);
+ m.addTo(this._map);
+ this._map.removeLayer(this._marker);
+ this._marker = null;
+ }
+ }
+ },
+
+ /**
+ * Click callback for UI
+ */
+ _switchUI: function(evt) {
+ L.DomEvent.stop(evt);
+ L.DomEvent.stopPropagation(evt);
+ L.DomEvent.preventDefault(evt);
+ if (this._showsCoordinates) {
+ //show textfields
+ this.expand();
+ } else {
+ //show coordinates
+ this.collapse();
+ }
+ },
+
+ onRemove: function(map) {
+ map.off("mousemove", this._update, this);
+ },
+
+ /**
+ * Mousemove callback function updating labels and input elements
+ */
+ _update: function(evt) {
+ var pos = evt.latlng,
+ opts = this.options;
+ if (pos) {
+ pos = pos.wrap();
+ this._currentPos = pos;
+ this._inputY.value = L.NumberFormatter.round(pos.lat, opts.decimals, opts.decimalSeperator);
+ this._inputX.value = L.NumberFormatter.round(pos.lng, opts.decimals, opts.decimalSeperator);
+ this._label.innerHTML = this._createCoordinateLabel(pos);
+ }
+ },
+
+ _createNewMarker: function() {
+ return this.options.markerType(null, this.options.markerProps);
+ }
+
+});
+
+//constructor registration
+L.control.coordinates = function(options) {
+ return new L.Control.Coordinates(options);
+};
+
+//map init hook
+L.Map.mergeOptions({
+ coordinateControl: false
+});
+
+L.Map.addInitHook(function() {
+ if (this.options.coordinateControl) {
+ this.coordinateControl = new L.Control.Coordinates();
+ this.addControl(this.coordinateControl);
+ }
+});
+L.NumberFormatter = {
+ round: function(num, dec, sep) {
+ var res = L.Util.formatNum(num, dec) + "",
+ numbers = res.split(".");
+ if (numbers[1]) {
+ var d = dec - numbers[1].length;
+ for (; d > 0; d--) {
+ numbers[1] += "0";
+ }
+ res = numbers.join(sep || ".");
+ }
+ return res;
+ },
+
+ toDMS: function(deg) {
+ var d = Math.floor(Math.abs(deg));
+ var minfloat = (Math.abs(deg) - d) * 60;
+ var m = Math.floor(minfloat);
+ var secfloat = (minfloat - m) * 60;
+ var s = Math.round(secfloat);
+ if (s == 60) {
+ m++;
+ s = "00";
+ }
+ if (m == 60) {
+ d++;
+ m = "00";
+ }
+ if (s < 10) {
+ s = "0" + s;
+ }
+ if (m < 10) {
+ m = "0" + m;
+ }
+ var dir = "";
+ if (deg < 0) {
+ dir = "-";
+ }
+ return ("" + dir + d + "° " + m + "' " + s + "''");
+ },
+
+ createValidNumber: function(num, sep) {
+ if (num && num.length > 0) {
+ var numbers = num.split(sep || ".");
+ try {
+ var numRes = Number(numbers.join("."));
+ if (isNaN(numRes)) {
+ return undefined;
+ }
+ return numRes;
+ } catch (e) {
+ return undefined;
+ }
+ }
+ return undefined;
+ }
+};
diff -r 77864ac346a53ec210546984480a230090e41964 -r 4a90e430efc3ee4e7ad6779cfc20364521a1ceb5 yt/visualization/mapserver/html/map_index.html
--- a/yt/visualization/mapserver/html/map_index.html
+++ b/yt/visualization/mapserver/html/map_index.html
@@ -5,6 +5,10 @@
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.2.0/leaflet.js"></script><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.2.0/leaflet.css" /><script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
+
+<script type="text/javascript" src="static/Leaflet.Coordinates-0.1.5.src.js"></script>
+<link rel="stylesheet" href="static/Leaflet.Coordinates-0.1.5.css" />
+
<script type="text/javascript">
function setFullScreen () {
$("#map").width($(window).width());
@@ -89,12 +93,34 @@
}
}
var map = new L.Map('map', {
- center: new L.LatLng(0., 0.),
- zoom: 2,
- layers: default_layer,
+ crs: L.CRS.Simple,
+ center: new L.LatLng(-128, -128),
+ zoom: 4,
+ layers: default_layer
});
+
L.control.layers(layer_group).addTo(map);
+ var unit = data['unit'], px2unit = data['px2unit'], decimals = 2;
+ var fmt = (n) => {
+ return L.NumberFormatter.round(n, decimals, ".")
+ };
+ L.control.coordinates({
+ position: "bottomleft", //optional default "bootomright"
+ decimals: 2, //optional default 4
+ decimalSeperator: ".", //optional default "."
+ // labelTemplateLat: "x: {y}" + unit, //optional default "Lat: {y}"
+ // labelTemplateLng: "y: {x}" + unit, //optional default "Lng: {x}"
+ enableUserInput: true, //optional default true
+ useDMS: false, //optional default false
+ useLatLngOrder: true, //ordering of labels, default false-> lng-lat
+ markerType: L.marker, //optional default L.marker
+ // markerProps: {}, //optional default {},
+ labelFormatterLng : (lng) => { return fmt((lng+128)/px2unit)+" "+unit }, //optional default none,
+ labelFormatterLat : (lat) => { return fmt((lat+128)/px2unit)+" "+unit }, //optional default none
+ }).addTo(map);
+
+
// Search widget
var search = SearchWidget();
});
diff -r 77864ac346a53ec210546984480a230090e41964 -r 4a90e430efc3ee4e7ad6779cfc20364521a1ceb5 yt/visualization/mapserver/pannable_map.py
--- a/yt/visualization/mapserver/pannable_map.py
+++ b/yt/visualization/mapserver/pannable_map.py
@@ -55,11 +55,19 @@
# This is a double-check, since we do not always mandate this for
# slices:
self.data[self.field] = self.data[self.field].astype("float64")
- bottle.route(":path#.+#", "GET")(self.static)
+ bottle.route("%s/static/:path" % route_prefix, "GET")(self.static)
self.takelog = takelog
self._lock = False
+ for unit in ['Gpc', 'Mpc', 'kpc', 'pc']:
+ v = self.ds.domain_width[0].in_units(unit).value
+ if v > 1:
+ break
+ self.unit = unit
+ self.px2unit = self.ds.domain_width[0].in_units(unit).value / 256
+
+
def lock(self):
import time
while self._lock:
@@ -83,8 +91,9 @@
yr = yl + dd*DW[1]
try:
self.lock()
+ w = 256 # pixels
data = self.data[field]
- frb = FixedResolutionBuffer(self.data, (xl, xr, yl, yr), (256, 256))
+ frb = FixedResolutionBuffer(self.data, (xl, xr, yl, yr), (w, w))
cmi, cma = get_color_bounds(self.data['px'], self.data['py'],
self.data['pdx'], self.data['pdy'],
data,
@@ -143,4 +152,5 @@
active = f[1] == self.field
d[ftype].append((f, active))
- return dict(data=d, active=self.field)
+ print(self.px2unit, self.unit)
+ return dict(data=d, px2unit=self.px2unit, unit=self.unit, active=self.field)
https://bitbucket.org/yt_analysis/yt/commits/3ba490843d84/
Changeset: 3ba490843d84
User: Corentin Cadiou
Date: 2018-01-18 17:10:47+00:00
Summary: add credit
Affected #: 2 files
diff -r 4a90e430efc3ee4e7ad6779cfc20364521a1ceb5 -r 3ba490843d843949dfc6be4967dd5c0ef44fdc67 yt/visualization/mapserver/html/Leaflet.Coordinates-0.1.5.css
--- a/yt/visualization/mapserver/html/Leaflet.Coordinates-0.1.5.css
+++ b/yt/visualization/mapserver/html/Leaflet.Coordinates-0.1.5.css
@@ -1,1 +1,6 @@
-.leaflet-control-coordinates{background-color:#D8D8D8;background-color:rgba(255,255,255,.8);cursor:pointer}.leaflet-control-coordinates,.leaflet-control-coordinates .uiElement input{-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}.leaflet-control-coordinates .uiElement{margin:4px}.leaflet-control-coordinates .uiElement .labelFirst{margin-right:4px}.leaflet-control-coordinates .uiHidden{display:none}.leaflet-control-coordinates .uiElement.label{color:inherit;font-weight:inherit;font-size:inherit;padding:0;display:inherit}
\ No newline at end of file
+/*
+ * From https://github.com/MrMufflon/Leaflet.Coordinates
+ *
+ * Fixed small issue about formatting by C. Cadiou (cphyc))
+ */
+.leaflet-control-coordinates{background-color:#D8D8D8;background-color:rgba(255,255,255,.8);cursor:pointer}.leaflet-control-coordinates,.leaflet-control-coordinates .uiElement input{-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}.leaflet-control-coordinates .uiElement{margin:4px}.leaflet-control-coordinates .uiElement .labelFirst{margin-right:4px}.leaflet-control-coordinates .uiHidden{display:none}.leaflet-control-coordinates .uiElement.label{color:inherit;font-weight:inherit;font-size:inherit;padding:0;display:inherit}
diff -r 4a90e430efc3ee4e7ad6779cfc20364521a1ceb5 -r 3ba490843d843949dfc6be4967dd5c0ef44fdc67 yt/visualization/mapserver/html/Leaflet.Coordinates-0.1.5.src.js
--- a/yt/visualization/mapserver/html/Leaflet.Coordinates-0.1.5.src.js
+++ b/yt/visualization/mapserver/html/Leaflet.Coordinates-0.1.5.src.js
@@ -1,4 +1,8 @@
-
+/*
+ * From https://github.com/MrMufflon/Leaflet.Coordinates
+ *
+ * Fixed small issue about formatting by C. Cadiou (cphyc))
+ */
/*
* L.Control.Coordinates is used for displaying current mouse coordinates on the map.
https://bitbucket.org/yt_analysis/yt/commits/43557bdd0604/
Changeset: 43557bdd0604
User: Corentin Cadiou
Date: 2018-01-18 17:10:55+00:00
Summary: move to own js
Affected #: 2 files
diff -r 3ba490843d843949dfc6be4967dd5c0ef44fdc67 -r 43557bdd0604b64a69c95990e1042e3d08c779da yt/visualization/mapserver/html/map.js
--- /dev/null
+++ b/yt/visualization/mapserver/html/map.js
@@ -0,0 +1,114 @@
+function setFullScreen () {
+ $("#map").width($(window).width());
+ $("#map").height($(window).height());
+}
+
+var SearchWidget = function () {
+ var obj = {
+ filter: function (searchStrs) {
+ console.log("filtering on " + searchStrs);
+ this._selector.each(function(i, el) {
+ var val = $(el).text();
+ // Search
+ var matched = searchStrs.map((str) => {
+ return val.indexOf(str) !== -1;
+ }).reduce((reduced, result) => {
+ return reduced && result;
+ }, true);
+ if (matched) {
+ $(el).show();
+ } else {
+ $(el).hide();
+ }
+ });
+ },
+ init: function () {
+ var self = this;
+
+ var searchElement = $('<div id="filter"><input type="text" placeholder="Filter layers"></div>');
+ var selector = $('.leaflet-control-layers-list label');
+
+ this._selector = selector;
+
+ // Add input in the DOM
+ selector.first().parent().prepend(searchElement);
+
+ // Listen to keyboard input
+ $('#filter input').keyup(function(ev) {
+ const val = $(this).val();
+ self.filter(val.split(" "));
+ });
+
+ },
+ _selector: null
+ };
+ obj.init();
+ return obj;
+};
+$(document).ready(function() {
+ // Initialize to full screen
+ setFullScreen();
+ // initialize the map on the "map" div with a given center and zoom
+ $.getJSON('/list', function(data) {
+ var layers = [],
+ layer_groups = [],
+ default_layer = [null];
+ var layer_group = {};
+
+ // Loop over field types
+ for (var type in data['data']) {
+ var dtype = data['data'][type];
+
+ // Loop over fields of given type
+ for (var field in dtype) {
+ var loc = dtype[field]
+ var field = loc[0],
+ active = loc[1],
+ url = 'map/' + field[0] + ',' + field[1] + '/{z}/{x}/{y}.png';
+
+ // Create new layer
+ var layer = new L.TileLayer(url, {id: 'MapID', maxzoom: 18});
+
+ // Create readable name
+ human_name = field.join(' ');
+
+ // Store it
+ layers.push(layer);
+ layer_group[human_name] = layer;
+ if (active) {
+ default_layer[0] = layer;
+ }
+ }
+ }
+ var map = new L.Map('map', {
+ crs: L.CRS.Simple,
+ center: new L.LatLng(-128, -128),
+ zoom: 4,
+ layers: default_layer
+ });
+
+ L.control.layers(layer_group).addTo(map);
+
+ var unit = data['unit'], px2unit = data['px2unit'], decimals = 2;
+ var fmt = (n) => {
+ return L.NumberFormatter.round(n, decimals, ".")
+ };
+ L.control.coordinates({
+ position: "bottomleft", //optional default "bootomright"
+ decimals: 2, //optional default 4
+ decimalSeperator: ".", //optional default "."
+ enableUserInput: true, //optional default true
+ useDMS: false, //optional default false
+ useLatLngOrder: true, //ordering of labels, default false-> lng-lat
+ markerType: L.marker, //optional default L.marker
+ labelFormatterLng : (lng) => { return fmt((lng+128)/px2unit)+" "+unit }, //optional default none,
+ labelFormatterLat : (lat) => { return fmt((lat+128)/px2unit)+" "+unit }, //optional default none
+ }).addTo(map);
+
+ // Search widget
+ var search = SearchWidget();
+ });
+
+ // Resize map automatically
+ $(window).resize(setFullScreen);
+});
diff -r 3ba490843d843949dfc6be4967dd5c0ef44fdc67 -r 43557bdd0604b64a69c95990e1042e3d08c779da yt/visualization/mapserver/html/map_index.html
--- a/yt/visualization/mapserver/html/map_index.html
+++ b/yt/visualization/mapserver/html/map_index.html
@@ -9,127 +9,7 @@
<script type="text/javascript" src="static/Leaflet.Coordinates-0.1.5.src.js"></script><link rel="stylesheet" href="static/Leaflet.Coordinates-0.1.5.css" />
-<script type="text/javascript">
-function setFullScreen () {
- $("#map").width($(window).width());
- $("#map").height($(window).height());
-}
-
-var SearchWidget = function () {
- var obj = {
- filter: function (searchStrs) {
- console.log("filtering on " + searchStrs);
- this._selector.each(function(i, el) {
- var val = $(el).text();
- // Search
- var matched = searchStrs.map((str) => {
- return val.indexOf(str) !== -1;
- }).reduce((reduced, result) => {
- return reduced && result;
- }, true);
- if (matched) {
- $(el).show();
- } else {
- $(el).hide();
- }
- });
- },
- init: function () {
- var self = this;
-
- var searchElement = $('<div id="filter"><input type="text" placeholder="Filter layers"></div>');
- var selector = $('.leaflet-control-layers-list label');
-
- this._selector = selector;
-
- // Add input in the DOM
- selector.first().parent().prepend(searchElement);
-
- // Listen to keyboard input
- $('#filter input').keyup(function(ev) {
- const val = $(this).val();
- self.filter(val.split(" "));
- });
-
- },
- _selector: null
- };
- obj.init();
- return obj;
-};
-$(document).ready(function() {
- // Initialize to full screen
- setFullScreen();
- // initialize the map on the "map" div with a given center and zoom
- $.getJSON('/list', function(data) {
- var layers = [],
- layer_groups = [],
- default_layer = [null];
- var layer_group = {};
-
- // Loop over field types
- for (var type in data['data']) {
- var dtype = data['data'][type];
-
- // Loop over fields of given type
- for (var field in dtype) {
- var loc = dtype[field]
- var field = loc[0],
- active = loc[1],
- url = 'map/' + field[0] + ',' + field[1] + '/{z}/{x}/{y}.png';
-
- // Create new layer
- var layer = new L.TileLayer(url, {id: 'MapID', maxzoom: 18});
-
- // Create readable name
- human_name = field.join(' ');
-
- // Store it
- layers.push(layer);
- layer_group[human_name] = layer;
- if (active) {
- default_layer[0] = layer;
- }
- }
- }
- var map = new L.Map('map', {
- crs: L.CRS.Simple,
- center: new L.LatLng(-128, -128),
- zoom: 4,
- layers: default_layer
- });
-
- L.control.layers(layer_group).addTo(map);
-
- var unit = data['unit'], px2unit = data['px2unit'], decimals = 2;
- var fmt = (n) => {
- return L.NumberFormatter.round(n, decimals, ".")
- };
- L.control.coordinates({
- position: "bottomleft", //optional default "bootomright"
- decimals: 2, //optional default 4
- decimalSeperator: ".", //optional default "."
- // labelTemplateLat: "x: {y}" + unit, //optional default "Lat: {y}"
- // labelTemplateLng: "y: {x}" + unit, //optional default "Lng: {x}"
- enableUserInput: true, //optional default true
- useDMS: false, //optional default false
- useLatLngOrder: true, //ordering of labels, default false-> lng-lat
- markerType: L.marker, //optional default L.marker
- // markerProps: {}, //optional default {},
- labelFormatterLng : (lng) => { return fmt((lng+128)/px2unit)+" "+unit }, //optional default none,
- labelFormatterLat : (lat) => { return fmt((lat+128)/px2unit)+" "+unit }, //optional default none
- }).addTo(map);
-
-
- // Search widget
- var search = SearchWidget();
- });
-
- // Resize map automatically
- $(window).resize(setFullScreen);
-});
-
-</script>
+<script type="text/javascript" src="static/map.js"></script><style>
body {
margin: 0;
https://bitbucket.org/yt_analysis/yt/commits/260b28112c20/
Changeset: 260b28112c20
User: Corentin Cadiou
Date: 2018-01-18 17:27:57+00:00
Summary: Fix units
Affected #: 1 file
diff -r 43557bdd0604b64a69c95990e1042e3d08c779da -r 260b28112c208eb9d8f1e8f3d9c20b0a6fb431aa yt/visualization/mapserver/html/map.js
--- a/yt/visualization/mapserver/html/map.js
+++ b/yt/visualization/mapserver/html/map.js
@@ -97,12 +97,16 @@
position: "bottomleft", //optional default "bootomright"
decimals: 2, //optional default 4
decimalSeperator: ".", //optional default "."
- enableUserInput: true, //optional default true
+ enableUserInput: false, //optional default true
useDMS: false, //optional default false
- useLatLngOrder: true, //ordering of labels, default false-> lng-lat
+ useLatLngOrder: false, //ordering of labels, default false-> lng-lat
markerType: L.marker, //optional default L.marker
- labelFormatterLng : (lng) => { return fmt((lng+128)/px2unit)+" "+unit }, //optional default none,
- labelFormatterLat : (lat) => { return fmt((lat+128)/px2unit)+" "+unit }, //optional default none
+ labelFormatterLng : (lng) => {
+ return fmt((lng+128)*px2unit) + " " + unit
+ }, //optional default none,
+ labelFormatterLat : (lat) => {
+ return fmt((lat+128)*px2unit) + " " + unit
+ }, //optional default none
}).addTo(map);
// Search widget
https://bitbucket.org/yt_analysis/yt/commits/96af32777a39/
Changeset: 96af32777a39
User: ngoldbaum
Date: 2018-03-14 15:42:15+00:00
Summary: Merge pull request #1668 from cphyc/mapserver-improvements
Mapserver improvements
Affected #: 7 files
diff -r 7591c092a25df72755d1035db46f0e470ccdaca8 -r 96af32777a3935c6ff9d979c2fcec7151b0551ae yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -130,7 +130,7 @@
print("Changeset = %s" % vstring.strip())
print("---")
return vstring
-
+
def _get_girder_client():
try:
@@ -192,7 +192,7 @@
title=cls.subparser, dest=cls.subparser)
sp = _subparsers[cls.subparser]
for name in names:
- sc = sp.add_parser(name, description=cls.description,
+ sc = sp.add_parser(name, description=cls.description,
help=cls.description)
sc.set_defaults(func=cls.run)
for arg in cls.args:
@@ -637,7 +637,7 @@
password=password1, lastName=last_name, admin=False)
hub_url = ytcfg.get("yt", "hub_url")
req = requests.post(hub_url + "/user", data=data)
-
+
if req.ok:
headers = {'Girder-Token': req.json()['authToken']['token']}
else:
@@ -653,7 +653,7 @@
print("Storing API key in configuration file")
set_config("yt", "hub_api_key", apiKey)
-
+
print()
print("SUCCESS!")
print()
@@ -725,7 +725,7 @@
IPython.embed(config=cfg,user_ns=local_ns)
class YTMapserverCmd(YTCommand):
- args = ("proj", "field", "weight", "linear", "center", "width",
+ args = ("proj", "field", "weight", "linear", "center", "width", "cmap",
dict(short="-a", longname="--axis", action="store", type=int,
dest="axis", default=0, help="Axis"),
dict(short ="-o", longname="--host", action="store", type=str,
@@ -768,13 +768,13 @@
if args.projection:
p = ProjectionPlot(ds, args.axis, args.field, weight_field=args.weight, data_source=ad,
center=center, width=width)
- p.set_log(args.field, args.takelog)
else:
p = SlicePlot(ds, args.axis, args.field, data_source=ad,
center=center, width=width)
- p.set_log(args.field, args.takelog)
+ p.set_log('all', args.takelog)
+ p.set_cmap('all', args.cmap)
- PannableMapServer(p.data_source, args.field, args.takelog)
+ PannableMapServer(p.data_source, args.field, args.takelog, args.cmap)
try:
import bottle
except ImportError:
@@ -847,7 +847,7 @@
class YTHubStartNotebook(YTCommand):
args = (
dict(dest="folderId", default=ytcfg.get("yt", "hub_sandbox"),
- nargs="?",
+ nargs="?",
help="(Optional) Hub folder to mount inside the Notebook"),
)
description = \
@@ -1012,7 +1012,7 @@
)
description = \
"""
- Start the Jupyter Notebook locally.
+ Start the Jupyter Notebook locally.
"""
def __call__(self, args):
kwargs = {}
@@ -1334,7 +1334,7 @@
args = (
dict(short="filename", action="store", type=str,
help="The name of the file to download", nargs='?',
- default=''),
+ default=''),
dict(short="location", action="store", type=str, nargs='?',
help="The location in which to place the file, can be "
"\"supp_data_dir\", \"test_data_dir\", or any valid "
@@ -1348,8 +1348,8 @@
)
description = \
"""
- Download a file from http://yt-project.org/data and save it to a
- particular location. Files can be saved to the locations provided
+ Download a file from http://yt-project.org/data and save it to a
+ particular location. Files can be saved to the locations provided
by the "test_data_dir" or "supp_data_dir" configuration entries, or
any valid path to a location on disk.
"""
diff -r 7591c092a25df72755d1035db46f0e470ccdaca8 -r 96af32777a3935c6ff9d979c2fcec7151b0551ae yt/visualization/mapserver/html/Leaflet.Coordinates-0.1.5.css
--- /dev/null
+++ b/yt/visualization/mapserver/html/Leaflet.Coordinates-0.1.5.css
@@ -0,0 +1,6 @@
+/*
+ * From https://github.com/MrMufflon/Leaflet.Coordinates
+ *
+ * Fixed small issue about formatting by C. Cadiou (cphyc))
+ */
+.leaflet-control-coordinates{background-color:#D8D8D8;background-color:rgba(255,255,255,.8);cursor:pointer}.leaflet-control-coordinates,.leaflet-control-coordinates .uiElement input{-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}.leaflet-control-coordinates .uiElement{margin:4px}.leaflet-control-coordinates .uiElement .labelFirst{margin-right:4px}.leaflet-control-coordinates .uiHidden{display:none}.leaflet-control-coordinates .uiElement.label{color:inherit;font-weight:inherit;font-size:inherit;padding:0;display:inherit}
diff -r 7591c092a25df72755d1035db46f0e470ccdaca8 -r 96af32777a3935c6ff9d979c2fcec7151b0551ae yt/visualization/mapserver/html/Leaflet.Coordinates-0.1.5.src.js
--- /dev/null
+++ b/yt/visualization/mapserver/html/Leaflet.Coordinates-0.1.5.src.js
@@ -0,0 +1,354 @@
+/*
+ * From https://github.com/MrMufflon/Leaflet.Coordinates
+ *
+ * Fixed small issue about formatting by C. Cadiou (cphyc))
+ */
+
+/*
+ * L.Control.Coordinates is used for displaying current mouse coordinates on the map.
+ */
+
+L.Control.Coordinates = L.Control.extend({
+ options: {
+ position: 'bottomright',
+ //decimals used if not using DMS or labelFormatter functions
+ decimals: 4,
+ //decimalseperator used if not using DMS or labelFormatter functions
+ decimalSeperator: ".",
+ //label templates for usage if no labelFormatter function is defined
+ labelTemplateLat: "Lat: {y}",
+ labelTemplateLng: "Lng: {x}",
+ //label formatter functions
+ labelFormatterLat: undefined,
+ labelFormatterLng: undefined,
+ //switch on/off input fields on click
+ enableUserInput: true,
+ //use Degree-Minute-Second
+ useDMS: false,
+ //if true lat-lng instead of lng-lat label ordering is used
+ useLatLngOrder: false,
+ //if true user given coordinates are centered directly
+ centerUserCoordinates: false,
+ //leaflet marker type
+ markerType: L.marker,
+ //leaflet marker properties
+ markerProps: {}
+ },
+
+ onAdd: function(map) {
+ this._map = map;
+
+ var className = 'leaflet-control-coordinates',
+ container = this._container = L.DomUtil.create('div', className),
+ options = this.options;
+
+ //label containers
+ this._labelcontainer = L.DomUtil.create("div", "uiElement label", container);
+ this._label = L.DomUtil.create("span", "labelFirst", this._labelcontainer);
+
+
+ //input containers
+ this._inputcontainer = L.DomUtil.create("div", "uiElement input uiHidden", container);
+ var xSpan, ySpan;
+ if (options.useLatLngOrder) {
+ ySpan = L.DomUtil.create("span", "", this._inputcontainer);
+ this._inputY = this._createInput("inputY", this._inputcontainer);
+ xSpan = L.DomUtil.create("span", "", this._inputcontainer);
+ this._inputX = this._createInput("inputX", this._inputcontainer);
+ } else {
+ xSpan = L.DomUtil.create("span", "", this._inputcontainer);
+ this._inputX = this._createInput("inputX", this._inputcontainer);
+ ySpan = L.DomUtil.create("span", "", this._inputcontainer);
+ this._inputY = this._createInput("inputY", this._inputcontainer);
+ }
+ xSpan.innerHTML = options.labelTemplateLng.replace("{x}", "");
+ ySpan.innerHTML = options.labelTemplateLat.replace("{y}", "");
+
+ L.DomEvent.on(this._inputX, 'keyup', this._handleKeypress, this);
+ L.DomEvent.on(this._inputY, 'keyup', this._handleKeypress, this);
+
+ //connect to mouseevents
+ map.on("mousemove", this._update, this);
+ map.on('dragstart', this.collapse, this);
+
+ map.whenReady(this._update, this);
+
+ this._showsCoordinates = true;
+ //wether or not to show inputs on click
+ if (options.enableUserInput) {
+ L.DomEvent.addListener(this._container, "click", this._switchUI, this);
+ }
+
+ return container;
+ },
+
+ /**
+ * Creates an input HTML element in given container with given classname
+ */
+ _createInput: function(classname, container) {
+ var input = L.DomUtil.create("input", classname, container);
+ input.type = "text";
+ L.DomEvent.disableClickPropagation(input);
+ return input;
+ },
+
+ _clearMarker: function() {
+ this._map.removeLayer(this._marker);
+ },
+
+ /**
+ * Called onkeyup of input fields
+ */
+ _handleKeypress: function(e) {
+ switch (e.keyCode) {
+ case 27: //Esc
+ this.collapse();
+ break;
+ case 13: //Enter
+ this._handleSubmit();
+ this.collapse();
+ break;
+ default: //All keys
+ this._handleSubmit();
+ break;
+ }
+ },
+
+ /**
+ * Called on each keyup except ESC
+ */
+ _handleSubmit: function() {
+ var x = L.NumberFormatter.createValidNumber(this._inputX.value, this.options.decimalSeperator);
+ var y = L.NumberFormatter.createValidNumber(this._inputY.value, this.options.decimalSeperator);
+ if (x !== undefined && y !== undefined) {
+ var marker = this._marker;
+ if (!marker) {
+ marker = this._marker = this._createNewMarker();
+ marker.on("click", this._clearMarker, this);
+ }
+ var ll = new L.LatLng(y, x);
+ marker.setLatLng(ll);
+ marker.addTo(this._map);
+ if (this.options.centerUserCoordinates) {
+ this._map.setView(ll, this._map.getZoom());
+ }
+ }
+ },
+
+ /**
+ * Shows inputs fields
+ */
+ expand: function() {
+ this._showsCoordinates = false;
+
+ this._map.off("mousemove", this._update, this);
+
+ L.DomEvent.addListener(this._container, "mousemove", L.DomEvent.stop);
+ L.DomEvent.removeListener(this._container, "click", this._switchUI, this);
+
+ L.DomUtil.addClass(this._labelcontainer, "uiHidden");
+ L.DomUtil.removeClass(this._inputcontainer, "uiHidden");
+ },
+
+ /**
+ * Creates the label according to given options and formatters
+ */
+ _createCoordinateLabel: function(ll) {
+ var opts = this.options,
+ x, y;
+ if (opts.customLabelFcn) {
+ return opts.customLabelFcn(ll, opts);
+ }
+ if (opts.labelFormatterLng) {
+ x = opts.labelFormatterLng(ll.lng);
+ } else {
+ x = L.Util.template(opts.labelTemplateLng, {
+ x: this._getNumber(ll.lng, opts)
+ });
+ }
+ if (opts.labelFormatterLat) {
+ y = opts.labelFormatterLat(ll.lat);
+ } else {
+ y = L.Util.template(opts.labelTemplateLat, {
+ y: this._getNumber(ll.lat, opts)
+ });
+ }
+ if (opts.useLatLngOrder) {
+ return y + " " + x;
+ }
+ return x + " " + y;
+ },
+
+ /**
+ * Returns a Number according to options (DMS or decimal)
+ */
+ _getNumber: function(n, opts) {
+ var res;
+ if (opts.useDMS) {
+ res = L.NumberFormatter.toDMS(n);
+ } else {
+ res = L.NumberFormatter.round(n, opts.decimals, opts.decimalSeperator);
+ }
+ return res;
+ },
+
+ /**
+ * Shows coordinate labels after user input has ended. Also
+ * displays a marker with popup at the last input position.
+ */
+ collapse: function() {
+ if (!this._showsCoordinates) {
+ this._map.on("mousemove", this._update, this);
+ this._showsCoordinates = true;
+ var opts = this.options;
+ L.DomEvent.addListener(this._container, "click", this._switchUI, this);
+ L.DomEvent.removeListener(this._container, "mousemove", L.DomEvent.stop);
+
+ L.DomUtil.addClass(this._inputcontainer, "uiHidden");
+ L.DomUtil.removeClass(this._labelcontainer, "uiHidden");
+
+ if (this._marker) {
+ var m = this._createNewMarker(),
+ ll = this._marker.getLatLng();
+ m.setLatLng(ll);
+
+ var container = L.DomUtil.create("div", "");
+ var label = L.DomUtil.create("div", "", container);
+ label.innerHTML = this._ordinateLabel(ll);
+
+ var close = L.DomUtil.create("a", "", container);
+ close.innerHTML = "Remove";
+ close.href = "#";
+ var stop = L.DomEvent.stopPropagation;
+
+ L.DomEvent
+ .on(close, 'click', stop)
+ .on(close, 'mousedown', stop)
+ .on(close, 'dblclick', stop)
+ .on(close, 'click', L.DomEvent.preventDefault)
+ .on(close, 'click', function() {
+ this._map.removeLayer(m);
+ }, this);
+
+ m.bindPopup(container);
+ m.addTo(this._map);
+ this._map.removeLayer(this._marker);
+ this._marker = null;
+ }
+ }
+ },
+
+ /**
+ * Click callback for UI
+ */
+ _switchUI: function(evt) {
+ L.DomEvent.stop(evt);
+ L.DomEvent.stopPropagation(evt);
+ L.DomEvent.preventDefault(evt);
+ if (this._showsCoordinates) {
+ //show textfields
+ this.expand();
+ } else {
+ //show coordinates
+ this.collapse();
+ }
+ },
+
+ onRemove: function(map) {
+ map.off("mousemove", this._update, this);
+ },
+
+ /**
+ * Mousemove callback function updating labels and input elements
+ */
+ _update: function(evt) {
+ var pos = evt.latlng,
+ opts = this.options;
+ if (pos) {
+ pos = pos.wrap();
+ this._currentPos = pos;
+ this._inputY.value = L.NumberFormatter.round(pos.lat, opts.decimals, opts.decimalSeperator);
+ this._inputX.value = L.NumberFormatter.round(pos.lng, opts.decimals, opts.decimalSeperator);
+ this._label.innerHTML = this._createCoordinateLabel(pos);
+ }
+ },
+
+ _createNewMarker: function() {
+ return this.options.markerType(null, this.options.markerProps);
+ }
+
+});
+
+//constructor registration
+L.control.coordinates = function(options) {
+ return new L.Control.Coordinates(options);
+};
+
+//map init hook
+L.Map.mergeOptions({
+ coordinateControl: false
+});
+
+L.Map.addInitHook(function() {
+ if (this.options.coordinateControl) {
+ this.coordinateControl = new L.Control.Coordinates();
+ this.addControl(this.coordinateControl);
+ }
+});
+L.NumberFormatter = {
+ round: function(num, dec, sep) {
+ var res = L.Util.formatNum(num, dec) + "",
+ numbers = res.split(".");
+ if (numbers[1]) {
+ var d = dec - numbers[1].length;
+ for (; d > 0; d--) {
+ numbers[1] += "0";
+ }
+ res = numbers.join(sep || ".");
+ }
+ return res;
+ },
+
+ toDMS: function(deg) {
+ var d = Math.floor(Math.abs(deg));
+ var minfloat = (Math.abs(deg) - d) * 60;
+ var m = Math.floor(minfloat);
+ var secfloat = (minfloat - m) * 60;
+ var s = Math.round(secfloat);
+ if (s == 60) {
+ m++;
+ s = "00";
+ }
+ if (m == 60) {
+ d++;
+ m = "00";
+ }
+ if (s < 10) {
+ s = "0" + s;
+ }
+ if (m < 10) {
+ m = "0" + m;
+ }
+ var dir = "";
+ if (deg < 0) {
+ dir = "-";
+ }
+ return ("" + dir + d + "° " + m + "' " + s + "''");
+ },
+
+ createValidNumber: function(num, sep) {
+ if (num && num.length > 0) {
+ var numbers = num.split(sep || ".");
+ try {
+ var numRes = Number(numbers.join("."));
+ if (isNaN(numRes)) {
+ return undefined;
+ }
+ return numRes;
+ } catch (e) {
+ return undefined;
+ }
+ }
+ return undefined;
+ }
+};
diff -r 7591c092a25df72755d1035db46f0e470ccdaca8 -r 96af32777a3935c6ff9d979c2fcec7151b0551ae yt/visualization/mapserver/html/map.js
--- /dev/null
+++ b/yt/visualization/mapserver/html/map.js
@@ -0,0 +1,118 @@
+function setFullScreen () {
+ $("#map").width($(window).width());
+ $("#map").height($(window).height());
+}
+
+var SearchWidget = function () {
+ var obj = {
+ filter: function (searchStrs) {
+ console.log("filtering on " + searchStrs);
+ this._selector.each(function(i, el) {
+ var val = $(el).text();
+ // Search
+ var matched = searchStrs.map((str) => {
+ return val.indexOf(str) !== -1;
+ }).reduce((reduced, result) => {
+ return reduced && result;
+ }, true);
+ if (matched) {
+ $(el).show();
+ } else {
+ $(el).hide();
+ }
+ });
+ },
+ init: function () {
+ var self = this;
+
+ var searchElement = $('<div id="filter"><input type="text" placeholder="Filter layers"></div>');
+ var selector = $('.leaflet-control-layers-list label');
+
+ this._selector = selector;
+
+ // Add input in the DOM
+ selector.first().parent().prepend(searchElement);
+
+ // Listen to keyboard input
+ $('#filter input').keyup(function(ev) {
+ const val = $(this).val();
+ self.filter(val.split(" "));
+ });
+
+ },
+ _selector: null
+ };
+ obj.init();
+ return obj;
+};
+$(document).ready(function() {
+ // Initialize to full screen
+ setFullScreen();
+ // initialize the map on the "map" div with a given center and zoom
+ $.getJSON('/list', function(data) {
+ var layers = [],
+ layer_groups = [],
+ default_layer = [null];
+ var layer_group = {};
+
+ // Loop over field types
+ for (var type in data['data']) {
+ var dtype = data['data'][type];
+
+ // Loop over fields of given type
+ for (var field in dtype) {
+ var loc = dtype[field]
+ var field = loc[0],
+ active = loc[1],
+ url = 'map/' + field[0] + ',' + field[1] + '/{z}/{x}/{y}.png';
+
+ // Create new layer
+ var layer = new L.TileLayer(url, {id: 'MapID', maxzoom: 18});
+
+ // Create readable name
+ human_name = field.join(' ');
+
+ // Store it
+ layers.push(layer);
+ layer_group[human_name] = layer;
+ if (active) {
+ default_layer[0] = layer;
+ }
+ }
+ }
+ var map = new L.Map('map', {
+ crs: L.CRS.Simple,
+ center: new L.LatLng(-128, -128),
+ zoom: 4,
+ layers: default_layer
+ });
+
+ L.control.layers(layer_group).addTo(map);
+
+ var unit = data['unit'], px2unit = data['px2unit'], decimals = 2;
+ var fmt = (n) => {
+ return L.NumberFormatter.round(n, decimals, ".")
+ };
+ L.control.coordinates({
+ position: "bottomleft", //optional default "bootomright"
+ decimals: 2, //optional default 4
+ decimalSeperator: ".", //optional default "."
+ enableUserInput: false, //optional default true
+ useDMS: false, //optional default false
+ useLatLngOrder: false, //ordering of labels, default false-> lng-lat
+ markerType: L.marker, //optional default L.marker
+ labelFormatterLng : (lng) => {
+ return fmt((lng+128)*px2unit) + " " + unit
+ }, //optional default none,
+ labelFormatterLat : (lat) => {
+ return fmt((lat+128)*px2unit) + " " + unit
+ }, //optional default none
+ }).addTo(map);
+
+ // Search widget
+ var search = SearchWidget();
+ });
+
+ // Resize map automatically
+ $(window).resize(setFullScreen);
+});
diff -r 7591c092a25df72755d1035db46f0e470ccdaca8 -r 96af32777a3935c6ff9d979c2fcec7151b0551ae yt/visualization/mapserver/html/map_index.html
--- a/yt/visualization/mapserver/html/map_index.html
+++ b/yt/visualization/mapserver/html/map_index.html
@@ -5,56 +5,18 @@
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.2.0/leaflet.js"></script><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.2.0/leaflet.css" /><script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
-<script type="text/javascript">
- $(document).ready(function() {
- // initialize the map on the "map" div with a given center and zoom
- $("#map").width($(window).width());
- $("#map").height($(window).height());
- $.getJSON('/list', function(data) {
- var layers = [],
- layer_groups = [],
- default_layer = [null];
- var layer_group = {};
-
- // Loop over field types
- for (var type in data['data']) {
- var dtype = data['data'][type];
-
- // Loop over fields of given type
- for (var field in dtype) {
- var loc = dtype[field]
- var field = loc[0],
- active = loc[1],
- url = 'map/' + field[0] + ',' + field[1] + '/{z}/{x}/{y}.png';
-
- // Create new layer
- var layer = new L.TileLayer(url, {id: 'MapID', maxzoom: 18});
+<script type="text/javascript" src="static/Leaflet.Coordinates-0.1.5.src.js"></script>
+<link rel="stylesheet" href="static/Leaflet.Coordinates-0.1.5.css" />
- // Create readable name
- human_name = field.join(' ');
-
- // Store it
- layers.push(layer);
- layer_group[human_name] = layer;
- if (active) {
- default_layer[0] = layer;
- }
- }
- }
- var map = new L.Map('map', {
- center: new L.LatLng(0.0, 0.0),
- zoom: 2,
- layers: default_layer
- });
-
- L.control.layers(layer_group).addTo(map);
- });
-
-})
-</script>
-</HEAD>
-<BODY>
- <DIV id="map" style="height: 512px; width: 512px;"></div>
-</BODY>
-</HTML>
+<script type="text/javascript" src="static/map.js"></script>
+<style>
+body {
+ margin: 0;
+}
+</style>
+</head>
+<body>
+ <div id="map" style="height: 500px; width: 500px;"></div>
+</body>
+</html>
diff -r 7591c092a25df72755d1035db46f0e470ccdaca8 -r 96af32777a3935c6ff9d979c2fcec7151b0551ae yt/visualization/mapserver/pannable_map.py
--- a/yt/visualization/mapserver/pannable_map.py
+++ b/yt/visualization/mapserver/pannable_map.py
@@ -40,24 +40,34 @@
class PannableMapServer(object):
_widget_name = "pannable_map"
- def __init__(self, data, field, takelog, route_prefix = ""):
+ def __init__(self, data, field, takelog, cmap, route_prefix = ""):
self.data = data
self.ds = data.ds
self.field = field
+ self.cmap = cmap
bottle.route("%s/map/:field/:L/:x/:y.png" % route_prefix)(self.map)
bottle.route("%s/map/:field/:L/:x/:y.png" % route_prefix)(self.map)
bottle.route("%s/" % route_prefix)(self.index)
+ bottle.route("%s/:field" % route_prefix)(self.index)
bottle.route("%s/index.html" % route_prefix)(self.index)
bottle.route("%s/list" % route_prefix, "GET")(self.list_fields)
# This is a double-check, since we do not always mandate this for
# slices:
self.data[self.field] = self.data[self.field].astype("float64")
- bottle.route(":path#.+#", "GET")(self.static)
+ bottle.route("%s/static/:path" % route_prefix, "GET")(self.static)
self.takelog = takelog
self._lock = False
+ for unit in ['Gpc', 'Mpc', 'kpc', 'pc']:
+ v = self.ds.domain_width[0].in_units(unit).value
+ if v > 1:
+ break
+ self.unit = unit
+ self.px2unit = self.ds.domain_width[0].in_units(unit).value / 256
+
+
def lock(self):
import time
while self._lock:
@@ -70,6 +80,7 @@
def map(self, field, L, x, y):
if ',' in field:
field = tuple(field.split(','))
+ cmap = self.cmap
dd = 1.0 / (2.0**(int(L)))
relx = int(x) * dd
rely = int(y) * dd
@@ -80,8 +91,9 @@
yr = yl + dd*DW[1]
try:
self.lock()
+ w = 256 # pixels
data = self.data[field]
- frb = FixedResolutionBuffer(self.data, (xl, xr, yl, yr), (256, 256))
+ frb = FixedResolutionBuffer(self.data, (xl, xr, yl, yr), (w, w))
cmi, cma = get_color_bounds(self.data['px'], self.data['py'],
self.data['pdx'], self.data['pdy'],
data,
@@ -97,14 +109,18 @@
if self.takelog:
cmi = np.log10(cmi)
cma = np.log10(cma)
- to_plot = apply_colormap(np.log10(frb[field]), color_bounds = (cmi, cma))
+ to_plot = apply_colormap(np.log10(frb[field]), color_bounds = (cmi, cma),
+ cmap_name=cmap)
else:
- to_plot = apply_colormap(frb[field], color_bounds = (cmi, cma))
+ to_plot = apply_colormap(frb[field], color_bounds = (cmi, cma),
+ cmap_name=cmap)
rv = write_png_to_string(to_plot)
return rv
- def index(self):
+ def index(self, field=None):
+ if field is not None:
+ self.field = field
return bottle.static_file("map_index.html",
root=os.path.join(local_dir, "html"))
@@ -136,4 +152,5 @@
active = f[1] == self.field
d[ftype].append((f, active))
- return dict(data=d, active=self.field)
+ print(self.px2unit, self.unit)
+ return dict(data=d, px2unit=self.px2unit, unit=self.unit, active=self.field)
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list