Bucket List

{{This article was originally posted on December 22, 2016. My posts were lost and after being found I am re-posting them.}}

One day (in 2011) got a whim to try and write a Python program to that will try and find the best combinations of numbers (within given range and given tolerances) that will add up to a fixed target total. Didn’t think of much use for it then, but have used it in multiple instances to get some good results. The algorithm works as the diagram below :

The Python code for it :

import random
def generateBucketList():
    fixedTargetTotal = 94
    bucketMidPoints = [[10, 5], [5, 10], [6], [5], [5], [6], [6], [8], [6], [8], [5, 5, 5, 5]]
    bucketAssign = [1, 2, 3]
    rangeFromMidPoint = [2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 4]
    bucketMidPoints = sum(bucketMidPoints, [])
    finalAssign = []
    if sum(bucketMidPoints) > fixedTargetTotal:  # reduce(lambda x, y: x + y, bucketMidPoints) > fixedTargetTotal:
        while sum(bucketAssign) != fixedTargetTotal:  # reduce(lambda x, y: x + y, bucketAssign) != fixedTargetTotal:
            # bucketAssign = [random.randint(int(0.6*i),i) for i in bucketMidPoints]
            bucketAssign = []
            for i in bucketMidPoints:
                if i != 0:
                    bucketAssign.append(random.randint(int(0.6 * i), i))
                else:
                    bucketAssign.append(i)
    else:
        marks = "Bucket dispersal is not above given expected Target Total"
    # Print the list in given order from here
    startMarker = 0
    endMarker = 0
    for i in rangeFromMidPoint:
        endMarker = endMarker + i
        tempList = bucketAssign[startMarker: endMarker]
        finalAssign.append(tempList)
        startMarker = startMarker + i
    for i, j in enumerate(finalAssign):
        print i + 1, " -> ", j
    print "\n"
    print bucketAssign, sum(bucketAssign)  # reduce(lambda x, y: x + y, bucketAssign)

if __name__ == "__main__":
    generateBucketList()
    print "Demo!!!..."

Weather Predictor — in Python

{{This article was originally posted on December 22, 2016. My posts were lost and after being found I am re-posting them.}}

“””This is based on my binge study to learn about climate change and predicting weather at rural community levels using low power devices. Original thought was to try and do community level weather predicting so that locals are aware of the changes that are occuring around them and plan for agriculture better.“”” Hearing much about climate change and weather pattern changes got me thinking if I could make a simple weather prediction system. For hardware I had a raspberry pi that had temperature sensor, humidity sensor and pressure sensor. Then I didn’t have rain guage or wind direction sensor, but I wanted to suppose that if I had all that, could I use the raspberry pi to predict weather parameters at local level. My thought if I could have a lot of cheap weather monitoring stations at community schools in villages, then I could use my system to predict the weather at the station as well as pass on the data to other stations. So other stations could predict using their data and the one sent from the first one. slowly the data would be passed to each other resulting in more accurate predictions. Without bothering about how to pass the data I looked at ways of creating a simple wether prediction system that could easily work off raspberry pi as well as be able to scale up to parallelly be able to predict these parameters when used at aggregator levels. I settled on the windowing technique to do the prediction as described on the paper : http://www.hindawi.com/journals/isrn/2013/156540/ Weather data is available through a CSV file in following format:

datemaxTempminTemprainfallmorningHumidityeveningHumidity
2004-01-0118.82.4096.981.7
2004-01-02191.1096.978.5
2004-01-0318.31.7010086.6
2004-01-0418.31096.782.6
2004-01-0517.81.3096.786.9
2004-01-0619.52094.465.7
2004-01-0720.9209772.5

Explanations : The way the algorithm is implemented right now is as follows: from the latest 7 days weather parameter data a 7 day dataframe is created this dataframe is compared against a running window of 7 days dataframe going through the whole year and then over years. the dataframe and testframe that creates the least delta is taken as similar weather predictions. The delta is added to dataframe and predictions given. My list of readings is below :Books :

  • DETECTING TREND AND OTHER CHANGES IN HYDROLOGICAL DATA Zbigniew W. Kundzewicz and Alice Robson (Editors) WMO/TD-No. 1013 (Geneva, May 2000)
  • Weather and Climate Extremes in a Changing Climate Regions of Focus: North America, Hawaii, Caribbean, and U.S. Pacific Islands U.S. Climate Change Science Program
  • Synthesis and Assessment Product 3.3 June 2008
  • Introduction to Time Series Analysis and Forecasting DOUGLAS C. MONTGOMERY, CHERYL L. JENNINGS, MURAT KULAHCI Wiley Publications 2008
  • An Introductory Study on Time Series Modeling and Forecasting Ratnadip Adhikari R. K. Agrawal
  • Python In Hydrology Sat Kumar Tomer Green Tea Press 2011

