Commit d7561ea8 authored by ecofractal's avatar ecofractal

upload fractaL code

parent fc42d928
This diff is collapsed.
# fractaL
# fractaL
fractaL is a tool for promotion of digital literacy and ecological thinking using images and sounds from environmental data.
https://ecofractal.gitlab.io/
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
{"description":{"title":"Global Land and Ocean Temperature Anomalies, January","units":"Degrees Celsius","base_period":"1901-2000","missing":-999},"data":{"1880":"-0.01","1881":"-0.03","1882":"0.08","1883":"-0.27","1884":"-0.19","1885":"-0.44","1886":"-0.12","1887":"-0.40","1888":"-0.39","1889":"-0.10","1890":"-0.36","1891":"-0.37","1892":"-0.23","1893":"-0.67","1894":"-0.43","1895":"-0.43","1896":"-0.10","1897":"-0.18","1898":"-0.03","1899":"-0.10","1900":"-0.23","1901":"-0.12","1902":"-0.09","1903":"-0.21","1904":"-0.54","1905":"-0.35","1906":"-0.18","1907":"-0.35","1908":"-0.37","1909":"-0.55","1910":"-0.31","1911":"-0.51","1912":"-0.28","1913":"-0.35","1914":"0.09","1915":"-0.13","1916":"-0.18","1917":"-0.43","1918":"-0.21","1919":"-0.23","1920":"-0.11","1921":"-0.06","1922":"-0.31","1923":"-0.21","1924":"-0.25","1925":"-0.32","1926":"0.17","1927":"-0.16","1928":"-0.07","1929":"-0.47","1930":"-0.32","1931":"-0.05","1932":"0.16","1933":"-0.31","1934":"-0.32","1935":"-0.29","1936":"-0.26","1937":"-0.17","1938":"-0.04","1939":"-0.17","1940":"-0.13","1941":"0.17","1942":"0.29","1943":"-0.03","1944":"0.42","1945":"0.16","1946":"0.22","1947":"-0.19","1948":"0.05","1949":"0.12","1950":"-0.28","1951":"-0.29","1952":"0.15","1953":"0.10","1954":"-0.24","1955":"0.09","1956":"-0.18","1957":"-0.12","1958":"0.30","1959":"0.12","1960":"-0.00","1961":"0.12","1962":"0.13","1963":"0.04","1964":"0.05","1965":"-0.07","1966":"-0.04","1967":"-0.11","1968":"-0.19","1969":"-0.13","1970":"0.12","1971":"-0.00","1972":"-0.24","1973":"0.26","1974":"-0.19","1975":"0.12","1976":"-0.02","1977":"0.06","1978":"0.16","1979":"0.16","1980":"0.31","1981":"0.47","1982":"0.14","1983":"0.52","1984":"0.28","1985":"0.18","1986":"0.33","1987":"0.31","1988":"0.55","1989":"0.22","1990":"0.36","1991":"0.45","1992":"0.47","1993":"0.38","1994":"0.29","1995":"0.55","1996":"0.27","1997":"0.37","1998":"0.60","1999":"0.50","2000":"0.34","2001":"0.48","2002":"0.70","2003":"0.69","2004":"0.60","2005":"0.62","2006":"0.46","2007":"0.88","2008":"0.27","2009":"0.59","2010":"0.70","2011":"0.47","2012":"0.42","2013":"0.58","2014":"0.69","2015":"0.82","2016":"1.06","2017":"0.91","2018":"0.72","2019":"0.88"}}
\ No newline at end of file
from . import midisource
from .core import *
__version__ = '0.0.2'
This diff is collapsed.
NOTES = [
['C'], ['C#', 'Db'], ['D'], ['D#', 'Eb'], ['E'], ['F'], ['F#', 'Gb'],
['G'], ['G#', 'Ab'], ['A'], ['A#', 'Bb'], ['B']
]
def get_keys():
base_keys = {
'c_major': ['C', 'D', 'E', 'F', 'G', 'A', 'B'],
'd_major': ['D', 'E', 'F#', 'G', 'A', 'B', 'C#'],
'e_major': ['E', 'F#', 'G#', 'A', 'B', 'C#', 'D#'],
'f_major': ['F', 'G', 'A', 'Bb', 'C', 'D', 'E', 'F'],
'g_major': ['G', 'A', 'B', 'C', 'D', 'E', 'F#'],
'a_major': ['A', 'B', 'C#', 'D', 'E', 'F#', 'G#', 'A'],
'b_major': ['B', 'C#', 'D#', 'E', 'F#', 'G#', 'A#', 'B'],
'c_sharp_major': ['Db', 'Eb', 'F', 'Gb', 'Ab', 'Bb', 'C', 'Db'],
'd_sharp_major': ['Eb', 'F', 'G', 'Ab', 'Bb', 'C', 'D'],
'f_sharp_major': ['F#', 'G#', 'A#', 'B', 'C#', 'D#', 'F', 'F#'],
'g_sharp_major': ['Ab', 'Bb', 'C', 'Db', 'Eb', 'F', 'G', 'Ab'],
'a_sharp_major': ['Bb', 'C', 'D', 'Eb', 'F', 'G', 'A', 'Bb']
}
base_keys['d_flat_major'] = base_keys['c_sharp_major']
base_keys['e_flat_major'] = base_keys['d_sharp_major']
base_keys['g_flat_major'] = base_keys['f_sharp_major']
base_keys['a_flat_major'] = base_keys['g_sharp_major']
base_keys['b_flat_major'] = base_keys['a_sharp_major']
return base_keys
KEYS = get_keys()
# Instrument and Percussion map from
# https://www.midi.org/specifications/item/gm-level-1-sound-set
INSTRUMENTS = {
'accordion': 22,
'acoustic bass': 33,
'acoustic grand piano': 1,
'acoustic guitar (nylon)': 25,
'acoustic guitar (steel)': 26,
'agogo': 114,
'alto sax': 66,
'applause': 127,
'bagpipe': 110,
'banjo': 106,
'baritone sax': 68,
'bassoon': 71,
'bird tweet': 124,
'blown bottle': 77,
'brass section': 62,
'breath noise': 122,
'bright acoustic piano': 2,
'celesta': 9,
'cello': 43,
'choir aahs': 53,
'church organ': 20,
'clarinet': 72,
'clavi': 8,
'contrabass': 44,
'distortion guitar': 31,
'drawbar organ': 17,
'dulcimer': 16,
'electric bass (finger)': 34,
'electric bass (pick)': 35,
'electric grand piano': 3,
'electric guitar (clean)': 28,
'electric guitar (jazz)': 27,
'electric guitar (muted)': 29,
'electric piano 1': 5,
'electric piano 2': 6,
'english horn': 70,
'fiddle': 111,
'flute': 74,
'french horn': 61,
'fretless bass': 36,
'fx 1 (rain)': 97,
'fx 2 (soundtrack)': 98,
'fx 3 (crystal)': 99,
'fx 4 (atmosphere)': 100,
'fx 5 (brightness)': 101,
'fx 6 (goblins)': 102,
'fx 7 (echoes)': 103,
'fx 8 (sci-fi)': 104,
'glockenspiel': 10,
'guitar fret noise': 121,
'guitar harmonics': 32,
'gunshot': 128,
'harmonica': 23,
'harpsichord': 7,
'helicopter': 126,
'honky-tonk piano': 4,
'kalimba': 109,
'koto': 108,
'lead 1 (square)': 81,
'lead 2 (sawtooth)': 82,
'lead 3 (calliope)': 83,
'lead 4 (chiff)': 84,
'lead 5 (charang)': 85,
'lead 6 (voice)': 86,
'lead 7 (fifths)': 87,
'lead 8 (bass + lead)': 88,
'marimba': 13,
'melodic tom': 118,
'music box': 11,
'muted trumpet': 60,
'oboe': 69,
'ocarina': 80,
'orchestra hit': 56,
'orchestral harp': 47,
'overdriven guitar': 30,
'pad 1 (new age)': 89,
'pad 2 (warm)': 90,
'pad 3 (polysynth)': 91,
'pad 4 (choir)': 92,
'pad 5 (bowed)': 93,
'pad 6 (metallic)': 94,
'pad 7 (halo)': 95,
'pad 8 (sweep)': 96,
'pan flute': 76,
'percussive organ': 18,
'piccolo': 73,
'pizzicato strings': 46,
'recorder': 75,
'reed organ': 21,
'reverse cymbal': 120,
'rock organ': 19,
'seashore': 123,
'shakuhachi': 78,
'shamisen': 107,
'shanai': 112,
'sitar': 105,
'slap bass 1': 37,
'slap bass 2': 38,
'soprano sax': 65,
'steel drums': 115,
'string ensemble 1': 49,
'string ensemble 2': 50,
'synth bass 1': 39,
'synth bass 2': 40,
'synth drum': 119,
'synth voice': 55,
'synthbrass 1': 63,
'synthbrass 2': 64,
'synthstrings 1': 51,
'synthstrings 2': 52,
'taiko drum': 117,
'tango accordion': 24,
'telephone ring': 125,
'tenor sax': 67,
'timpani': 48,
'tinkle bell': 113,
'tremolo strings': 45,
'trombone': 58,
'trumpet': 57,
'tuba': 59,
'tubular bells': 15,
'vibraphone': 12,
'viola': 42,
'violin': 41,
'voice oohs': 54,
'whistle': 79,
'woodblock': 116,
'xylophone': 14
}
PERCUSSION = {
'acoustic bass drum': 35,
'acoustic snare': 38,
'bass drum 1': 36,
'cabasa': 69,
'chinese cymbal': 52,
'claves': 75,
'closed hi hat': 42,
'cowbell': 56,
'crash cymbal 1': 49,
'crash cymbal 2': 57,
'electric snare': 40,
'hand clap': 39,
'hi bongo': 60,
'hi wood block': 76,
'hi-mid tom': 48,
'high agogo': 67,
'high floor tom': 43,
'high timbale': 65,
'high tom': 50,
'long guiro': 74,
'long whistle': 72,
'low agogo': 68,
'low bongo': 61,
'low conga': 64,
'low floor tom': 41,
'low timbale': 66,
'low tom': 45,
'low wood block': 77,
'low-mid tom': 47,
'maracas': 70,
'mute cuica': 78,
'mute hi conga': 62,
'mute triangle': 80,
'open cuica': 79,
'open hi conga': 63,
'open hi-hat': 46,
'open triangle': 81,
'pedal hi-hat': 44,
'ride bell': 53,
'ride cymbal 1': 51,
'ride cymbal 2': 59,
'short guiro': 73,
'short whistle': 71,
'side stick': 37,
'splash cymbal': 55,
'tambourine': 54,
'vibraslap': 58
}
\ No newline at end of file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri May 10 10:31:39 2019
@author: s_tatus
"""
import numpy as np
import scipy
import fractaL.core as fractal
img = scipy.misc.imread("sample_data/img/box2.png")
img = fractal.rgb2gray(img)
#90 is the threshold that will vary accordinly to the picture
img = fractal.fracdim(img, 90)
print("Minkowski–Bouligand dimension (computed): ", img)
print("Haussdorf dimension (theoretical): ", (np.log(3)/np.log(2)))
'''
Multitrack Code - fractaL April 15th 2019
Here, you can find the code to build a multiple MIDI instrument sound using
different environmental variables.
@author: smjacques
'''
import pandas as pd
import fractaL.core as fractal
#import data in a dataframe(df) format
df = pd.read_csv('sample_data/multilong.csv')
test = fractal.normalize_climate_multi(df)
# Let's add some instruments to each track!
instruments_to_add = [
'violin', 'hi wood block', 'melodic tom'
]
multitrack_data_with_instruments = []
for index, track in enumerate(test):
multitrack_data_with_instruments.append([instruments_to_add[index]] + track)
# test a drum track with a solid beat
max_number_of_beats = multitrack_data_with_instruments[1][-2][1]
bass_drum = []
for beat in range(0, int(max_number_of_beats + 1)):
bass_drum.append((beat, 1))
beat_track = ['bass drum 1'] + bass_drum
multitrack_data_with_instruments.append(beat_track)
print(multitrack_data_with_instruments)
fractal.play_midi_from_data(multitrack_data_with_instruments,
track_type='multiple', key='f_major')
\ No newline at end of file
'''
This is a fractaL code developed to sonify data.
Partially based on Sonify library.
@author: smjacques
'''
import json
import matplotlib.pyplot as plt
import pandas as pd
import fractaL.core as fractal
#from fractaL.core import normalize_climate_data, csv_to_MIDITime_data
from miditime.miditime import MIDITime
with open('sample_data/1880-2019.json') as data_file:
climate_json = json.load(data_file)
json_pd = climate_json
normalized_climate_data = fractal.normalize_climate_data(climate_json)
plt.scatter(*zip(*normalized_climate_data))
#print(normalized_climate_data)
'''
Convert Array to pandas
'''
#define labels date and temperature
labels = ['date', 'temperature']
climatefile = pd.DataFrame.from_records(normalized_climate_data, columns=labels)
'''export the dataframe to csv. then read it with csv_to_MIDITime function'''
climatefile.to_csv('sample_data/climatefile.csv', index=False)
climate_ex = fractal.csv_to_MIDITime_data('sample_data/climatefile.csv')
###
#Instantiate the class with a tempo (120bpm), the name file name
#MIDITime(tempo=120, outfile='miditime.mid', seconds_per_year=5, base_octave=5,
# octave_range=1, custom_epoch=None)
#*For data before 1970 the custom_epoch (UNIX Time) must be setted up
###
mymidi = MIDITime(120, 'fractal.mid',100, 4, 2)
# Make a beat based on days_sice_epoch(maybe change to UNIX time - more common)
my_data_timed = [{'beat': mymidi.beat(d['days_since_epoch']),
'magnitude': d['magnitude']} for d in climate_ex]
#Setting starting time
start_time = my_data_timed[0]['beat']
{"description":{"title":"Global Land and Ocean Temperature Anomalies, January","units":"Degrees Celsius","base_period":"1901-2000","missing":-999},"data":{"1880":"-0.01","1881":"-0.03","1882":"0.08","1883":"-0.27","1884":"-0.19","1885":"-0.44","1886":"-0.12","1887":"-0.40","1888":"-0.39","1889":"-0.10","1890":"-0.36","1891":"-0.37","1892":"-0.23","1893":"-0.67","1894":"-0.43","1895":"-0.43","1896":"-0.10","1897":"-0.18","1898":"-0.03","1899":"-0.10","1900":"-0.23","1901":"-0.12","1902":"-0.09","1903":"-0.21","1904":"-0.54","1905":"-0.35","1906":"-0.18","1907":"-0.35","1908":"-0.37","1909":"-0.55","1910":"-0.31","1911":"-0.51","1912":"-0.28","1913":"-0.35","1914":"0.09","1915":"-0.13","1916":"-0.18","1917":"-0.43","1918":"-0.21","1919":"-0.23","1920":"-0.11","1921":"-0.06","1922":"-0.31","1923":"-0.21","1924":"-0.25","1925":"-0.32","1926":"0.17","1927":"-0.16","1928":"-0.07","1929":"-0.47","1930":"-0.32","1931":"-0.05","1932":"0.16","1933":"-0.31","1934":"-0.32","1935":"-0.29","1936":"-0.26","1937":"-0.17","1938":"-0.04","1939":"-0.17","1940":"-0.13","1941":"0.17","1942":"0.29","1943":"-0.03","1944":"0.42","1945":"0.16","1946":"0.22","1947":"-0.19","1948":"0.05","1949":"0.12","1950":"-0.28","1951":"-0.29","1952":"0.15","1953":"0.10","1954":"-0.24","1955":"0.09","1956":"-0.18","1957":"-0.12","1958":"0.30","1959":"0.12","1960":"-0.00","1961":"0.12","1962":"0.13","1963":"0.04","1964":"0.05","1965":"-0.07","1966":"-0.04","1967":"-0.11","1968":"-0.19","1969":"-0.13","1970":"0.12","1971":"-0.00","1972":"-0.24","1973":"0.26","1974":"-0.19","1975":"0.12","1976":"-0.02","1977":"0.06","1978":"0.16","1979":"0.16","1980":"0.31","1981":"0.47","1982":"0.14","1983":"0.52","1984":"0.28","1985":"0.18","1986":"0.33","1987":"0.31","1988":"0.55","1989":"0.22","1990":"0.36","1991":"0.45","1992":"0.47","1993":"0.38","1994":"0.29","1995":"0.55","1996":"0.27","1997":"0.37","1998":"0.60","1999":"0.50","2000":"0.34","2001":"0.48","2002":"0.70","2003":"0.69","2004":"0.60","2005":"0.62","2006":"0.46","2007":"0.88","2008":"0.27","2009":"0.59","2010":"0.70","2011":"0.47","2012":"0.42","2013":"0.58","2014":"0.69","2015":"0.82","2016":"1.06","2017":"0.91","2018":"0.72","2019":"0.88"}}
\ No newline at end of file
date,temperature
0.0,37.00578034682081
0.21582733812949642,35.88439306358382
0.43165467625899284,42.052023121387286
0.6474820143884893,22.427745664739888
0.8633093525179857,26.913294797687865
1.079136690647482,12.895953757225435
1.2949640287769786,30.838150289017342
1.5107913669064748,15.138728323699423
1.7266187050359714,15.699421965317923
1.9424460431654675,31.95953757225434
2.158273381294964,17.38150289017341
2.3741007194244603,16.820809248554916
2.589928057553957,24.670520231213878
2.805755395683453,0.0
3.0215827338129495,13.456647398843934
3.237410071942446,13.456647398843934
3.4532374100719427,31.95953757225434
3.669064748201439,27.47398843930636
3.884892086330935,35.88439306358382
4.100719424460432,31.95953757225434
4.316546762589928,24.670520231213878
4.532374100719425,30.838150289017342
4.748201438848921,32.52023121387284
4.9640287769784175,25.79190751445087
5.179856115107914,7.289017341040463
5.39568345323741,17.94219653179191
5.611510791366906,27.47398843930636
5.827338129496403,17.94219653179191
6.043165467625899,16.820809248554916
6.258992805755396,6.728323699421964
6.474820143884892,20.184971098265898
6.690647482014389,8.971098265895955
6.9064748201438855,21.86705202312139
7.122302158273381,17.94219653179191
7.338129496402878,42.61271676300578
7.553956834532373,30.277456647398846
7.76978417266187,27.47398843930636
7.985611510791367,13.456647398843934
8.201438848920864,25.79190751445087
8.417266187050359,24.670520231213878
8.633093525179856,31.398843930635845
8.848920863309353,34.20231213872833
9.06474820143885,20.184971098265898
9.280575539568346,25.79190751445087
9.496402877697841,23.54913294797688
9.712230215827338,19.6242774566474
9.928057553956835,47.09826589595376
10.143884892086332,28.595375722543356
10.359712230215829,33.64161849710983
10.575539568345324,11.213872832369946
10.79136690647482,19.6242774566474
11.007194244604316,34.763005780346816
11.223021582733812,46.53757225433527
11.43884892086331,20.184971098265898
11.654676258992806,19.6242774566474
11.870503597122301,21.306358381502893
12.086330935251798,22.988439306358384
12.302158273381295,28.034682080924856
12.517985611510792,35.323699421965316
12.733812949640289,28.034682080924856
12.949640287769784,30.277456647398846
13.16546762589928,47.09826589595376
13.381294964028777,53.826589595375715
13.597122302158274,35.88439306358382
13.812949640287771,61.11560693641619
14.028776978417266,46.53757225433527
14.244604316546763,49.90173410404624
14.46043165467626,26.913294797687865
14.676258992805757,40.369942196531795
14.892086330935253,44.294797687861276
15.107913669064747,21.86705202312139
15.323741007194245,21.306358381502893
15.53956834532374,45.97687861271677
15.755395683453235,43.17341040462428
15.971223021582734,24.10982658959538
16.18705035971223,42.61271676300578
16.402877697841728,27.47398843930636
16.618705035971225,30.838150289017342
16.834532374100718,54.38728323699422
17.050359712230218,44.294797687861276
17.26618705035971,37.566473988439306
17.48201438848921,44.294797687861276
17.697841726618705,44.855491329479776
17.9136690647482,39.8092485549133
18.1294964028777,40.369942196531795
18.345323741007192,33.64161849710983
18.561151079136692,35.323699421965316
18.776978417266186,31.398843930635845
18.992805755395683,26.913294797687865
19.20863309352518,30.277456647398846
19.424460431654676,44.294797687861276
19.640287769784173,37.566473988439306
19.85611510791367,24.10982658959538
20.071942446043163,52.14450867052023
20.287769784172664,26.913294797687865
20.503597122302157,44.294797687861276
20.719424460431657,36.445086705202314
20.93525179856115,40.93063583815029
21.151079136690647,46.53757225433527
21.366906474820144,46.53757225433527
21.58273381294964,54.94797687861272
21.798561151079138,63.91907514450868
22.01438848920863,45.41618497109827
22.230215827338128,66.72254335260115
22.446043165467625,53.26589595375722
22.66187050359712,47.65895953757226
22.87769784172662,56.06936416184971
23.093525179856115,54.94797687861272
23.309352517985612,68.40462427745666
23.52517985611511,49.90173410404624
23.741007194244602,57.7514450867052
23.956834532374103,62.79768786127169
24.172661870503596,63.91907514450868
24.388489208633096,58.8728323699422
24.60431654676259,53.826589595375715
24.820143884892087,68.40462427745666
25.035971223021583,52.70520231213874
25.25179856115108,58.3121387283237
25.467625899280577,71.20809248554913
25.68345323741007,65.60115606936415
25.899280575539567,56.630057803468205
26.115107913669064,64.47976878612717
26.33093525179856,76.81502890173411
26.546762589928058,76.2543352601156
26.762589928057555,71.20809248554913
26.978417266187048,72.32947976878613
27.194244604316548,63.35838150289018
27.41007194244604,86.90751445086705
27.625899280575542,52.70520231213874
27.841726618705035,70.64739884393063
28.057553956834532,76.81502890173411
28.27338129496403,63.91907514450868
28.489208633093526,61.11560693641619
28.705035971223023,70.08670520231215
28.92086330935252,76.2543352601156
29.136690647482013,83.54335260115606
29.352517985611513,97.0
29.568345323741006,88.58959537572255
29.784172661870507,77.93641618497111
30.0,86.90751445086705
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
{"temp":{"2004":30.3,"2005":27.1,"2006":0,"2007":28.2,"2008":0,"2009":28.7,"2010":27.7,"20041":24,"20051":0,"20061":23.1,"20071":22.7,"20081":23.1,"20082":22.3,"20083":21.5,"20084":21.3,"20085":21,"20086":20.7,"20091":29,"20092":29,"20093":29,"20094":29,"20095":21.7,"20096":21.7,"20097":21.7,"20101":27.5,"20102":27.1}}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment