Skip to content

Commit

Permalink
Merge pull request sgrid#57 from axiom-data-science/defaults
Browse files Browse the repository at this point in the history
Global defaults, passing back 'id' though REST interface, bug fixes

Former-commit-id: 5446d3b
  • Loading branch information
kwilcox committed Jul 17, 2015
2 parents f2e7a4e + 15d2afd commit 274d540
Show file tree
Hide file tree
Showing 20 changed files with 1,101 additions and 100 deletions.
7 changes: 6 additions & 1 deletion wms/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from django.contrib import admin
from wms.models import Dataset, Server, Group, VirtualLayer, Layer
from wms.models import Dataset, Server, Group, VirtualLayer, Layer, Variable


@admin.register(Server)
Expand Down Expand Up @@ -36,6 +36,11 @@ def has_add_permission(self, request):
return False


@admin.register(Variable)
class VariableAdmin(admin.ModelAdmin):
list_display = ('std_name', 'units', 'logscale', 'default_min', 'default_max')


@admin.register(Dataset)
class DatasetAdmin(admin.ModelAdmin):
list_display = ('name', 'slug', 'title', 'keep_up_to_date')
Expand Down
44 changes: 44 additions & 0 deletions wms/migrations/0029_auto_20150716_1639.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('wms', '0028_auto_20150710_1637'),
]

operations = [
migrations.CreateModel(
name='Variable',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('std_name', models.CharField(help_text=b"The 'standard_name' of this variable", max_length=200)),
('units', models.CharField(help_text=b"The 'units' of this variable", max_length=200, blank=True)),
('logscale', models.BooleanField(default=False, help_text=b'If this variable should default to a log scale')),
('default_min', models.FloatField(default=None, help_text=b'If no colorscalerange is specified, this is used for the min. If None, autoscale is used.', null=True, blank=True)),
('default_max', models.FloatField(default=None, help_text=b'If no colorscalerange is specified, this is used for the max. If None, autoscale is used.', null=True, blank=True)),
],
options={
},
bases=(models.Model,),
),
migrations.AlterUniqueTogether(
name='variable',
unique_together=set([('std_name', 'units')]),
),
migrations.AddField(
model_name='layer',
name='logscale',
field=models.NullBooleanField(default=None, help_text=b'If this dataset variable should default to a log scale'),
preserve_default=True,
),
migrations.AddField(
model_name='virtuallayer',
name='logscale',
field=models.NullBooleanField(default=None, help_text=b'If this dataset variable should default to a log scale'),
preserve_default=True,
),
]
20 changes: 20 additions & 0 deletions wms/migrations/0030_auto_20150716_1648.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('wms', '0029_auto_20150716_1639'),
]

operations = [
migrations.AlterField(
model_name='variable',
name='logscale',
field=models.NullBooleanField(default=None, help_text=b'If this variable should default to a log scale'),
preserve_default=True,
),
]
1 change: 1 addition & 0 deletions wms/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from wms.models.style import Style
from wms.models.group import Group
from wms.models.server import Server
from wms.models.variable import Variable
from wms.models.layer import Layer, VirtualLayer

from wms.models.datasets.base import Dataset
Expand Down
29 changes: 28 additions & 1 deletion wms/models/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from django.db import models

from wms.models import Style
from wms.models import Style, Variable
from wms.utils import DotDict

from wms import logger

Expand All @@ -12,6 +13,7 @@ class LayerBase(models.Model):
var_name = models.CharField(max_length=200, help_text="Variable name from dataset")
std_name = models.CharField(max_length=200, blank=True, help_text="The 'standard_name' from the dataset variable")
units = models.CharField(max_length=200, blank=True, help_text="The 'units' from the dataset variable")
logscale = models.NullBooleanField(default=None, null=True, help_text="If this dataset variable should default to a log scale")
description = models.CharField(max_length=200, blank=True, help_text="Descriptive name of this layer, optional")
dataset = models.ForeignKey('Dataset')
active = models.BooleanField(default=False)
Expand All @@ -27,6 +29,24 @@ class Meta:
def access_name(self):
return self.var_name

@property
def defaults(self):

lmin = self.default_min
lmax = self.default_max
llog = self.logscale

default = Variable.objects.filter(std_name=self.std_name, units=self.units).first()
if default:
if lmin is None and default.default_min:
lmin = default.default_min
if lmax is None and default.default_max:
lmax = default.default_max
if llog is None and default.logscale is not None:
llog = default.logscale

return DotDict(min=lmin, max=lmax, logscale=llog)

def __unicode__(self):
z = self.var_name
z += ' ({})'.format(self.std_name) if self.std_name else ''
Expand Down Expand Up @@ -68,9 +88,16 @@ def make_vector_layer(cls, us, vs, std_name, style, dataset_id):
v_match = '_'.join([ x for x in v.standard_name.split('_') if x not in ['y', 'northward']])

if u_match == v_match:
if hasattr(u, 'units'):
units = u.units
elif hasattr(v, 'units'):
units = v.units
else:
units = None
try:
vl = VirtualLayer.objects.create(var_name='{},{}'.format(u._name, v._name),
std_name=std_name,
units=units,
description="U ({}) and V ({}) vectors".format(u._name, v._name),
dataset_id=dataset_id,
active=True)
Expand Down
16 changes: 16 additions & 0 deletions wms/models/variable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
from django.db import models


class Variable(models.Model):
std_name = models.CharField(max_length=200, help_text="The 'standard_name' of this variable")
units = models.CharField(max_length=200, blank=True, help_text="The 'units' of this variable")
logscale = models.NullBooleanField(default=None, null=True, help_text="If this variable should default to a log scale")
default_min = models.FloatField(null=True, default=None, blank=True, help_text="If no colorscalerange is specified, this is used for the min. If None, autoscale is used.")
default_max = models.FloatField(null=True, default=None, blank=True, help_text="If no colorscalerange is specified, this is used for the max. If None, autoscale is used.")

class Meta:
unique_together = ('std_name', 'units',)

def __unicode__(self):
return '{}_{}'.format(self.std_name, self.units)
Binary file added wms/static/img/clear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wms/static/img/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 274d540

Please sign in to comment.