fetches hek data and makes thematic maps as requested
337465
def main():
    
    args = get_args()
    config = Config(args.config)

    # Load dates
    if os.path.isfile(args.dates):
        with open(args.dates) as f:
            dates = [dateparser.parse(line.split(" ")[0]) for line in f.readlines()]
    else:  # assume it's a date
        dates = [dateparser.parse(args.dates)]

    if args.verbose:
        print("Dates are:")
        for date in dates:
            print(date)

    for date in dates:
        if args.verbose:
            print('Processing {}'.format(date))
        suvi_data = Fetcher(date, ['suvi-l2-ci195'],
                            suvi_composite_path=config.suvi_composite_path).fetch(multithread=False)['suvi-l2-ci195']
        if suvi_data[0] is not None:
            config.expert = 'HEK'
            responses = query_hek(date)
            thmap = make_thmap(suvi_data, responses, config)
            Outgest(os.path.join(args.output, "thmap_hek_{}.fits".format(date.strftime("%Y%m%d%H%M%S"))),
                    thmap, {"c195": suvi_data[0], "suvi-l2-ci195": suvi_data[0]}, args.config).save()
1274767
def from_indexed_arrays(cls, name, verts, normals):
        """"""

        # Put header in string
        wavefront_str = "o {name}\n".format(name=name)


        new_verts, face_indices = face_index(verts)
        assert new_verts.shape[1] == 3, "verts should be Nx3 array"
        assert face_indices.ndim == 2

        face_indices = fan_triangulate(face_indices)

        # Write Vertex data from vert_dict
        for vert in new_verts:
            wavefront_str += "v {0} {1} {2}\n".format(*vert)

        # Write (false) UV Texture data
        wavefront_str += "vt 1.0 1.0\n"

        for norm in normals:
            wavefront_str += "vn {0} {1} {2}\n".format(*norm)

        assert len(face_indices) == len(normals) * 2
        for norm_idx, vert_idx,  in enumerate(face_indices):
            wavefront_str += "f"
            for vv in vert_idx:
                wavefront_str += " {}/{}/{}".format(vv + 1, 1, (norm_idx // 2) + 1 )
            wavefront_str += "\n"

        return cls(string=wavefront_str)
1167952
def init_heatmap(x_vec, y_vec, hist_matrix, fig, colormap='Blues',
                 alpha=1, grid=False, colorbar=True,
                 vmax='auto', vmin='auto', crop=True):
    
    plt.figure(fig.number)
    ax = fig.gca()

    # set vmax and vmin
    vma = np.amax(hist_matrix) if vmax == 'auto' else vmax
    vmi = np.amin(hist_matrix) if vmin == 'auto' else vmin

    # an error check
    if vma <= vmi:
        vma = vmi + 1

    # grid the space for pcolormesh
    x_grid, y_grid = np.meshgrid(x_vec, y_vec)

    hmap = ax.pcolormesh(x_grid, y_grid, np.array(hist_matrix),
               cmap=colormap, alpha=alpha, shading='gouraud',
               vmax=vma, vmin=vmi)

    if colorbar:
        plt.colorbar(hmap)

    if not grid:
        ax.grid(False)

    if crop:
        ax.set_xlim([x_vec[0], x_vec[-1]])
        ax.set_ylim([y_vec[0], y_vec[-1]])
1131472
def get_data_files():
    
    import os

    path = os.path.dirname(__file__)
    path = os.path.join(path, 'data')
    r = dict(
        Alpha_inf_hyrec_file = os.path.join(path, 'hyrec', 'Alpha_inf.dat'),
        R_inf_hyrec_file = os.path.join(path, 'hyrec', 'R_inf.dat'),
        two_photon_tables_hyrec_file = os.path.join(path, 'hyrec', 'two_photon_tables.dat'),
        sBBN_file = os.path.join(path, 'bbn', 'sBBN.dat'),
    )
    return r
1003969
def ImagesHDU(model):
    '''
    

    '''

    # Get mission cards
    cards = model._mission.HDUCards(model.meta, hdu=4)

    # Add EVEREST info
    cards.append(('COMMENT', '************************'))
    cards.append(('COMMENT', '*     EVEREST INFO     *'))
    cards.append(('COMMENT', '************************'))
    cards.append(('MISSION', model.mission, 'Mission name'))
    cards.append(('VERSION', EVEREST_MAJOR_MINOR, 'EVEREST pipeline version'))
    cards.append(('SUBVER', EVEREST_VERSION, 'EVEREST pipeline subversion'))
    cards.append(('DATE', strftime('%Y-%m-%d'),
                  'EVEREST file creation date (YYYY-MM-DD)'))

    # The images
    format = '%dD' % model.pixel_images[0].shape[1]
    arrays = [pyfits.Column(name='STAMP1', format=format,
                            array=model.pixel_images[0]),
              pyfits.Column(name='STAMP2', format=format,
                            array=model.pixel_images[1]),
              pyfits.Column(name='STAMP3', format=format,
                            array=model.pixel_images[2])]

    # Create the HDU
    header = pyfits.Header(cards=cards)
    cols = pyfits.ColDefs(arrays)
    hdu = pyfits.BinTableHDU.from_columns(
        cols, header=header, name='POSTAGE STAMPS')

    return hdu
1285425
def loadkml(self, filename):
        ''''''
        #Open the zip file
        nodes = self.readkmz(filename)

        self.snap_points = []

        #go through each object in the kml...
        for n in nodes:     
            point = self.readObject(n)

            #and place any polygons on the map
            if self.mpstate.map is not None and point[0] == 'Polygon':
                self.snap_points.extend(point[2])

                #print("Adding " + point[1])
                newcolour = (random.randint(0, 255), 0, random.randint(0, 255))
                curpoly = mp_slipmap.SlipPolygon(point[1], point[2],
                                                             layer=2, linewidth=2, colour=newcolour)
                self.mpstate.map.add_object(curpoly)
                self.allayers.append(curpoly)
                self.curlayers.append(point[1])
                
                
            #and points - barrell image and text
            if self.mpstate.map is not None and point[0] == 'Point':
                #print("Adding " + point[1])
                icon = self.mpstate.map.icon('barrell.png')
                curpoint = mp_slipmap.SlipIcon(point[1], latlon = (point[2][0][0], point[2][0][1]), layer=3, img=icon, rotation=0, follow=False)
                curtext = mp_slipmap.SlipLabel(point[1], point = (point[2][0][0], point[2][0][1]), layer=4, label=point[1], colour=(0,255,255))
                self.mpstate.map.add_object(curpoint)
                self.mpstate.map.add_object(curtext)
                self.allayers.append(curpoint)
                self.alltextlayers.append(curtext)
                self.curlayers.append(point[1])
                self.curtextlayers.append(point[1])
        self.menu_needs_refreshing = True
435089
def main(src_file, dest_file, **kwargs):
    
    mmap = mapnik.Map(1, 1)
    # allow [zoom] filters to work
    mmap.srs = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null'
    load_kwargs = dict([(k, v) for (k, v) in kwargs.items() if k in ('cache_dir', 'scale', 'verbose', 'datasources_cfg', 'user_styles')])
    cascadenik.load_map(mmap, src_file, dirname(realpath(dest_file)), **load_kwargs)
    
    (handle, tmp_file) = tempfile.mkstemp(suffix='.xml', prefix='cascadenik-mapnik-')
    os.close(handle)
    mapnik.save_map(mmap, tmp_file)
    
    if kwargs.get('pretty'):
        doc = ElementTree.fromstring(open(tmp_file, 'rb').read())
        cascadenik._compile.indent(doc)
        f = open(tmp_file, 'wb')
        ElementTree.ElementTree(doc).write(f)
        f.close()
        
    # manually unlinking seems to be required on windows
    if os.path.exists(dest_file):
        os.unlink(dest_file)

    os.chmod(tmp_file, 0666^os.umask(0))
    shutil.move(tmp_file, dest_file)
    return 0
973476
def get_dataset(self, key, info):
        """"""
        logger.debug('Reading dataset {}'.format(key.name))

        # Read data from file and calibrate if necessary
        if 'longitude' in key.name:
            data = self.geo_data['lon']
        elif 'latitude' in key.name:
            data = self.geo_data['lat']
        else:
            tic = datetime.now()
            data = self.calibrate(self.nc['data'].isel(time=0),
                                  calibration=key.calibration,
                                  channel=key.name)
            logger.debug('Calibration time: {}'.format(datetime.now() - tic))

        # Mask space pixels
        data = data.where(self.meta['earth_mask'])

        # Set proper dimension names
        data = data.rename({'xc': 'x', 'yc': 'y'})

        # Update metadata
        self._update_metadata(data, ds_info=info)

        return data
614290
def load_map_coordinates(map_file):
    
    if map_file[-4:] == ".pkl":
        map_data = pickle.load(open(map_file))
        lon = map_data['lon']
        lat = map_data['lat']
    else:
        map_data = Dataset(map_file)
        if "lon" in map_data.variables.keys():
            lon = map_data.variables['lon'][:]
            lat = map_data.variables['lat'][:]
        else:
            lon = map_data.variables["XLONG"][0]
            lat = map_data.variables["XLAT"][0]
    return lon, lat
624711
def map(h2: Histogram2D, *, show_zero: bool = True, show_values: bool = False, **kwargs) -> dict:
    """"""
    vega = _create_figure(kwargs)

    values_arr = get_data(h2, kwargs.pop("density", None), kwargs.pop("cumulative", None))
    values = values_arr.tolist()
    value_format = get_value_format(kwargs.pop("value_format", None))

    _add_title(h2, vega, kwargs)
    _create_scales(h2, vega, kwargs)
    _create_axes(h2, vega, kwargs)
    _create_cmap_scale(values_arr, vega, kwargs)
    _create_colorbar(vega, kwargs)

    x = h2.get_bin_centers(0)
    y = h2.get_bin_centers(1)
    x1 = h2.get_bin_left_edges(0)
    x2 = h2.get_bin_right_edges(0)
    y1 = h2.get_bin_left_edges(1)
    y2 = h2.get_bin_right_edges(1)

    data = []
    for i in range(h2.shape[0]):
        for j in range(h2.shape[1]):
            if not show_zero and values[i][j] == 0:
                continue
            item = {
                "x": float(x[i]),
                "x1": float(x1[i]),
                "x2": float(x2[i]),
                "y": float(y[j]),
                "y1": float(y1[j]),
                "y2": float(y2[j]),
                "c": float(values[i][j])
            }
            if show_values:
                item["label"] = value_format(values[i][j])
            data.append(item)

    vega["data"] = [{
        "name": "table",
        "values": data
    }]

    vega["marks"] = [
        {
            "type": "rect",
            "from": {"data": "table"},
            "encode": {
                "enter": {
                    "x": {"scale": "xscale", "field": "x1"},
                    "x2": {"scale": "xscale", "field": "x2"},
                    "y": {"scale": "yscale", "field": "y1"},
                    "y2": {"scale": "yscale", "field": "y2"},
                    "fill": {"scale": "color", "field": "c"},
                    "stroke": {"value": 0},
                    # "strokeWidth": {"value": 0},
                    # "fillColor": {"value": "#ffff00"}
                },
                "update": {
                    "fillOpacity": {"value": kwargs.pop("alpha", 1)}
                },
                # "hover": {
                #     "fillOpacity": {"value": 0.5}
                # }
            }
        }
    ]

    if show_values:
        vega["marks"].append(
            {
                "type": "text",
                "from": {"data": "table"},
                "encode": {
                    "enter": {
                        "align": {"value": "center"},
                        "baseline": {"value": "middle"},
                        "fontSize": {"value": 13},
                        "fontWeight": {"value": "bold"},
                        "text": {"field": "label"},
                        "x": {"scale": "xscale", "field": "x"},
                        "y": {"scale": "yscale", "field": "y"},
                    }
                }
            }
        )

    return vega
1121223
def _map_from_binaries(self, eopatch, dst_shape, request_data):
        
        if self.feature_name in eopatch[self.feature_type]:
            raster = eopatch[self.feature_type][self.feature_name].squeeze()
        else:
            raster = np.ones(dst_shape, dtype=self.raster_dtype) * self.no_data_val

        new_raster = self._reproject(eopatch, self._to_binary_mask(request_data))

        # update raster
        raster[new_raster != 0] = new_raster[new_raster != 0]

        return raster
449312
def get_cmap(self):
        

        # now generate the colormap from the ordered list
        r = []
        g = []
        b = []
        for p in self._colorpoint_list:
            r.append((p[0], p[1][0]*1.0, p[2][0]*1.0))
            g.append((p[0], p[1][1]*1.0, p[2][1]*1.0))
            b.append((p[0], p[1][2]*1.0, p[2][2]*1.0))

        # store the formatted dictionary
        c = {'red':r, 'green':g, 'blue':b}

        # now set the dang thing
        return _mpl.colors.LinearSegmentedColormap('custom', c)
1319915
def make_figure_hmaps(extractors, what):
    
    import matplotlib.pyplot as plt
    fig = plt.figure()
    ncalcs = len(extractors)
    for i, ex in enumerate(extractors):
        oq = ex.oqparam
        n_poes = len(oq.poes)
        sitecol = ex.get('sitecol')
        hmaps = ex.get(what)
        [imt] = hmaps.imt
        [kind] = hmaps.kind
        for j, poe in enumerate(oq.poes):
            ax = fig.add_subplot(n_poes, ncalcs, j * ncalcs + i + 1)
            ax.grid(True)
            ax.set_xlabel('hmap for IMT=%s, kind=%s, poe=%s\ncalculation %d, '
                          'inv_time=%dy' %
                          (imt, kind, poe, ex.calc_id, oq.investigation_time))
            bmap = basemap('cyl', sitecol)
            bmap.scatter(sitecol['lon'], sitecol['lat'],
                         c=hmaps[kind][:, 0, j], cmap='jet')
    return plt
742501
def get_dataset(self, key, info):
        """"""
        logger.debug('Reading dataset {}'.format(key.name))

        # Read data from file and calibrate if necessary
        if 'longitude' in key.name:
            data = self.nc['lon']
        elif 'latitude' in key.name:
            data = self.nc['lat']
        else:
            raise KeyError("Unknown dataset: {}".format(key.name))

        # Set proper dimension names
        data = data.rename({'xc': 'x', 'yc': 'y'})

        # Update metadata
        data.attrs.update(info)
        return data
1365886
def _get_data_files(self):
        """"""
        self.analyze_manifest()
        return list(map(self._get_pkg_data_files, self.packages or ()))
408193
def make_map():
    """"""
    map = Mapper(directory=config['pylons.paths']['controllers'],
                 always_scan=config['debug'], explicit=True)
    map.minimization = False
    
    # The ErrorController route (handles 404/500 error pages); it should
    # likely stay at the top, ensuring it can always be resolved
    map.connect('/error/{action}', controller='error')
    map.connect('/error/{action}/{id}', controller='error')

    # CUSTOM ROUTES HERE

    # mapfiles routes
    map.connect('/mapfiles/default', controller='mapfiles', action='get_default_mapfile') 
    map.resource('MapFiles','mapfiles') 
    map.connect('/mapfiles/{id}/symbols', controller='mapfiles', action='get_symbols')
    map.connect('/mapfiles/{id}/fonts', controller='mapfiles', action='get_fonts')
    map.connect('/mapfiles/{id}/download', controller='mapfiles', action='download_mapfile') 
    map.connect('/mapfiles/{id}/wms', controller='mapfiles', action='wms_proxy') 

    # datastores routes
    map.resource('DataStores', 'datastores')

    # datasources routes
    map.connect('/datastores/{datastore_id}/datasources',
                controller='datasources', conditions={'method': ['POST']}, action='create')
    map.connect('/datastores/{datastore_id}/datasources',
                controller='datasources', action='index')
    map.connect('/datastores/{datastore_id}/datasources/{datasource_id}',
                controller='datasources', action='show')
    map.connect('/datastores/{datastore_id}/datasources/{datasource_id}/columns',
                controller='datasources', action='showcolumns')
    map.connect('/datastores/{datastore_id}/datasources/{datasource_id}/mapfile',
                controller='datasources', action='showmapfile')

    # layertemplates routes
    map.resource('LayerTemplates', 'layertemplates')

    # auth routes
    map.connect('/signin', controller='main', action='signin')
    map.connect('/signout', controller='main', action='signout')

    # default route for root ;)
    map.connect('/', controller='main', action='index')
    map.connect('/layout.js', controller='main', action='layout')

    map.connect('/{controller}/{action}')
    map.connect('/{controller}/{action}/{id}')


    return map
227149
def parse_map_Ns(self):
        """"""
        Kd = os.path.join(self.dir, " ".join(self.values[1:]))
        self.this_material.set_texture_specular_highlight(Kd)