From 596da00d20ebbf1fb795576ebddbeeff7827a48f Mon Sep 17 00:00:00 2001 From: Goutte Date: Thu, 5 Apr 2018 02:30:43 +0200 Subject: [PATCH] Add more exceptions for Earth. --- CHANGELOG.md | 4 ++-- config.yml | 8 ++++++-- web/run.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- web/static/js/swapp.js | 2 +- web/static/js/swapp.ls | 2 +- 5 files changed, 84 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1ecea8..3081799 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,8 +41,8 @@ et prendre aussi ## 1.3 -- [ ] Earth pdyn = pv² -- [ ] Earth omnihour B is a Vector3 +- [x] Earth pdyn = pv² (TBD) +- [x] Earth omnihour B is a Vector3, use the first scalar - [ ] Layers - SW Catalogs - Auroral Emissions diff --git a/config.yml b/config.yml index 5e10ba4..835919c 100644 --- a/config.yml +++ b/config.yml @@ -172,15 +172,17 @@ targets: - slug: 'omni_hour_all' parameters: pdyn: 'RamP' -# btan: '' - slug: 'ace_swepam_real' + # [u'Time', u'Dens', u'Vel', u'Temp', u'flag', u'StartTime', u'StopTime'] parameters: dens: 'Dens' vtot: 'Vel' temp: 'Temp' - btan: 'Bgsm' # /!. VECTOR2 + #btan: 'Bgsm' # /!. VECTOR2 (actually, does not exist) sa: - slug: 'omni_hour_all' + parameters: + pdyn: 'RamP' - slug: 'ace_swepam_real' parameters: dens: 'Dens' @@ -188,6 +190,8 @@ targets: temp: 'Temp' sb: - slug: 'omni_hour_all' + parameters: + pdyn: 'RamP' - slug: 'ace_swepam_real' parameters: dens: 'Dens' diff --git a/web/run.py b/web/run.py index 3daff80..a3e7717 100755 --- a/web/run.py +++ b/web/run.py @@ -10,7 +10,7 @@ import tarfile import time import urllib from csv import writer as csv_writer -from math import sqrt +from math import sqrt, isnan from os import environ, remove as removefile from os.path import isfile, join, abspath, dirname @@ -419,6 +419,51 @@ def retrieve_amda_netcdf(orbiter, what, started_at, stopped_at): return list(set(local_netc_files)) # remove possible dupes +# class DataParser: +# """ +# Default data parser +# A wip to try to handle code exeptions sanely. +# """ +# +# # Override these using the model configuration +# default_nc_keys = { +# 'hee': 'HEE', +# 'vtot': 'V', +# 'magn': 'B', +# 'temp': 'T', +# 'dens': 'N', +# 'pdyn': 'P_dyn', +# 'atse': 'Delta_angle', +# } +# +# def __init__(self, target, model): +# self.target = target +# self.model = model +# pass +# +# def _read_var(self, nc, _keys, _key, mandatory=False): +# try: +# return nc.variables[_keys[_key]] +# except KeyError: +# pass +# if mandatory: +# raise Exception("No variable '%s' found in NetCDF." % _keys[_key]) +# return [None] * len(nc.variables['Time']) # slow -- use numpy? +# +# def parse(self, cdf_handle): +# nc_keys = self.default_nc_keys.copy() +# +# times = cdf_handle.variables['Time'] # YYYY DOY HH MM SS .ms +# data_v = self._read_var(cdf_handle, nc_keys, 'vtot') +# data_b = self._read_var(cdf_handle, nc_keys, 'magn') +# data_t = self._read_var(cdf_handle, nc_keys, 'temp') +# data_n = self._read_var(cdf_handle, nc_keys, 'dens') +# data_p = self._read_var(cdf_handle, nc_keys, 'pdyn') +# data_a = self._read_var(cdf_handle, nc_keys, 'atse') +# +# return zip() + + def get_data_for_target(target_config, input_slug, started_at, stopped_at): """ @@ -518,7 +563,9 @@ def get_data_for_target(target_config, input_slug, log.debug("%s: opening model NETCDF4 '%s'..." % (target_config['name'], model_file)) cdf_handle = Dataset(model_file, "r", format="NETCDF4") + # log.debug(cdf_handle.variables.keys()) + times = cdf_handle.variables['Time'] # YYYY DOY HH MM SS .ms data_v = _read_var(cdf_handle, nc_keys, 'vtot') data_b = _read_var(cdf_handle, nc_keys, 'magn') @@ -546,9 +593,17 @@ def get_data_for_target(target_config, input_slug, except Exception: log.error("Failed to parse time from %s." % ltime) raise + if s0 <= dtime <= s1: dkey = round_time(dtime, 60*60).strftime(precision) + x_hee = None + y_hee = None + if dkey in orbit_data: + x_hee = orbit_data[dkey][0] + y_hee = orbit_data[dkey][1] + + # First exception: V may be a vector instead of a scalar if hasattr(datum_v, '__len__'): vrad = datum_v[0] vtan = datum_v[1] @@ -558,14 +613,26 @@ def get_data_for_target(target_config, input_slug, vtan = None vtot = datum_v - x_hee = None - y_hee = None + # Second exception: Earth is always at (1, 0) if target_config['slug'] == 'earth': x_hee = 1 y_hee = 0 - if dkey in orbit_data: - x_hee = orbit_data[dkey][0] - y_hee = orbit_data[dkey][1] + + # Third exception: B is a Vector3 or a Vector2 for Earth + if target_config['slug'] == 'earth': + if model['slug'] == 'omni_hour_all': # Vector3 + datum_b = datum_b[0] + # if model['slug'] == 'ace_swepam_real': # Vector2 + # datum_b = datum_b[0] + if model['slug'] == 'omni_hour_all': + datum_p = datum_n * vtot * vtot + if model['slug'] == 'ace_swepam_real': + datum_p = datum_n * vtot * vtot + if vtot is None or isnan(vtot): + continue + + # Keep adding exceptions here until you can't or become mad + # /!\ MUST be in the same order as PROPERTIES all_data[dkey] = ( dtime.strftime("%Y-%m-%dT%H:%M:%S+00:00"), @@ -781,7 +848,6 @@ def get_catalog_layers(input_slug, target_slug): 'start': start_time, 'stop': stop_time, }) - #log.debug('Inspect C') return catalog_layers @@ -1299,6 +1365,7 @@ def cache_warmup(): @app.route("/log") +@app.route("/log.html") def log_show(): with open(LOG_FILE, 'r') as f: contents = f.read() diff --git a/web/static/js/swapp.js b/web/static/js/swapp.js index 08a3053..2251788 100644 --- a/web/static/js/swapp.js +++ b/web/static/js/swapp.js @@ -748,7 +748,7 @@ }; TimeSeries.prototype.createCatalogLayer = function(started_at, stopped_at){ var layer_rect; - layer_rect = this.plotWrapper.append("rect").attr('y', 0).attr('height', this.plotHeight).attr('fill', '#FFFD6492'); + layer_rect = this.plotWrapper.append("rect").attr('y', 0).attr('height', this.plotHeight).attr('fill', '#FFFD64C2'); return layer_rect; }; TimeSeries.prototype.resizeCatalogLayers = function(){ diff --git a/web/static/js/swapp.ls b/web/static/js/swapp.ls index cd96de8..81a651c 100644 --- a/web/static/js/swapp.ls +++ b/web/static/js/swapp.ls @@ -673,7 +673,7 @@ export class TimeSeries layer_rect = @plotWrapper.append("rect") .attr('y', 0) .attr('height', @plotHeight) - .attr('fill', '#FFFD6492') + .attr('fill', '#FFFD64C2') # Not triggered, mouse events are captured before they reach this rect #layer_rect.append('svg:title').text("I AM TEXT") layer_rect -- libgit2 0.21.2