From a2c1b3ca8b584af42beff2066c811eba0992f354 Mon Sep 17 00:00:00 2001 From: Goutte Date: Fri, 22 Feb 2019 15:07:15 +0100 Subject: [PATCH] Fix an issue with data being ignored. Works on Mercury. Uranus and Neptune still lack data. --- web/run.py | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------- 1 file changed, 68 insertions(+), 58 deletions(-) diff --git a/web/run.py b/web/run.py index 991284c..4261467 100755 --- a/web/run.py +++ b/web/run.py @@ -704,13 +704,14 @@ def get_data_for_target(target_config, input_slug, except Exception: log.error("Failed to parse time from %s." % ltime) raise + # Keep only what's in the interval if s0 <= dtime <= s1: dkey = round_time(dtime, 60*60).strftime(precision) orbit_data[dkey] = datum_hee cdf_handle.close() all_data = {} # keys are datetime as str, values tuples of data - strip_before_date = None + for model in models: s0, s1 = _sta_sto(model, started_at, stopped_at) model_files = retrieve_amda_netcdf( @@ -748,6 +749,12 @@ def get_data_for_target(target_config, input_slug, # Alpha, RamP, E, Beta, Ma, Kp, R, DST, # AE, Flux, Flag, F10_Index, StartTime, StopTime + # Don't ignore, but instead, compute a mean ? + # Look for discretisation ? temporal drizzling ? 1D drizzling ? + # The easy linear mean feels a bit rough too. Running mean too. + # FIXME + ignored_count = 0 + log.debug("%s: aggregating data from '%s'..." % (target_config['name'], model_file)) for ltime, datum_v, datum_b, datum_t, datum_n, datum_p, datum_a \ @@ -759,63 +766,66 @@ def get_data_for_target(target_config, input_slug, log.error("Failed to parse time from %s." % ltime) raise - if s0 <= dtime <= s1: - droundtime = round_time(dtime, 60*60) - dkey = droundtime.strftime(precision) - - x_hee = None - y_hee = None - if dkey in orbit_data: - x_hee = orbit_data[dkey][0] / ASTRONOMICAL_UNIT_IN_KM - y_hee = orbit_data[dkey][1] / ASTRONOMICAL_UNIT_IN_KM - - # First exception: V may be a vector instead of a scalar - if hasattr(datum_v, '__len__'): - vrad = datum_v[0] - vtan = datum_v[1] - vtot = sqrt(vrad * vrad + vtan * vtan) - else: # eg: Earth - vrad = None - vtan = None - vtot = datum_v - - # Second exception: Earth is always at (1, 0) - if target_config['slug'] == 'earth': - x_hee = 1 - y_hee = 0 - - # 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 * 1.6726e-6 - if model['slug'] == 'ace_swepam_real': - datum_p = datum_n * vtot * vtot * 1.6726e-6 - if vtot is None or isnan(vtot): - continue - - # Keep adding exceptions here until you can't or become mad - - first = False - if strip_before_date is None: - first = True - strip_before_date = droundtime - - # First model has priority, and also sets a leftmost time - if first or ( - (dkey not in all_data) and - (droundtime > strip_before_date) - ): - # /!\ MUST be in the same order as PROPERTIES - all_data[dkey] = ( - dtime.strftime("%Y-%m-%dT%H:%M:%S+00:00"), - vrad, vtan, vtot, - datum_b, datum_t, datum_p, datum_n, datum_a, - x_hee, y_hee - ) + if not (s0 <= dtime <= s1): + continue # Cull what's out of the interval + + droundtime = round_time(dtime, 60*60) + dkey = droundtime.strftime(precision) + + x_hee = None + y_hee = None + if dkey in orbit_data: + x_hee = orbit_data[dkey][0] / ASTRONOMICAL_UNIT_IN_KM + y_hee = orbit_data[dkey][1] / ASTRONOMICAL_UNIT_IN_KM + + # First exception: V may be a vector instead of a scalar + if hasattr(datum_v, '__len__'): + vrad = datum_v[0] + vtan = datum_v[1] + vtot = sqrt(vrad * vrad + vtan * vtan) + else: # eg: Earth + vrad = None + vtan = None + vtot = datum_v + + # Second exception: Earth is always at (1, 0) + if target_config['slug'] == 'earth': + x_hee = 1 + y_hee = 0 + + # 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 * 1.6726e-6 # ? + if model['slug'] == 'ace_swepam_real': + datum_p = datum_n * vtot * vtot * 1.6726e-6 # ? + if vtot is None or isnan(vtot): + continue + + # Keep adding exceptions here until you can't or become mad + + # Crude/Bad drizzling condition : first found datum in the hour + # gets to set the data. Improve this. + if dkey not in all_data: + # /!. The Set value MUST be in the same order as PROPERTIES + all_data[dkey] = ( + dtime.strftime("%Y-%m-%dT%H:%M:%S+00:00"), + vrad, vtan, vtot, + datum_b, datum_t, datum_p, datum_n, datum_a, + x_hee, y_hee + ) + else: + ignored_count += 1 + + # Improve this loop so as to remove this stinky debug log + if ignored_count > 0: + log.debug(" Ignored %d datum(s) during ~\"drizzling\"." + % ignored_count) + cdf_handle.close() return all_data -- libgit2 0.21.2