Articles :

  • Trend analysis of rainfall and temperature data for India Sharad K. Jain and Vijay Kumar
  • Detecting changes in rainfall pattern and seasonality index vis-`a-vis increasing water scarcity in Maharashtra Pulak Guhathakurta and Elizabeth Saji
  • Trend Detection in the Temporal Pattern of the Precipitation at Different Timescales – Application to a Case Study: the Watershed of the Stream Gauging Station of Torrão Do Alentejo. Ana RAMALHEIRA, Maria Manuela PORTELA, Cristina FAEL
  • Correlation and Regression without Sums of Squares (Kendall’s Tau) Rudy A. Gideon
  • Change detection in hydrological records—a review of the methodology / Revue méthodologique de la détection de changements dans les chroniques hydrologiques Zbigniew W. Kundzewicz & Alice J. Robson
  • Changes in the intra-annual rainfall pattern as an evidence of climate change Carlos Manuel Cotafo Martins
  • Application of Data Mining Techniques in Weather Prediction and Climate Change Studies Folorunsho Olaiya

github repo : https://github.com/pravenj/weatherPredict

Rijal Samabeshi Dewali — Lung

{{This article was originally posted on December 22, 2016. My posts were lost and after being found I am re-posting them.}}

Recently (6th-8th Dec) I visited Lung, Pyuthan, Mid-Western Region of Nepal for the Rijal Dewali. My in-laws are Rijals. They hail from Lung, Pyuthan and still form important figures of the 4 day festival that drew over 200,000 people this year.

Many will say that the puja is 2 days, but I beg to differ based on the oral history that is recited as chants by the Dhamis during the program. They say “Panchami awahan…… Asthami Puja” — that makes it a total of 4 days.

The Dewali is believed to have started by the Rijals of Lung 400 years ago and is a spectacle of events mainly on the 3rd and 4th, starting by the lighting of the traditional lamp at sundown, followed by karnal band, drums and 100s of Dhamis chanting mantras and bells. The Dewali program seems to revolve around bells with all the Dhamis wearing bells on their bodies as well as ringing of the bells continuously throughout the last 2 days.

The 4th day saw the Aalam procession, which for a distance of about 1 kilometers too the best part of 4 hours. Starting off with just a bamboo pole carried by a person, it slowly grew to a volume with all the red and white cloth placed by the devotees. The Aalam procession saw most of the Dhamis singing and dancing and was a spectacle to see.

Once the Aalam arrived at the Gaura, from its starting point of the Kulghar, puja was conducted at the Gaura and then the goat cutting began.

Few points that I noticed:

  • There was very less or no use of tika material like Aabir, sindur, etc.
  • Bells, bells and more bells everywhere
  • Participation of whole communities, gender, caste, etc… It really stood for democracy
  • History and the process of the festival was sung as incantations by the Dhamis
  • Red and white color occupied all significance

My thinking — this puja seems to be somehow dedicated to wind.

Videos:

https://youtu.be/MUnn5TW167I — Start of the Puja (after Sundown) and early morning procession
https://youtu.be/OowaQclQC1k — Procession continues with trance and dance
https://youtu.be/AU0AhR_pSYs — Special dance. Salute to those who can guess what is the dance called and what the person who is wearing the special dress is called
Last video : https://youtu.be/y0VXckXouPg — son is shocked to realize that most of the Dhamis and Pujaris are his Grand-fathers.

Jump Search

{{This article was originally posted on December 22, 2016. My posts were lost and after being found I am re-posting them.}}

Few years ago (I think in 2013), I read this article on Jump Search : http://www.stoimen.com/blog/2011/12/12/computer-algorithms-jump-search/ Since the code presented was in php, got the urge to try it in Python. So wrote the code, forgot about it and discovered it in my hard drive few months ago. So putting it up as an archive. The Jump Search works as in picture below:

Fig.: diagrammatic representation of how jump search works

My Python code is as given below:

import math

def jumpSearch(noToSearch, lis):
    lenOfList = len(lis)
    prev = 0
    counter = 0
    step = int(math.floor(math.sqrt(lenOfList)))
    while lis[step if step < lenOfList else (lenOfList-1)] < noToSearch:
        prev = step
        print "Inside while : ", prev
        step = step + int(math.floor(math.sqrt(lenOfList)))
        counter = counter + 1
        print "Count : ", counter
        if step >= lenOfList:
            break
    while lis[prev] < noToSearch:
        prev = prev + 1
        counter = counter + 1
        print "Count : ", counter
    return prev+1

if __name__ == "__main__":
    lis = range(1,1000)
    print jumpSearch(624, lis)