Wolfram Research

Function Repository Resource:

TimeToSunburn

Source Notebook

Compute the exposure time for skin to sunburn based on the UV index

Contributed by: Jason Martinez

ResourceFunction["TimeToSunburn"][uvinfo]

determines the time to sunburn for a range of skin types based on the UV index information in uvinfo.

ResourceFunction["TimeToSunburn"][uvinfo,targetinfo]

determines the time to sunburn based on uvinfo and the skin type and SPF details in targetinfo.

ResourceFunction["TimeToSunburn"][uvinfo,targetinfo,property]

returns the property for targetinfo based on uvinfo.

Details

uvinfo specifies the UV index for the calculations and should be an Association with one of the keys "UVIndex" or "Location". "UVIndex" can be a non-negative number for a static UV index or a non-negative TimeSeries representing the UV index over a period of time. "Location" can be a GeoPosition or Entity and is used to retrieve a recent UV forecast for a location.
With "Location" or TimeSeries input a "StartTime" and "EndTime" can be provided. The time provided should be a DateObject or DateList. If they are not provided, then the start time is assumed to be the current time with an end time encompassing the next day.
targetinfo provides information on the subject of the UV exposure and should be an Association with one or more of the keys "SkinType" or "SPF". "SkinType" can be an integer between 1 or 6 or a "SkinType" Entity. "SPF" is the solar protection factor and must be an integer greater than or equal to 1.
If a "SkinType" is not specified, then an Association of time to sunburn for the six supported skin types will be returned.
If "SPF" is not provided, it is assumed to be equal to 1.
ResourceFunction["TimeToSunburn"] takes the following properties:
"Recommendation" safety recommendations for maximal UV index
"Time" exposure time to sunburn
By default, ResourceFunction["TimeToSunburn"] returns "Time". It will also take the property argument "PropertyAssociation" to return an Association of the properties.
"Recommendation" uses the maximum UV index in a time series or forecast.

Examples

Basic Examples (2) 

Compute the exposure time to sunburn for a UV index of 6 over a range of skin types:

In[1]:=
ResourceFunction["TimeToSunburn"][<|"UVIndex" -> 6|>]
Out[1]=

Find the sunburn time for a specific skin type and SPF 30 sunscreen:

In[2]:=
ResourceFunction[
 "TimeToSunburn"][<|"UVIndex" -> 6|>, <|
  "SkinType" -> Entity["SkinType", "SkinTypeI"], "SPF" -> 30|>]
Out[2]=

Calculate time to sunburn in New York City using UV forecasts:

In[3]:=
ResourceFunction[
 "TimeToSunburn"][<|
  "Location" -> Entity["City", {"NewYork", "NewYork", "UnitedStates"}]|>]
Out[3]=

Scope (4) 

Obtain safety recommendations for UV indexes:

In[4]:=
ResourceFunction[
 "TimeToSunburn"][<|"UVIndex" -> 6|>, "Recommendation"]
Out[4]=

Compute all properties in a property Association:

In[5]:=
ResourceFunction[
 "TimeToSunburn"][<|"UVIndex" -> 10|>, <|"SkinType" -> 2, "SPF" -> 30|>, "PropertyAssociation"]
Out[5]=

Calculate the time to sunburn based on an input time series:

In[6]:=
ts = TemporalData[
  TimeSeries, {{{0., 0., 0., 0., 0., 0.1904296875, 0.576171875, 0.986328125, 1.3818359375, 1.4990234375, 1.4794921875, 0.9912109375, 0.478515625, 0.146484375, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}}, {
TemporalData`DateSpecification[{2021, 1, 23, 0, 0, 0.}, {
      2021, 1, 24, 0, 0, 0.}, {1, "Hour"}]}, 1, {"Continuous", 1}, {
    "Discrete", 1}, 1, {
    ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}, ValueDimensions -> 1}}, True, 12.2];
start = DateObject[ts["FirstDate"], "Hour"] + Quantity[8, "Hours"];
end = DateObject[ts["FirstDate"], "Hour"] + Quantity[12, "Hours"];
DateListPlot[{ts, TimeSeriesWindow[ts, {start, end}]}]
Out[6]=

Compute the time to sunburn starting at the beginning of the time series:

In[7]:=
ResourceFunction[
 "TimeToSunburn"][<|"UVIndex" -> ts, "StartTime" -> ts["FirstTime"]|>]
Out[7]=

Start the exposure time just before peak UV index:

In[8]:=
ResourceFunction[
 "TimeToSunburn"][<|"UVIndex" -> ts, "StartTime" -> start|>]
Out[8]=

Limit exposure to a window near maximal exposure:

In[9]:=
ResourceFunction[
 "TimeToSunburn"][<|"UVIndex" -> ts, "StartTime" -> start, "EndTime" -> end|>]
Out[9]=

Calculate time to sunburn based on forecasts with defined starting and ending times:

In[10]:=
ResourceFunction[
 "TimeToSunburn"][<|
  "Location" -> Entity["City", {"Melbourne", "Victoria", "Australia"}], "StartTime" -> (Now + Quantity[5, "Hours"]), "EndTime" -> (Now + Quantity[8, "Hours"])|>]
Out[10]=

Properties and Relations (1) 

Skin type entities can be used to find many properties of different skin types:

In[11]:=
Entity["SkinType", "SkinTypeIII"]["PropertyAssociation"]
Out[11]=

Possible Issues (3) 

The UV index should be a positive number or a time series with positive values:

In[12]:=
ResourceFunction["TimeToSunburn"][<|"UVIndex" -> -1|>]
Out[12]=
In[13]:=
ts = TimeSeries[{2, 1, 6, 5, -7, 4}, {{1, 2, 5, 10, 12, 15}}];
ResourceFunction["TimeToSunburn"][<|"UVIndex" -> ts|>]
Out[13]=

SPF values must be integers greater than 0:

In[14]:=
ResourceFunction["TimeToSunburn"][<|"UVIndex" -> 6|>, <|"SPF" -> 0|>]
Out[14]=

TimeToSunburn returns Missing["NotApplicable"] when the time to sunburn exceeds the UV exposure time:

In[15]:=
ts = TemporalData[
  TimeSeries, {{{0., 0., 0., 0., 0., 0.1904296875, 0.576171875, 0.986328125, 1.3818359375, 1.4990234375, 1.4794921875, 0.9912109375, 0.478515625, 0.146484375, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.}}, {
TemporalData`DateSpecification[{2021, 1, 23, 0, 0, 0.}, {
      2021, 1, 24, 0, 0, 0.}, {1, "Hour"}]}, 1, {"Continuous", 1}, {
    "Discrete", 1}, 1, {
    ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}, ValueDimensions -> 1}}, True, 12.2];
start = DateObject[ts["FirstDate"], "Hour"] + Quantity[8, "Hours"];
end = DateObject[ts["FirstDate"], "Hour"] + Quantity[11, "Hours"];
In[16]:=
ResourceFunction[
 "TimeToSunburn"][<|"UVIndex" -> ts, "StartTime" -> start|>, <|
  "SkinType" -> Entity["SkinType", "SkinTypeIV"]|>]
Out[16]=
In[17]:=
ResourceFunction[
 "TimeToSunburn"][<|"UVIndex" -> ts, "StartTime" -> start, "EndTime" -> end|>, <|
  "SkinType" -> Entity["SkinType", "SkinTypeIV"]|>]
Out[17]=

Resource History

Related Resources

License Information