Package: pysolardb
pysolardbPython library to access LE2P solar database SolarDBSource code accessible via the github repository:pySolarDBREQUIREMENT: You will need to either use a python version superior or equal to python3.10 or
install a.bz2support package and thelibffipackage on your machine (libbz2-dev and libffi-dev for Ubuntu)InstallationUsing pippipinstallpysolardbSuggestion: You will need a token to allow data access.In the following, we  will use an instance of theSolarDBclass as an example.frompysolardb.SolarDBimportSolarDBsolar=SolarDB(token="YOUR_TOKEN")# if the token is already saved in the environmentsolar=SolarDB(logging_level=20)Note: You will be notified if a newer version of the package exists on Pypi when the SolarDB object is created.You can disable part of the messages by setting thelogging_levelduring the instanciation or by usingsetLoggerLevel:importloggingsolar.setLoggerLevel(logging.WARNING)# using and integersolar.setLoggerLevel(30)Keep in mind that the requests will sometimes result in empty answers. Setting the logger level to a lower level might help identifying such cases.CLass DiagramUtils methods: Register, Login, Status and LogoutNote: You can configure the '~/.bashrc' file in your home directory to allow the library to automatically recover and use your authentication token.In the~/.bashrcfile:exportSolarDBToken=YOUR_AUTHENTICATION_TOKENRegisterIf you do not already possess a token, use theregistermethod to receive a new one by email:solar.register(email="YOUR_EMAIL_ADDRESS")LoginAssuming you did not configure your '~/.bashrc' file, logged out or just received your token, you will need to use theloginmethod before being able to access the solar data:solar.login(token="YOUR_AUTHENTICATION_TOKEN")StatusThestatusmethod verifies if the user is still logged in SolarDB.solar.status()Remark: This method becomes obsolete for logging levels higher than INFO.LogoutThelogoutmethod disables the access to SolarDB data.solar.logout()Recovering the sites, types and sensors listSites recoveryThegetAllSitesmethod returns a list of strings containing all the alias sites present in SolarDB.solar.getAllSites()Types recoveryThegetAllTypesmethod returns a list of strings containing all the data types present in SolarDB.solar.getAllTypes()Sensors recoveryThegetSensorsmethod returns a list of strings containing the sensor IDs extracted from SolarDB. To narrow down the sensors, use the following parameters:sites : list[str] (optional)sensor_types : list[str] (optional)solar.getSensors()# search the diffuse and global irradiance sensors at Le Port Mairiesolar.getSensors(sites=["leportmairie"],sensor_types=["DHI","GHI"])Data collectionNote: The following data recovery methods will return empty dictionaries unless they recieve at least one site, type and/or sensor ID as parameters.Raw data recoveryThegetDatamethod recovers all the data associated to a list of alias sites, types and/or sensor IDs. It takes at least one of the following parameters:sites : list[string]sensor_types : list[string]sensors : list[string]start : string (optional)stop : string (optional)aggrFn : string (optional)aggrEvery : string (optional)# get the global irradiance and air temperature values from Vacaos and Plaine Des Palmistes Parc National taking the average value for each week over the last 2 yearsdata=solar.getData(sites=["plaineparcnational","vacoas"],sensor_types=["GHI"],start="-2y",aggrFn="mean",aggrEvery="1w")The data we just collected can then be used to plot the evolution of the global irradiance:importmatplotlib.pyplotaspltfromdatetimeimportdatetimeasdtalias=["plaineparcnational","vacoas"]dtype=["GHI","TA"]data=solar.getData(sites=alias,sensor_types=dtype,start="-2y",aggrFn="mean",aggrEvery="1w")# extract the global irradiance dates and values for Vacoas from the 'data' dictionarysensors=solar.getSensors(sites=[alias[1]],sensor_types=["GHI"])plt.figure()forsensorinsensors:dates=data[alias[1]][sensor]["dates"]values=data[alias[1]][sensor]["values"]# change the dates to a datetime formatdates=[dt.strptime(date,"%Y-%m-%dT%H:%M:%SZ")fordateindates]# plot the average global irradiance per week for the last 2 yearsplt.plot(dates,values)plt.legend(labels=sensors)plt.show()Get the sensors' active period for specific sitesThegetBoundsmethod returns a dictionary containing the active time period per sensor per site. it takes at least one of the following the parameters:sites : list[string] (optional)sensor_types : list[string] (optional)sensors : list[string] (optional)# get the temporal bounds of each sensor at Saint Louis Lycée Jean Jolyalias=['saintlouisjeanjoly']dtype=['GHI']bounds=solar.getBounds(sensor_types=dtype,sites=alias)prettyBounds=[]forsiteinbounds:forsensorinbounds[site]:prettyBounds.append(sensor+"= start: "+bounds[site][sensor]["start"]\+" | stop: "+bounds[site][sensor]["stop"])print("\n".join(prettyBounds))Dataframe recoveryThegetSiteDataframemethod returns a pandas dataframe containing the data associated to a site for a requested time period using the following parameters:site : stringsensor_types : list[string] (optional)start : string (optional)stop : string (optional)This dataframe can then be converted to a CSV file using the pandas library:# get the pandas dataframe of the data for Amitié over the last weekdf=solar.getSiteDataframe(site="amitie",start="-1w")# print the first rows of our dataframeprint(df.head())# save the dataframe in a CSV filetry:df.to_csv("FILEPATH"+"FILENAME.csv")exceptExceptionase:solar.logger.warning(e)Metadata recoveryRecover the campaigns' metadataThegetCampaignsmethod is used to recover the metadata associated with the different campaigns of the IOS-Net project in a dictionary. You can use the following parameters:id : string (optional)name : string (optional)territory : string (optional)alias : string (optional)solar.getCampaigns()# get the campaigns' metadata for Mauritiussolar.getCampaigns(territory="Mauritius")Extract the instruments' metadataThegetInstrumentsmethod recovers the metadata associated to the instruments used by the IOS-Net project. It takes the following parameters:id : string (optional)name : string (optional)label : string (optional)serial : string (optional)solar.getInstruments()Get the measures' metadataThegetMeasuresmethod recovers the metadata that is associated with the different types of measures. You can use the parameters:id : string (optional)name : string (optional)measure_type : string (optional)nested : boolean (optional)solar.getMeasures()# get the metadata for UV measuressolar.getMeasures(measure_type="UVAB")Recover the models' metadataThegetModelsmethod recovers the metadata associated to the sensor types. You can use these parameters :id : string (optional)name : string (optional)model_type : string (optional)solar.getModels()