Repository: electricitymaps/electricitymaps-contrib

Issue:
California is down due to negative nuclear production
[Kibana](https://kibana.electricitymap.org/app/kibana#/discover/10af54f0-0c4a-11e9-85c1-1d63df8c862c?_g=(refreshInterval:('$$hashKey':'object:232',display:'5%20minutes',pause:!f,section:2,value:300000),time:(from:now-24h,mode:quick,to:now))&_a=(columns:!(message,extra.key,level),filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,index:'96f67170-0c49-11e9-85c1-1d63df8c862c',key:level,negate:!f,params:(query:ERROR,type:phrase),type:phrase,value:ERROR),query:(match:(level:(query:ERROR,type:phrase)))),('$state':(store:appState),meta:(alias:!n,disabled:!f,index:'96f67170-0c49-11e9-85c1-1d63df8c862c',key:extra.key,negate:!f,params:(query:US-CAL-CISO,type:phrase),type:phrase,value:US-CAL-CISO),query:(match:(extra.key:(query:US-CAL-CISO,type:phrase))))),index:'96f67170-0c49-11e9-85c1-1d63df8c862c',interval:auto,query:(language:lucene,query:''),sort:!('@timestamp',desc))):
>invalid point: {'zoneKey': 'US-CAL-CISO', 'production': defaultdict(<class 'float'>, {'solar': 0.0, 'wind': 35.0, 'geothermal': 537.0, 'biomass': 385.0, 'hydro': 916.0, 'coal': 16.0, 'nuclear': -34.0, 'gas': 10688.0, 'unknown': 0.0}), 'storage': defaultdict(<class 'float'>, {'battery': 3.0}), 'source': 'caiso.com', 'datetime': datetime.datetime(2020, 10, 28, 4, 10, tzinfo=tzfile('/usr/share/zoneinfo/US/Pacific')), 'schemaVersion': 3}, reason:US-CAL-CISO: key nuclear has negative value -34.0

Given the small value and that it's zero on the [CAISO web site](http://www.caiso.com/TodaysOutlook/Pages/supply.aspx), this is probably self consumption. Some googling shows that both units of Diablo Canyon, California's sole nuclear power plant, are [down for maintainance](https://keyt.com/news/san-luis-obispo-county/2020/10/15/pge-removes-diablo-canyons-unit-2-for-unexpected-maintenance/).


Discussion:
That sounds right. I can also see some other negative values from the data source:
![image](https://user-images.githubusercontent.com/12124251/97691926-569a3100-1a9f-11eb-8aed-e3de567bf540.png)

Do you or anyone else know how we can account for the self-consumption? Could we estimate the self-consumption and add it to the value?

Resolving patch:
diff --git a/parsers/US_CA.py b/parsers/US_CA.py
--- a/parsers/US_CA.py
+++ b/parsers/US_CA.py
@@ -5,13 +5,14 @@
 import requests
 from bs4 import BeautifulSoup
 from collections import defaultdict
+import logging
 
 FUEL_SOURCE_CSV = 'http://www.caiso.com/outlook/SP/fuelsource.csv'
 
 MX_EXCHANGE_URL = 'http://www.cenace.gob.mx/Paginas/Publicas/Info/DemandaRegional.aspx'
 
 def fetch_production(zone_key='US-CA', session=None, target_datetime=None,
-                     logger=None):
+                     logger: logging.Logger = logging.getLogger(__name__)):
     """Requests the last known production mix (in MW) of a given country
 
     Arguments:
@@ -82,8 +83,8 @@ def fetch_production(zone_key='US-CA', session=None, target_datetime=None,
         for ca_gen_type, mapped_gen_type in production_map.items():
             production = float(csv[ca_gen_type][i])
             
-            if mapped_gen_type == 'solar' and production < 0:
-                logger.warn('Solar production for US_CA was reported as less than 0 and was clamped')
+            if production < 0 and (mapped_gen_type == 'solar' or mapped_gen_type == 'nuclear'):
+                logger.warn(ca_gen_type + ' production for US_CA was reported as less than 0 and was clamped')
                 production = 0.0
             
             # if another mean of production created a value, sum them up


Test patch: