Tuesday, 1 February 2022

VSCODE Javascript ----how to Implicit import library

I want to hide "import" when referencing the library, that is, local/global import, and use the contents of the library normally Can it be achieved, or is it already achieved?

I use these codes in a plug-in loader, so I don’t need to import it. It’s just a tool for prompting to view annotations.

I am using VSCODE and its built-in JavaScript

example:

import { mc } from "./Libary/Game/Player";

mc.runcmd('kill u m')

want to use:

mc.runcmd('kill u m')

And you can also see comments and function types, etc.



from VSCODE Javascript ----how to Implicit import library

Getting count of permutations in a faster way

Using this code to get count of permutations is slow on big numbers as the partition part takes long time to calculate all the partitions for a number like 100 and because of all the partitions in the ram, it is very ram consuming. Any solution to get count of permutations in a faster way? Thanks.

If we have get_permutations_count(10,10) means all the permutations in the length of 10 using 10 distinct symbols and If we have get_permutations_count(10,1) means all the permutations in the length of 10 using 1 distinct symbol which going to be 10 as those permutations will be 0000000000 1111111111 2222222222 333333333 ... 9999999999.

from sympy.utilities.iterables import partitions
from sympy import factorial

def get_permutations_count(all_symbols_count, used_symbols_count):
    m = n = all_symbols_count
    r = n - used_symbols_count
    while True:
        result = 0
        for partition in partitions(r):
            length = 0
            if 2 * r > n:
                for k, v in partition.items():
                    length += (k + 1) * v
            if length > n:
                pass
            else:
                C = binomial(m, n - r)
                d = n - r
                for v in partition.values():
                    C *= binomial(d, v)
                    d -= v
                # permutations
                P = 1
                for k in partition.keys():
                    for v in range(partition[k]):
                        P *= factorial(k + 1)
                P = factorial(n) // P
                result += C * P
        return result

if __name__ == "__main__":
print(get_permutations_count(300, 270)) # takes long time to calculate
print(get_permutations_count(10, 9) # prints: 163296000
print(get_permutations_count(10, 10)) # prints: 3628800


from Getting count of permutations in a faster way

How can a choropleth map be combined with a shaded raster in Python?

I want to plot characteristics of areas on a map, but with very uneven population density, the larger tiles misleadingly attract attention. Think of averages (of test scores, say) by ZIP codes.

High-resolution maps are available to separate inhabited locales and even density within them. The Python code below does produce a raster colored according to the average such density for every pixel.

However, what I would really need is coloring from a choropleth map of the same area (ZIP codes of Hungary in this case) but the coloring affecting only points that would show up on the raster anyway. The raster could only determine the gamma of the pixel (or maybe height in some 3D analog). What is a good way to go about this?

A rasterio.mask.mask somehow?

(By the way, an overlay with the ZIP code boundaries would also be nice, but I have a better understanding of how that could work with GeoViews.)

import rasterio
import os
import datashader as ds
from datashader import transfer_functions as tf
import xarray as xr
from matplotlib.cm import viridis

# download a GeoTIFF from this location: https://data.humdata.org/dataset/hungary-high-resolution-population-density-maps-demographic-estimates
data_path = '~/Downloads/'
file_name = 'HUN_youth_15_24.tif'  # young people
file_path = os.path.join(data_path, file_name)
src = rasterio.open(file_path)
da = xr.open_rasterio(file_path)
cvs = ds.Canvas(plot_width=5120, plot_height=2880)
img = tf.shade(cvs.raster(da,layer=1), cmap=viridis)
ds.utils.export_image(img, "map", export_path=data_path, fmt=".png")


from How can a choropleth map be combined with a shaded raster in Python?