Mateusz BOGDAN

Logo

My personal site, with a short presentation of who I am, my academic and professional activities and research interests !

Home
Research
Publications
Teachings
Datavisualisation
Code
Miscellanous

Code snippets

-

Some useful tricks and hacks I use frequently, mostly in Python.

Python Basics

All my code snippets, my sort of personal cheet sheat, has been moved to this web site (in French), which I am developing as part of my teaching activities (work in progress). It is intended for students and covers Python fundamentals as well as practical dataframe tips.

Maps and GIS related questions

Recently I’ve ben working with maps in python applications. I mostly use geopandas, dash-leaflet, plotly.scattermapbox, etc.

Distance between two points on a sphere

Compute the distance in km (or meters) between 2 points of the globe defined by their respective lat / lon.

Moving on a sphere

Miscellaneous Functions

Daylength computation

What is the length of the day in hours ?

I needed to compute the length of days for a complete year, and I started using python libraries like pvlib with its module solarposition() or suntime to get the hours of sunset and sunrise. I kept looking for other solutions as I wanted to avoid dependancies, and i found a post on stackoverflow which gives you exactly that.

It is based on a paper by [Forsytthe et al., 1995], named A Model Comparison for Daylength as a Function of Latitude and Day of Year. It uses only the day_of_year and latitude and returns the length of the day in hours (and even have different definitions for the length of a day).

Usefully, one can provide a list of days of the year (or rather an np.array), and the function will return an array of the same length with daylengths :

def day_length(J, L):
    """
    -----------------------------------------------------------------------------------------
    Based upon : "A model comparison for daylength as a function of latitude and day of year"
    Forsythe et al., 1995, Ecological Modelling 80 (1995) 87-95
    -----------------------------------------------------------------------------------------
    Parameters
    ----------
    J: int / list of int / array 
        day of the year.
    L: float 
        latitude (in °)

    Returns
    -------
    Lenght of the day(s) in hours
    
    To account for various definitions of daylength, modify the "p" value accordingly.
    * Sunrise/Sunset is when the center of the sun is even with the horizon 
    p = 0
    * Sunrise/Sunset is when the top of the sun is even with horizon
    p = 0.26667
    * Sunrise/Sunset is when the top of the sun is apparently even with horizon
    p = 0.8333

    """
    p = 0.8333
    phi = np.arcsin(
            0.39795 * ( np.cos( 0.2163108 + 2 * np.arctan( 0.9671396 * np.tan( 0.00860 * (J-186) ) ) ) )
        )
    D = 24 - (24/np.pi)*np.arccos(
              ( np.sin( p*np.pi/180 ) + np.sin( L*np.pi/180 ) * np.sin( phi ) ) / (np.cos(L*np.pi/180) * np.cos( phi ) )
        )

    return D

Web developments

I also contribute to bridging research and practice through web applications and digital tools.

National railway ridership map

Access
Frequ_nat_sncf

Parisian railway network ridership map and analysis

Access Frequ_idf_sncf